# About cudaHostGetDevicePointer problem

**URL:** <https://forums.developer.nvidia.com/t/about-cudahostgetdevicepointer-problem/8615>\
**Category:** CUDA Programming and Performance\
**Created:** [March 30, 2009, 1:33am UTC](https://forums.developer.nvidia.com/t/about-cudahostgetdevicepointer-problem/8615 "2009-03-30T01:33:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![darot](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@darot](https://forums.developer.nvidia.com/u/darot)\
**Post date:** [March 30, 2009, 1:33am UTC](https://forums.developer.nvidia.com/t/about-cudahostgetdevicepointer-problem/8615/1 "2009-03-30T01:33:14Z")

</div>

My Board is GTX 285.

CUDA version is 2.2Beta

I think it support Zero copy access.

But to run the code below and called cudaHostGetDevicePointer function retruned error code “5” which is not list in reference document(only 0, 1, 2 are listed).

Is there anybody know why?

```auto
unsigned short *ptrS_h, *ptrS_d;

char *ptrD1_h, *ptrD1_d,*ptrD2_h, *ptrD2_d;

const int SizeX=8192;

const int SizeY=5000;

int cudaError;

cudaSetDevice(0);

cudaSetDeviceFlags( cudaDeviceMapHost );

cudaError=cudaHostAlloc( (void**) &(ptrS_h), sizeof(unsigned short) * SizeX*SizeY, cudaHostAllocMapped | cudaHostAllocPortable );

cudaError=cudaHostAlloc( (void**) &(ptrD1_h), sizeof(char) * SizeX*SizeY, cudaHostAllocMapped | cudaHostAllocPortable );

cudaError=cudaHostAlloc( (void**) &(ptrD2_h), sizeof(char) * SizeX*SizeY, cudaHostAllocMapped | cudaHostAllocPortable );

if (cudaError) printf ("Failed to allocate pinned memory \n");

cudaError=cudaHostGetDevicePointer( (void**) &(ptrS_d), ptrS_h, 0 );

cudaError=cudaHostGetDevicePointer( (void**) &(ptrD1_d), ptrD1_h, 0 );

cudaError=cudaHostGetDevicePointer( (void**) &(ptrD2_d), ptrD2_h, 0 );

if (cudaError) printf ("Failed to get device pointer,Error Code = %d\n",cudaError);

printf ("Sucess \n");

getch();

return 0;

```

---

<div class="post-metadata">

**Author:** ![darot](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@darot](https://forums.developer.nvidia.com/u/darot)\
**Post date:** [March 30, 2009, 2:22am UTC](https://forums.developer.nvidia.com/t/about-cudahostgetdevicepointer-problem/8615/2 "2009-03-30T02:22:25Z")

</div>

I found that after I put cudaSetDeviceFlags( cudaDeviceMapHost ) before cudaSetDevice(0);

then it worked, why?

> [@](#):
>
> My Board is GTX 285.
> 
> CUDA version is 2.2Beta
> 
> I think it support Zero copy access.
> 
> But to run the code below and called cudaHostGetDevicePointer function retruned error code “5” which is not list in reference document(only 0, 1, 2 are listed).
> 
> Is there anybody know why?
> 
> ```auto
> unsigned short *ptrS_h, *ptrS_d;
> 
> char *ptrD1_h, *ptrD1_d,*ptrD2_h, *ptrD2_d;
> 
> const int SizeX=8192;
> 
> const int SizeY=5000;
> 
> int cudaError;
> 
> cudaSetDevice(0);
> 
> cudaSetDeviceFlags( cudaDeviceMapHost );
> 
> cudaError=cudaHostAlloc( (void**) &(ptrS_h), sizeof(unsigned short) * SizeX*SizeY, cudaHostAllocMapped | cudaHostAllocPortable );
> 
> cudaError=cudaHostAlloc( (void**) &(ptrD1_h), sizeof(char) * SizeX*SizeY, cudaHostAllocMapped | cudaHostAllocPortable );
> 
> cudaError=cudaHostAlloc( (void**) &(ptrD2_h), sizeof(char) * SizeX*SizeY, cudaHostAllocMapped | cudaHostAllocPortable );
> 
> if (cudaError) printf ("Failed to allocate pinned memory \n");
> 
> cudaError=cudaHostGetDevicePointer( (void**) &(ptrS_d), ptrS_h, 0 );
> 
> cudaError=cudaHostGetDevicePointer( (void**) &(ptrD1_d), ptrD1_h, 0 );
> 
> cudaError=cudaHostGetDevicePointer( (void**) &(ptrD2_d), ptrD2_h, 0 );
> 
> if (cudaError) printf ("Failed to get device pointer,Error Code = %d\n",cudaError);
> 
> printf ("Sucess \n");
> 
> getch();
> 
> return 0;
> 
> ```
