Utility functions used as helpers in other ClojureCUDA namespaces. The user of the ClojureCUDA library would probably not need to use any of the functions defined here.


(error err-code details)(error err-code)

Converts an CUDA error code to an ExceptionInfo with richer, user-friendly information.

Accepts a long err-code that should be one of the codes defined in CUDA standard, and an optional details argument that could be anything that you think is informative.

Also see the discussion about


(error 0) => an ExceptionInfo instance
(error -5 {:comment "Why here?""}) => an ExceptionInfo instance



(maybe form)

Evaluates form in try/catch block; if a CUDA-related exception is caught, substitutes the result with the ExceptionInfo object.



(with-check err-code form)

Evaluates form if err-code is not zero (CUDA_SUCCESS), otherwise throws an appropriate ExceptionInfo with decoded informative details. It helps fith JCuda methods that return error codes directly, while returning computation results through side-effects in arguments.


(with-check (some-jcuda-call-that-returns-error-code) result)



(with-check-arr err-code form)

Evaluates form if the integer in the err-code primitive int array is 0, Otherwise throws an exception corresponding to the error code. Similar to with-check, but with the error code being held in an array instead of being a primitive number. It helps with JCuda methods that return results directly, and signal errors through side-effects in a primitive array argument.

(let [err (int-array 1)
      res (some-jcuda-call err)]
   (with-checl-arr err res))