clRead/Write Image Problem

I’m new to this forum, because I recently started to work with openCL.
I got an strange Error, caused by an wrong Image Buffer. But I don’t know what’s wrong with the initialization of the Image. Here’s the smallest piece of Code which shows the problem:

// 1-Dimensional Image RGBA with the following values --> just 256 Greyvalues from 
// black to white in RGBA 
unsigned char* transferFunc = new unsigned char[4*256];
for(int i=0;i<256;i++)
	// R
	transferFunc[i] = i;
	// G 
	transferFunc[i+1] = i;
	// B
	transferFunc[i+2] = i;
	// A
	transferFunc[i+3] = i;

cl_image_format transferFunc_format;
transferFunc_format.image_channel_order = CL_RGBA;
transferFunc_format.image_channel_data_type = CL_UNORM_INT8;

size_t origin[3] = {0,0,0};
size_t region[3] = {256,1,1};
d_transferFuncArray = clCreateImage2D(cxGPUContext, CL_MEM_READ_ONLY , &transferFunc_format, 256,1, 0, NULL, &ciErrNum);
ciErrNum |= clEnqueueWriteImage(cqCommandQueue,d_transferFuncArray,CL_TRUE,origin,region,256*4*sizeof(unsigned char),0,transferFunc,0,NULL,NULL);
ciErrNum |= clSetKernelArg(ckKernel, 14, sizeof(d_volumeArray), (void *) &d_volumeArray);
ciErrNum |= clSetKernelArg(ckKernel, 15, sizeof(d_transferFuncArray), (void *) &d_transferFuncArray);


unsigned char* buf = (unsigned char*) malloc(256*4*sizeof(unsigned char));
ciErrNum |= clEnqueueReadImage(cqCommandQueue,d_transferFuncArray,CL_TRUE,origin,region,0,0,buf,0,0,0);
for(int c = 0;c<4;c++)
	for(int i=0;i<256;i++)
		std::cout << i << "-->" << buf[(i*4) + c] << std::endl;

So I’m just creating an 2-Dimensional Image with the width 256 and the height 1. I’m writing the image to device memory and later reading it from there. But the values differ, although the image is set CL_MEM_READ_ONLY. So there has to be a fault in reading or writing, but I don’t get it for days. The values after the reading in every channel seem to be fine until the 64th element of every channel (RGBA). If I’m trying this with a Image that has only one channel for example CL_R all values are correct.

I don’t have any clue, what causes the problem. I’ve tried various settings, but allways got the same error.


Problem solved. I made an mistake by the initialization of the image so there was actually no mistake in the openCL code.

Sorry I didn’t find the edit button. That’s why I replied.