Hi,
I’m trying to convert RGBA grayscale image to single channel buffer. But I have problem with clEnqueueReadBuffer . There is no compilation error but during execution, "Bus error " at execution.
error = clEnqueueReadBuffer(command_queue,
gpu_graybuffer,
CL_TRUE,
0,
sizeof(unsigned char)*SIZE,
&cpu_graybuffer,
0, NULL, NULL);
additional codes :
#define WIDTH 32
#define HEIGHT 32
#define SIZE WIDTH * HEIGHT
...
unsigned char *cpu_graybuffer;
cpu_graybuffer = (unsigned char*)malloc(SIZE);
...
cl_mem gpu_image = clCreateImage2D (context,
CL_MEM_READ_ONLY ,
&format,
width,
height,
rowpitch,
0,
&error);
...
cl_mem gpu_graybuffer = clCreateBuffer ( context,
CL_MEM_WRITE_ONLY,
sizeof(unsigned char)*SIZE,
NULL,
&error);
and maybe where the problem comes, the kernel :
// rgb to grayscale & multi-channel to simple channel
__kernel void rgb_to_gray(__read_only image2d_t image, __global unsigned char *grayscale)
{
const sampler_t sampler=CLK_NORMALIZED_COORDS_FALSE|CLK_ADDRESS_CLAMP|CLK_FILTER_NEAREST;
int x = get_global_id(0); // width
int y = get_global_id(1); // height
uint4 pixel;
//READ PIXEL
pixel = read_imageui(imageIn,sampler,(int2)(x,y));
grayscale[ (HEIGHT-y-1) * HEIGHT + x ] = pixel.x;
// grayscale[0]='a';
}
Maybe, "clEnqueueCopyImageToBuffer" can be another/better solution?
Thanks for sharing your experience.