确保 thrust 不会从主机到设备 memcpy

Ensure that thrust doesnt memcpy from host to device

我使用了下面的方法,希望避免从主机到设备的memcpy。 thrust库是否确保进程中不会有主机到设备的memcpy?

void EScanThrust(float * d_in, float * d_out)
{
     thrust::device_ptr<float> dev_ptr(d_in);
     thrust::device_ptr<float> dev_out_ptr(d_out);

     thrust::exclusive_scan(dev_ptr, dev_ptr + size, dev_out_ptr);
}

这里d_ind_out是用cudaMalloc准备的,d_in是用cudaMemcpy填充数据的,然后调用这个函数

Does thrust library ensure that there wont be a memcpy from host to device in the process?

您显示的代码不应涉及任何主机->设备复制。 (怎么可能?在您显示的代码中,任何地方都没有引用任何主机数据。)

对于实际代码,使用 profiler 验证底层 CUDA activity 很容易,例如:

nvprof --print-gpu-trace ./my_exe

如果您的分析代码序列保持简短,则很容易将底层 CUDA activity 与生成该 activity 的推力代码对齐。如果您只想分析较长序列的一小段,那么您可以 turn profiling on and off or else use NVTX markers 在分析器输出中确定所需的范围。