diff --git a/paddle/fluid/operators/cast_op.h b/paddle/fluid/operators/cast_op.h index c54c811b25b66050586247595c42ca695455d7ef..e82eeb240c1a20a6f46ca32a1e9b9f23fe99f667 100644 --- a/paddle/fluid/operators/cast_op.h +++ b/paddle/fluid/operators/cast_op.h @@ -63,14 +63,11 @@ class CastOpKernel : public framework::OpKernel { out->mutable_data(dev_ctx.GetPlace(), static_cast(out_dtype)); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*in); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*out); - auto pt_out_dtype = pten::TransToPtenDataType( static_cast(out_dtype)); // call new kernel - pten::CastKernel(dev_ctx, *pt_x.get(), pt_out_dtype, pt_out.get()); + pten::CastKernel(dev_ctx, *in, pt_out_dtype, out); } }; diff --git a/paddle/fluid/operators/cholesky_solve_op.h b/paddle/fluid/operators/cholesky_solve_op.h index 94b68bff8f446200de563897eb9e9d10b433987a..157679f4fc90b45ff886158645b238e46e8b5a8a 100644 --- a/paddle/fluid/operators/cholesky_solve_op.h +++ b/paddle/fluid/operators/cholesky_solve_op.h @@ -202,10 +202,7 @@ class CholeskySolveGradKernel : public framework::OpKernel { commonterm_for_range(commonterm_functor); commonterm_conj = helper.Transpose(commonterm_conj); - auto pt_x = paddle::experimental::MakePtenDenseTensor(commonterm); - auto pt_y = paddle::experimental::MakePtenDenseTensor(commonterm_conj); - auto pt_z = paddle::experimental::MakePtenDenseTensor(commonterm); - pten::AddKernel(dev_ctx, *pt_x.get(), *pt_y.get(), -1, pt_z.get()); + pten::AddKernel(dev_ctx, commonterm, commonterm_conj, -1, &commonterm); auto mat_dim_u = math::CreateMatrixDescriptor(u_bst.dims(), 0, false); auto mat_dim_c = diff --git a/paddle/fluid/operators/conj_op.h b/paddle/fluid/operators/conj_op.h index 6df982abb8612f18c57b94af9ec9c9b28711ad14..e6958ed18b8eed9d8aace74f6f9df52a2b30041e 100644 --- a/paddle/fluid/operators/conj_op.h +++ b/paddle/fluid/operators/conj_op.h @@ -34,11 +34,9 @@ class ConjKernel : public framework::OpKernel { out->mutable_data(context.GetPlace(), size_t(x->numel() * sizeof(T))); auto& dev_ctx = context.device_context(); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*x); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*out); // call new kernel - pten::ConjKernel(dev_ctx, *pt_x.get(), pt_out.get()); + pten::ConjKernel(dev_ctx, *x, out); } }; diff --git a/paddle/fluid/operators/dot_op.h b/paddle/fluid/operators/dot_op.h index ceb8a28e8aa4cc54c384e757bf0099c76eb05cb4..ed8eb64d9e1e020334e7e95b9023a9dd4a36e720 100644 --- a/paddle/fluid/operators/dot_op.h +++ b/paddle/fluid/operators/dot_op.h @@ -40,13 +40,8 @@ class DotKernel : public framework::OpKernel { auto& dev_ctx = ctx.device_context(); out->mutable_data(x->place()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*x); - auto pt_y = paddle::experimental::MakePtenDenseTensor(*y); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*out); - // call new kernel - pten::DotKernel(dev_ctx, *pt_x.get(), *pt_y.get(), - pt_out.get()); + pten::DotKernel(dev_ctx, *x, *y, out); } }; @@ -63,17 +58,11 @@ class DotGradKernel : public framework::OpKernel { if (tensor_dx) tensor_dx->mutable_data(ctx.GetPlace()); if (tensor_dy) tensor_dy->mutable_data(ctx.GetPlace()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*tensor_x); - auto pt_y = paddle::experimental::MakePtenDenseTensor(*tensor_y); - auto pt_dout = paddle::experimental::MakePtenDenseTensor(*tensor_dout); - auto pt_dx = paddle::experimental::MakePtenDenseTensor(*tensor_dx); - auto pt_dy = paddle::experimental::MakePtenDenseTensor(*tensor_dy); - auto& dev_ctx = ctx.device_context(); // call new kernel - pten::DotGradKernel(dev_ctx, *pt_x, *pt_y, *pt_dout, pt_dx.get(), - pt_dy.get()); + pten::DotGradKernel(dev_ctx, *tensor_x, *tensor_y, *tensor_dout, + tensor_dx, tensor_dy); } }; diff --git a/paddle/fluid/operators/fill_any_like_op.h b/paddle/fluid/operators/fill_any_like_op.h index 19f6e7a4ef51fe9b900d82b879c4d91915ee2694..d5b3d89c3d777056204fc635487d375d617c50bb 100644 --- a/paddle/fluid/operators/fill_any_like_op.h +++ b/paddle/fluid/operators/fill_any_like_op.h @@ -60,11 +60,9 @@ class FillAnyLikeKernel : public framework::OpKernel { std::isnan(value), false, platform::errors::InvalidArgument("The filled value is NaN.")); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*out); - const auto& dev_ctx = context.template device_context(); // call new kernel - pten::FullLikeKernel(dev_ctx, value, pt_out.get()); + pten::FullLikeKernel(dev_ctx, value, out); } }; diff --git a/paddle/fluid/operators/flatten_op.h b/paddle/fluid/operators/flatten_op.h index 8e54ecb922f5a1d12d2b643e6ab01dd16201d0cf..624bc9c567fb55677faf719dd4ed6bccb7ffb7f8 100644 --- a/paddle/fluid/operators/flatten_op.h +++ b/paddle/fluid/operators/flatten_op.h @@ -131,12 +131,9 @@ class FlattenContiguousRangeKernel : public framework::OpKernel { auto &stop_axis = context.Attr("stop_axis"); auto &dev_ctx = context.device_context(); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*in); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*out); - // call new kernel - pten::FlattenKernel(dev_ctx, *pt_x.get(), start_axis, - stop_axis, pt_out.get()); + pten::FlattenKernel(dev_ctx, *in, start_axis, stop_axis, + out); } }; @@ -152,20 +149,8 @@ class FlattenContiguousRangeGradKernel : public framework::OpKernel { d_x->mutable_data(ctx.GetPlace(), d_out->type()); auto &dev_ctx = ctx.device_context(); - auto pt_d_x = paddle::experimental::MakePtenDenseTensor(*d_x); - auto pt_d_out = paddle::experimental::MakePtenDenseTensor(*d_out); - - // Because the holder of xshape may be nullptr, we can't use - // MakePtenDenseTensor. - // So, we create a new DenseTensor to save the dims of xshape. - pten::DenseTensorMeta xshape_meta{pten::TransToPtenDataType(d_x->type()), - xshape->dims(), d_x->layout()}; - auto pt_xshape = - pten::Empty(dev_ctx, std::move(xshape_meta)); - // call new kernel - pten::FlattenGradKernel(dev_ctx, *pt_d_out.get(), - pt_xshape, pt_d_x.get()); + pten::FlattenGradKernel(dev_ctx, *d_out, *xshape, d_x); } }; diff --git a/paddle/fluid/operators/lu_op.h b/paddle/fluid/operators/lu_op.h index da448fbd35a9f066966b5ccc7478142cdc6a4285..f241caa857a07aefdab8e918c33ed5410b2b367b 100644 --- a/paddle/fluid/operators/lu_op.h +++ b/paddle/fluid/operators/lu_op.h @@ -220,11 +220,8 @@ void Tensor_Add(const DeviceContext& dev_ctx, const framework::Tensor& src1, const framework::Tensor& src2, framework::Tensor* out) { out->Resize(src1.dims()); out->mutable_data(dev_ctx.GetPlace()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(src1); - auto pt_y = paddle::experimental::MakePtenDenseTensor(src2); - auto pt_z = paddle::experimental::MakePtenDenseTensor(*out); - pten::AddKernel(dev_ctx, *pt_x.get(), *pt_y.get(), -1, - pt_z.get()); + + pten::AddKernel(dev_ctx, src1, src2, -1, out); } template @@ -232,11 +229,8 @@ void Tensor_Sub(const DeviceContext& dev_ctx, const framework::Tensor& src1, const framework::Tensor& src2, framework::Tensor* out) { out->Resize(src1.dims()); out->mutable_data(dev_ctx.GetPlace()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(src1); - auto pt_y = paddle::experimental::MakePtenDenseTensor(src2); - auto pt_z = paddle::experimental::MakePtenDenseTensor(*out); - pten::SubtractKernel(dev_ctx, *pt_x.get(), *pt_y.get(), -1, - pt_z.get()); + + pten::SubtractKernel(dev_ctx, src1, src2, -1, out); } template diff --git a/paddle/fluid/operators/matmul_v2_op.h b/paddle/fluid/operators/matmul_v2_op.h index 9ab77cdcaec0a7e1c8c323e4ac21111b1ab19170..67b0fec734c1279771ee38e3c82355af46a04a7b 100644 --- a/paddle/fluid/operators/matmul_v2_op.h +++ b/paddle/fluid/operators/matmul_v2_op.h @@ -52,13 +52,8 @@ class MatMulV2Kernel : public framework::OpKernel { auto& dev_ctx = ctx.device_context(); Out->mutable_data(X->place()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*X); - auto pt_y = paddle::experimental::MakePtenDenseTensor(*Y); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*Out); - // call new kernel - pten::MatmulKernel(dev_ctx, *pt_x, *pt_y, trans_x, trans_y, - pt_out.get()); + pten::MatmulKernel(dev_ctx, *X, *Y, trans_x, trans_y, Out); } }; @@ -151,19 +146,11 @@ class MatMulV2GradKernel : public framework::OpKernel { if (dx) dx->mutable_data(ctx.GetPlace()); if (dy) dy->mutable_data(ctx.GetPlace()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*x); - auto pt_y = paddle::experimental::MakePtenDenseTensor(*y); - auto pt_dout = paddle::experimental::MakePtenDenseTensor(*dout); - auto pt_dx = dx ? paddle::experimental::MakePtenDenseTensor(*dx) - : std::unique_ptr(nullptr); - auto pt_dy = dy ? paddle::experimental::MakePtenDenseTensor(*dy) - : std::unique_ptr(nullptr); - auto& dev_ctx = ctx.device_context(); // call new kernel - pten::MatmulGradKernel(dev_ctx, *pt_x, *pt_y, *pt_dout, transpose_x, - transpose_y, pt_dx.get(), pt_dy.get()); + pten::MatmulGradKernel(dev_ctx, *x, *y, *dout, transpose_x, transpose_y, + dx, dy); } }; @@ -188,21 +175,11 @@ class MatMulV2DoubleGradKernel : public framework::OpKernel { if (dy) dy->mutable_data(context.GetPlace()); if (ddout) ddout->mutable_data(context.GetPlace()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*x); - auto pt_y = paddle::experimental::MakePtenDenseTensor(*y); - auto pt_dout = paddle::experimental::MakePtenDenseTensor(*dout); - auto pt_ddx = paddle::experimental::MakePtenDenseTensor(*ddx); - auto pt_ddy = paddle::experimental::MakePtenDenseTensor(*ddy); - auto pt_dx = paddle::experimental::MakePtenDenseTensor(*dx); - auto pt_dy = paddle::experimental::MakePtenDenseTensor(*dy); - auto pt_ddout = paddle::experimental::MakePtenDenseTensor(*ddout); - auto& dev_ctx = context.device_context(); // call new kernel - pten::MatmulDoubleGradKernel(dev_ctx, *pt_x, *pt_y, *pt_dout, *pt_ddx, - *pt_ddy, transpose_x, transpose_y, - pt_dx.get(), pt_dy.get(), pt_ddout.get()); + pten::MatmulDoubleGradKernel(dev_ctx, *x, *y, *dout, *ddx, *ddy, + transpose_x, transpose_y, dx, dy, ddout); } }; @@ -238,28 +215,11 @@ class MatMulV2TripleGradKernel : public framework::OpKernel { if (out_d_ddx) out_d_ddx->mutable_data(context.GetPlace()); if (out_d_ddy) out_d_ddy->mutable_data(context.GetPlace()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*x); - auto pt_y = paddle::experimental::MakePtenDenseTensor(*y); - auto pt_dout = paddle::experimental::MakePtenDenseTensor(*dout); - auto pt_ddx = paddle::experimental::MakePtenDenseTensor(*ddx); - auto pt_ddy = paddle::experimental::MakePtenDenseTensor(*ddy); - auto pt_d_dx = paddle::experimental::MakePtenDenseTensor(*d_dx); - auto pt_d_dy = paddle::experimental::MakePtenDenseTensor(*d_dy); - auto pt_d_ddout = paddle::experimental::MakePtenDenseTensor(*d_ddout); - - auto pt_out_d_x = paddle::experimental::MakePtenDenseTensor(*out_d_x); - auto pt_out_d_y = paddle::experimental::MakePtenDenseTensor(*out_d_y); - auto pt_out_d_dout = paddle::experimental::MakePtenDenseTensor(*out_d_dout); - auto pt_out_d_ddx = paddle::experimental::MakePtenDenseTensor(*out_d_ddx); - auto pt_out_d_ddy = paddle::experimental::MakePtenDenseTensor(*out_d_ddy); - auto& dev_ctx = context.device_context(); // call new kernel - pten::MatmulTripleGradKernel(dev_ctx, *pt_x, *pt_y, *pt_dout, *pt_ddx, - *pt_ddy, *pt_d_dx, *pt_d_dy, *pt_d_ddout, - transpose_x, transpose_y, pt_out_d_x.get(), - pt_out_d_y.get(), pt_out_d_dout.get(), - pt_out_d_ddx.get(), pt_out_d_ddy.get()); + pten::MatmulTripleGradKernel( + dev_ctx, *x, *y, *dout, *ddx, *ddy, *d_dx, *d_dy, *d_ddout, transpose_x, + transpose_y, out_d_x, out_d_y, out_d_dout, out_d_ddx, out_d_ddy); } }; diff --git a/paddle/fluid/operators/scale_op.h b/paddle/fluid/operators/scale_op.h index a6f4f6e27204ed783f9eb9ff86977a208c43c995..da7c8c607a92a978ffa745884d99ea6dd780bd53 100644 --- a/paddle/fluid/operators/scale_op.h +++ b/paddle/fluid/operators/scale_op.h @@ -65,12 +65,8 @@ class ScaleKernel : public framework::OpKernel { out->mutable_data(in->place()); auto& dev_ctx = ctx.device_context(); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*in); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*out); - // call new kernel - pten::ScaleKernel(dev_ctx, *pt_x.get(), scale, bias, bias_after_scale, - pt_out.get()); + pten::ScaleKernel(dev_ctx, *in, scale, bias, bias_after_scale, out); } }; diff --git a/paddle/fluid/operators/sign_op.h b/paddle/fluid/operators/sign_op.h index 8294cd2c5f1450b00f225082cf9a3735e0912b20..737560d314a15dda0ef9b95481ae020b10108e13 100644 --- a/paddle/fluid/operators/sign_op.h +++ b/paddle/fluid/operators/sign_op.h @@ -34,11 +34,8 @@ class SignKernel : public framework::OpKernel { auto& dev_ctx = context.device_context(); out->mutable_data(x->place()); - auto pt_x = paddle::experimental::MakePtenDenseTensor(*x); - auto pt_out = paddle::experimental::MakePtenDenseTensor(*out); - // call new kernel - pten::SignKernel(dev_ctx, *pt_x.get(), pt_out.get()); + pten::SignKernel(dev_ctx, *x, out); } };