Improve error handling for CUDA backend.

In particular: actually return error codes, and do so even when not in debug
mode. See #213.