Sunday, April 17, 2011

CUDA - if I could do it all over again.

I've been doing some CUDA work for a client for almost a year now. An image processing library. This was my first experience with GPGPU type stuff, not counting a few miscellaneous shaders over the years. I figured I would jot down some notes that I wish I had when I started.

First, I wouldn't do CUDA again. A year ago I chose it over OpenCL because OCL was even less mature and widely used than it is now. So why have I changed my mind? Mostly because I'm mad at CUDA. I don't actually know OpenCL to be better, I'm just fed up with CUDA nonsense. But anyway, here's what I've learned..

- use the driver API. Visual Studio doesn't integrate well with .cu files. The debugger barely works, no automatic dependencies. There were lots of silly restrictions when I started (no 16-bit floats, all file-scope variables static) which have since been removed. The driver API seems to be less of a moving target.

- ask questions on the forums. the documentation is poorly written and maintained. there is important information only available in the forums.

- use the "CUDA Templates" project on SourceForge, or something similar. The cuda api is inconsistent and just basically poorly designed.

- if running on Windows Vista/7, be aware that the docs are lying to you. Kernel launches are said to be asynchronous, so in theory you should be able to start a kernel and do something with the CPU in the meantime. Not so simple on Vista/7. Commands sent to the GPU are batched by a queue inside the CUDA drivers. You need to jump through hoops to force a flush before the kernel will actually start. Search the forums, as that's the only place this hidden "feature" is documented.


No comments:

Post a Comment