2

我是 cuda 驱动 Api 接口的新手,但我认为 CUdeviceptr 看起来像一个句柄参数。所以我对 CUdeviceptr 和 npp8u * 之间的转换感到困惑。

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

我试着像上面那样写转换,对吗!

4

3 回答 3

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.

于 2014-05-23T05:25:35.750 回答
2

unsigned char通过在转换为之前将指针降级为CUdeviceptr,您将屏蔽除最低有效 8 位之外的所有src.

写吧:

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

于 2014-05-23T21:06:48.210 回答
-1

通常你不会明确地这样做,而是在传递给 cudaMalloc 时将 Npp8u* 转换为 void **:

Npp8u * src;
int length = ...
cudaMalloc( (void **)(&src), sizeof( Npp8u ) * length );
于 2014-05-22T19:20:36.743 回答