PDA

View Full Version : QtOpenCL does not support type double?



Caius Aérobus
7th May 2012, 22:05
Here is a simple program that works with floats, but replace float by double everywhere, including in the OpenCL code, and you get this:

indata:
0,000000 1,000000 2,000000 3,000000
1,000000 2,000000 3,000000 4,000000
2,000000 3,000000 4,000000 5,000000
3,000000 4,000000 5,000000 6,000000
outdata:
0,000000 1,000000 2,000000 3,000000
1,000000 2,000000 3,000000 4,000000
0,000000 0,000000 0,000000 0,000000
0,000000 0,000000 0,000000 0,000000

So does it mean that QtOpenCL does not support doubles? It seems that it is not possible to setArg a double.

QCLContext CLcontext;
if (!CLcontext.create()) {
this->Warning("Could not create OpenCL context for the GPU\n");
qApp->quit();
}
QCLVector<double> inbuffer = CLcontext.createVector<double>(kernel_size.width()*kernel_size.height(), QCLMemoryObject::ReadOnly);
QCLVector<double> outbuffer = CLcontext.createVector<double>(kernel_size.width()*kernel_size.height(), QCLMemoryObject::WriteOnly);
int idx=0;
for (int i=0 ; i<kernel_size.width() ; i++)
for (int j=0 ; j<kernel_size.height() ; j++,idx++)
inbuffer[idx] = (double)(i + j);

QCLProgram CLprogram = CLcontext.buildProgramFromSourceFile("./program.cl");
QCLKernel CLkernel = CLprogram.createKernel("program");
CLkernel.setGlobalWorkSize(kernel_size.width()*ker nel_size.height());
CLkernel.setArg(0, outbuffer);
CLkernel.setArg(1, inbuffer);

CLkernel.run();

int id=0;
this->Print("indata:");
for (int j=0 ; j<kernel_size.height() ; j++) {
for (int i=0 ; i<kernel_size.width() ; i++,id++)
this->Print(" %lf\r", inbuffer[id]);
this->Print(" ");
}
id=0;
this->Print("outdata:");
for (int j=0 ; j<kernel_size.height() ; j++) {
for (int i=0 ; i<kernel_size.width() ; i++,id++)
this->Print(" %lf\r", outbuffer[id]);
this->Print(" ");
}


__kernel void program(__global __write_only double *output,
__global __read_only double *input)
{
unsigned int index = get_global_id(0);
output[index] = input[index];
}