[cuda]异步内存拷贝中的默认同步

CUDA中的Memcpy分为同步和异步两种。对于Unified Memory区域的拷贝,都是相对于主机同步的。从设备到主机的页对齐内存拷贝在函数返回后可能还未完成DMA,而从设备到设备的拷贝不进行主机侧同步。异步拷贝主要体现在从设备到页对齐主机内存的情况。测试程序表明,从设备到页对齐内存拷贝是异步的,而从设备到设备内存拷贝是同步的,需要等待拷贝完成才会返回。
摘要由CSDN通过智能技术生成

Memcpy

In the reference documentation, each memcpy function is categorized as synchronous or asynchronous, corresponding to the definitions below.

Synchronous
  • All transfers involving Unified Memory regions are fully synchronous with respect to the host.
  • For transfers from pageable host memory to device memory, a stream sync is performed before the copy is initiated. The function will return once the pageable buffer has been copied to the staging memory for DMA transfer to device memory, but the DMA to final destination may not have completed.
  • For transfers from pinned host memory to device memory, the function is synchronous with respect to the host.
  • For transfers from device to either pageable or pinned host memory, the function returns only once the copy has completed.
  • For transfers from device memory to device memory, no host-side synchronization is performed.
  • For transfers from any host memory to any host memory, the function is fully synchronous with respect to the host.
Asynchronous
  • For transfers from device memory to pageable host memory, the function will return only once the copy has completed.
  • For transfers from any host memory to any host memory, the function is fully synchronous with respect to the host.
  • For all other transfers, the function is fully asynchronous. If pageable memory must first be staged to pinned memory, this will be handled asynchronously with a worker thread.

按照上述的参考文献,从 devicehost 拷贝数据,如果 hostpageable,那么即使使用 cudaMemcpyAsync ,也是同步的,不是异步的,测试程序如下:

#include <cuda_runtime.h>
#include <stdint.h>
#include <assert.h>
#include <chrono>
#include <iostream>

int main()
{
   
    void *d_ptr = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值