Your kernel code is actually fine (although the code you've posted sets every pixel to white, so it would be hard to tell if it was working!). The issue is in the way you are creating the image. When you specify shape=(100,100,4)
in your cl.Image
constructor, you are actually asking for a 3D image.
The simplest way to get your example code to produce something useful is to modify these lines:
f = cl.ImageFormat(cl.channel_order.R, cl.channel_type.UNSIGNED_INT8)
....
dst_image = cl.Image(ctx, mf.WRITE_ONLY , f, shape=(100,100,4))
...
cl.enqueue_copy(queue, postimage, dst_image,
origin=(0, 0, 0),
region=(100,100,4))
to
f = cl.ImageFormat(cl.channel_order.RGBA, cl.channel_type.UNSIGNED_INT8)
....
dst_image = cl.Image(ctx, mf.WRITE_ONLY , f, shape=(100,100))
....
cl.enqueue_copy(queue, postimage, dst_image,
origin=(0, 0),
region=(100,100))
Here I've changed to image format to RGBA, which matches what the matplotlib
image display function appears to expect (I'm not familiar with that library, so it might be that you can get it to display single channel images too). I've also modified the lines that create the image and copy it back to the host to be 2D, rather than 3D.
Now, if you change your kernel to write this data to the image:
write_imagef(dst, (int2)(column, row), (float4)(1.0f, 0.0f, 0.0f, 1.0f));
you should get a nice red output image!