Skip to content

Conversation

kexinzhao
Copy link
Contributor

@kexinzhao kexinzhao commented May 4, 2018

DeserializeFromStream function calls TensorFromStream, where it has the following code:

if (platform::is_gpu_place(dev_ctx.GetPlace())) {
#ifdef PADDLE_WITH_CUDA
Tensor cpu_tensor;
cpu_tensor.Resize(framework::make_ddim(dims));
framework::VisitDataType(
desc.data_type(),
DeserializedDataFunctor(&buf, &cpu_tensor, ctx.GetPlace()));
is.read(static_cast<char*>(buf), cpu_tensor.memory_size());
auto dst_place = dev_ctx.GetPlace();
framework::TensorCopy(cpu_tensor, dst_place, dev_ctx, tensor);
#else
PADDLE_THROW("Unexpected branch");
#endif
} else {
framework::VisitDataType(
desc.data_type(),
DeserializedDataFunctor(&buf, tensor, ctx.GetPlace()));
is.read(static_cast<char*>(buf), tensor->memory_size());

This means that TensorFromStream will first load tensor from disk to CPU place, if the load op is run on GPU place, it will copy the tensor to GPU via framework::TensorCopy(cpu_tensor, dst_place, dev_ctx, tensor);

So in the load op, we don't need to do the copy from CPU to GPU again.

@wangkuiyi wangkuiyi requested review from Xreki and reyoung May 4, 2018 21:49
Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent

@kexinzhao kexinzhao merged commit 170ac72 into PaddlePaddle:develop May 9, 2018
@kexinzhao kexinzhao deleted the prune_load_op branch May 9, 2018 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants