Geting an CL_INVALID_OPERATION when creating an image2d

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

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_*

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.

I see. I checked it and apparently there is no image support on macs yet.

Thanks