halide/Halide — pull request #312 by dsharletg (2014-05-27 17:06:32+00:00)
Title: Thread safe GPU contexts and improved error handling

This is a very large and long overdue pull request, my apologies on both counts! Due to the size of the pull request, I started making changes in separate branches. Some of the changes you might expect to be in this pull request are in subsequent pull requests that are ready to be submitted once this one is merged.

Here is a summary of the changes and some notes:

- The major change is to modify the GPU context management system (for OpenCL and CUDA, OpenGL is still to come). After much discussion with Andrew, we decided to implement this system of acquire/release, which allows a Halide user to replace the weak acquire/release functions to provide their own context.
- This system also allows for acquire/release to implement a mutex or other synchronization system to ensure Halide access to the context is thread safe. The default implementation uses a simple spin lock (to avoid runtime dependencies on libraries).
- There are a few new tests regarding context lifetime, and a new test that uses the GPU from a parallel for loop (to test thread safety of the GPU context access). Another (static) test for acquire/release is in a branch that I will submit a pull request for soon.
- The CUDA error checking macros have a return in them. This is very stinky code, I have another pull request that is ready to go immediately after this one that will remove these macros, very similar to the way the OpenCL runtime code looks in this pull request.
- This pull request also removes a lot of the GPU API call profiling debug output, another subsequent pull request will add much of this data back in.
- The OpenCL target passes all tests up to multi_way_select. This test doesn't pass for an unrelated reason to these changes (halide_malloc gets generated in the device code, which isn't supported), this is something I plan to look at soon.
- The PTX target passed all tests