2

I am new to cuda driver Api interface but I think that CUdeviceptr looks like a handle parameter.So I confused about the convertion between CUdeviceptr and npp8u *.

Npp8u * src;
......
unsigned char temp;
temp = src;
CUdeviceptr devPtr;
.......
devPtr = (CUdeviceptr)temp;

I try to write the convertion like above,is that right!

user2968731
  • 117
  • 1
  • 9

3 Answers3

4

cuDevicePtr is, in fact, a raw pointer, not a handle. You can see the original architect of the CUDA driver and driver API discuss this here (and school me in the process). So if you have an existing "typed" device pointer, it is safe to cast it to a cuDevicePtr, or vice versa, for example:

cuDevicePtr m;
cuMemAlloc(&m, size);

Npp8U* p = (Npp8U*)(m);
// Pass p to NPP library functions...

is legal and should work.

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • Thanks,it complied successfully.But "Npp8U* p = (Npp8U*)(m)",p is error pointer.In the other hand,I have tried "Npp*p = *(Npp8u **)&m",it also complied successfully and that p is error pointer. – user2968731 May 23 '14 at 09:29
  • 1
    @user2968731: Then you are doing something wrong. WIthout seeing a concrete example I cannot tell you what. – talonmies May 23 '14 at 10:11
2

By demoting the pointer to unsigned char before converting to CUdeviceptr, you are masking off all but the least significant 8 bits of src.

Just write:

Npp8u *src; CUdeviceptr devPtr = (CUdeviceptr) (uintptr_t) src;

ArchaeaSoftware
  • 4,332
  • 16
  • 21
-1

Typically you wouldn't do this explicitly, but rather cast Npp8u* to a void ** when passing to cudaMalloc:

Npp8u * src;
int length = ...
cudaMalloc( (void **)(&src), sizeof( Npp8u ) * length );
Andy
  • 1,663
  • 10
  • 17