clUtil: a library for making OpenCL as painless as CUDA

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.

Hopefully GPL (?)

I’m glad I saw your post when I did. I’m also working on a set of utilities to help get a handle on painful parts of the API, yet doing this while trying to get a tricky bit of numerical code to run in parallel on my GPU.

It would be great to save myself the trouble and just use a set of well designed utilities – not to mention benefit from another’s experience.

Could you post a link to a repository or a site where your code is hosted?

Thanks!

Oh yeah, forgot the link. And yes, it’s GPL’d.

http://code.google.com/p/clutil/