clBuildProgram fails when write_imageui is used

Hi!

I’m trying to build a simple kernel, but it fails when I use write_imageui. The kernel should just copy an image to another. I know that there isn’t probably any sense in making such kernel, but I’m just trying to learn the language. Anyway, here is the kernel:

const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE |
CLK_ADDRESS_CLAMP_TO_EDGE |
CLK_FILTER_NEAREST;

__kernel void copy(image2d_t src, image2d_t dst)
{
int2 pos;
uint4 input;
int x = get_global_id(0);
int y = get_global_id(1);

pos.x = x;
pos.y = y;

input = read_imageui(src, sampler, pos);
write_imageui(dst, pos, input);

}

If I put it like above, clBuildProgram gives me error code -42 (btw how can I determine what error that is?). But if I comment the last line out it compiles just fine. Any idea what is going on?

P.S. I’m using Nvidia SDK and my GPU is GF9500GT.

-hnyk

I believe you will need to put “write_only” before your destination image in your kernel definition. By default images are “read_only”.

You can look up what -42 is in the opencl header file.

You should also try to get back the program build log by calling clGetProgramBuildInfo. That should include a detailed error string as to why the program failed to build.

Thanks. The “__write_only” specifier did the trick.