diff --git a/paddle/fluid/framework/tensor_util.cc b/paddle/fluid/framework/tensor_util.cc index 33ef3b91866f477910b105b15014854788a070d5..3bc24bc1e5d0ef4cfeb7182326044c80a92fbd79 100644 --- a/paddle/fluid/framework/tensor_util.cc +++ b/paddle/fluid/framework/tensor_util.cc @@ -99,6 +99,8 @@ void TensorCopy(const Tensor& src, const platform::Place& dst_place, PADDLE_THROW("ctx is not belong to dst_gpu_place or src_gpu_place."); } } + } else { + PADDLE_THROW("Copy from %s to %s is not supported.", src_place, dst_place); } #endif } @@ -166,6 +168,8 @@ void TensorCopySync(const Tensor& src, const platform::Place& dst_place, auto dst_gpu_place = boost::get(dst_place); memory::Copy(dst_gpu_place, dst_ptr, src_pinned_place, src_ptr, size, nullptr); + } else { + PADDLE_THROW("Copy from %s to %s is not supported.", src_place, dst_place); } #endif } diff --git a/paddle/fluid/operators/reader/buffered_reader.cc b/paddle/fluid/operators/reader/buffered_reader.cc index 16cb08f4190a3b76f4795b838697dca81e67e007..b332450c252e0c5799591fd1a8f23009685be5ec 100644 --- a/paddle/fluid/operators/reader/buffered_reader.cc +++ b/paddle/fluid/operators/reader/buffered_reader.cc @@ -128,9 +128,18 @@ void BufferedReader::ReadAsync(size_t i) { boost::get(cpu_place), cpu_ptr, size, stream_); } else { + platform::CUDAPinnedPlace cuda_pinned_place; + framework::LoDTensor cuda_pinned_tensor; + cuda_pinned_tensor.Resize(cpu[i].dims()); + auto cuda_pinned_ptr = + cuda_pinned_tensor.mutable_data(cuda_pinned_place, cpu[i].type()); + memory::Copy(cuda_pinned_place, cuda_pinned_ptr, + boost::get(cpu_place), cpu_ptr, + size); memory::Copy(boost::get(place_), gpu_ptr, - boost::get(cpu_place), cpu_ptr, size, - stream_); + cuda_pinned_place, cuda_pinned_ptr, size, stream_); + PADDLE_ENFORCE(cudaStreamSynchronize(stream_), + "cuda stream sync error."); } gpu[i].set_lod(cpu[i].lod()); }