我是 cuda 驱动 Api 接口的新手,但我认为 CUdeviceptr 看起来像一个句柄参数。所以我对 CUdeviceptr 和 npp8u * 之间的转换感到困惑。
Npp8u * src;
......
unsigned char temp;
temp = src;
CUdeviceptr devPtr;
.......
devPtr = (CUdeviceptr)temp;
我试着像上面那样写转换,对吗!
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.
unsigned char
通过在转换为之前将指针降级为CUdeviceptr
,您将屏蔽除最低有效 8 位之外的所有src
.
写吧:
Npp8u *src;
CUdeviceptr devPtr = (CUdeviceptr) (uintptr_t) src;
通常你不会明确地这样做,而是在传递给 cudaMalloc 时将 Npp8u* 转换为 void **:
Npp8u * src;
int length = ...
cudaMalloc( (void **)(&src), sizeof( Npp8u ) * length );