Skip to content

Instantly share code, notes, and snippets.

@Robadob
Last active July 23, 2020 11:32
Show Gist options
  • Save Robadob/6a84b47ee450b82efe4a5092b44aa771 to your computer and use it in GitHub Desktop.
Save Robadob/6a84b47ee450b82efe4a5092b44aa771 to your computer and use it in GitHub Desktop.
#ifndef __header_cuh_
#define __header_cuh_
#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
//Cuda call
inline void HandleCUDAError(const char *file,
int line,
cudaError_t status = cudaGetLastError()) {
#ifdef _DEBUG
cudaDeviceSynchronize();
#endif
if (status != CUDA_SUCCESS || (status = cudaGetLastError()) != CUDA_SUCCESS)
{
if (status == cudaErrorUnknown)
{
printf("%s(%i) An Unknown CUDA Error Occurred :(\n", file, line);
printf("Perhaps performing the same operation under the CUDA debugger with Memory Checker enabled could help!\n");
printf("If this error only occurs outside of NSight debugging sessions, or causes the system to lock up. It may be caused by not passing the required amount of shared memory to a kernal launch that uses runtime sized shared memory.\n", file, line);
printf("Also possible you have forgotten to allocate texture memory you are trying to read\n");
printf("Passing a buffer to 'cudaGraphicsSubResourceGetMappedArray' or a texture to 'cudaGraphicsResourceGetMappedPointer'.\n");
getchar();
exit(1);
}
printf("%s(%i) CUDA Error Occurred;\n%s\n", file, line, cudaGetErrorString(status));
getchar();
exit(1);
}
}
#define CUDA_CALL( err ) (HandleCUDAError(__FILE__, __LINE__ , err))
#define CUDA_CHECK() (HandleCUDAError(__FILE__, __LINE__))
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment