Please explain the question in more details. Probably use some code. What do you mean by invalid number of bits?
Lets try with the following snippet.
data_format.image_channel_order = CL_RGBA;
data_format.image_channel_data_type = CL_UNORM_INT8;
According to the specification OpenCL implementation must maintain the minimum precision specified by the number of bits in image_channel_data_type. If the image format specified by image_channel_data_type and
image_channel_order cannot be supported by the OpenCL implementation, then call to the clCreateImage2/3D() will return a NULL memory object.
I want to check the validity of the values set to the data_format before sending it to the either of the functions clCreateImage2D/clCreateImage3D() so that i do not get a NULL memory object.
How do i do it ?
Still not very sure about the question.
IMHO you need to have 3 things to create a image: cl_image_format, cl_image_desc, and a host side buffer to create image from. Do you mean that you do not have control over host side buffer? It may be in any format or of any size?
Note clCreateImage2D/3D have been deprecated since OpenCL 1.2. Use clCreateImage instead.
How do i check if the user mention INVALID image_channel_order or INVALID image_channel_data_type. The VALID values are mentioned in the table of OpenCL spec 1.1.
Since i am developing on NVIDIA device, i am yet to work with the updated spec unfortunately.
How can we know before whether a particular image_channel_order or data_type is invalid, without checking it against the input?
As per OpenCL recommended way is to catch the error from the API clCreateImage2D/3D:
clCreateImage2D 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 the
following error values returned in errcode_ret:
CL_INVALID_CONTEXT if context is not a valid context.
CL_INVALID_VALUE if values specified in flags are not valid.
CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in image_format are
not valid or if image_format is NULL.
CL_INVALID_IMAGE_SIZE if image_width or image_height are 0 or if they exceed
values specified in CL_DEVICE_IMAGE2D_MAX_WIDTH or
CL_DEVICE_IMAGE2D_MAX_HEIGHT respectively for all devices in context or if values
specified by image_row_pitch do not follow rules described in the argument description
CL_INVALID_HOST_PTR if host_ptr is NULL and CL_MEM_USE_HOST_PTR or
CL_MEM_COPY_HOST_PTR are set in flags or if host_ptr is not NULL but
CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags.
CL_IMAGE_FORMAT_NOT_SUPPORTED if the image_format is not supported.
CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory for
CL_INVALID_OPERATION if there are no devices in context that support images (i.e.
CL_DEVICE_IMAGE_SUPPORT specified in table 4.3 is CL_FALSE).
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