Hi!
I have a strange problem here. I have a very simple kernel, each item writes a fix color(red) to a texture. I create a grid with the size of the image in the host application so i expect that the whole image is red. Using the cpu with the current intel opencl sdk everything works fine.
But using the GPU with a Gefoce GT 330, only half of the pixels in x direction are red. The rest is filled with a random color.
ipf::parser::cl::CLContext context;
context.create(CL_DEVICE_TYPE_GPU);
if(!context.createCommandQueue(CL_QUEUE_PROFILING_ENABLE))
std::cout<<"CommandQueue Failed"<<std::endl;
std::string path =
ipf::util::config.get<std::string>("ipf.shader.path") + "/";
path += "test.cl";
ipf::parser::cl::CLProgram prog = context.createProgram(path);
if(!prog.build())
std::cout<<prog.log()<<std::endl;
int width = 392;
int height = 392;
ipf::parser::cl::CLKernel k = prog.createKernel("writeimage");
QImage result(QSize(width,height),QImage::Format_ARGB32);
cl_image_format format;
format.image_channel_order = CL_BGRA;
format.image_channel_data_type = CL_UNORM_INT8;
cl_int error = 0;
cl_mem dest = clCreateImage2D(context.contextID(),
CL_MEM_WRITE_ONLY,
&format,
width,height,0,NULL,&error);
if(error != CL_SUCCESS)
std::cout<<"Error: "<<ipf::parser::cl::CLContext::errorName(error)
<<std::endl;
error = clSetKernelArg(k.kernelID(),0,sizeof(cl_mem),&dest);
if(error != CL_SUCCESS)
std::cout<<"Error: "<<ipf::parser::cl::CLContext::errorName(error)
<<std::endl;
size_t local[2] =
{
8,8
};
size_t global[2] =
{
width,height
};
error = clEnqueueNDRangeKernel(
context.commandQueue().commandQueueID(), k.kernelID(), 2,
0,global,local,0,0,NULL);
if(error != CL_SUCCESS)
std::cerr<<"CLKernel::run(): "<<
ipf::parser::cl::CLContext::errorName(error)<<std::endl;
size_t origin[] =
{
0,0,0
};
size_t region[] =
{
width,height,1
};
error = clEnqueueReadImage(context.commandQueue().commandQueueID(),
dest,CL_TRUE,
origin,
region,
width*4,
0,result.bits(),0,NULL,NULL);
if(error != CL_SUCCESS)
std::cerr<<"Error: "<<
ipf::parser::cl::CLContext::errorName(error)<<std::endl;
result.save("geht.png");
The context and queue creation is wrappend with some c++ code. I use qt for saving the image. Im quite sure the image format is setup correctly because i took it from the QtOpenCL lib. With this lib btw my kernel works correctly so it should not be a driver bug.
Here is the kernel:
__kernel void writeimage(__write_only image2d_t dest)
{
int2 pos = (int2)(get_global_id(0),get_global_id(1));
float4 pixel = (float4)(0,0,1,1);
//pixel=read_imagef(src,sampler,pos);
write_imagef(dest,pos,clamp(pixel,0.0f,1.0f));
}
The result using the code above, is an image with the size of 392x392 pixels. But only 196x392 from the leftside is red, the rest is filled with (i guess) random color. Anybody sees the problem? Im staring at the code for a couple of hours but i dont find the mistake.
Is there something from with the EnqueueNDRange call?