C Specification
An image object may be created using the function
// Provided by CL_VERSION_1_2
cl_mem clCreateImage(
cl_context context,
cl_mem_flags flags,
const cl_image_format* image_format,
const cl_image_desc* image_desc,
void* host_ptr,
cl_int* errcode_ret);
| clCreateImage is missing before version 1.2. |
An image object may also be created with additional properties using the function
// Provided by CL_VERSION_3_0
cl_mem clCreateImageWithProperties(
cl_context context,
const cl_mem_properties* properties,
cl_mem_flags flags,
const cl_image_format* image_format,
const cl_image_desc* image_desc,
void* host_ptr,
cl_int* errcode_ret);
| clCreateImageWithProperties is missing before version 3.0. |
Parameters
-
context is a valid OpenCL context used to create the image object.
-
properties is an optional list of properties for the image object and their corresponding values. The list is terminated with the special property
0. If no properties are required, properties may beNULL. OpenCL 3.0 does not define any optional properties for images, but extensions may define properties as described in the https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#external-image-memory-properties-table. -
flags is a bit-field that is used to specify allocation and usage information about the image memory object being created and is described in the supported memory flag values table.
-
image_format is a pointer to a structure that describes format properties of the image to be allocated. A 1D image buffer can be created from a buffer by specifying a buffer object in image_desc→mem_object. If the
cl_khr_extension is supported, a 2D image can be created from a buffer by specifying a buffer object in image_desc→mem_object. If theimage2d_ from_ buffer cl_ext_extension is supported, an image of any type can be created from a buffer by specifying a buffer object in image_desc→mem_object. A 2D image can be created from another 2D image object by specifying an image object in the image_desc→mem_object. Refer to the Image Format Descriptor section for a detailed description of the image format descriptor.image_ from_ buffer -
image_desc is a pointer to a structure that describes type and dimensions of the image to be allocated. Refer to the Image Descriptor section for a detailed description of the image descriptor.
-
host_ptr is a pointer to the image data that may already be allocated by the application. Refer to the table below for a description of how large the buffer that host_ptr points to must be.
-
errcode_ret will return an appropriate error code. If errcode_ret is
NULL, no error code is returned.
Description
The alignment requirements for data stored in image objects are described in Alignment of Application Data Types.
For all image types except CL_MEM_, if the value
specified for flags is 0, the default is used which is CL_MEM_.
For CL_MEM_ image type, or an image created from
another memory object (image or buffer), if the CL_MEM_,
CL_MEM_ or CL_MEM_ values are not specified in flags,
they are inherited from the corresponding memory access qualifiers associated
with mem_object.
The CL_MEM_, CL_MEM_ and CL_MEM_
values cannot be specified in flags but are inherited from the
corresponding memory access qualifiers associated with mem_object.
If CL_MEM_ is specified in the memory access qualifier values
associated with mem_object it does not imply any additional copies when
the image is created from mem_object.
If the CL_MEM_, CL_MEM_ or
CL_MEM_ values are not specified in flags, they are
inherited from the corresponding memory access qualifiers associated with
mem_object.
Mipmap Images
A mipmapped 1D image, 1D image array, 2D image, 2D image array or 3D image is created by specifying num_mip_levels to be a value greater than one in image_desc. The dimensions of a mipmapped image can be a power of two or a non-power of two. Each successively smaller mipmap level is half the size of the previous level, rounded down to the nearest integer.
The following restrictions apply when mipmapped images are created with clCreateImage:
-
CL_MEM_orUSE_ HOST_ PTR CL_MEM_cannot be specified if a mipmapped image is created.COPY_ HOST_ PTR -
The host_ptr argument to clCreateImage must be a
NULLvalue. -
Mip-mapped images cannot be created for
CL_MEM_images, depth images or multi-sampled (i.e. msaa) images.OBJECT_ IMAGE1D_ BUFFER
Image Data in Host Memory
For a 3D image or 2D image array, the image data specified by host_ptr is stored as a linear sequence of adjacent 2D image slices or 2D images respectively. Each 2D image is a linear sequence of adjacent scanlines. Each scanline is a linear sequence of image elements.
For a 2D image, the image data specified by host_ptr is stored as a linear sequence of adjacent scanlines. Each scanline is a linear sequence of image elements.
For a 1D image array, the image data specified by host_ptr is stored as a linear sequence of adjacent 1D images. Each 1D image is stored as a single scanline which is a linear sequence of adjacent elements.
For 1D image or 1D image buffer, the image data specified by host_ptr is stored as a single scanline which is a linear sequence of adjacent elements.
Image elements are stored according to their image format as described in the Image Format Descriptor section.
| Property | Property Value | Description |
|---|---|---|
provided by the |
|
Specifies the list of OpenCL devices (terminated with
|
If CL_MEM_ is not specified as part of properties,
the memory object created by clCreateBufferWithProperties or
clCreateImageWithProperties is by default associated with all devices in the
context.
The properties used to create an image from an external memory handle are
described for the corresponding
extensions.
When an image is created from an external memory handle, the
flags used to specify usage information for the image must not
include CL_MEM_, CL_MEM_, or
CL_MEM_, and the host_ptr argument must be NULL.
When images are created from an external memory handle, implementations may
acquire information about image attributes such as format and layout at the
time of creation.
When such information is acquired at image creation time, it is used for the
lifetime of the image object.
If CL_MEM_ is set in flags, the image created is
an immutable memory object that cannot be modified by the implementation
after creation, and one and only one of the following conditions must be met:
-
Either
CL_MEM_orCOPY_ HOST_ PTR CL_MEM_must be set in flags.USE_ HOST_ PTR -
An external memory handle must be included in properties.
If the image being created is created from another memory object and that memory
object is an immutable memory object, then CL_MEM_ must be set
in flags.
clCreateImage and clCreateImageWithProperties returns a valid non-zero
image object and errcode_ret is set to CL_SUCCESS if the image object
is created successfully.
Otherwise, they return a NULL value with one of the following error values
returned in errcode_ret:
-
CL_INVALID_CONTEXT -
if context is not a valid context
-
-
CL_INVALID_OPERATION -
if there are no devices in context that support images (i.e.
CL_DEVICE_specified in the Device Queries table isIMAGE_ SUPPORT CL_FALSE)
-
-
CL_INVALID_PROPERTY -
if a property name in properties is not a supported property name
-
if the value specified for a supported property name is not valid
-
if the same property name is specified more than once
-
if properties does not include a supported external memory handle and
CL_MEM_is specified as part of propertiesDEVICE_ HANDLE_ LIST_ KHR -
if properties includes more than one external memory handle
-
-
CL_INVALID_DEVICE -
if a device identified by the property
CL_MEM_is not a valid device or is not associated with contextDEVICE_ HANDLE_ LIST_ KHR -
if a device identified by property
CL_MEM_cannot import the requested external memory object typeDEVICE_ HANDLE_ LIST_ KHR -
if
CL_MEM_is not specified as part of properties and one or more devices in context cannot import the requested external memory object typeDEVICE_ HANDLE_ LIST_ KHR
-
-
CL_INVALID_VALUE -
if values specified in flags are not valid as defined in the Memory Flags table
-
if an image is being created from another memory object (buffer or image) under one of the following circumstances:
-
mem_object was created with
CL_MEM_and flags specifiesWRITE_ ONLY CL_MEM_orREAD_ WRITE CL_MEM_READ_ ONLY -
mem_object was created with
CL_MEM_and flags specifiesREAD_ ONLY CL_MEM_orREAD_ WRITE CL_MEM_WRITE_ ONLY -
flags specifies
CL_MEM_orUSE_ HOST_ PTR CL_MEM_orALLOC_ HOST_ PTR CL_MEM_COPY_ HOST_ PTR
-
-
if an image is being created from another memory object (buffer or image) and mem_object was created with
CL_MEM_and flags specifiesHOST_ WRITE_ ONLY CL_MEM_HOST_ READ_ ONLY -
if mem_object was created with
CL_MEM_and flags specifiesHOST_ READ_ ONLY CL_MEM_HOST_ WRITE_ ONLY -
if mem_object was created with
CL_MEM_and_flags_ specifiesHOST_ NO_ ACCESS CL_MEM_orHOST_ READ_ ONLY CL_MEM_HOST_ WRITE_ ONLY -
if properties includes a supported external memory handle and flags includes
CL_MEM_,USE_ HOST_ PTR CL_MEM_, orALLOC_ HOST_ PTR CL_MEM_COPY_ HOST_ PTR -
if
CL_MEM_is set in flags andIMMUTABLE_ EXT CL_MEM_,READ_ WRITE CL_MEM_, orWRITE_ ONLY CL_MEM_is set in flagsHOST_ WRITE_ ONLY -
if
CL_MEM_is not set in flags and mem_object was created withIMMUTABLE_ EXT CL_MEM_IMMUTABLE_ EXT -
if
CL_MEM_is set in flags and none of the following conditions are met:IMMUTABLE_ EXT -
CL_MEM_orCOPY_ HOST_ PTR CL_MEM_is set in flagsUSE_ HOST_ PTR -
the image is being created from another memory object (buffer or image)
-
properties includes an external memory handle
-
-
-
CL_INVALID_IMAGE_ FORMAT_ DESCRIPTOR -
if image_format is
NULL -
if values specified in image_format are not valid
-
if properties includes an AHardwareBuffer external memory handle and image_format is not
NULL -
if an image is created from a buffer and the row pitch, or slice pitch, if the
cl_ext_extension is supported, or base address alignment do not follow the rules described for creating an image from a bufferimage_ from_ buffer
-
-
CL_INVALID_IMAGE_ DESCRIPTOR -
if properties includes an AHardwareBuffer external memory handle and image_desc is not
NULL
-
-
CL_INVALID_IMAGE_ SIZE -
if the image dimensions specified in image_desc are not valid or exceed the maximum image dimensions described in the Device Queries table for all devices in context
-
if the
cl_ext_extension is supported and an image is created from a buffer and the buffer passed in mem_object is too small to be used as a data store for the image, e.g. if its size is smaller than the value returned forimage_ from_ buffer CL_IMAGE_for the parameters used to create the imageREQUIREMENTS_ SIZE_ EXT
-
-
CL_INVALID_HOST_ PTR -
if host_ptr is
NULLandCL_MEM_orUSE_ HOST_ PTR CL_MEM_are set in flagsCOPY_ HOST_ PTR -
if host_ptr is not
NULLbutCL_MEM_orCOPY_ HOST_ PTR CL_MEM_are not set in flagsUSE_ HOST_ PTR -
if properties includes a supported external memory handle and host_ptr is not
NULL
-
-
CL_IMAGE_FORMAT_ NOT_ SUPPORTED -
if there are no devices in context that support image_format
-
if properties includes an AHardwareBuffer external memory handle and the AHardwareBuffer format is not supported
-
-
CL_MEM_OBJECT_ ALLOCATION_ FAILURE -
if there is a failure to allocate memory for the image object
-
-
CL_OUT_OF_ RESOURCES -
if there is a failure to allocate resources required by the OpenCL implementation on the device
-
-
CL_OUT_OF_ HOST_ MEMORY -
if there is a failure to allocate resources required by the OpenCL implementation on the host
-
| Image Type | Size of buffer that host_ptr points to |
|---|---|
missing before version 1.2. |
≥ image_row_pitch |
missing before version 1.2. |
≥ image_row_pitch |
|
≥ image_row_pitch × image_height |
|
≥ image_slice_pitch × image_depth |
missing before version 1.2. |
≥ image_slice_pitch × image_array_size |
missing before version 1.2. |
≥ image_slice_pitch × image_array_size |
Document Notes
For more information, see the OpenCL Specification
This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.