|
|
|
@ -32,7 +32,11 @@ void Copy<platform::CPUPlace, platform::CUDAPlace>(
|
|
|
|
|
platform::CPUPlace dst_place, void* dst, platform::CUDAPlace src_place,
|
|
|
|
|
const void* src, size_t num, cudaStream_t stream) {
|
|
|
|
|
platform::SetDeviceId(src_place.device);
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyDeviceToHost, stream);
|
|
|
|
|
if (stream) {
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyDeviceToHost, stream);
|
|
|
|
|
} else {
|
|
|
|
|
platform::GpuMemcpySync(dst, src, num, cudaMemcpyDeviceToHost);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
@ -40,7 +44,11 @@ void Copy<platform::CUDAPlace, platform::CPUPlace>(
|
|
|
|
|
platform::CUDAPlace dst_place, void* dst, platform::CPUPlace src_place,
|
|
|
|
|
const void* src, size_t num, cudaStream_t stream) {
|
|
|
|
|
platform::SetDeviceId(dst_place.device);
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyHostToDevice, stream);
|
|
|
|
|
if (stream) {
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyHostToDevice, stream);
|
|
|
|
|
} else {
|
|
|
|
|
platform::GpuMemcpySync(dst, src, num, cudaMemcpyHostToDevice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
@ -49,10 +57,19 @@ void Copy<platform::CUDAPlace, platform::CUDAPlace>(
|
|
|
|
|
const void* src, size_t num, cudaStream_t stream) {
|
|
|
|
|
if (dst_place == src_place) {
|
|
|
|
|
platform::SetDeviceId(src_place.device);
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyDeviceToDevice, stream);
|
|
|
|
|
if (stream) {
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyDeviceToDevice, stream);
|
|
|
|
|
} else {
|
|
|
|
|
platform::GpuMemcpySync(dst, src, num, cudaMemcpyDeviceToDevice);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
platform::GpuMemcpyPeer(dst, dst_place.device, src, src_place.device, num,
|
|
|
|
|
stream);
|
|
|
|
|
if (stream) {
|
|
|
|
|
platform::GpuMemcpyPeerAsync(dst, dst_place.device, src, src_place.device,
|
|
|
|
|
num, stream);
|
|
|
|
|
} else {
|
|
|
|
|
platform::GpuMemcpyPeerSync(dst, dst_place.device, src, src_place.device,
|
|
|
|
|
num);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -83,7 +100,11 @@ void Copy<platform::CUDAPinnedPlace, platform::CUDAPlace>(
|
|
|
|
|
platform::CUDAPlace src_place, const void* src, size_t num,
|
|
|
|
|
cudaStream_t stream) {
|
|
|
|
|
platform::SetDeviceId(src_place.device);
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyDeviceToHost, stream);
|
|
|
|
|
if (stream) {
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyDeviceToHost, stream);
|
|
|
|
|
} else {
|
|
|
|
|
platform::GpuMemcpySync(dst, src, num, cudaMemcpyDeviceToHost);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
@ -92,7 +113,11 @@ void Copy<platform::CUDAPlace, platform::CUDAPinnedPlace>(
|
|
|
|
|
platform::CUDAPinnedPlace src_place, const void* src, size_t num,
|
|
|
|
|
cudaStream_t stream) {
|
|
|
|
|
platform::SetDeviceId(dst_place.device);
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyHostToDevice, stream);
|
|
|
|
|
if (stream) {
|
|
|
|
|
platform::GpuMemcpyAsync(dst, src, num, cudaMemcpyHostToDevice, stream);
|
|
|
|
|
} else {
|
|
|
|
|
platform::GpuMemcpySync(dst, src, num, cudaMemcpyHostToDevice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|