From 3121f889e1cd7efe7be46f9ed3882b69566121df Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 3 Nov 2021 11:08:00 +0800 Subject: [PATCH] change api->include and hapi->api (#36938) --- paddle/fluid/framework/operator.h | 2 +- paddle/fluid/framework/pten_utils.h | 4 +- paddle/fluid/imperative/prepared_operator.h | 2 +- paddle/fluid/operators/dot_op.h | 6 +- paddle/fluid/operators/fill_any_like_op.h | 4 +- paddle/fluid/operators/matmul_v2_op.h | 6 +- paddle/fluid/operators/mean_op.h | 6 +- paddle/fluid/operators/scale_op.h | 6 +- paddle/fluid/operators/sign_op.h | 4 +- paddle/pten/CMakeLists.txt | 15 +++- paddle/pten/{hapi => }/all.cc | 6 +- paddle/pten/{hapi => }/all.h | 13 ++-- paddle/pten/api/CMakeLists.txt | 9 +-- paddle/pten/api/all.cc | 4 +- paddle/pten/api/all.h | 5 +- .../pten/{hapi => api}/include/backend_set.h | 0 paddle/pten/api/include/creation.h | 34 ++++----- paddle/pten/api/include/linalg.h | 30 +++----- paddle/pten/api/include/manipulation.h | 58 ++++++-------- paddle/pten/api/include/math.h | 65 ++-------------- paddle/pten/{hapi => api}/include/tensor.h | 0 paddle/pten/{hapi => api}/lib/CMakeLists.txt | 0 paddle/pten/{hapi => api}/lib/creation.cc | 10 +-- .../pten/{hapi => api}/lib/kernel_dispatch.h | 4 +- paddle/pten/{hapi => api}/lib/linalg.cc | 10 +-- paddle/pten/{hapi => api}/lib/manipulation.cc | 8 +- paddle/pten/{hapi => api}/lib/math.cc | 10 +-- .../{hapi => api}/lib/utils/CMakeLists.txt | 0 .../pten/{hapi => api}/lib/utils/allocator.cc | 2 +- .../pten/{hapi => api}/lib/utils/allocator.h | 0 .../pten/{hapi => api}/lib/utils/storage.cc | 2 +- paddle/pten/{hapi => api}/lib/utils/storage.h | 0 .../{hapi => api}/lib/utils/tensor_utils.cc | 2 +- .../{hapi => api}/lib/utils/tensor_utils.h | 4 +- .../lib/utils/tests/CMakeLists.txt | 0 .../lib/utils/tests/test_storage.cc | 4 +- .../lib/utils/tests/test_tensor_utils.cc | 2 +- paddle/pten/hapi/CMakeLists.txt | 3 - paddle/pten/hapi/include/creation.h | 33 -------- paddle/pten/hapi/include/linalg.h | 30 -------- paddle/pten/hapi/include/manipulation.h | 25 ------ paddle/pten/hapi/include/math.h | 27 ------- paddle/pten/{api => }/include/core.h | 0 paddle/pten/include/creation.h | 39 ++++++++++ paddle/pten/{api => }/include/infershape.h | 0 paddle/pten/include/linalg.h | 38 ++++++++++ paddle/pten/include/manipulation.h | 39 ++++++++++ paddle/pten/include/math.h | 76 +++++++++++++++++++ paddle/pten/kernels/cuda/math.cu | 2 +- paddle/pten/tests/test_copy_api.cc | 2 +- paddle/pten/tests/test_dot_api.cc | 6 +- paddle/pten/tests/test_fill_api.cc | 6 +- paddle/pten/tests/test_flatten_api.cc | 6 +- paddle/pten/tests/test_matmul_api.cc | 4 +- paddle/pten/tests/test_mean_api.cc | 6 +- paddle/pten/tests/test_scale_api.cc | 6 +- 56 files changed, 343 insertions(+), 342 deletions(-) rename paddle/pten/{hapi => }/all.cc (82%) rename paddle/pten/{hapi => }/all.h (69%) rename paddle/pten/{hapi => api}/include/backend_set.h (100%) rename paddle/pten/{hapi => api}/include/tensor.h (100%) rename paddle/pten/{hapi => api}/lib/CMakeLists.txt (100%) rename paddle/pten/{hapi => api}/lib/creation.cc (90%) rename paddle/pten/{hapi => api}/lib/kernel_dispatch.h (97%) rename paddle/pten/{hapi => api}/lib/linalg.cc (93%) rename paddle/pten/{hapi => api}/lib/manipulation.cc (91%) rename paddle/pten/{hapi => api}/lib/math.cc (88%) rename paddle/pten/{hapi => api}/lib/utils/CMakeLists.txt (100%) rename paddle/pten/{hapi => api}/lib/utils/allocator.cc (93%) rename paddle/pten/{hapi => api}/lib/utils/allocator.h (100%) rename paddle/pten/{hapi => api}/lib/utils/storage.cc (96%) rename paddle/pten/{hapi => api}/lib/utils/storage.h (100%) rename paddle/pten/{hapi => api}/lib/utils/tensor_utils.cc (98%) rename paddle/pten/{hapi => api}/lib/utils/tensor_utils.h (94%) rename paddle/pten/{hapi => api}/lib/utils/tests/CMakeLists.txt (100%) rename paddle/pten/{hapi => api}/lib/utils/tests/test_storage.cc (95%) rename paddle/pten/{hapi => api}/lib/utils/tests/test_tensor_utils.cc (98%) delete mode 100644 paddle/pten/hapi/CMakeLists.txt delete mode 100644 paddle/pten/hapi/include/creation.h delete mode 100644 paddle/pten/hapi/include/linalg.h delete mode 100644 paddle/pten/hapi/include/manipulation.h delete mode 100644 paddle/pten/hapi/include/math.h rename paddle/pten/{api => }/include/core.h (100%) create mode 100644 paddle/pten/include/creation.h rename paddle/pten/{api => }/include/infershape.h (100%) create mode 100644 paddle/pten/include/linalg.h create mode 100644 paddle/pten/include/manipulation.h create mode 100644 paddle/pten/include/math.h diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index 575ce8956d4..b75dcade6fc 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -40,7 +40,7 @@ limitations under the License. */ #include "paddle/fluid/platform/variant.h" #include "paddle/utils/flat_hash_map.h" -#include "paddle/pten/api/include/core.h" +#include "paddle/pten/include/core.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/framework/pten_utils.h b/paddle/fluid/framework/pten_utils.h index aab756f50e3..6fe02ad4a4a 100644 --- a/paddle/fluid/framework/pten_utils.h +++ b/paddle/fluid/framework/pten_utils.h @@ -25,8 +25,8 @@ limitations under the License. */ #include "paddle/fluid/imperative/type_defs.h" #include "paddle/fluid/platform/macros.h" #include "paddle/fluid/platform/place.h" -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" +#include "paddle/pten/include/core.h" #include "paddle/utils/flat_hash_map.h" #include "paddle/utils/small_vector.h" diff --git a/paddle/fluid/imperative/prepared_operator.h b/paddle/fluid/imperative/prepared_operator.h index fab67e87c79..144f921861f 100644 --- a/paddle/fluid/imperative/prepared_operator.h +++ b/paddle/fluid/imperative/prepared_operator.h @@ -27,7 +27,7 @@ #include "paddle/fluid/imperative/layer.h" #include "paddle/fluid/imperative/type_defs.h" -#include "paddle/pten/api/include/core.h" +#include "paddle/pten/include/core.h" DECLARE_bool(use_mkldnn); diff --git a/paddle/fluid/operators/dot_op.h b/paddle/fluid/operators/dot_op.h index 6a025fdd9cc..f6877c57a5c 100644 --- a/paddle/fluid/operators/dot_op.h +++ b/paddle/fluid/operators/dot_op.h @@ -20,9 +20,9 @@ #include "paddle/fluid/platform/for_range.h" // only can include the headers in paddle/pten/api dirs -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/linalg.h" -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/linalg.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/operators/fill_any_like_op.h b/paddle/fluid/operators/fill_any_like_op.h index fc649f42c51..5e2d06672c3 100644 --- a/paddle/fluid/operators/fill_any_like_op.h +++ b/paddle/fluid/operators/fill_any_like_op.h @@ -19,8 +19,8 @@ limitations under the License. */ #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/pten_utils.h" -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/creation.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/creation.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/operators/matmul_v2_op.h b/paddle/fluid/operators/matmul_v2_op.h index 1d361ae45da..ee95881caa9 100644 --- a/paddle/fluid/operators/matmul_v2_op.h +++ b/paddle/fluid/operators/matmul_v2_op.h @@ -26,9 +26,9 @@ limitations under the License. */ #include "paddle/fluid/operators/reduce_ops/reduce_sum_op.h" // only can include the headers in paddle/pten/api dirs -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/linalg.h" -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/linalg.h" #if defined(__NVCC__) || defined(__HIPCC__) #include "paddle/fluid/operators/reduce_ops/cub_reduce.h" diff --git a/paddle/fluid/operators/mean_op.h b/paddle/fluid/operators/mean_op.h index f909b96c919..2b398771c5c 100644 --- a/paddle/fluid/operators/mean_op.h +++ b/paddle/fluid/operators/mean_op.h @@ -18,9 +18,9 @@ limitations under the License. */ #include "paddle/fluid/framework/pten_utils.h" // only can include the headers in paddle/top/api dirs -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/math.h" -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/math.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/operators/scale_op.h b/paddle/fluid/operators/scale_op.h index 0d7113a6f4d..a75c9fd4fd2 100644 --- a/paddle/fluid/operators/scale_op.h +++ b/paddle/fluid/operators/scale_op.h @@ -18,9 +18,9 @@ limitations under the License. */ #include "paddle/fluid/framework/pten_utils.h" // only can include the headers in paddle/top/api dirs -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/math.h" -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/math.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/operators/sign_op.h b/paddle/fluid/operators/sign_op.h index 0e3036115e3..b7a46cc5467 100644 --- a/paddle/fluid/operators/sign_op.h +++ b/paddle/fluid/operators/sign_op.h @@ -20,8 +20,8 @@ limitations under the License. */ #include "paddle/fluid/operators/eigen/eigen_function.h" // only can include the headers in paddle/pten/api dirs -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/math.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/math.h" namespace paddle { namespace operators { diff --git a/paddle/pten/CMakeLists.txt b/paddle/pten/CMakeLists.txt index c1fe2d552af..0444fa593c0 100644 --- a/paddle/pten/CMakeLists.txt +++ b/paddle/pten/CMakeLists.txt @@ -1,7 +1,6 @@ -# pten api +# pten (low level) api headers: include +# pten (high level) api add_subdirectory(api) -# pten high level api -add_subdirectory(hapi) # pten core components add_subdirectory(core) # pten kernels for diff device @@ -10,3 +9,13 @@ add_subdirectory(kernels) add_subdirectory(infershape) # pten tests add_subdirectory(tests) + +# make an unity target for compile deps +set(PTEN_DEPS convert_utils dense_tensor kernel_factory kernel_context) +set(PTEN_DEPS ${PTEN_DEPS} math_cpu linalg_cpu creation_cpu manipulation_cpu) +set(PTEN_DEPS ${PTEN_DEPS} unary binary) +if(WITH_GPU OR WITH_ROCM) + set(PTEN_DEPS ${PTEN_DEPS} math_cuda linalg_cuda creation_cuda manipulation_cuda) +endif() + +cc_library(pten SRCS all.cc DEPS ${PTEN_DEPS}) diff --git a/paddle/pten/hapi/all.cc b/paddle/pten/all.cc similarity index 82% rename from paddle/pten/hapi/all.cc rename to paddle/pten/all.cc index 4ea6fabeecf..d8d96e1cd46 100644 --- a/paddle/pten/hapi/all.cc +++ b/paddle/pten/all.cc @@ -12,8 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/all.h" +#include "paddle/pten/all.h" -namespace paddle { -namespace experimental {} // namespace experimental -} // namespace paddle +namespace pten {} // namespace pten diff --git a/paddle/pten/hapi/all.h b/paddle/pten/all.h similarity index 69% rename from paddle/pten/hapi/all.h rename to paddle/pten/all.h index 1a2a4199e7b..e8e41a8c3ea 100644 --- a/paddle/pten/hapi/all.h +++ b/paddle/pten/all.h @@ -14,9 +14,10 @@ limitations under the License. */ #pragma once -// user apis -#include "paddle/pten/hapi/include/creation.h" -#include "paddle/pten/hapi/include/linalg.h" -#include "paddle/pten/hapi/include/manipulation.h" -#include "paddle/pten/hapi/include/math.h" -#include "paddle/pten/hapi/include/tensor.h" +// develop apis +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/creation.h" +#include "paddle/pten/include/infershape.h" +#include "paddle/pten/include/linalg.h" +#include "paddle/pten/include/manipulation.h" +#include "paddle/pten/include/math.h" diff --git a/paddle/pten/api/CMakeLists.txt b/paddle/pten/api/CMakeLists.txt index 1c107519324..4b427b3b4a3 100644 --- a/paddle/pten/api/CMakeLists.txt +++ b/paddle/pten/api/CMakeLists.txt @@ -1,8 +1,3 @@ -set(PTEN_DEPS convert_utils dense_tensor kernel_factory kernel_context) -set(PTEN_DEPS ${PTEN_DEPS} math_cpu linalg_cpu creation_cpu manipulation_cpu) -set(PTEN_DEPS ${PTEN_DEPS} unary binary) -if(WITH_GPU OR WITH_ROCM) - set(PTEN_DEPS ${PTEN_DEPS} math_cuda linalg_cuda creation_cuda manipulation_cuda) -endif() +add_subdirectory(lib) -cc_library(pten SRCS all.cc DEPS ${PTEN_DEPS}) +cc_library(pten_hapi SRCS all.cc DEPS linalg_api math_api creation_api) diff --git a/paddle/pten/api/all.cc b/paddle/pten/api/all.cc index 0704d6c516f..c270fbb0706 100644 --- a/paddle/pten/api/all.cc +++ b/paddle/pten/api/all.cc @@ -14,4 +14,6 @@ limitations under the License. */ #include "paddle/pten/api/all.h" -namespace pten {} // namespace pten +namespace paddle { +namespace experimental {} // namespace experimental +} // namespace paddle diff --git a/paddle/pten/api/all.h b/paddle/pten/api/all.h index c760960967d..3a2c7b3fa98 100644 --- a/paddle/pten/api/all.h +++ b/paddle/pten/api/all.h @@ -14,10 +14,9 @@ limitations under the License. */ #pragma once -// develop apis -#include "paddle/pten/api/include/core.h" +// user apis #include "paddle/pten/api/include/creation.h" -#include "paddle/pten/api/include/infershape.h" #include "paddle/pten/api/include/linalg.h" #include "paddle/pten/api/include/manipulation.h" #include "paddle/pten/api/include/math.h" +#include "paddle/pten/api/include/tensor.h" diff --git a/paddle/pten/hapi/include/backend_set.h b/paddle/pten/api/include/backend_set.h similarity index 100% rename from paddle/pten/hapi/include/backend_set.h rename to paddle/pten/api/include/backend_set.h diff --git a/paddle/pten/api/include/creation.h b/paddle/pten/api/include/creation.h index 9795d88f818..755038adb1f 100644 --- a/paddle/pten/api/include/creation.h +++ b/paddle/pten/api/include/creation.h @@ -14,26 +14,20 @@ #pragma once -#include "paddle/pten/api/include/infershape.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/kernels/cpu/creation.h" -#include "paddle/pten/kernels/cuda/creation.h" +#include "paddle/pten/api/include/tensor.h" +#include "paddle/pten/common/data_type.h" +#include "paddle/pten/common/scalar.h" -namespace pten { +namespace paddle { +namespace experimental { -// TODO(YuanRisheng) This function name should be same as User API name. -// TODO(zyfncg) Automatic code generation -template -DenseTensor FillAnyLike(const ContextT& dev_ctx, - const DenseTensor& x, - const Scalar& val) { - auto out_meta = UnchangedInferShape(x.meta()); - const auto allocator = - std::make_shared( - dev_ctx.GetPlace()); - pten::DenseTensor dense_out(allocator, out_meta); - FillAnyLike(dev_ctx, x, val, &dense_out); - return dense_out; -} +Tensor full_like(const Tensor& x, + const Scalar& value, + DataType dtype = DataType::UNDEFINED); -} // namespace pten +Tensor ones_like(const Tensor& x, DataType dtype = DataType::UNDEFINED); + +Tensor zeros_like(const Tensor& x, DataType dtype = DataType::UNDEFINED); + +} // namespace experimental +} // namespace paddle diff --git a/paddle/pten/api/include/linalg.h b/paddle/pten/api/include/linalg.h index 0d4c7a60fbc..c28c1330184 100644 --- a/paddle/pten/api/include/linalg.h +++ b/paddle/pten/api/include/linalg.h @@ -14,25 +14,17 @@ #pragma once -// See Note: [ How do we organize the kernel directory ] -#include "paddle/pten/api/include/infershape.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/kernels/cpu/linalg.h" -#include "paddle/pten/kernels/cuda/linalg.h" +#include "paddle/pten/api/include/tensor.h" -namespace pten { +namespace paddle { +namespace experimental { -template -DenseTensor Dot(const ContextT& dev_ctx, - const DenseTensor& x, - const DenseTensor& y) { - auto out_meta = DotInferShape(x.meta(), y.meta()); - const auto allocator = - std::make_shared( - dev_ctx.GetPlace()); - pten::DenseTensor dense_out(allocator, out_meta); - Dot(dev_ctx, x, y, &dense_out); - return dense_out; -} +Tensor dot(const Tensor& x, const Tensor& y); -} // namespace pten +Tensor matmul(const Tensor& x, + const Tensor& y, + bool transpose_x, + bool transpose_y); + +} // namespace experimental +} // namespace paddle diff --git a/paddle/pten/api/include/manipulation.h b/paddle/pten/api/include/manipulation.h index 1f867686a6e..fe8c01cb74b 100644 --- a/paddle/pten/api/include/manipulation.h +++ b/paddle/pten/api/include/manipulation.h @@ -1,39 +1,25 @@ -// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ #pragma once -// See Note: [ How do we organize the kernel directory ] -#include "paddle/pten/api/include/infershape.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/kernels/cpu/manipulation.h" -#include "paddle/pten/kernels/cuda/manipulation.h" - -namespace pten { - -template -DenseTensor Flatten(const ContextT& dev_ctx, - const DenseTensor& x, - int start_axis, - int stop_axis) { - auto out_meta = FlattenInferShape(x.meta(), start_axis, stop_axis); - const auto allocator = - std::make_shared( - dev_ctx.GetPlace()); - pten::DenseTensor dense_out(allocator, out_meta); - Flatten(dev_ctx, x, start_axis, stop_axis, &dense_out); - return dense_out; -} - -} // namespace pten +#include "paddle/pten/api/include/tensor.h" + +namespace paddle { +namespace experimental { + +Tensor flatten(const Tensor& x, int start_axis, int stop_axis); + +} // namespace experimental +} // namespace paddle diff --git a/paddle/pten/api/include/math.h b/paddle/pten/api/include/math.h index fa512e8d6db..9fea515646d 100644 --- a/paddle/pten/api/include/math.h +++ b/paddle/pten/api/include/math.h @@ -14,63 +14,14 @@ limitations under the License. */ #pragma once -// See Note: [ How do we organize the kernel directory ] -#include "paddle/pten/api/include/infershape.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/kernels/cpu/math.h" -#include "paddle/pten/kernels/cuda/math.h" +#include "paddle/pten/api/include/tensor.h" -namespace pten { +namespace paddle { +namespace experimental { -template -DenseTensor Sign(const ContextT& dev_ctx, const DenseTensor& x) { - auto out_meta = UnchangedInferShape(x.meta()); - const auto allocator = - std::make_shared( - dev_ctx.GetPlace()); - pten::DenseTensor dense_out(allocator, out_meta); - Sign(dev_ctx, x, &dense_out); - return dense_out; -} +// TODO(chenweihang): add scale API +// TODO(chenweihang): move mean API into stat.h/cc +Tensor mean(const Tensor& x); -template -DenseTensor Mean(const ContextT& dev_ctx, const DenseTensor& x) { - auto out_meta = ReductionInferShape(x.meta()); - const auto allocator = - std::make_shared( - dev_ctx.GetPlace()); - pten::DenseTensor dense_out(allocator, out_meta); - Mean(dev_ctx, x, &dense_out); - return dense_out; -} - -template -DenseTensor Scale(const ContextT& dev_ctx, - const DenseTensor& x, - float scale, - float bias, - bool bias_after_scale) { - auto out_meta = UnchangedInferShape(x.meta()); - const auto allocator = - std::make_shared( - dev_ctx.GetPlace()); - pten::DenseTensor dense_out(allocator, out_meta); - Scale(dev_ctx, x, scale, bias, bias_after_scale, &dense_out); - return dense_out; -} - -template -DenseTensor Scale(const ContextT& dev_ctx, - const DenseTensor& x, - const DenseTensor& scale, - float bias, - bool bias_after_scale) { - auto out_meta = UnchangedInferShape(x.meta()); - const auto allocator = - std::make_shared( - dev_ctx.GetPlace()); - pten::DenseTensor dense_out(allocator, out_meta); - ScaleHost(dev_ctx, x, scale, bias, bias_after_scale, &dense_out); - return dense_out; -} -} // namespace pten +} // namespace experimental +} // namespace paddle diff --git a/paddle/pten/hapi/include/tensor.h b/paddle/pten/api/include/tensor.h similarity index 100% rename from paddle/pten/hapi/include/tensor.h rename to paddle/pten/api/include/tensor.h diff --git a/paddle/pten/hapi/lib/CMakeLists.txt b/paddle/pten/api/lib/CMakeLists.txt similarity index 100% rename from paddle/pten/hapi/lib/CMakeLists.txt rename to paddle/pten/api/lib/CMakeLists.txt diff --git a/paddle/pten/hapi/lib/creation.cc b/paddle/pten/api/lib/creation.cc similarity index 90% rename from paddle/pten/hapi/lib/creation.cc rename to paddle/pten/api/lib/creation.cc index cda8d24b5e6..893f8b6fbc6 100644 --- a/paddle/pten/hapi/lib/creation.cc +++ b/paddle/pten/api/lib/creation.cc @@ -12,16 +12,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/include/creation.h" +#include "paddle/pten/api/include/creation.h" #include #include "glog/logging.h" -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/infershape.h" -#include "paddle/pten/hapi/lib/kernel_dispatch.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" +#include "paddle/pten/api/lib/kernel_dispatch.h" +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/infershape.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/lib/kernel_dispatch.h b/paddle/pten/api/lib/kernel_dispatch.h similarity index 97% rename from paddle/pten/hapi/lib/kernel_dispatch.h rename to paddle/pten/api/lib/kernel_dispatch.h index f61f3297d6d..567c21eeee9 100644 --- a/paddle/pten/hapi/lib/kernel_dispatch.h +++ b/paddle/pten/api/lib/kernel_dispatch.h @@ -18,10 +18,10 @@ limitations under the License. */ #include #include +#include "paddle/pten/api/include/backend_set.h" +#include "paddle/pten/api/include/tensor.h" #include "paddle/pten/common/data_type.h" #include "paddle/pten/common/layout.h" -#include "paddle/pten/hapi/include/backend_set.h" -#include "paddle/pten/hapi/include/tensor.h" // TODO(chenweihang): split KernelName, Key, Kernel, Factory into diff files #include "paddle/pten/core/convert_utils.h" diff --git a/paddle/pten/hapi/lib/linalg.cc b/paddle/pten/api/lib/linalg.cc similarity index 93% rename from paddle/pten/hapi/lib/linalg.cc rename to paddle/pten/api/lib/linalg.cc index 3f13f546ee2..587b9cd0f27 100644 --- a/paddle/pten/hapi/lib/linalg.cc +++ b/paddle/pten/api/lib/linalg.cc @@ -12,19 +12,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/include/linalg.h" +#include "paddle/pten/api/include/linalg.h" #include #include "glog/logging.h" -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/infershape.h" +#include "paddle/pten/api/lib/kernel_dispatch.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_context.h" -#include "paddle/pten/hapi/lib/kernel_dispatch.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/infershape.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/lib/manipulation.cc b/paddle/pten/api/lib/manipulation.cc similarity index 91% rename from paddle/pten/hapi/lib/manipulation.cc rename to paddle/pten/api/lib/manipulation.cc index fa60bac6d1a..9f071ce8c2d 100644 --- a/paddle/pten/hapi/lib/manipulation.cc +++ b/paddle/pten/api/lib/manipulation.cc @@ -12,14 +12,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/include/manipulation.h" +#include "paddle/pten/api/include/manipulation.h" #include #include "glog/logging.h" -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/hapi/lib/kernel_dispatch.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" +#include "paddle/pten/api/lib/kernel_dispatch.h" +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/include/core.h" #include "paddle/pten/infershape/unary.h" namespace paddle { diff --git a/paddle/pten/hapi/lib/math.cc b/paddle/pten/api/lib/math.cc similarity index 88% rename from paddle/pten/hapi/lib/math.cc rename to paddle/pten/api/lib/math.cc index 5e4e96d3330..6cb7849e529 100644 --- a/paddle/pten/hapi/lib/math.cc +++ b/paddle/pten/api/lib/math.cc @@ -12,16 +12,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/include/math.h" +#include "paddle/pten/api/include/math.h" #include #include "glog/logging.h" -#include "paddle/pten/api/include/core.h" -#include "paddle/pten/api/include/infershape.h" -#include "paddle/pten/hapi/lib/kernel_dispatch.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" +#include "paddle/pten/api/lib/kernel_dispatch.h" +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/include/core.h" +#include "paddle/pten/include/infershape.h" #include "paddle/pten/infershape/unary.h" namespace paddle { diff --git a/paddle/pten/hapi/lib/utils/CMakeLists.txt b/paddle/pten/api/lib/utils/CMakeLists.txt similarity index 100% rename from paddle/pten/hapi/lib/utils/CMakeLists.txt rename to paddle/pten/api/lib/utils/CMakeLists.txt diff --git a/paddle/pten/hapi/lib/utils/allocator.cc b/paddle/pten/api/lib/utils/allocator.cc similarity index 93% rename from paddle/pten/hapi/lib/utils/allocator.cc rename to paddle/pten/api/lib/utils/allocator.cc index 0c364c97e4d..e80152431e7 100644 --- a/paddle/pten/hapi/lib/utils/allocator.cc +++ b/paddle/pten/api/lib/utils/allocator.cc @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/lib/utils/allocator.h" +#include "paddle/pten/api/lib/utils/allocator.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/lib/utils/allocator.h b/paddle/pten/api/lib/utils/allocator.h similarity index 100% rename from paddle/pten/hapi/lib/utils/allocator.h rename to paddle/pten/api/lib/utils/allocator.h diff --git a/paddle/pten/hapi/lib/utils/storage.cc b/paddle/pten/api/lib/utils/storage.cc similarity index 96% rename from paddle/pten/hapi/lib/utils/storage.cc rename to paddle/pten/api/lib/utils/storage.cc index 0682b25c6e0..ba26e7f600d 100644 --- a/paddle/pten/hapi/lib/utils/storage.cc +++ b/paddle/pten/api/lib/utils/storage.cc @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/lib/utils/storage.h" +#include "paddle/pten/api/lib/utils/storage.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/lib/utils/storage.h b/paddle/pten/api/lib/utils/storage.h similarity index 100% rename from paddle/pten/hapi/lib/utils/storage.h rename to paddle/pten/api/lib/utils/storage.h diff --git a/paddle/pten/hapi/lib/utils/tensor_utils.cc b/paddle/pten/api/lib/utils/tensor_utils.cc similarity index 98% rename from paddle/pten/hapi/lib/utils/tensor_utils.cc rename to paddle/pten/api/lib/utils/tensor_utils.cc index f7641f424f4..628fde3a1a4 100644 --- a/paddle/pten/hapi/lib/utils/tensor_utils.cc +++ b/paddle/pten/api/lib/utils/tensor_utils.cc @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/lib/utils/tensor_utils.h b/paddle/pten/api/lib/utils/tensor_utils.h similarity index 94% rename from paddle/pten/hapi/lib/utils/tensor_utils.h rename to paddle/pten/api/lib/utils/tensor_utils.h index a2b2688362a..625d6702f8b 100644 --- a/paddle/pten/hapi/lib/utils/tensor_utils.h +++ b/paddle/pten/api/lib/utils/tensor_utils.h @@ -19,11 +19,11 @@ limitations under the License. */ #include "paddle/fluid/framework/lod_tensor.h" #include "paddle/fluid/framework/variable.h" +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/api/lib/utils/storage.h" #include "paddle/pten/core/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_factory.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/hapi/lib/utils/storage.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/lib/utils/tests/CMakeLists.txt b/paddle/pten/api/lib/utils/tests/CMakeLists.txt similarity index 100% rename from paddle/pten/hapi/lib/utils/tests/CMakeLists.txt rename to paddle/pten/api/lib/utils/tests/CMakeLists.txt diff --git a/paddle/pten/hapi/lib/utils/tests/test_storage.cc b/paddle/pten/api/lib/utils/tests/test_storage.cc similarity index 95% rename from paddle/pten/hapi/lib/utils/tests/test_storage.cc rename to paddle/pten/api/lib/utils/tests/test_storage.cc index fbbcd2a3ee0..fc95f95f26e 100644 --- a/paddle/pten/hapi/lib/utils/tests/test_storage.cc +++ b/paddle/pten/api/lib/utils/tests/test_storage.cc @@ -16,8 +16,8 @@ limitations under the License. */ #include "gtest/gtest.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/hapi/lib/utils/storage.h" +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/api/lib/utils/storage.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/lib/utils/tests/test_tensor_utils.cc b/paddle/pten/api/lib/utils/tests/test_tensor_utils.cc similarity index 98% rename from paddle/pten/hapi/lib/utils/tests/test_tensor_utils.cc rename to paddle/pten/api/lib/utils/tests/test_tensor_utils.cc index 56184eec70f..fd52b96542c 100644 --- a/paddle/pten/hapi/lib/utils/tests/test_tensor_utils.cc +++ b/paddle/pten/api/lib/utils/tests/test_tensor_utils.cc @@ -14,7 +14,7 @@ limitations under the License. */ #include "gtest/gtest.h" -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/hapi/CMakeLists.txt b/paddle/pten/hapi/CMakeLists.txt deleted file mode 100644 index 4b427b3b4a3..00000000000 --- a/paddle/pten/hapi/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_subdirectory(lib) - -cc_library(pten_hapi SRCS all.cc DEPS linalg_api math_api creation_api) diff --git a/paddle/pten/hapi/include/creation.h b/paddle/pten/hapi/include/creation.h deleted file mode 100644 index 6f978be9952..00000000000 --- a/paddle/pten/hapi/include/creation.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include "paddle/pten/common/data_type.h" -#include "paddle/pten/common/scalar.h" -#include "paddle/pten/hapi/include/tensor.h" - -namespace paddle { -namespace experimental { - -Tensor full_like(const Tensor& x, - const Scalar& value, - DataType dtype = DataType::UNDEFINED); - -Tensor ones_like(const Tensor& x, DataType dtype = DataType::UNDEFINED); - -Tensor zeros_like(const Tensor& x, DataType dtype = DataType::UNDEFINED); - -} // namespace experimental -} // namespace paddle diff --git a/paddle/pten/hapi/include/linalg.h b/paddle/pten/hapi/include/linalg.h deleted file mode 100644 index 6e78b50af11..00000000000 --- a/paddle/pten/hapi/include/linalg.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include "paddle/pten/hapi/include/tensor.h" - -namespace paddle { -namespace experimental { - -Tensor dot(const Tensor& x, const Tensor& y); - -Tensor matmul(const Tensor& x, - const Tensor& y, - bool transpose_x, - bool transpose_y); - -} // namespace experimental -} // namespace paddle diff --git a/paddle/pten/hapi/include/manipulation.h b/paddle/pten/hapi/include/manipulation.h deleted file mode 100644 index 4622032f5ad..00000000000 --- a/paddle/pten/hapi/include/manipulation.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#pragma once - -#include "paddle/pten/hapi/include/tensor.h" - -namespace paddle { -namespace experimental { - -Tensor flatten(const Tensor& x, int start_axis, int stop_axis); - -} // namespace experimental -} // namespace paddle diff --git a/paddle/pten/hapi/include/math.h b/paddle/pten/hapi/include/math.h deleted file mode 100644 index db4010c1c14..00000000000 --- a/paddle/pten/hapi/include/math.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#pragma once - -#include "paddle/pten/hapi/include/tensor.h" - -namespace paddle { -namespace experimental { - -// TODO(chenweihang): add scale API -// TODO(chenweihang): move mean API into stat.h/cc -Tensor mean(const Tensor& x); - -} // namespace experimental -} // namespace paddle diff --git a/paddle/pten/api/include/core.h b/paddle/pten/include/core.h similarity index 100% rename from paddle/pten/api/include/core.h rename to paddle/pten/include/core.h diff --git a/paddle/pten/include/creation.h b/paddle/pten/include/creation.h new file mode 100644 index 00000000000..0fb3f905e03 --- /dev/null +++ b/paddle/pten/include/creation.h @@ -0,0 +1,39 @@ +// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/include/infershape.h" +#include "paddle/pten/kernels/cpu/creation.h" +#include "paddle/pten/kernels/cuda/creation.h" + +namespace pten { + +// TODO(YuanRisheng) This function name should be same as User API name. +// TODO(zyfncg) Automatic code generation +template +DenseTensor FillAnyLike(const ContextT& dev_ctx, + const DenseTensor& x, + const Scalar& val) { + auto out_meta = UnchangedInferShape(x.meta()); + const auto allocator = + std::make_shared( + dev_ctx.GetPlace()); + pten::DenseTensor dense_out(allocator, out_meta); + FillAnyLike(dev_ctx, x, val, &dense_out); + return dense_out; +} + +} // namespace pten diff --git a/paddle/pten/api/include/infershape.h b/paddle/pten/include/infershape.h similarity index 100% rename from paddle/pten/api/include/infershape.h rename to paddle/pten/include/infershape.h diff --git a/paddle/pten/include/linalg.h b/paddle/pten/include/linalg.h new file mode 100644 index 00000000000..70eebac5b68 --- /dev/null +++ b/paddle/pten/include/linalg.h @@ -0,0 +1,38 @@ +// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +// See Note: [ How do we organize the kernel directory ] +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/include/infershape.h" +#include "paddle/pten/kernels/cpu/linalg.h" +#include "paddle/pten/kernels/cuda/linalg.h" + +namespace pten { + +template +DenseTensor Dot(const ContextT& dev_ctx, + const DenseTensor& x, + const DenseTensor& y) { + auto out_meta = DotInferShape(x.meta(), y.meta()); + const auto allocator = + std::make_shared( + dev_ctx.GetPlace()); + pten::DenseTensor dense_out(allocator, out_meta); + Dot(dev_ctx, x, y, &dense_out); + return dense_out; +} + +} // namespace pten diff --git a/paddle/pten/include/manipulation.h b/paddle/pten/include/manipulation.h new file mode 100644 index 00000000000..236f7c7af95 --- /dev/null +++ b/paddle/pten/include/manipulation.h @@ -0,0 +1,39 @@ +// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +// See Note: [ How do we organize the kernel directory ] +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/include/infershape.h" +#include "paddle/pten/kernels/cpu/manipulation.h" +#include "paddle/pten/kernels/cuda/manipulation.h" + +namespace pten { + +template +DenseTensor Flatten(const ContextT& dev_ctx, + const DenseTensor& x, + int start_axis, + int stop_axis) { + auto out_meta = FlattenInferShape(x.meta(), start_axis, stop_axis); + const auto allocator = + std::make_shared( + dev_ctx.GetPlace()); + pten::DenseTensor dense_out(allocator, out_meta); + Flatten(dev_ctx, x, start_axis, stop_axis, &dense_out); + return dense_out; +} + +} // namespace pten diff --git a/paddle/pten/include/math.h b/paddle/pten/include/math.h new file mode 100644 index 00000000000..0a61a94aa8d --- /dev/null +++ b/paddle/pten/include/math.h @@ -0,0 +1,76 @@ +/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#pragma once + +// See Note: [ How do we organize the kernel directory ] +#include "paddle/pten/api/lib/utils/allocator.h" +#include "paddle/pten/include/infershape.h" +#include "paddle/pten/kernels/cpu/math.h" +#include "paddle/pten/kernels/cuda/math.h" + +namespace pten { + +template +DenseTensor Sign(const ContextT& dev_ctx, const DenseTensor& x) { + auto out_meta = UnchangedInferShape(x.meta()); + const auto allocator = + std::make_shared( + dev_ctx.GetPlace()); + pten::DenseTensor dense_out(allocator, out_meta); + Sign(dev_ctx, x, &dense_out); + return dense_out; +} + +template +DenseTensor Mean(const ContextT& dev_ctx, const DenseTensor& x) { + auto out_meta = ReductionInferShape(x.meta()); + const auto allocator = + std::make_shared( + dev_ctx.GetPlace()); + pten::DenseTensor dense_out(allocator, out_meta); + Mean(dev_ctx, x, &dense_out); + return dense_out; +} + +template +DenseTensor Scale(const ContextT& dev_ctx, + const DenseTensor& x, + float scale, + float bias, + bool bias_after_scale) { + auto out_meta = UnchangedInferShape(x.meta()); + const auto allocator = + std::make_shared( + dev_ctx.GetPlace()); + pten::DenseTensor dense_out(allocator, out_meta); + Scale(dev_ctx, x, scale, bias, bias_after_scale, &dense_out); + return dense_out; +} + +template +DenseTensor Scale(const ContextT& dev_ctx, + const DenseTensor& x, + const DenseTensor& scale, + float bias, + bool bias_after_scale) { + auto out_meta = UnchangedInferShape(x.meta()); + const auto allocator = + std::make_shared( + dev_ctx.GetPlace()); + pten::DenseTensor dense_out(allocator, out_meta); + ScaleHost(dev_ctx, x, scale, bias, bias_after_scale, &dense_out); + return dense_out; +} +} // namespace pten diff --git a/paddle/pten/kernels/cuda/math.cu b/paddle/pten/kernels/cuda/math.cu index 0ead1f8048b..cc1a7bef4f1 100644 --- a/paddle/pten/kernels/cuda/math.cu +++ b/paddle/pten/kernels/cuda/math.cu @@ -28,9 +28,9 @@ namespace cub = hipcub; #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/float16.h" +#include "paddle/pten/api/lib/utils/tensor_utils.h" #include "paddle/pten/core/convert_utils.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/hapi/lib/utils/tensor_utils.h" namespace pten { diff --git a/paddle/pten/tests/test_copy_api.cc b/paddle/pten/tests/test_copy_api.cc index fcebe9a310d..4bf16e7517b 100644 --- a/paddle/pten/tests/test_copy_api.cc +++ b/paddle/pten/tests/test_copy_api.cc @@ -18,8 +18,8 @@ limitations under the License. */ #include "paddle/pten/core/kernel_registry.h" #include "paddle/pten/kernels/cpu/utils.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/dense_tensor.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" PT_DECLARE_MODULE(UtilsCPU); diff --git a/paddle/pten/tests/test_dot_api.cc b/paddle/pten/tests/test_dot_api.cc index 5401b665444..f79854e557e 100644 --- a/paddle/pten/tests/test_dot_api.cc +++ b/paddle/pten/tests/test_dot_api.cc @@ -15,13 +15,13 @@ limitations under the License. */ #include #include -#include "paddle/pten/hapi/include/linalg.h" +#include "paddle/pten/api/include/linalg.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/api/include/linalg.h" +#include "paddle/pten/include/linalg.h" PT_DECLARE_MODULE(LinalgCPU); diff --git a/paddle/pten/tests/test_fill_api.cc b/paddle/pten/tests/test_fill_api.cc index 5a788226086..a83ed76a6f8 100644 --- a/paddle/pten/tests/test_fill_api.cc +++ b/paddle/pten/tests/test_fill_api.cc @@ -15,13 +15,13 @@ limitations under the License. */ #include #include -#include "paddle/pten/hapi/include/creation.h" +#include "paddle/pten/api/include/creation.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/api/include/creation.h" +#include "paddle/pten/include/creation.h" PT_DECLARE_MODULE(CreationCPU); diff --git a/paddle/pten/tests/test_flatten_api.cc b/paddle/pten/tests/test_flatten_api.cc index dfb777678a9..ca8ca38f65a 100644 --- a/paddle/pten/tests/test_flatten_api.cc +++ b/paddle/pten/tests/test_flatten_api.cc @@ -15,13 +15,13 @@ limitations under the License. */ #include #include -#include "paddle/pten/hapi/include/manipulation.h" +#include "paddle/pten/api/include/manipulation.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/api/include/manipulation.h" +#include "paddle/pten/include/manipulation.h" PT_DECLARE_MODULE(ManipulationCPU); diff --git a/paddle/pten/tests/test_matmul_api.cc b/paddle/pten/tests/test_matmul_api.cc index b0579834519..83a70c905b6 100644 --- a/paddle/pten/tests/test_matmul_api.cc +++ b/paddle/pten/tests/test_matmul_api.cc @@ -15,11 +15,11 @@ limitations under the License. */ #include #include -#include "paddle/pten/hapi/include/linalg.h" +#include "paddle/pten/api/include/linalg.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" #include "paddle/pten/kernels/cuda/utils.h" PT_DECLARE_MODULE(LinalgCPU); diff --git a/paddle/pten/tests/test_mean_api.cc b/paddle/pten/tests/test_mean_api.cc index b3da90659d0..4dd4222daab 100644 --- a/paddle/pten/tests/test_mean_api.cc +++ b/paddle/pten/tests/test_mean_api.cc @@ -15,13 +15,13 @@ limitations under the License. */ #include #include -#include "paddle/pten/hapi/include/math.h" +#include "paddle/pten/api/include/math.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/api/include/math.h" +#include "paddle/pten/include/math.h" PT_DECLARE_MODULE(MathCPU); diff --git a/paddle/pten/tests/test_scale_api.cc b/paddle/pten/tests/test_scale_api.cc index 9f80d6d2cc1..2ecf6d199b5 100644 --- a/paddle/pten/tests/test_scale_api.cc +++ b/paddle/pten/tests/test_scale_api.cc @@ -15,13 +15,13 @@ limitations under the License. */ #include #include -#include "paddle/pten/hapi/include/math.h" +#include "paddle/pten/api/include/math.h" +#include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/hapi/lib/utils/allocator.h" -#include "paddle/pten/api/include/math.h" +#include "paddle/pten/include/math.h" PT_DECLARE_MODULE(MathCPU); -- GitLab