Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Created August 19, 2015 16:41
Show Gist options
  • Save Trass3r/022a3dc263ccdfb4f700 to your computer and use it in GitHub Desktop.
Save Trass3r/022a3dc263ccdfb4f700 to your computer and use it in GitHub Desktop.
CUDA simple memory wrapper class
template <typename T>
struct CUDAMem
{
T* ptr;
CUDAMem()
: ptr(0)
{
cudaError_t err = cudaMallocArray(&ptr, sizeof(T));
if (err != cudaSuccess)
fprintf(stderr, "%s(%i): CUDA error : %s : (%d) %s.\n",
__FILE__, __LINE__, errorMessage, (int)err, cudaGetErrorString(err));
}
~CUDAMem()
{
cudaFreeArray(ptr);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment