CUDAkk
July 28, 2009, 6:43am
1
Hi All,
I have installed CUDA 2.3 driver , toolkit and SDK and i want to use pinned memory but when I see the cudaDeviceProp structure then one of its member value is
canMapHostMemory 1 .
I want to know what this value indicates?
CUDAkk
July 28, 2009, 6:49am
2
I think it indicates this property is on .
CUDAkk
July 28, 2009, 7:35am
3
Hi ,
I have written code for using pinned memory :-
char *device = NULL;
unsigned int flags;
int device Count, idev = 0;
unsigned char*a ; // Pinned memory allocated on the CPU
unsigned char*d_a, // Device pointers for mapped memory
cudaDeviceProp deviceProp;
cudaError err = cudaSetDevice(idev);
err = cudaGetDeviceProperties(&deviceProp, idev);
flags = cudaHostAllocMapped;
err = cudaHostAlloc((void **)&a, dstSize, flags);
In my case :
dstSize = 17280000
flag = 2 ( cudaHostAllocMapped )
But after executing the line
I got error cudaErrorUnknown .
can any one help on this ?
CUDAkk
July 28, 2009, 10:01am
4
I have seen SDK 2.3 project simpleZeroCopy code and I try to implement it in my code. But I have some confusion on using it.
Is following code should be only on main function or I can write it in any function :
int n, nelem, idev, deviceCount;
char *device = NULL;
unsigned int flags;
size_t bytes;
unsigned char *a, *b, *c; // Pinned memory allocated on the CPU
unsigned char *d_a, *d_b, *d_c; // Device pointers for mapped memory
float errorNorm, refNorm, ref, diff;
cudaDeviceProp deviceProp;
/* Get the device selected by the user or default to 0, and then set it. */
if(cutGetCmdLineArgumentstr(argc, (const char**)argv, "device", &device))
{
cudaGetDeviceCount(&deviceCount);
idev = atoi(device);
if(idev >= deviceCount || idev < 0)
{
fprintf(stderr, "Invalid device number %d, using default device 0.\n",
idev);
idev = 0;
}
}
else
{
idev = 0;
}
cudaError err1 = cudaSetDevice(idev);
/* Verify the selected device supports mapped memory and set the device
flags for mapping host memory. */
err1 = cudaGetDeviceProperties(&deviceProp, idev);
err1 = cudaSetDeviceFlags(cudaDeviceMapHost);
/* Allocate mapped CPU memory. */
nelem = 17280000;
bytes = nelem*sizeof(unsigned char);
flags = cudaHostAllocMapped;
err1 = cudaHostAlloc((void **)&a, bytes, flags);
err1 = cudaHostAlloc((void **)&b, bytes, flags);
err1 = cudaHostAlloc((void **)&c, bytes, flags);
err1 = cudaHostGetDevicePointer((void **)&d_a, (void *)a, 0);
err1 = cudaHostGetDevicePointer((void **)&d_b, (void *)b, 0);
err1 = cudaHostGetDevicePointer((void **)&d_c, (void *)c, 0);
Because if I write it on main function then it works fine but if I write it any other function then it gives error. Please help…
CUDAkk
July 28, 2009, 10:04am
5
This problem is solved . We can write it any function . Actually I got this error because of prior error.
And what was your error?
I got also a “cudaErrorUnknown” when I try to allocate pinned memory with cudaHostAlloc().
Thanks
Make sure you’re first calling:
cudaSetDeviceFlags(cudaDeviceMapHost);