OpenCL Image reading not working on dynamically allocated array -
i'm writing opencl program applies convolution matrix on image. works fine if store pixel on array image[height*width][4]
(line 65,commented) (sorry, speak spanish, , code in spanish). but, since images i'm working large, need allocate memory dynamically. execute code, , segmentation fault
error.
after poor man's debugging, found out problem arises after executing kernel , reading output image host, storing data dynamically allocated array. can't access data of array without getting error.
i think problem way clenqueuereadimage
function (line 316) writes image data image
array. array allocated dynamically, has no predefined "structure".
but need solution, , can't find it, nor on own or on internet.
the c program , opencl kernel here: https://gist.github.com/migagh/6dd0fddfa09f5aabe7eb0c2934e58cbe
don't use pointers pointers (unsigned char**). use regular pointer instead:
unsigned char* image = (unsigned char*)malloc(sizeof(unsigned char)*ancho*alto*4);
then in loop:
for(i=0; i<ancho*alto; i++){ unsigned char* pixel = (unsigned char*)malloc(sizeof(unsigned char)*4); fread (pixel, 4, 1, bmp_entrada); image[i*4] = pixel[0]; image[i*4+1] = pixel[1]; image[i*4+2] = pixel[2]; image[i*4+3] = pixel[3]; free(pixel); }
Comments
Post a Comment