Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace framework::TensorCopy phi::Copy #64131

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion paddle/fluid/operators/array_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ArrayOp : public framework::OperatorBase {
platform::is_custom_place(i_tensor.place())) {
// FIXME: Avoid copy from GPU to CPU
phi::DenseTensor t;
framework::TensorCopy(i_tensor, platform::CPUPlace(), dev_ctx, &t);
phi::Copy(dev_ctx, i_tensor, phi::CPUPlace(), false, &t);
dev_ctx.Wait();
offset = static_cast<size_t>(*t.data<int64_t>());
} else {
Expand Down
7 changes: 5 additions & 2 deletions paddle/fluid/operators/detection/collect_fpn_proposals_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ class GPUCollectFpnProposalsOpKernel : public framework::OpKernel<T> {

// copy batch id list to GPU
phi::DenseTensor roi_batch_id_list_gpu;
framework::TensorCopy(
roi_batch_id_list, dev_ctx.GetPlace(), &roi_batch_id_list_gpu);
phi::Copy(dev_ctx,
roi_batch_id_list,
dev_ctx.GetPlace(),
false,
&roi_batch_id_list_gpu);

phi::DenseTensor index_in_t;
int* idx_in =
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/operators/expand_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ class ExpandGradKernel : public framework::OpKernel<T> {
auto* out0 =
context.Output<phi::DenseTensor>(framework::GradVarName("X"));
out0->mutable_data<T>(context.GetPlace());
framework::TensorCopy(
*in0, context.GetPlace(), context.device_context(), out0);
phi::Copy(
context.device_context(), *in0, context.GetPlace(), false, out0);
} else {
PADDLE_ENFORCE_GE(dims,
1,
Expand Down
3 changes: 1 addition & 2 deletions paddle/fluid/operators/get_tensor_from_selected_rows_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class GetTensorFromSelectedRowsKernel {

out->Resize(x->value().dims());
out->mutable_data(ctx.GetPlace(), x->value().type());
framework::TensorCopy(
x->value(), ctx.GetPlace(), ctx.device_context(), out);
phi::Copy(ctx.device_context(), x->value(), ctx.GetPlace(), false, out);
}
};

Expand Down
10 changes: 5 additions & 5 deletions paddle/fluid/operators/squeeze_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ class Squeeze2Kernel : public framework::OpKernel<T> {
auto out_dims = GetOutputShape(axes, x_dims, true);

out->mutable_data(context.GetPlace(), in->type());
framework::TensorCopy(
*in,
context.GetPlace(),
context.template device_context<platform::DeviceContext>(),
out);
phi::Copy(context.template device_context<platform::DeviceContext>(),
*in,
context.GetPlace(),
false,
out);
out->Resize(out_dims);
}
};
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/operators/tensorrt/tensorrt_engine_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ class TensorRTEngineOp : public framework::OperatorBase {
// check the input_tensor
if (!platform::is_gpu_place(t.place())) {
phi::DenseTensor out;
framework::TensorCopy(t, dev_place, dev_ctx, &out);
phi::Copy(dev_ctx, t, dev_place, false, &out);
t.ShareDataWith(out);
}
auto t_shape = common::vectorize<int64_t>(t.dims());
Expand Down Expand Up @@ -854,7 +854,7 @@ class TensorRTEngineOp : public framework::OperatorBase {
auto int32_tensor = scope.FindVar(y_t)->GetMutable<phi::DenseTensor>();
int32_tensor->Resize(fluid_t->dims());
dev_ctx.Alloc<int32_t>(int32_tensor);
framework::TensorCopy(*fluid_t, dev_place, dev_ctx, int32_tensor);
phi::Copy(dev_ctx, *fluid_t, dev_place, false, int32_tensor);
*fluid_t = phi::Cast<int32_t>(
reinterpret_cast<const phi::GPUContext &>(dev_ctx),
*int32_tensor,
Expand All @@ -870,7 +870,7 @@ class TensorRTEngineOp : public framework::OperatorBase {
auto fp32_tensor = scope.FindVar(y_t)->GetMutable<phi::DenseTensor>();
fp32_tensor->Resize(fluid_t->dims());
dev_ctx.Alloc<float>(fp32_tensor);
framework::TensorCopy(*fluid_t, dev_place, dev_ctx, fp32_tensor);
phi::Copy(dev_ctx, *fluid_t, dev_place, false, fp32_tensor);
*fluid_t =
phi::Cast<float>(reinterpret_cast<const phi::GPUContext &>(dev_ctx),
*fp32_tensor,
Expand Down