empol

No output from kernel

Discussion created by empol on May 11, 2010
Latest reply on May 14, 2010 by empol

I made some GUI app, which takes a picture (BMP) and just copies it over kernel. Works fine, but just only for some resolutions. it works for 600x450 but doesn't for 800x600.

Second problem: when i modified kernel to modify image it also has no output. Small modification - adding some value (under 255) for every color of pixel. Tested on black image (every pixel is RGB(0,0,0)).

So it works only for specific resolutions and only copy data.

 

With debugger i found that there is notrhing in the output buffer.

There is allocated pixelarray (array of uchar4) for output data, but after clEnqueueReadBuffer pixelarray length is 0.

I think it's kernel problem, but can't find what's wrong. The same situation with CPU and GPU.

kernel before modification (works for some resolutions): __kernel void hello(__global uchar4 * in, __global uchar4 * out) { unsigned int sizeX = get_global_size(0); unsigned int sizey = get_global_size(1); unsigned int x = get_global_id(0); unsigned int y = get_global_id(1); uint Index = y + x * sizey; out[Index] = in[Index]; } after modification (doesn't work at all): __kernel void hello(__global uchar4 * in, __global uchar4 * out) { unsigned int sizeX = get_global_size(0); unsigned int sizey = get_global_size(1); unsigned int x = get_global_id(0); unsigned int y = get_global_id(1); uchar4 mod = (uchar4)(50,50,80,0); uint Index = y + x * sizey; out[Index] = in[Index] + mod; } Functions to copy buffers an run kernel: private: void writeBuffer(cl_command_queue commandQueue, cl_mem inCL, System::Drawing::Image^ image) { cl_int err; array<unsigned char>^ chararray = ConvertImageToCharArray(image); ImgBuf^ imgbuf = CharArrayToPixelArray(chararray, image->Width, image->Height); pixelArray^ pa = imgbuf->pa; err = clEnqueueWriteBuffer( commandQueue, inCL, 1, 0, sizeof(pa), &pa, 0, 0, 0); checkErr(err, "clEnqueueWriteBuffer failed"); } private: System::Drawing::Image^ readBuffer(cl_command_queue commandQueue, cl_mem outCL) { cl_event events; cl_int err; pixelArray^ parr = gcnew pixelArray(imgi->Width * imgi->Height); System::Drawing::Image^ image; array<unsigned char>^ chararray; err = clEnqueueReadBuffer( commandQueue, outCL, 1, 0, sizeof(parr), &parr, 0, 0, &events); checkErr(err, "clEnqueueReadBuffer failed"); err = clWaitForEvents(1, &events); checkErr(err, "clWaitForEvents failed"); chararray = PixelArrayToCharArray(parr, lg); image = ConvertCharArrayToImage(chararray); return image; } private: void runKernel(cl_command_queue commandQueue, cl_kernel kernel) { cl_int err; cl_event events; cl_int width = imgi->Width; cl_int height = imgi->Height; size_t global[] = {width, height}; size_t local[] = {1,1}; err = clEnqueueNDRangeKernel( commandQueue, kernel, 2, NULL, global, local, 0, NULL, &events); checkErr(err, "clEnqueueNDRangeKernel failed"); err = clWaitForEvents(1, &events); checkErr(err, "clWaitForEvents failed"); }

Outcomes