cudacheck
¶
API documentation for cudacheck.h
.
Error checking code for CUDA calls and kernels.
Defines
-
EXITERROR¶
true
Used withinErrorCheck
. If true, exit if an error is found
-
cudaErrorCheckCall(code)¶
Take a CUDA error message
code
, and passes it ontoErrorCheck
to check for errors. This can be wrapped around any call tocudaMalloc
,cudaMemcpy
, orcudaFree
.Example usage:
Usesfloat *d_array=NULL; int num_values=1e6; cudaErrorCheckCall( cudaMalloc( (void**)&(d_array), num_values*sizeof(float)) );
__FILE__
and__LINE__
to get file name and line number to pass on toErrorCheck
- 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 viawherekernel <<< grid , threads, 0 >>>(__VA_ARGS__)
__VA_ARGS__
passes on the arguments located at...
cudaErrorCheckKernel
then passes the stringmessage
on toErrorCheck
, along with the file name and line number via__FILE__
and__LINE__
, and checks the errors from bothcudaGetLastError()
andcudaDeviceSynchronize()
after running the kernel.For example, if
fancy_kernel
takes the argumentsarg1
andarg2
, 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 runkernel
withthreads – [in] A
dim3
containing thread specifications to runkernel
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. Usesfile
andline
to report where the error happened. Optional boolabort
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