How to use CUB and Thrust in one CUDA code

扶醉桌前 提交于 2019-12-01 13:37:39

This is not appropriate:

 int          *d_num_segments=&Nseg;

You cannot take the address of a host variable and use it as a device pointer.

Instead do this:

int *d_num_segments;
cudaMalloc(&d_num_segments, sizeof(int));

This allocates space on the device for the size of data (a single integer that cub will write to), and assigns the address of that allocation to your d_num_segments variable. This then becomes a valid device pointer.

In (*ordinary, non-UM) CUDA, it is illegal dereference a host address in device code, or a device address in host code.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!