diff --git a/mindspore/ccsrc/device/gpu/cuda_driver.cc b/mindspore/ccsrc/device/gpu/cuda_driver.cc index 85329a4069a03fe010d83e916ea3a012c62d2d14..0dee53df641335fdede8b65341fa04a908c5fcbc 100644 --- a/mindspore/ccsrc/device/gpu/cuda_driver.cc +++ b/mindspore/ccsrc/device/gpu/cuda_driver.cc @@ -102,7 +102,7 @@ bool CudaDriver::CopyHostMemToDeviceAsync(const DeviceMemPtr &dst, const void *s bool CudaDriver::CopyDeviceMemToHostAsync(const HostMemPtr &dst, const DeviceMemPtr &src, size_t size, DeviceStream stream) { - auto ret = cudaMemcpyAsync(dst, src, size, cudaMemcpyHostToDevice, (cudaStream_t)stream); + auto ret = cudaMemcpyAsync(dst, src, size, cudaMemcpyDeviceToHost, (cudaStream_t)stream); if (ret != cudaSuccess) { MS_LOG(ERROR) << "cudaMemcpyAsync failed, ret[" << static_cast(ret) << "], " << cudaGetErrorString(ret); return false; diff --git a/mindspore/ccsrc/device/gpu/gpu_device_address.cc b/mindspore/ccsrc/device/gpu/gpu_device_address.cc index c27a1aa65b65f92341406edbb326dd931326030d..c4c1094293a9259e81508c58025e0f453bba50c9 100644 --- a/mindspore/ccsrc/device/gpu/gpu_device_address.cc +++ b/mindspore/ccsrc/device/gpu/gpu_device_address.cc @@ -37,7 +37,13 @@ bool GPUDeviceAddress::SyncDeviceToHost(const std::vector &, size_t size, T bool GPUDeviceAddress::SyncHostToDevice(const std::vector &, size_t, TypeId, const void *host_ptr) const { MS_EXCEPTION_IF_NULL(host_ptr); - return GPUDeviceManager::GetInstance().CopyHostMemToDevice(ptr_, host_ptr, size_); + auto &stream = GPUDeviceManager::GetInstance().default_stream(); + MS_EXCEPTION_IF_NULL(stream); + if (!GPUDeviceManager::GetInstance().CopyHostMemToDeviceAsync(ptr_, host_ptr, size_, stream)) { + MS_LOG(ERROR) << "CopyHostMemToDeviceAsync failed"; + return false; + } + return GPUDeviceManager::GetInstance().SyncStream(stream); } GPUDeviceAddress::~GPUDeviceAddress() { diff --git a/mindspore/ccsrc/device/gpu/gpu_device_manager.cc b/mindspore/ccsrc/device/gpu/gpu_device_manager.cc index e505fdc218cd2667919a2a2150f20f1ea64cce52..9f5f37c606ad1c45cc98c88048de333e75942da8 100644 --- a/mindspore/ccsrc/device/gpu/gpu_device_manager.cc +++ b/mindspore/ccsrc/device/gpu/gpu_device_manager.cc @@ -89,6 +89,16 @@ bool GPUDeviceManager::CopyDeviceMemToHost(const HostMemPtr &dst, const DeviceMe bool GPUDeviceManager::CopyHostMemToDevice(const DeviceMemPtr &dst, const void *src, size_t size) const { return CudaDriver::CopyHostMemToDevice(dst, src, size); } + +bool GPUDeviceManager::CopyDeviceMemToHostAsync(const HostMemPtr &dst, const DeviceMemPtr &src, size_t size, + DeviceStream stream) const { + return CudaDriver::CopyDeviceMemToHostAsync(dst, src, size, stream); +} + +bool GPUDeviceManager::CopyHostMemToDeviceAsync(const DeviceMemPtr &dst, const void *src, size_t size, + DeviceStream stream) const { + return CudaDriver::CopyHostMemToDeviceAsync(dst, src, size, stream); +} } // namespace gpu } // namespace device } // namespace mindspore diff --git a/mindspore/ccsrc/device/gpu/gpu_device_manager.h b/mindspore/ccsrc/device/gpu/gpu_device_manager.h index a546b999a43c678e538fc5e31893e068b45c8041..b6b630181eb7442ffa1bc905768f40dc93e047c6 100644 --- a/mindspore/ccsrc/device/gpu/gpu_device_manager.h +++ b/mindspore/ccsrc/device/gpu/gpu_device_manager.h @@ -47,6 +47,9 @@ class GPUDeviceManager { bool CopyDeviceMemToHost(const HostMemPtr &dst, const DeviceMemPtr &src, size_t size) const; bool CopyHostMemToDevice(const DeviceMemPtr &dst, const void *src, size_t size) const; + bool CopyDeviceMemToHostAsync(const HostMemPtr &dst, const DeviceMemPtr &src, size_t size, DeviceStream stream) const; + bool CopyHostMemToDeviceAsync(const DeviceMemPtr &dst, const void *src, size_t size, DeviceStream stream) const; + static GPUDeviceManager &GetInstance() { static GPUDeviceManager instance; return instance;