提交 c70a97f4 编写于 作者: C chengduo 提交者: gongweibao

Use CUDAPinnedPlace in buffered_reader (#19112)

Use CUDAPinnedPlace in buffered_reader
上级 ef46918a
......@@ -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<platform::CUDAPlace>(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
}
......
......@@ -128,9 +128,18 @@ void BufferedReader::ReadAsync(size_t i) {
boost::get<platform::CUDAPlace>(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<platform::CPUPlace>(cpu_place), cpu_ptr,
size);
memory::Copy(boost::get<platform::CUDAPlace>(place_), gpu_ptr,
boost::get<platform::CPUPlace>(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());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册