Skip to content

Instantly share code, notes, and snippets.

@inducer
Created July 17, 2014 19:13
Show Gist options
  • Save inducer/98d599c9c5b5969103b8 to your computer and use it in GitHub Desktop.
Save inducer/98d599c9c5b5969103b8 to your computer and use it in GitHub Desktop.
cuMemHostRegister failure reproducer
#include <cuda.h>
#include <stdio.h>
#include <stdexcept>
#include <iostream>
#define CUDAPP_CALL_GUARDED(NAME, ARGLIST) \
{ \
CUresult cu_status_code; \
cu_status_code = NAME ARGLIST; \
if (cu_status_code != CUDA_SUCCESS) \
{ \
printf("routine '%s' failed with code '%d'\n", #NAME, cu_status_code); \
abort(); \
} \
}
int main()
{
int N = 1024;
size_t size = N * sizeof(float);
float* h_A = (float*)malloc(size);
CUDAPP_CALL_GUARDED(cuInit, (0));
// Get number of devices supporting CUDA
int deviceCount = 0;
CUDAPP_CALL_GUARDED(cuDeviceGetCount, (&deviceCount));
if (deviceCount == 0) {
printf("There is no device supporting CUDA.\n");
exit (0);
}
// Get handle for device 0
CUdevice cuDevice;
CUDAPP_CALL_GUARDED(cuDeviceGet, (&cuDevice, 0));
// Create context
CUcontext cuContext;
CUDAPP_CALL_GUARDED(cuCtxCreate, (&cuContext, 0, cuDevice));
CUDAPP_CALL_GUARDED(cuMemHostRegister, (h_A, size, 0));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment