CLCREATEIMAGE(3clc)
π CLCREATEIMAGE(3clc) β OpenCL Manual, section 3clc π
okay so bestie, welcome to the OpenCL Manual, section 3clc. this page is literally about clCreateImage. no cap. let's get into it. π«Ά
πΈ NAME πΈ
clCreateImage β Creates a 1D image, 1D image buffer, 1D image array, 2D image, 2D image array or 3D image object. β¨
β¨ SYNOPSIS β¨
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);
π PARAMETERS π
contextβ A valid OpenCL context on which the image object is to be created. πflagsβ A bit-field that is used to specify allocation and usage information about the image memory object being created and is described in the table below. π
For all image types except CL_MEM_OBJECT_IMAGE1D_BUFFER, if value specified for flags is 0, the default is used which is CL_MEM_READ_WRITE. π
β¨ to be continuedβ¦ β¨
Okay so β quick vibe check on that first bit before we get into the flag buffet, because CL_MEM_OBJECT_IMAGE1D_BUFFER plays by its own lil rules. π
For CL_MEM_OBJECT_IMAGE1D_BUFFER image type: if you don't pass CL_MEM_READ_WRITE, CL_MEM_READ_ONLY or CL_MEM_WRITE_ONLY in flags, bestie, they get inherited from the corresponding memory access qualifiers attached to buffer. The CL_MEM_USE_HOST_PTR, CL_MEM_ALLOC_HOST_PTR and CL_MEM_COPY_HOST_PTR values cannot be specified in flags at all β but they're inherited from the corresponding memory access qualifiers associated with buffer. And if CL_MEM_COPY_HOST_PTR shows up in the memory access qualifier values for buffer, it does not imply any additional copies when the sub-buffer is created from buffer. Same energy for CL_MEM_HOST_WRITE_ONLY, CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS β if you leave them out of flags, they get inherited from the corresponding memory access qualifiers associated with buffer. π«Ά
β¨ the cl_mem_flags lineup (the main character list) β¨
CL_MEM_READ_WRITEβ this flag says the memory object will be read and written by a kernel. This is the default, so if you're not specifying anything, congrats, you're already here. πCL_MEM_WRITE_ONLYβ this flag says the memory object will be written but not read by a kernel.
π¨ Reading from a buffer or image object created with CL_MEM_WRITE_ONLY inside a kernel is undefined. Not "maybe weird", not "probably fine" β undefined. Do not do it.
CL_MEM_READ_WRITE and CL_MEM_WRITE_ONLY are mutually exclusive. Pick one, queen.
CL_MEM_READ_ONLYβ this flag says the memory object is a read-only memory object when used inside a kernel.
π¨ Writing to a buffer or image object created with CL_MEM_READ_ONLY inside a kernel is undefined. Same deal as above, same energy.
CL_MEM_READ_WRITE or CL_MEM_WRITE_ONLY and CL_MEM_READ_ONLY are mutually exclusive.
CL_MEM_USE_HOST_PTRβ this flag is valid only ifhost_ptris notNULL. If you specify it, it means the application wants the OpenCL implementation to use the memory referenced byhost_ptras the storage bits for the memory object.
OpenCL implementations are allowed to cache the buffer contents pointed to by host_ptr in device memory. That cached copy can be used when kernels are executed on a device. π§ β¨
π The result of OpenCL commands that operate on multiple buffer objects created with the same host_ptr or overlapping host regions is considered to be undefined. Don't be messy.
Refer to the dataTypes(3clc) for host_ptr for memory objects (buffer and images) created using CL_MEM_USE_HOST_PTR.
CL_MEM_ALLOC_HOST_PTRβ this flag says the application wants the OpenCL implementation to allocate memory from host accessible memory.
CL_MEM_ALLOC_HOST_PTR and CL_MEM_USE_HOST_PTR are mutually exclusive. βοΈ
CL_MEM_COPY_HOST_PTRβ this flag is valid only ifhost_ptris notNULL. If specified, it means the application wants the OpenCL implementation to allocate memory for the memory object and copy the data from the memory referenced byhost_ptr.
CL_MEM_COPY_HOST_PTR and CL_MEM_USE_HOST_PTR are mutually exclusive.
CL_MEM_COPY_HOST_PTR can be used with CL_MEM_ALLOC_HOST_PTR to initialize the contents of the cl_mem object allocated using host-accessible (e.g. PCIe) memory. π
CL_MEM_HOST_WRITE_ONLYβ this flag says the host will only write to the memory object (using OpenCL APIs that enqueue a write or a map for write). This can be used to optimize write access from the host β like, for example, enabling write combined allocations for memory objects for devices that communicate with the host over a system bus such as PCIe. π₯CL_MEM_HOST_READ_ONLYβ this flag says the host will only read the memory object (using OpenCL APIs that enqueue a read or a map for read).
CL_MEM_HOST_WRITE_ONLY and CL_MEM_HOST_READ_ONLY are mutually exclusive.
CL_MEM_HOST_NO_ACCESSβ this flag says the host will not read or write the memory object.
CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_READ_ONLY and CL_MEM_HOST_NO_ACCESS are
picking up right where that table left offβ¦ the final row just says mutually exclusive. which is the polite way of saying bestie, those two? you can't run both. pick one. π
image_formatβ a pointer to a struct describing the format properties of the image you're about to allocate. the full tea on the image format descriptor lives incl_image_format(3clc). πimage_descβ a pointer to a struct describing the type and dimensions of the image to be allocated. more deets over atimageDescriptor(3clc). β¨host_ptrβ a pointer to the image data that may already be allocated by the application. the table below tells you exactly how big the buffer thathost_ptrpoints to has to be. π«ΆCL_MEM_OBJECT_IMAGE1Dβ size of buffer must be β₯image_row_pitchCL_MEM_OBJECT_IMAGE1D_BUFFERβ size of buffer must be β₯image_row_pitchCL_MEM_OBJECT_IMAGE2Dβ size of buffer must be β₯image_row_pitch * image_heightCL_MEM_OBJECT_IMAGE3Dβ size of buffer must be β₯image_slice_pitch * image_depthCL_MEM_OBJECT_IMAGE1D_ARRAYβ size of buffer must be β₯image_slice_pitch * image_array_sizeCL_MEM_OBJECT_IMAGE2D_ARRAYβ size of buffer must be β₯image_slice_pitch * image_array_size
okay so how does the data actually sit in there? π¦
for a 3D image or a 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. layers on layers on layers, iconic honestly. π
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. simple. clean. slay. πΈ
for a 1D image array, the image data specified by host_ptr is stored as a linear sequence of adjacent 1D images respectively. each 1D image or 1D image buffer is a single scanline which is a linear sequence of adjacent elements. π
errcode_retβ will return an appropriate error code. and iferrcode_retisNULL? then no error code is returned. no receipts, no problem. π
π¨ ERRORS π¨
clCreateImage returns a valid non-zero image object and errcode_ret is set to CL_SUCCESS if the image object is created successfully. otherwise? it returns a NULL value with one of these error values handed back in errcode_ret: π
CL_INVALID_CONTEXTifcontextis not a valid context.CL_INVALID_VALUEif values specified inflagsare not valid.CL_INVALID_IMAGE_FORMAT_DESCRIPTORif values specified inimage_formatare not valid or ifimage_formatisNULL.CL_INVALID_IMAGE_DESCRIPTORif values specified inimage_descare not valid or ifimage_descisNULL.CL_INVALID_IMAGE_SIZEif image dimensions specified inimage_descexceed the minimum maximum image dimensions described in the table of allowed values for param_name forclGetDeviceInfo(3clc)for all devices incontext.CL_INVALID_HOST_PTRifhost_ptrinimage_descisNULLandCL_MEM_USE_HOST_PTRorCL_MEM_COPY_HOST_PTRare set inflagsor ifhost_ptris notNULLbutCL_MEM_COPY_HOST_PTRorCL_MEM_USE_HOST_PTRare not set inflags.CL_INVALID_VALUEif a 1D image buffer is being created and the buffer object was created withCL_MEM_WRITE_ONLYandflagsspecifiesCL_MEM_READ_WRITEorCL_MEM_READ_ONLY, or if the buffer object was created withCL_MEM_READ_ONLYandflagsspecifiesCL_MEM_READ_WRITEorCL_MEM_WRITE_ONLY, or ifflagsspecifiesCL_MEM_USE_HOST_PTRorCL_MEM_ALLOC_HOST_PTRorCL_MEM_COPY_HOST_PTR.CL_INVALID_VALUEif a 1D image buffer is being created and the buffer object was created withCL_MEM_HOST_WRITE_ONLYandflagsspecifiesCL_MEM_HOST_READ_ONLY, or if the buffer object was created withCL_MEM_HOST_READ_ONLYandflagsspecifiesCL_MEM_HOST_WRITE_ONLY, or if the buffer object was created withCL_MEM_HOST_NO_ACCESSandflagsspecifiesCL_MEM_HOST_READ_ONLYorCL_MEM_HOST_WRITE_ONLY.CL_IMAGE_FORMAT_NOT_SUPPORTEDif theimage_formatis not supported.CL_MEM_OBJECT_ALLOCATION_FAILUREif there is a failure to allocate memory for image object.CL_INVALID_OPERATIONif there are no devices incontextthat support images (i.e.CL_DEVICE_IMAGE_SUPPORT(specified in the table of OpenCL Device Queries forclGetDeviceInfo(3clc)) isCL_FALSE).CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device.CL_OUT_OF_HOST_MEMORYif there is a failure to allocate resources required by the OpenCL implementation on the host.
heads up bestie: that CL_INVALID_VALUE for 1D image buffers is a whole vibe check on its own β read it twice, your flags and your buffer's flags have to actually agree. π
π SPECIFICATION π
OpenCL Specification[1]
π SEE ALSO π
imageDescriptor(3clc), cl_image_format(3clc), classDiagram(3clc)
π AUTHORS π
The Khronos Group
π COPYRIGHT π
Copyright Β© 2007-2011 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the following conditions: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Materials.
Wait, let me say that again in the exact words, no cap:
Copyright Β© 2007-2011 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.
okay ignore my little detour above β the version right under the heading is the real one, that's the exact text, no edits. π
π NOTES π
- OpenCL Specification page 90, section 5.3.1 - Creating Image Objects
and that's the whole page bestie!! π«Ά this one came from The Khronos Group, dated 01/14/2021, and the page itself is CLCREATEIMAGE(3clc). go forth and allocate your images correctly, you've absolutely got this. β¨π
π¦ where this page comes from
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms