>> Monday, May 28, 2012

Combine shared data into as few buffers as possible and combine them into an array or vector.

It takes time for the CPU to coordinate the GPU's OpenCL/OpenGL processing, so it's good to keep this to a minimum. More specifically, you want to call clEnqueueAcquireGLObjects as few times as possible. This function can synchronize multiple buffers with a single call, but only if they're placed in contiguous memory locations (such as inside an array or a vector).

For example, the following code creates and synchronizes two distinct buffers:

The second example is simpler because it only calls clEnqueueAcquireGLObjects once. This reduces the synchronization time required for OpenCL-OpenGL interoperability.

Place OpenCL and OpenGL function calls in separate classes.

My C++/Qt project has become very complex, and if I placed all the OpenCL/OpenGL function calls in the same class, it would be impossible to read. So, in addition to my GLWidget class, I created two helper classes: GLUtils and CLUtils. The first contains static functions related to OpenGL and the second contains static functions related to OpenCL.

These classes are friends of the GLWidget class, which means they can access its private resources. This separation has made my code easier to read and debug.

On an unrelated note, the AMD Fusion Developer Summit is two weeks away, but the agenda doesn't say anything about the session topics. Does AMD think people are going to attend without knowing what's going to be discussed? It's like advertising a rock concert without telling people who's playing.
Read more...

>> Monday, May 14, 2012

I downloaded and recompiled the Qt source code, installed the Qt Add-In for Visual Studio 2010, and created a completely new project in Visual Studio. Now that I've stopped using Qt Creator, OpenCL-OpenGL interoperability works in Windows 7.

So I take back what I wrote earlier. Qt-OpenCL-OpenGL applications can work on Windows, but you have to be careful.

>> Saturday, May 5, 2012

My OpenCL-OpenGL-Qt application works wonderfully in Linux, but AFDS wants presentations given using Windows computers. So I've spent a great deal of time trying to build my application on Windows 7 using Qt Creator. This means dealing with GLEW, DLL incompatibilities, and spaces in directory names like C:\Program Files. Yuck.

I finally got the application to compile, but the OpenCL-OpenGL interoperability doesn't work. The OpenGL component works and the OpenCL component works, but they're not talking to one another. I invoked clGetGLContextInfoKHR, which verified that my GPU is capable of OpenCL-OpenGL interoperability. I've tried every coding trick I can think of, but it's still not working.

As a last resort, I decided to try Qt's QCLContextGL class, which is supposed to make it easy to combine OpenCL and OpenGL. This is part of the QtOpenCL module, whose build instructions say that it should be compiled with the Qt source code instead of the Qt SDK. I downloaded the Qt source code and tried to build it, but the zlib.dll library was missing. I downloaded the zlib source code, compiled it with Visual Studio, and placed the *.lib/*.dll/*.h files in the right folders. But I'd misread the error. Qt Creator wants zdll.lib, not zlib.dll. Ha. Silly me.

After fixing all the problems with the source code compilation, I attempted to compile the QtOpenCL module. Qt Creator gave me two errors, and they're both described here. There are no solutions at this time, so I'm going to give up on Windows and stick to Linux. If anyone asks whether OpenGL-OpenCL interoperability works on Windows, I'll tell them to use GLUT instead of Qt. It hurts to type that.

Tomorrow, the wonderful BBC series Sherlock will be available for American audiences. I can't wait. I may be a moron, but I can still live vicariously through Sherlock Holmes.