cudaMemcpy 传输类型:默认与 HostToDevice/DeviceToHost
cudaMemcpy transfer kinds: Default vs HostToDevice/DeviceToHost
cudaMemcpy
允许程序员显式指定内存传输方向。
手动指定内存传输方向(cudaMemcpyDeviceToHost
/cudaMemcpyHostToDevice
/cudaMemcpyDeviceToDevice
)而不是让cuda从指针自动推断(cudaMemcpyDefault
)有什么好处吗价值观?
来自 cudaMemcpy()
的文档:
[...] Passing cudaMemcpyDefault
is recommended, in which case the type of transfer is inferred from the pointer values. However, cudaMemcpyDefault
is only allowed on systems that support unified virtual addressing. [...]
因此,如果您的 GPU 允许统一虚拟寻址,请使用 cudaMemcpyDefault
,否则您别无选择,只能显式。
您可以通过
查询您的系统是否支持
cudaGetDeviceProperties()
with the device property cudaDeviceProp::unifiedAddressing
.
tl;dr:几乎肯定没有优势。
当 GPU 开始能够通过检查地址(“统一虚拟寻址”)轻松识别内存 space 时,IIRC 添加了 cudaMemcpyDefault
。在此之前,您必须指定方向。例如,参见 CUDA 3 文档,可访问 here。在 API 参考中查找 cudaMemcpyKind - 没有默认值,只有 H2H、H2D、D2H 和 H2H。
当这个改变时,我想 nVIDIA 不重载函数或以不同的方式命名它是有意义的,而只是为新功能添加一个不同的常量值。
我不是 100% 确定没有区别,只是非常合理;从轶事个人经历来说,我还没有看到任何 advantage/difference。复制当然不会更快。
cudaMemcpy
允许程序员显式指定内存传输方向。
手动指定内存传输方向(cudaMemcpyDeviceToHost
/cudaMemcpyHostToDevice
/cudaMemcpyDeviceToDevice
)而不是让cuda从指针自动推断(cudaMemcpyDefault
)有什么好处吗价值观?
来自 cudaMemcpy()
的文档:
[...] Passing
cudaMemcpyDefault
is recommended, in which case the type of transfer is inferred from the pointer values. However,cudaMemcpyDefault
is only allowed on systems that support unified virtual addressing. [...]
因此,如果您的 GPU 允许统一虚拟寻址,请使用 cudaMemcpyDefault
,否则您别无选择,只能显式。
您可以通过
查询您的系统是否支持
cudaGetDeviceProperties()
with the device propertycudaDeviceProp::unifiedAddressing
.
tl;dr:几乎肯定没有优势。
当 GPU 开始能够通过检查地址(“统一虚拟寻址”)轻松识别内存 space 时,IIRC 添加了cudaMemcpyDefault
。在此之前,您必须指定方向。例如,参见 CUDA 3 文档,可访问 here。在 API 参考中查找 cudaMemcpyKind - 没有默认值,只有 H2H、H2D、D2H 和 H2H。
当这个改变时,我想 nVIDIA 不重载函数或以不同的方式命名它是有意义的,而只是为新功能添加一个不同的常量值。
我不是 100% 确定没有区别,只是非常合理;从轶事个人经历来说,我还没有看到任何 advantage/difference。复制当然不会更快。