Improve error handling for CUDA backend.

In particular: actually return error codes, and do so even when not in debug
mode. See #213.
Merge remote-tracking branch 'upstream/cuda-error-handling'