本文介绍了在cudaFree()之前需要cudaDeviceSynchronize()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CUDA版本10.1.Pascal GPU.所有命令均发布到默认流:

CUDA version 10.1. Pascal GPU. All commands are issued to the default stream:

void * ptr;
cudaMalloc(&ptr, ...);

launch_kernel<<<...>>>(ptr);

cudaDeviceSynchronize();     // Is this required?
cudaFree(ptr);

答案是否通过 cudaMallocManaged()更改?

推荐答案

某些CUDA API调用,例如 cudaMalloc(),cudaFree(),cudaHostAlloc(),设备到设备的复制等.GPU的虚拟内存地址映射.这些调用导致设备同步,因此您无需调用 cudaDeviceSynchronize(),因为它已在同步.

Some CUDA API calls such as cudaMalloc(), cudaFree(), cudaHostAlloc(), device to device copies etc. change the virtual memory address mapping of GPU. These calls are causing device synchronization, so that you don't need to call cudaDeviceSynchronize() because it is already synchronizing.

cudaMallocManaged()也会发生同样的情况.

The same happens with the cudaMallocManaged().

这篇关于在cudaFree()之前需要cudaDeviceSynchronize()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 04:23