I’ve been working on a library called clUtil that makes OpenCL significantly easier to use. You no longer need handles to kernels, command queues, contexts, etc. as the library handles all of that for you.
Here’s an example of a full clUtil program:
kernel.cl:
__kernel void fill(__global float* array, unsigned int arrayLength, float val)
{
if(get_global_id(0) < arrayLength)
{
array[get_global_id(0)] = val;
}
}
main.cc
#include <clUtil.h>
int main(int argc, char** argv)
{
const char* kernelFiles[] = {“kernel.cl”};
cl_mem buffer;
float array[2000];
unsigned int length = 2000;
float val = 20.0f;
clUtilInitialize(kernelFiles, 1);
clUtilAlloc(sizeof(array), &buffer);
clUtilEnqueueKernel("fill", clUtilGrid(length, 64), buffer, length, val);
clUtilDeviceGet(array, sizeof(array), buffer);
clUtilFree(buffer);
clUtilFinalize();
}
It exploits a bunch of C++0x features to do this, so you’ll need gcc 4.4 or later.
Furthermore, it supports fairly advanced features, like out of order execution, callbacks. I’m starting to add some basic functions, (sort, scan, sum, etc.) that can called within a kernel so you don’t have to write them.