@@ -69,9 +69,9 @@ struct CastDataType {
6969};
7070
7171template <typename T>
72- void GpuCopy (T *src, T *dst, PlaceType src_plc, PlaceType dst_plc,
73- int64_t ele_size) {
74- #ifdef PADDLE_WITH_CUDA
72+ void DeviceCopy (T *src, T *dst, PlaceType src_plc, PlaceType dst_plc,
73+ int64_t ele_size) {
74+ #if defined( PADDLE_WITH_CUDA)
7575 platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance ();
7676 int device_num = paddle::platform::GetCurrentDeviceId ();
7777 platform::CUDAPlace gpu_place (device_num);
@@ -111,6 +111,10 @@ void GpuCopy(T *src, T *dst, PlaceType src_plc, PlaceType dst_plc,
111111 " Only GPU related Copy can reach this func." ));
112112 }
113113 hipStreamSynchronize (dev_ctx->stream ());
114+ #else
115+ PADDLE_THROW (platform::errors::Unavailable (
116+ " This function can only be used if compiled with"
117+ " either -DWITH_ROCM=ON or -DWITH_GPU=ON" ));
114118#endif
115119}
116120
@@ -158,7 +162,7 @@ T *Tensor::mutable_data() {
158162 case static_cast <int >(PlaceType::kCPU ): {
159163 return tensor->mutable_data <T>(platform::CPUPlace ());
160164 }
161- #ifdef PADDLE_WITH_CUDA
165+ #if defined( PADDLE_WITH_CUDA)
162166 case static_cast <int >(PlaceType::kGPU ): {
163167 int device_num = platform::GetCurrentDeviceId ();
164168 return tensor->mutable_data <T>(platform::CUDAPlace (device_num));
@@ -244,7 +248,7 @@ Tensor Tensor::copy_to(const PlaceType &target_place) const {
244248 if ((src_place == PlaceType::kCPU ) && (target_place == PlaceType::kCPU )) {
245249 std::memcpy (static_cast <void *>(p_target_data), p_src_data, ele_size);
246250 } else if (supported_gpu_transform) {
247- GpuCopy <T>(p_src_data, p_target_data, src_place, target_place, ele_size);
251+ DeviceCopy <T>(p_src_data, p_target_data, src_place, target_place, ele_size);
248252 } else {
249253 PADDLE_THROW (platform::errors::Unavailable (
250254 " Not supported place transform of place: %d to place: %d" ,
@@ -440,7 +444,7 @@ bool Tensor::is_initialized() const {
440444 } \
441445 }
442446
443- #ifdef PADDLE_WITH_CUDA
447+ #if defined( PADDLE_WITH_CUDA)
444448DEFINE_STREAM (cudaStream_t)
445449#elif defined(PADDLE_WITH_HIP)
446450DEFINE_STREAM (hipStream_t)
0 commit comments