PDA

View Full Version : Geting an CL_INVALID_OPERATION when creating an image2d



ssyed
05-10-2011, 04:24 PM
I'm running openCL on MAC OSX (snow leopard 10.6)
I am running the following code

cl_image_format imgType;
imgType.image_channel_order = CL_RGBA;
imgType.image_channel_data_type = CL_FLOAT;
cl_mem im_A = clCreateImage2D(clGPUContext, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, &imgType, WA/4, HA/4, sizeof(float)*WA, h_A, &errcode);

(WA,HA are the widths and heights of the image (both are divisible by 4) and h_A is a WA*HA block of floats that were malloc'd

Any ideas what is going on?
Also is it generally better to use CL_MEM_COPY_HOST_PTR than to use CL_USE_HOST_PTR for speed?

Thanks

flavius
05-11-2011, 01:06 AM
Have you checked that your device supports images and your image fits into the HW limitations? See clGetDeviceInfo with CL_DEVICE_IMAGE_SUPPORT and CL_DEVICE_IMAGE2D_MAX_*

david.garcia
05-11-2011, 05:29 AM
What flavius said, plus check that RGBA float32 image formats are supported using clGetSupportedImageFormats().


Also is it generally better to use CL_MEM_COPY_HOST_PTR than to use CL_USE_HOST_PTR for speed?

CL_USE_HOST_PTR should be faster in general. However, not in every case the implementation will be able to take your host pointer and map it to the device's address space, which in turn means that there will be copies back and forth.

For best performance across the board I recommend creating images with CL_MEM_ALLOC_HOST_PTR, then use clEnqueueMapImage() to get a pointer to the image data and then overwrite it with whatever contents you want. It takes a few more lines of code but it makes almost sure that the CPU and GPU will truly be sharing data and avoiding copies.

ssyed
05-12-2011, 12:43 AM
I see. I checked it and apparently there is no image support on macs yet.

Thanks