cudacheck

API documentation for cudacheck.h.

Error checking code for CUDA calls and kernels.

Defines

EXITERROR

true Used within ErrorCheck. If true, exit if an error is found

cudaErrorCheckCall(code)

Take a CUDA error message code, and passes it onto ErrorCheck to check for errors. This can be wrapped around any call to cudaMalloc, cudaMemcpy, or cudaFree.

Example usage:

      float *d_array=NULL;
      int num_values=1e6;
      cudaErrorCheckCall( cudaMalloc( (void**)&(d_array), num_values*sizeof(float)) );
Uses __FILE__ and __LINE__ to get file name and line number to pass on to ErrorCheck

Parameters:
  • code[in] A cudaError_t code

cudaErrorCheckKernel(message, kernel, grid, threads, ...)

Takes a CUDA kernel, runs it with given arguments, and passes results onto ErrorCheck to check for errors.

All arguements need to run kernel must be included after the listed arguments here. kernel is then run via

    kernel <<< grid , threads, 0 >>>(__VA_ARGS__)
where __VA_ARGS__ passes on the arguments located at ...

cudaErrorCheckKernel then passes the string message on to ErrorCheck, along with the file name and line number via __FILE__ and __LINE__, and checks the errors from both cudaGetLastError() and cudaDeviceSynchronize() after running the kernel.

For example, if fancy_kernel takes the arguments arg1 and arg2, to run it with 10 grids of 64 threads, run the following:

      dim3 grid, threads;
      grid.x = 10
      threads.x = 64
      cudaErrorCheckKernel("Call to fancy_kernel",
                          fancy_kernel, grid, threads,
                          arg1, arg2);

Parameters:
  • message[in] Message to report when an error occurs

  • kernel[in] Name of kernel to be run

  • grid[in] A dim3 containing grid specifications to run kernel with

  • threads[in] A dim3 containing thread specifications to run kernel with

  • ...[in] All arguments to be passed into kernel

Functions

inline void ErrorCheck(const char *message, cudaError_t code, const char *file, int line, bool abort = EXITERROR)

Take a CUDA error message (code), and checks whether an error occurred.

If an error happened, uses message to give more information to the user, along with the decoded CUDA error message. Uses file and line to report where the error happened. Optional bool abort means you can switch off exiting if an error is found (default true)

Parameters:
  • message[in] User supplied error message

  • code[in] Error message out of CUDA call (e.g. cudaMalloc)

  • file[in] Name of file call was made in

  • line[in] Line of file call was made in

  • abort[in] If true, exit the CUDA code when an error is found