Tue
Aug 7

Odd things about OpenCL on a Mac

While working with OpenCL, two things came to light that weren't obvious from the documentation.

The first is that OpenCL kernels are subject to a timeout, which appears to be five seconds.

That's kind of reasonable -- I had wondered how OS X managed to multiplex GPU resources between OpenCL programs and graphics tasks, and it turns out that it doesn't: it simply can't use the GPU while an OpenCL program is running. So it puts a five-second limit on the kernel.

The second thing is not reasonable: when Mac OS X times the kernel out, the user interface doesn't recover. That is, the UI never updates again. The system is totally fine otherwise, as I can connect to it via SSH and shut it down.

This is a nasty bug, as it makes writing long-running kernels quite tedious. Perhaps it's a Mac driver issue (Radeon HD 6750M in my case).

The solution for development is to avoid the problem by testing the kernel on a computer which doesn't have a timeout -- I'm now using a headless Linux box to do it (apparently no connected display = no timeout on Windows, Linux, and OS X).

And now that I know about the timeout, I can work around it (by ensuring the kernel doesn't run for longer than 5s, and continously restarting it with new data).

(I have to say that I haven't tested this thoroughly, just observed that a) a kernel which takes 4s works fine and a kernel which takes slightly longer does not, and b) 5s seems to be a standard timeout for OpenCL kernels)