Description

Image objects specified as arguments to a kernel can be declared to be read-only or write-only.

For OpenCL C 2.0, or with the __opencl_c_read_write_images feature, image objects specified as arguments to a kernel can additionally be declared to be read-write.

The __read_only (or read_only) access qualifier specifies that the image object is only being read by a kernel or function. The __write_only (or write_only) access qualifier specifies that the image object is only being written to by a kernel or function. The __read_write (or read_write) access qualifier specifies that the image object may be both read from or written to by a kernel or function.

The default access qualifier is read_only, if no access qualifier is declared.

In the following example

kernel void
foo (read_only image2d_t imageA,
     write_only image2d_t imageB)
{
    ...
}

imageA is a read-only 2D image object, and image is a write-only 2D image object.

The sampler-less read image and write image built-ins can be used with image declared with the __read_write (or read_write) qualifier. Calls to built-ins that read from an image using a sampler for images declared with the __read_write (or read_write) qualifier will be a compilation error.

Pipe objects specified as arguments to a kernel also use these access qualifiers. See the detailed description on how these access qualifiers can be used with pipes.

The __read_only, __write_only, __read_write, read_only, write_only and read_write names are reserved for use as access qualifiers and shall not be used otherwise.

See Also

Document Notes

For more information, see the OpenCL C Specification

This page is extracted from the OpenCL C Specification. Fixes and changes should be made to the Specification, not directly.

Copyright 2014-2023 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0