From a1e40dc66160f9cd0ac413e7bdd5f4d2b387d772 Mon Sep 17 00:00:00 2001 From: Feiyu Chan Date: Mon, 24 Jan 2022 16:49:42 +0800 Subject: [PATCH] [Pten] Migration of eigen numeric extensions and functors in paddle/fluid/operatos/eigen (#39124) * migration of functors in paddle/fluid/operators/eigen and paddle/fluid/platform/eigen_ext.h * update path of data types like float16.h in includes in extensions.h --- paddle/fluid/framework/data_type.h | 2 +- paddle/fluid/operators/CMakeLists.txt | 1 - paddle/fluid/operators/eigen/CMakeLists.txt | 9 - paddle/fluid/operators/eigen/eigen_function.h | 216 ++---------- .../kernel_primitives/functor_primitives.h | 2 +- paddle/fluid/operators/optimizers/lamb_op.h | 2 +- paddle/fluid/platform/bfloat16_test.cc | 2 +- paddle/fluid/platform/complex_test.cc | 34 +- paddle/fluid/platform/complex_test.cu | 36 +- paddle/fluid/platform/float16_test.cc | 2 +- paddle/fluid/platform/float16_test.cu | 2 +- .../pten/kernels/funcs/eigen/CMakeLists.txt | 9 + .../kernels/funcs}/eigen/broadcast.cc | 35 +- .../kernels/funcs}/eigen/broadcast.cu | 37 +- .../kernels/funcs}/eigen/constant.cc | 10 +- .../kernels/funcs}/eigen/constant.cu | 12 +- .../pten/kernels/funcs/eigen/eigen_function.h | 319 ++++++++++++++++++ .../kernels/funcs}/eigen/elementwise.cc | 36 +- .../kernels/funcs}/eigen/elementwise.cu | 32 +- .../kernels/funcs}/eigen/erf.cc | 27 +- .../kernels/funcs}/eigen/erf.cu | 22 +- .../kernels/funcs/eigen/extensions.h} | 164 +++++---- .../kernels/funcs}/eigen/l1_norm.cc | 28 +- .../kernels/funcs}/eigen/l1_norm.cu | 25 +- .../kernels/funcs}/eigen/loss.cc | 62 ++-- .../kernels/funcs}/eigen/loss.cu | 62 ++-- .../kernels/funcs}/eigen/pad.cc | 31 +- .../kernels/funcs}/eigen/pad.cu | 39 ++- .../kernels/funcs}/eigen/reverse.cc | 18 +- .../kernels/funcs}/eigen/reverse.cu | 16 +- .../kernels/funcs}/eigen/scale.cc | 29 +- .../kernels/funcs}/eigen/scale.cu | 30 +- .../kernels/funcs}/eigen/sign.cc | 15 +- .../kernels/funcs}/eigen/sign.cu | 18 +- .../kernels/funcs}/eigen/slice.cc | 38 ++- .../kernels/funcs}/eigen/slice.cu | 39 ++- 36 files changed, 855 insertions(+), 606 deletions(-) delete mode 100644 paddle/fluid/operators/eigen/CMakeLists.txt rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/broadcast.cc (77%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/broadcast.cu (76%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/constant.cc (86%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/constant.cu (80%) create mode 100644 paddle/pten/kernels/funcs/eigen/eigen_function.h rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/elementwise.cc (52%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/elementwise.cu (55%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/erf.cc (71%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/erf.cu (77%) rename paddle/{fluid/platform/eigen_ext.h => pten/kernels/funcs/eigen/extensions.h} (63%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/l1_norm.cc (62%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/l1_norm.cu (65%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/loss.cc (69%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/loss.cu (69%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/pad.cc (73%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/pad.cu (68%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/reverse.cc (81%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/reverse.cu (83%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/scale.cc (67%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/scale.cu (64%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/sign.cc (77%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/sign.cu (73%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/slice.cc (72%) rename paddle/{fluid/operators => pten/kernels/funcs}/eigen/slice.cu (68%) diff --git a/paddle/fluid/framework/data_type.h b/paddle/fluid/framework/data_type.h index 791e9a83fa0..dbde9aa24ff 100644 --- a/paddle/fluid/framework/data_type.h +++ b/paddle/fluid/framework/data_type.h @@ -20,9 +20,9 @@ limitations under the License. */ #include "paddle/fluid/framework/framework.pb.h" #include "paddle/fluid/platform/bfloat16.h" #include "paddle/fluid/platform/complex.h" -#include "paddle/fluid/platform/eigen_ext.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/float16.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/operators/CMakeLists.txt b/paddle/fluid/operators/CMakeLists.txt index f8a27da00ba..d18ff6f6bfe 100644 --- a/paddle/fluid/operators/CMakeLists.txt +++ b/paddle/fluid/operators/CMakeLists.txt @@ -8,7 +8,6 @@ set(pybind_file_final ${PADDLE_BINARY_DIR}/paddle/fluid/pybind/pybind.h) file(WRITE ${pybind_file} "// Generated by the paddle/fluid/operators/CMakeLists.txt. DO NOT EDIT!\n\n") add_subdirectory(math) -add_subdirectory(eigen) add_subdirectory(controlflow) add_subdirectory(detection) add_subdirectory(elementwise) diff --git a/paddle/fluid/operators/eigen/CMakeLists.txt b/paddle/fluid/operators/eigen/CMakeLists.txt deleted file mode 100644 index 8b64e35b935..00000000000 --- a/paddle/fluid/operators/eigen/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -file(GLOB EIGEN_CC_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cc") -file(GLOB EIGEN_CU_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cu") -if(WITH_GPU) - nv_library(eigen_function SRCS ${EIGEN_CC_SOURCES} ${EIGEN_CU_SOURCES} DEPS eigen3) -elseif(WITH_ROCM) - hip_library(eigen_function SRCS ${EIGEN_CC_SOURCES} ${EIGEN_CU_SOURCES} DEPS eigen3) -else() - cc_library(eigen_function SRCS ${EIGEN_CC_SOURCES} DEPS eigen3) -endif() diff --git a/paddle/fluid/operators/eigen/eigen_function.h b/paddle/fluid/operators/eigen/eigen_function.h index 9a3be7ca439..a460e4c04c5 100644 --- a/paddle/fluid/operators/eigen/eigen_function.h +++ b/paddle/fluid/operators/eigen/eigen_function.h @@ -18,243 +18,71 @@ limitations under the License. */ #ifndef NOMINMAX #define NOMINMAX #endif -#include "unsupported/Eigen/CXX11/Tensor" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" namespace paddle { namespace operators { template -struct EigenBroadcast { - using Array = Eigen::DSizes; - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using InType32BitIndex = - Eigen::TensorMap, - Eigen::Aligned>; - using OutType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType32BitIndex = - Eigen::TensorMap, - Eigen::Aligned>; - static void Eval(const EigenDevice& dev, OutType out, InType in, - const Array& bcast); - static void Eval(const EigenDevice& dev, OutType32BitIndex out, - InType32BitIndex in, const Array& bcast); -}; +using EigenBroadcast = pten::funcs::EigenBroadcast; template -struct EigenBroadcastGrad { - using Array = Eigen::DSizes; - using Array2 = Eigen::DSizes; - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType out, InType in, - const Array& reduce_dims, const Array2& reshape_dims); -}; +using EigenBroadcastGrad = + pten::funcs::EigenBroadcastGrad; template -struct EigenConstant { - using Type = Eigen::TensorMap< - Eigen::Tensor>; - static void Eval(const EigenDevice& dev, Type out, const T value); -}; +using EigenConstant = pten::funcs::EigenConstant; template -struct EigenSign { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in); -}; +using EigenSign = pten::funcs::EigenSign; template -struct EigenReverse { - using Array = Eigen::DSizes; - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = Eigen::TensorMap< - Eigen::Tensor>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in, - const Array& reverse); -}; +using EigenReverse = pten::funcs::EigenReverse; template -struct EigenAdd { - using InType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - using OutType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in, - const T value); -}; +using EigenAdd = pten::funcs::EigenAdd; template -struct EigenSub { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType out, const InType& left, - const InType& right); -}; +using EigenSub = pten::funcs::EigenSub; template -struct EigenSlice { - using Array = Eigen::DSizes; - using Array32Bit = Eigen::DSizes; - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using InType32BitIndex = - Eigen::TensorMap, - Eigen::Aligned>; - using OutType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType32BitIndex = - Eigen::TensorMap, - Eigen::Aligned>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in, - const Array& offsets, const Array& extents); - static void Eval(const EigenDevice& dev, OutType32BitIndex out, - const InType32BitIndex& in, const Array32Bit& offsets, - const Array32Bit& extents); -}; +using EigenSlice = pten::funcs::EigenSlice; template -struct EigenPad { - using Array = std::array, Rank>; - using Array32Bit = std::array, Rank>; - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using InType32BitIndex = - Eigen::TensorMap, - Eigen::Aligned>; - using OutType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType32BitIndex = - Eigen::TensorMap, - Eigen::Aligned>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in, - const Array& padding, const T value); - static void Eval(const EigenDevice& dev, OutType32BitIndex out, - const InType32BitIndex& in, const Array32Bit& padding, - const T value); -}; +using EigenPad = pten::funcs::EigenPad; template -struct EigenScale { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in, - const T scale, const T bias, const bool bias_after_scale); -}; +using EigenScale = pten::funcs::EigenScale; template -struct EigenErf { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in); -}; +using EigenErf = pten::funcs::EigenErf; template -struct EigenErfGrad { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType din, const InType& in, - const InType& dout); -}; +using EigenErfGrad = pten::funcs::EigenErfGrad; template -struct EigenRankLoss { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType out, const InType& label, - const InType& left, const InType& right); -}; +using EigenRankLoss = pten::funcs::EigenRankLoss; template -struct EigenRankLossGrad { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void EvalLeft(const EigenDevice& dev, OutType dleft, - const InType& dout, const InType& label, - const InType& left, const InType& right); - static void EvalRight(const EigenDevice& dev, OutType dright, - const InType& dout, const InType& label, - const InType& left, const InType& right); -}; +using EigenRankLossGrad = pten::funcs::EigenRankLossGrad; template -struct EigenLogLoss { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType out, const InType& pred, - const InType& label, const T& epsilon); -}; +using EigenLogLoss = pten::funcs::EigenLogLoss; template -struct EigenLogLossGrad { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType dpred, const InType& dloss, - const InType& pred, const InType& label, const T& epsilon); -}; +using EigenLogLossGrad = pten::funcs::EigenLogLossGrad; template -struct EigenHingeLoss { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType loss, const InType& pred, - const InType& label); -}; +using EigenHingeLoss = pten::funcs::EigenHingeLoss; template -struct EigenHingeLossGrad { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType dpred, const InType& dloss, - const InType& pred, const InType& label); -}; +using EigenHingeLossGrad = pten::funcs::EigenHingeLossGrad; template -struct EigenL1Norm { - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - static void Eval(const EigenDevice& dev, OutType out, const InType& in); -}; +using EigenL1Norm = pten::funcs::EigenL1Norm; template -struct EigenL1NormGrad { - using Array = Eigen::DSizes; - using InType = Eigen::TensorMap< - Eigen::Tensor>; - using OutType = - Eigen::TensorMap>; - static void Eval(const EigenDevice& dev, OutType din, const InType& dout, - const InType& in, const Array& bcast); -}; +using EigenL1NormGrad = pten::funcs::EigenL1NormGrad; } // namespace operators } // namespace paddle diff --git a/paddle/fluid/operators/kernel_primitives/functor_primitives.h b/paddle/fluid/operators/kernel_primitives/functor_primitives.h index 5e3c1fc202d..03610d45890 100644 --- a/paddle/fluid/operators/kernel_primitives/functor_primitives.h +++ b/paddle/fluid/operators/kernel_primitives/functor_primitives.h @@ -15,9 +15,9 @@ #pragma once #include "paddle/fluid/operators/amp/fp16_type_traits.h" -#include "paddle/fluid/platform/eigen_ext.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/float16.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/operators/optimizers/lamb_op.h b/paddle/fluid/operators/optimizers/lamb_op.h index 6d98522d752..9a3eaa66caa 100644 --- a/paddle/fluid/operators/optimizers/lamb_op.h +++ b/paddle/fluid/operators/optimizers/lamb_op.h @@ -22,8 +22,8 @@ limitations under the License. */ #include "paddle/fluid/operators/math/algorithm.h" #include "paddle/fluid/operators/math/selected_rows_functor.h" #include "paddle/fluid/operators/math/squared_l2_norm.h" -#include "paddle/fluid/platform/eigen_ext.h" #include "paddle/fluid/platform/for_range.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/platform/bfloat16_test.cc b/paddle/fluid/platform/bfloat16_test.cc index dc2d3aa73ba..cac9767dc29 100644 --- a/paddle/fluid/platform/bfloat16_test.cc +++ b/paddle/fluid/platform/bfloat16_test.cc @@ -10,7 +10,7 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "paddle/fluid/platform/bfloat16.h" -#include "paddle/fluid/platform/eigen_ext.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" #define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h #include "gtest/gtest.h" diff --git a/paddle/fluid/platform/complex_test.cc b/paddle/fluid/platform/complex_test.cc index 4d13161e94f..05171495a88 100644 --- a/paddle/fluid/platform/complex_test.cc +++ b/paddle/fluid/platform/complex_test.cc @@ -14,7 +14,7 @@ #include "paddle/fluid/platform/complex.h" #include -#include "paddle/fluid/platform/eigen_ext.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" #define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h #include "gtest/gtest.h" @@ -267,56 +267,56 @@ TEST(complex, print) { TEST(complex, isinf) { // *********** complex ************* complex a; - a.real = float(INFINITY); + a.real = static_cast(INFINITY); EXPECT_EQ(std::isinf(a), true); - a.imag = float(INFINITY); + a.imag = static_cast(INFINITY); EXPECT_EQ(std::isinf(a), true); - complex b = float(INFINITY); + complex b = static_cast(INFINITY); EXPECT_EQ(std::isinf(b), true); - complex c(float(INFINITY), 0); + complex c(static_cast(INFINITY), 0); EXPECT_EQ(std::isinf(c), true); // *********** complex ************* complex a1; - a1.real = double(INFINITY); + a1.real = static_cast(INFINITY); EXPECT_EQ(std::isinf(a1), true); - a1.imag = double(INFINITY); + a1.imag = static_cast(INFINITY); EXPECT_EQ(std::isinf(a1), true); - complex b1 = double(INFINITY); + complex b1 = static_cast(INFINITY); EXPECT_EQ(std::isinf(b1), true); - complex c1(double(INFINITY), 0); + complex c1(static_cast(INFINITY), 0); EXPECT_EQ(std::isinf(c1), true); } TEST(complex, isnan) { // *********** complex ************* complex a; - a.real = float(NAN); + a.real = static_cast(NAN); EXPECT_EQ(std::isnan(a), true); - a.imag = float(NAN); + a.imag = static_cast(NAN); EXPECT_EQ(std::isnan(a), true); - complex b = float(NAN); + complex b = static_cast(NAN); EXPECT_EQ(std::isnan(b), true); - complex c(float(NAN), 0); + complex c(static_cast(NAN), 0); EXPECT_EQ(std::isnan(c), true); // *********** complex ************* complex a1; - a1.real = double(NAN); + a1.real = static_cast(NAN); EXPECT_EQ(std::isnan(a1), true); - a1.imag = double(NAN); + a1.imag = static_cast(NAN); EXPECT_EQ(std::isnan(a1), true); - complex b1 = double(NAN); + complex b1 = static_cast(NAN); EXPECT_EQ(std::isnan(b1), true); - complex c1(double(NAN), 0); + complex c1(static_cast(NAN), 0); EXPECT_EQ(std::isnan(c1), true); } diff --git a/paddle/fluid/platform/complex_test.cu b/paddle/fluid/platform/complex_test.cu index b46d1b7b271..8f1dea10446 100644 --- a/paddle/fluid/platform/complex_test.cu +++ b/paddle/fluid/platform/complex_test.cu @@ -23,8 +23,8 @@ #include "paddle/fluid/framework/lod_tensor.h" #include "paddle/fluid/framework/tensor_util.h" -#include "paddle/fluid/platform/eigen_ext.h" #include "paddle/fluid/platform/enforce.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) namespace paddle { @@ -303,59 +303,59 @@ TEST(complex, print) { TEST(complex, isinf) { // *********** complex ************* complex a; - a.real = float(INFINITY); + a.real = static_cast(INFINITY); EXPECT_EQ(std::isinf(a), true); - a.imag = float(INFINITY); + a.imag = static_cast(INFINITY); EXPECT_EQ(std::isinf(a), true); - complex b = float(INFINITY); + complex b = static_cast(INFINITY); EXPECT_EQ(std::isinf(b), true); - complex c(float(INFINITY), 0); + complex c(static_cast(INFINITY), 0); EXPECT_EQ(std::isinf(c), true); // *********** complex ************* complex a1; - a1.real = double(INFINITY); + a1.real = static_cast(INFINITY); EXPECT_EQ(std::isinf(a1), true); - a1.imag = double(INFINITY); + a1.imag = static_cast(INFINITY); EXPECT_EQ(std::isinf(a1), true); - complex b1 = double(INFINITY); + complex b1 = static_cast(INFINITY); EXPECT_EQ(std::isinf(b1), true); - complex c1(double(INFINITY), 0); + complex c1(static_cast(INFINITY), 0); EXPECT_EQ(std::isinf(c1), true); } TEST(complex, isnan) { // *********** complex ************* complex a; - a.real = float(NAN); + a.real = static_cast(NAN); EXPECT_EQ(std::isnan(a), true); - a.imag = float(NAN); + a.imag = static_cast(NAN); EXPECT_EQ(std::isnan(a), true); - complex b = float(NAN); + complex b = static_cast(NAN); EXPECT_EQ(std::isnan(b), true); - complex c(float(NAN), 0); + complex c(static_cast(NAN), 0); EXPECT_EQ(std::isnan(c), true); // *********** complex ************* complex a1; - a1.real = double(NAN); + a1.real = static_cast(NAN); EXPECT_EQ(std::isnan(a1), true); - a1.imag = double(NAN); + a1.imag = static_cast(NAN); EXPECT_EQ(std::isnan(a1), true); - complex b1 = double(NAN); + complex b1 = static_cast(NAN); EXPECT_EQ(std::isnan(b1), true); - complex c1(double(NAN), 0); + complex c1(static_cast(NAN), 0); EXPECT_EQ(std::isnan(c1), true); } } // namespace platform } // namespace paddle -#endif \ No newline at end of file +#endif diff --git a/paddle/fluid/platform/float16_test.cc b/paddle/fluid/platform/float16_test.cc index 56633a35116..b1132952e72 100644 --- a/paddle/fluid/platform/float16_test.cc +++ b/paddle/fluid/platform/float16_test.cc @@ -14,8 +14,8 @@ limitations under the License. */ #define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h #include "gtest/gtest.h" #include "paddle/fluid/framework/lod_tensor.h" -#include "paddle/fluid/platform/eigen_ext.h" #include "paddle/fluid/platform/enforce.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" namespace paddle { namespace platform { diff --git a/paddle/fluid/platform/float16_test.cu b/paddle/fluid/platform/float16_test.cu index 8be774441fe..7a047d790ab 100644 --- a/paddle/fluid/platform/float16_test.cu +++ b/paddle/fluid/platform/float16_test.cu @@ -19,8 +19,8 @@ limitations under the License. */ #include "paddle/fluid/framework/lod_tensor.h" #include "paddle/fluid/framework/tensor_util.h" -#include "paddle/fluid/platform/eigen_ext.h" #include "paddle/fluid/platform/enforce.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" #define ARITHMETIC_KERNEL(op_type, sign) \ __global__ void op_type(const half *in1, const half *in2, half *out) { \ diff --git a/paddle/pten/kernels/funcs/eigen/CMakeLists.txt b/paddle/pten/kernels/funcs/eigen/CMakeLists.txt index e69de29bb2d..8b64e35b935 100644 --- a/paddle/pten/kernels/funcs/eigen/CMakeLists.txt +++ b/paddle/pten/kernels/funcs/eigen/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB EIGEN_CC_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cc") +file(GLOB EIGEN_CU_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cu") +if(WITH_GPU) + nv_library(eigen_function SRCS ${EIGEN_CC_SOURCES} ${EIGEN_CU_SOURCES} DEPS eigen3) +elseif(WITH_ROCM) + hip_library(eigen_function SRCS ${EIGEN_CC_SOURCES} ${EIGEN_CU_SOURCES} DEPS eigen3) +else() + cc_library(eigen_function SRCS ${EIGEN_CC_SOURCES} DEPS eigen3) +endif() diff --git a/paddle/fluid/operators/eigen/broadcast.cc b/paddle/pten/kernels/funcs/eigen/broadcast.cc similarity index 77% rename from paddle/fluid/operators/eigen/broadcast.cc rename to paddle/pten/kernels/funcs/eigen/broadcast.cc index dab25f95493..8d6c6c1e82b 100644 --- a/paddle/fluid/operators/eigen/broadcast.cc +++ b/paddle/pten/kernels/funcs/eigen/broadcast.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,11 +11,11 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenBroadcast { @@ -31,13 +31,17 @@ struct EigenBroadcast { Eigen::TensorMap, Eigen::Aligned>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, InType in, + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + InType in, const Array& bcast) { out.device(dev) = in.broadcast(bcast); } - static void Eval(const Eigen::DefaultDevice& dev, OutType32BitIndex out, - InType32BitIndex in, const Array& bcast) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType32BitIndex out, + InType32BitIndex in, + const Array& bcast) { out.device(dev) = in.broadcast(bcast); } }; @@ -50,8 +54,11 @@ struct EigenBroadcastGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, InType in, - const Array& reduce_dims, const Array2& reshape_dims) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + InType in, + const Array& reduce_dims, + const Array2& reshape_dims) { out.device(dev) = in.reshape(reshape_dims).sum(reduce_dims).reshape(out.dimensions()); } @@ -65,14 +72,14 @@ struct EigenBroadcastGrad { template struct FUNCTOR; \ template struct FUNCTOR INSTANTIATION(EigenBroadcast, bool); -INSTANTIATION(EigenBroadcast, platform::float16); +INSTANTIATION(EigenBroadcast, dtype::float16); INSTANTIATION(EigenBroadcast, float); INSTANTIATION(EigenBroadcast, double); INSTANTIATION(EigenBroadcast, int); INSTANTIATION(EigenBroadcast, int64_t); INSTANTIATION(EigenBroadcastGrad, bool); INSTANTIATION(EigenBroadcastGrad, float); -INSTANTIATION(EigenBroadcastGrad, platform::float16); +INSTANTIATION(EigenBroadcastGrad, dtype::float16); INSTANTIATION(EigenBroadcastGrad, double); INSTANTIATION(EigenBroadcastGrad, int); INSTANTIATION(EigenBroadcastGrad, int64_t); @@ -82,5 +89,5 @@ template struct EigenBroadcastGrad; template struct EigenBroadcastGrad; #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/broadcast.cu b/paddle/pten/kernels/funcs/eigen/broadcast.cu similarity index 76% rename from paddle/fluid/operators/eigen/broadcast.cu rename to paddle/pten/kernels/funcs/eigen/broadcast.cu index 63e244d393a..5a9c26358a3 100644 --- a/paddle/fluid/operators/eigen/broadcast.cu +++ b/paddle/pten/kernels/funcs/eigen/broadcast.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,11 +11,11 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenBroadcast { @@ -31,13 +31,17 @@ struct EigenBroadcast { Eigen::TensorMap, Eigen::Aligned>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, InType in, + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + InType in, const Array& bcast) { out.device(dev) = in.broadcast(bcast); } - static void Eval(const Eigen::GpuDevice& dev, OutType32BitIndex out, - InType32BitIndex in, const Array& bcast) { + static void Eval(const Eigen::GpuDevice& dev, + OutType32BitIndex out, + InType32BitIndex in, + const Array& bcast) { out.device(dev) = in.broadcast(bcast); } }; @@ -50,8 +54,11 @@ struct EigenBroadcastGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, InType in, - const Array& reduce_dims, const Array2& reshape_dims) { + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + InType in, + const Array& reduce_dims, + const Array2& reshape_dims) { out.device(dev) = in.reshape(reshape_dims).sum(reduce_dims).reshape(out.dimensions()); } @@ -65,23 +72,23 @@ struct EigenBroadcastGrad { template struct FUNCTOR; \ template struct FUNCTOR INSTANTIATION(EigenBroadcast, bool); -INSTANTIATION(EigenBroadcast, platform::float16); +INSTANTIATION(EigenBroadcast, dtype::float16); INSTANTIATION(EigenBroadcast, float); INSTANTIATION(EigenBroadcast, double); INSTANTIATION(EigenBroadcast, int); INSTANTIATION(EigenBroadcast, int64_t); INSTANTIATION(EigenBroadcastGrad, bool); INSTANTIATION(EigenBroadcastGrad, float); -INSTANTIATION(EigenBroadcastGrad, platform::float16); +INSTANTIATION(EigenBroadcastGrad, dtype::float16); INSTANTIATION(EigenBroadcastGrad, double); INSTANTIATION(EigenBroadcastGrad, int); INSTANTIATION(EigenBroadcastGrad, int64_t); template struct EigenBroadcastGrad; -template struct EigenBroadcastGrad; +template struct EigenBroadcastGrad; template struct EigenBroadcastGrad; template struct EigenBroadcastGrad; template struct EigenBroadcastGrad; #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/constant.cc b/paddle/pten/kernels/funcs/eigen/constant.cc similarity index 86% rename from paddle/fluid/operators/eigen/constant.cc rename to paddle/pten/kernels/funcs/eigen/constant.cc index 45b03ccbf10..5eb25f9bb9a 100644 --- a/paddle/fluid/operators/eigen/constant.cc +++ b/paddle/pten/kernels/funcs/eigen/constant.cc @@ -11,10 +11,10 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenConstant { @@ -27,5 +27,5 @@ struct EigenConstant { template struct EigenConstant; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/constant.cu b/paddle/pten/kernels/funcs/eigen/constant.cu similarity index 80% rename from paddle/fluid/operators/eigen/constant.cu rename to paddle/pten/kernels/funcs/eigen/constant.cu index cf4a2917f7d..c33da70e6a0 100644 --- a/paddle/fluid/operators/eigen/constant.cu +++ b/paddle/pten/kernels/funcs/eigen/constant.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,10 +11,10 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenConstant { @@ -27,5 +27,5 @@ struct EigenConstant { template struct EigenConstant; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/pten/kernels/funcs/eigen/eigen_function.h b/paddle/pten/kernels/funcs/eigen/eigen_function.h new file mode 100644 index 00000000000..75ba543dd9c --- /dev/null +++ b/paddle/pten/kernels/funcs/eigen/eigen_function.h @@ -0,0 +1,319 @@ +/* Copyright (c) 2022 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 +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include "unsupported/Eigen/CXX11/Tensor" + +namespace pten { +namespace funcs { + +template +struct EigenBroadcast { + using Array = Eigen::DSizes; + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using InType32BitIndex = + Eigen::TensorMap, + Eigen::Aligned>; + using OutType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType32BitIndex = + Eigen::TensorMap, + Eigen::Aligned>; + static void Eval(const EigenDevice& dev, + OutType out, + InType in, + const Array& bcast); + static void Eval(const EigenDevice& dev, + OutType32BitIndex out, + InType32BitIndex in, + const Array& bcast); +}; + +template +struct EigenBroadcastGrad { + using Array = Eigen::DSizes; + using Array2 = Eigen::DSizes; + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType out, + InType in, + const Array& reduce_dims, + const Array2& reshape_dims); +}; + +template +struct EigenConstant { + using Type = Eigen::TensorMap< + Eigen::Tensor>; + static void Eval(const EigenDevice& dev, Type out, const T value); +}; + +template +struct EigenSign { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, OutType out, const InType& in); +}; + +template +struct EigenReverse { + using Array = Eigen::DSizes; + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = Eigen::TensorMap< + Eigen::Tensor>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& in, + const Array& reverse); +}; + +template +struct EigenAdd { + using InType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + using OutType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& in, + const T value); +}; + +template +struct EigenSub { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& left, + const InType& right); +}; + +template +struct EigenSlice { + using Array = Eigen::DSizes; + using Array32Bit = Eigen::DSizes; + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using InType32BitIndex = + Eigen::TensorMap, + Eigen::Aligned>; + using OutType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType32BitIndex = + Eigen::TensorMap, + Eigen::Aligned>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& in, + const Array& offsets, + const Array& extents); + static void Eval(const EigenDevice& dev, + OutType32BitIndex out, + const InType32BitIndex& in, + const Array32Bit& offsets, + const Array32Bit& extents); +}; + +template +struct EigenPad { + using Array = std::array, Rank>; + using Array32Bit = std::array, Rank>; + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using InType32BitIndex = + Eigen::TensorMap, + Eigen::Aligned>; + using OutType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType32BitIndex = + Eigen::TensorMap, + Eigen::Aligned>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& in, + const Array& padding, + const T value); + static void Eval(const EigenDevice& dev, + OutType32BitIndex out, + const InType32BitIndex& in, + const Array32Bit& padding, + const T value); +}; + +template +struct EigenScale { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& in, + const T scale, + const T bias, + const bool bias_after_scale); +}; + +template +struct EigenErf { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, OutType out, const InType& in); +}; + +template +struct EigenErfGrad { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType din, + const InType& in, + const InType& dout); +}; + +template +struct EigenRankLoss { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& label, + const InType& left, + const InType& right); +}; + +template +struct EigenRankLossGrad { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void EvalLeft(const EigenDevice& dev, + OutType dleft, + const InType& dout, + const InType& label, + const InType& left, + const InType& right); + static void EvalRight(const EigenDevice& dev, + OutType dright, + const InType& dout, + const InType& label, + const InType& left, + const InType& right); +}; + +template +struct EigenLogLoss { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType out, + const InType& pred, + const InType& label, + const T& epsilon); +}; + +template +struct EigenLogLossGrad { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType dpred, + const InType& dloss, + const InType& pred, + const InType& label, + const T& epsilon); +}; + +template +struct EigenHingeLoss { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType loss, + const InType& pred, + const InType& label); +}; + +template +struct EigenHingeLossGrad { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType dpred, + const InType& dloss, + const InType& pred, + const InType& label); +}; + +template +struct EigenL1Norm { + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + static void Eval(const EigenDevice& dev, OutType out, const InType& in); +}; + +template +struct EigenL1NormGrad { + using Array = Eigen::DSizes; + using InType = Eigen::TensorMap< + Eigen::Tensor>; + using OutType = + Eigen::TensorMap>; + static void Eval(const EigenDevice& dev, + OutType din, + const InType& dout, + const InType& in, + const Array& bcast); +}; + +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/elementwise.cc b/paddle/pten/kernels/funcs/eigen/elementwise.cc similarity index 52% rename from paddle/fluid/operators/eigen/elementwise.cc rename to paddle/pten/kernels/funcs/eigen/elementwise.cc index bedecfe5c22..700bd1363c9 100644 --- a/paddle/fluid/operators/eigen/elementwise.cc +++ b/paddle/pten/kernels/funcs/eigen/elementwise.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,19 +11,25 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenAdd { - using InType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - using OutType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& in, const T value) { + using InType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + using OutType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& in, + const T value) { out.device(dev) = in + value; } }; @@ -39,13 +45,15 @@ struct EigenSub { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& left, const InType& right) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& left, + const InType& right) { out.device(dev) = left - right; } }; template struct EigenSub; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/elementwise.cu b/paddle/pten/kernels/funcs/eigen/elementwise.cu similarity index 55% rename from paddle/fluid/operators/eigen/elementwise.cu rename to paddle/pten/kernels/funcs/eigen/elementwise.cu index a750a06284f..999046b74a9 100644 --- a/paddle/fluid/operators/eigen/elementwise.cu +++ b/paddle/pten/kernels/funcs/eigen/elementwise.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,18 +11,24 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenAdd { - using InType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - using OutType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& in, + using InType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + using OutType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& in, const T value) { out.device(dev) = in + value; } @@ -39,7 +45,9 @@ struct EigenSub { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& left, + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& left, const InType& right) { out.device(dev) = left - right; } @@ -47,5 +55,5 @@ struct EigenSub { template struct EigenSub; -} // namespace operators -} // namespace paddle +} // namespace fucns +} // namespace pten diff --git a/paddle/fluid/operators/eigen/erf.cc b/paddle/pten/kernels/funcs/eigen/erf.cc similarity index 71% rename from paddle/fluid/operators/eigen/erf.cc rename to paddle/pten/kernels/funcs/eigen/erf.cc index 6c2c734c977..1ebb9f84846 100644 --- a/paddle/fluid/operators/eigen/erf.cc +++ b/paddle/pten/kernels/funcs/eigen/erf.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,12 +11,12 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/eigen_ext.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenErf { @@ -24,7 +24,8 @@ struct EigenErf { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, const InType& in) { out.device(dev) = in.erf(); } @@ -36,8 +37,10 @@ struct EigenErfGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType din, - const InType& in, const InType& dout) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType din, + const InType& in, + const InType& dout) { din.device(dev) = dout * static_cast(M_2_SQRTPI) * (-(in.square())).exp(); } @@ -46,10 +49,10 @@ struct EigenErfGrad { #define INSTANTIATION(FUNCTOR) \ template struct FUNCTOR; \ template struct FUNCTOR; \ - template struct FUNCTOR + template struct FUNCTOR INSTANTIATION(EigenErf); INSTANTIATION(EigenErfGrad); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/erf.cu b/paddle/pten/kernels/funcs/eigen/erf.cu similarity index 77% rename from paddle/fluid/operators/eigen/erf.cu rename to paddle/pten/kernels/funcs/eigen/erf.cu index 632205bdcbf..1971f5abbce 100644 --- a/paddle/fluid/operators/eigen/erf.cu +++ b/paddle/pten/kernels/funcs/eigen/erf.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -14,12 +14,12 @@ limitations under the License. */ #ifndef _USE_MATH_DEFINES #define _USE_MATH_DEFINES #endif -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/eigen_ext.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenErf { @@ -38,7 +38,9 @@ struct EigenErfGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType din, const InType& in, + static void Eval(const Eigen::GpuDevice& dev, + OutType din, + const InType& in, const InType& dout) { din.device(dev) = dout * static_cast(M_2_SQRTPI) * (-(in.square())).exp(); @@ -48,10 +50,10 @@ struct EigenErfGrad { #define INSTANTIATION(FUNCTOR) \ template struct FUNCTOR; \ template struct FUNCTOR; \ - template struct FUNCTOR + template struct FUNCTOR INSTANTIATION(EigenErf); INSTANTIATION(EigenErfGrad); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/platform/eigen_ext.h b/paddle/pten/kernels/funcs/eigen/extensions.h similarity index 63% rename from paddle/fluid/platform/eigen_ext.h rename to paddle/pten/kernels/funcs/eigen/extensions.h index 872a6cf062e..a67b3268f09 100644 --- a/paddle/fluid/platform/eigen_ext.h +++ b/paddle/pten/kernels/funcs/eigen/extensions.h @@ -1,4 +1,4 @@ -// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +// Copyright (c) 2022 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. @@ -14,25 +14,25 @@ #pragma once -#include "paddle/fluid/platform/bfloat16.h" -#include "paddle/fluid/platform/complex.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/bfloat16.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/common/float16.h" #include "paddle/pten/core/hostdevice.h" #include "unsupported/Eigen/CXX11/Tensor" namespace Eigen { -using float16 = paddle::platform::float16; +using float16 = pten::dtype::float16; template -using complex = paddle::platform::complex; +using complex = pten::dtype::complex; template struct NumTraits; template <> -struct NumTraits - : GenericNumTraits { +struct NumTraits + : GenericNumTraits { enum { IsSigned = true, IsInteger = false, @@ -40,23 +40,23 @@ struct NumTraits RequireInitialization = false }; - HOSTDEVICE static inline paddle::platform::bfloat16 epsilon() { - return paddle::platform::raw_uint16_to_bfloat16(0x3400); + HOSTDEVICE static inline pten::dtype::bfloat16 epsilon() { + return pten::dtype::raw_uint16_to_bfloat16(0x3400); } - HOSTDEVICE static inline paddle::platform::bfloat16 dummy_precision() { - return paddle::platform::bfloat16(1e-5f); + HOSTDEVICE static inline pten::dtype::bfloat16 dummy_precision() { + return pten::dtype::bfloat16(1e-5f); } - HOSTDEVICE static inline paddle::platform::bfloat16 highest() { - return paddle::platform::raw_uint16_to_bfloat16(0x7f7f); + HOSTDEVICE static inline pten::dtype::bfloat16 highest() { + return pten::dtype::raw_uint16_to_bfloat16(0x7f7f); } - HOSTDEVICE static inline paddle::platform::bfloat16 lowest() { - return paddle::platform::raw_uint16_to_bfloat16(0xff7f); + HOSTDEVICE static inline pten::dtype::bfloat16 lowest() { + return pten::dtype::raw_uint16_to_bfloat16(0xff7f); } - HOSTDEVICE static inline paddle::platform::bfloat16 infinity() { - return paddle::platform::raw_uint16_to_bfloat16(0x7f80); + HOSTDEVICE static inline pten::dtype::bfloat16 infinity() { + return pten::dtype::raw_uint16_to_bfloat16(0x7f80); } - HOSTDEVICE static inline paddle::platform::bfloat16 quiet_NaN() { - return paddle::platform::raw_uint16_to_bfloat16(0xffc1); + HOSTDEVICE static inline pten::dtype::bfloat16 quiet_NaN() { + return pten::dtype::raw_uint16_to_bfloat16(0xffc1); } }; @@ -114,20 +114,20 @@ struct NumTraits : GenericNumTraits { }; HOSTDEVICE static inline float16 epsilon() { - return paddle::platform::raw_uint16_to_float16(0x0800); + return pten::dtype::raw_uint16_to_float16(0x0800); } HOSTDEVICE static inline float16 dummy_precision() { return float16(1e-2f); } HOSTDEVICE static inline float16 highest() { - return paddle::platform::raw_uint16_to_float16(0x7bff); + return pten::dtype::raw_uint16_to_float16(0x7bff); } HOSTDEVICE static inline float16 lowest() { - return paddle::platform::raw_uint16_to_float16(0xfbff); + return pten::dtype::raw_uint16_to_float16(0xfbff); } HOSTDEVICE static inline float16 infinity() { - return paddle::platform::raw_uint16_to_float16(0x7c00); + return pten::dtype::raw_uint16_to_float16(0x7c00); } HOSTDEVICE static inline float16 quiet_NaN() { - return paddle::platform::raw_uint16_to_float16(0x7c01); + return pten::dtype::raw_uint16_to_float16(0x7c01); } }; @@ -136,96 +136,86 @@ namespace numext { //////////// bfloat methods ///////////// template <> -HOSTDEVICE inline bool(isnan)(const paddle::platform::bfloat16& a) { - return (paddle::platform::isnan)(a); +HOSTDEVICE inline bool(isnan)(const pten::dtype::bfloat16& a) { + return (pten::dtype::isnan)(a); } template <> -HOSTDEVICE inline bool(isinf)(const paddle::platform::bfloat16& a) { - return (paddle::platform::isinf)(a); +HOSTDEVICE inline bool(isinf)(const pten::dtype::bfloat16& a) { + return (pten::dtype::isinf)(a); } template <> -HOSTDEVICE inline bool(isfinite)(const paddle::platform::bfloat16& a) { - return (paddle::platform::isfinite)(a); +HOSTDEVICE inline bool(isfinite)(const pten::dtype::bfloat16& a) { + return (pten::dtype::isfinite)(a); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 exp( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::expf(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 exp(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::expf(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 expm1( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::expm1f(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 expm1(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::expm1f(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 erf( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::erff(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 erf(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::erff(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 log( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::logf(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 log(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::logf(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 tanh( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::tanhf(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 tanh(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::tanhf(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 sqrt( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::sqrtf(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 sqrt(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::sqrtf(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 ceil( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::ceilf(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 ceil(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::ceilf(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 floor( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::floorf(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 floor(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::floorf(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 round( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::roundf(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 round(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::roundf(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 pow( - const paddle::platform::bfloat16& a, const paddle::platform::bfloat16& b) { - return paddle::platform::bfloat16( +HOSTDEVICE inline pten::dtype::bfloat16 pow(const pten::dtype::bfloat16& a, + const pten::dtype::bfloat16& b) { + return pten::dtype::bfloat16( ::powf(static_cast(a), static_cast(b))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 abs( - const paddle::platform::bfloat16& a) { - return paddle::platform::bfloat16(::fabs(static_cast(a))); +HOSTDEVICE inline pten::dtype::bfloat16 abs(const pten::dtype::bfloat16& a) { + return pten::dtype::bfloat16(::fabs(static_cast(a))); } template <> -HOSTDEVICE inline paddle::platform::bfloat16 mini( - const paddle::platform::bfloat16& a, const paddle::platform::bfloat16& b) { +HOSTDEVICE inline pten::dtype::bfloat16 mini(const pten::dtype::bfloat16& a, + const pten::dtype::bfloat16& b) { return b < a ? b : a; } template <> -HOSTDEVICE inline paddle::platform::bfloat16 maxi( - const paddle::platform::bfloat16& a, const paddle::platform::bfloat16& b) { +HOSTDEVICE inline pten::dtype::bfloat16 maxi(const pten::dtype::bfloat16& a, + const pten::dtype::bfloat16& b) { return a < b ? b : a; } @@ -233,17 +223,17 @@ HOSTDEVICE inline paddle::platform::bfloat16 maxi( template <> HOSTDEVICE inline bool(isnan)(const complex& a) { - return (paddle::platform::isnan)(a); + return (pten::dtype::isnan)(a); } template <> HOSTDEVICE inline bool(isinf)(const complex& a) { - return (paddle::platform::isinf)(a); + return (pten::dtype::isinf)(a); } template <> HOSTDEVICE inline bool(isfinite)(const complex& a) { - return (paddle::platform::isfinite)(a); + return (pten::dtype::isfinite)(a); } template <> @@ -256,17 +246,17 @@ HOSTDEVICE inline complex exp(const complex& a) { template <> HOSTDEVICE inline complex log(const complex& a) { - return paddle::platform::log(a); + return pten::dtype::log(a); } template <> HOSTDEVICE inline complex tanh(const complex& a) { - return paddle::platform::tanh(a); + return pten::dtype::tanh(a); } template <> HOSTDEVICE inline complex sqrt(const complex& a) { - return paddle::platform::sqrt(a); + return pten::dtype::sqrt(a); } template <> @@ -287,29 +277,29 @@ HOSTDEVICE inline complex round(const complex& a) { template <> HOSTDEVICE inline complex pow(const complex& a, const complex& b) { - return paddle::platform::pow(a, b); + return pten::dtype::pow(a, b); } template <> HOSTDEVICE inline float abs(const complex& a) { - return paddle::platform::abs(a); + return pten::dtype::abs(a); } //////////// complex methods ///////////// template <> HOSTDEVICE inline bool(isnan)(const complex& a) { - return (paddle::platform::isnan)(a); + return (pten::dtype::isnan)(a); } template <> HOSTDEVICE inline bool(isinf)(const complex& a) { - return (paddle::platform::isinf)(a); + return (pten::dtype::isinf)(a); } template <> HOSTDEVICE inline bool(isfinite)(const complex& a) { - return (paddle::platform::isfinite)(a); + return (pten::dtype::isfinite)(a); } template <> @@ -322,17 +312,17 @@ HOSTDEVICE inline complex exp(const complex& a) { template <> HOSTDEVICE inline complex log(const complex& a) { - return paddle::platform::log(a); + return pten::dtype::log(a); } template <> HOSTDEVICE inline complex tanh(const complex& a) { - return paddle::platform::tanh(a); + return pten::dtype::tanh(a); } template <> HOSTDEVICE inline complex sqrt(const complex& a) { - return paddle::platform::sqrt(a); + return pten::dtype::sqrt(a); } template <> @@ -353,29 +343,29 @@ HOSTDEVICE inline complex round(const complex& a) { template <> HOSTDEVICE inline complex pow(const complex& a, const complex& b) { - return paddle::platform::pow(a, b); + return pten::dtype::pow(a, b); } template <> HOSTDEVICE inline double abs(const complex& a) { - return paddle::platform::abs(a); + return pten::dtype::abs(a); } //////////// float16 methods ///////////// template <> HOSTDEVICE inline bool(isnan)(const float16& a) { - return (paddle::platform::isnan)(a); + return (pten::dtype::isnan)(a); } template <> HOSTDEVICE inline bool(isinf)(const float16& a) { - return (paddle::platform::isinf)(a); + return (pten::dtype::isinf)(a); } template <> HOSTDEVICE inline bool(isfinite)(const float16& a) { - return (paddle::platform::isfinite)(a); + return (pten::dtype::isfinite)(a); } template <> diff --git a/paddle/fluid/operators/eigen/l1_norm.cc b/paddle/pten/kernels/funcs/eigen/l1_norm.cc similarity index 62% rename from paddle/fluid/operators/eigen/l1_norm.cc rename to paddle/pten/kernels/funcs/eigen/l1_norm.cc index e7ed60f7666..37d06b7879f 100644 --- a/paddle/fluid/operators/eigen/l1_norm.cc +++ b/paddle/pten/kernels/funcs/eigen/l1_norm.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,18 +11,21 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenL1Norm { using InType = Eigen::TensorMap< Eigen::Tensor>; - using OutType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, + using OutType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, const InType& in) { out.device(dev) = in.abs().sum(); } @@ -35,8 +38,11 @@ struct EigenL1NormGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType din, - const InType& dout, const InType& in, const Array& bcast) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType din, + const InType& dout, + const InType& in, + const Array& bcast) { din.device(dev) = dout.broadcast(bcast) * in.sign(); } }; @@ -44,5 +50,5 @@ struct EigenL1NormGrad { template struct EigenL1Norm; template struct EigenL1NormGrad; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/l1_norm.cu b/paddle/pten/kernels/funcs/eigen/l1_norm.cu similarity index 65% rename from paddle/fluid/operators/eigen/l1_norm.cu rename to paddle/pten/kernels/funcs/eigen/l1_norm.cu index a27cd7ae6b7..00156597dc5 100644 --- a/paddle/fluid/operators/eigen/l1_norm.cu +++ b/paddle/pten/kernels/funcs/eigen/l1_norm.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,17 +11,19 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenL1Norm { using InType = Eigen::TensorMap< Eigen::Tensor>; - using OutType = Eigen::TensorMap, Eigen::RowMajor, Eigen::DenseIndex>>; + using OutType = Eigen::TensorMap, + Eigen::RowMajor, + Eigen::DenseIndex>>; static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& in) { out.device(dev) = in.abs().sum(); } @@ -34,8 +36,11 @@ struct EigenL1NormGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType din, const InType& dout, - const InType& in, const Array& bcast) { + static void Eval(const Eigen::GpuDevice& dev, + OutType din, + const InType& dout, + const InType& in, + const Array& bcast) { din.device(dev) = dout.broadcast(bcast) * in.sign(); } }; @@ -43,5 +48,5 @@ struct EigenL1NormGrad { template struct EigenL1Norm; template struct EigenL1NormGrad; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/loss.cc b/paddle/pten/kernels/funcs/eigen/loss.cc similarity index 69% rename from paddle/fluid/operators/eigen/loss.cc rename to paddle/pten/kernels/funcs/eigen/loss.cc index 469456537d9..2a762fadd81 100644 --- a/paddle/fluid/operators/eigen/loss.cc +++ b/paddle/pten/kernels/funcs/eigen/loss.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,10 +11,10 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenRankLoss { @@ -22,8 +22,10 @@ struct EigenRankLoss { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& label, const InType& left, + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& label, + const InType& left, const InType& right) { out.device(dev) = (1.0f + (left - right).exp()).log() - label * (left - right); @@ -37,15 +39,21 @@ struct EigenRankLossGrad { using OutType = Eigen::TensorMap>; - static void EvalLeft(const Eigen::DefaultDevice& dev, OutType dleft, - const InType& dout, const InType& label, - const InType& left, const InType& right) { + static void EvalLeft(const Eigen::DefaultDevice& dev, + OutType dleft, + const InType& dout, + const InType& label, + const InType& left, + const InType& right) { dleft.device(dev) = dout * (1.0f / (1.0f + (right - left).exp()) - label); } - static void EvalRight(const Eigen::DefaultDevice& dev, OutType dright, - const InType& dout, const InType& label, - const InType& left, const InType& right) { + static void EvalRight(const Eigen::DefaultDevice& dev, + OutType dright, + const InType& dout, + const InType& label, + const InType& left, + const InType& right) { dright.device(dev) = -dout * (1.0f / (1.0f + (right - left).exp()) - label); } }; @@ -59,8 +67,11 @@ struct EigenLogLoss { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& pred, const InType& label, const T& epsilon) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& pred, + const InType& label, + const T& epsilon) { out.device(dev) = (-(label * (pred + epsilon).log()) - ((static_cast(1) - label) * (static_cast(1) - pred + epsilon).log())); @@ -73,8 +84,11 @@ struct EigenLogLossGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType dpred, - const InType& dloss, const InType& pred, const InType& label, + static void Eval(const Eigen::DefaultDevice& dev, + OutType dpred, + const InType& dloss, + const InType& pred, + const InType& label, const T& epsilon) { dpred.device(dev) = dloss * @@ -92,8 +106,10 @@ struct EigenHingeLoss { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType loss, - const InType& pred, const InType& label) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType loss, + const InType& pred, + const InType& label) { loss.device(dev) = (static_cast(1) - pred * (static_cast(2) * label - static_cast(1))) .cwiseMax(static_cast(0)); @@ -106,8 +122,10 @@ struct EigenHingeLossGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType dpred, - const InType& dloss, const InType& pred, + static void Eval(const Eigen::DefaultDevice& dev, + OutType dpred, + const InType& dloss, + const InType& pred, const InType& label) { auto alt_labels = static_cast(2) * label - static_cast(1); dpred.device(dev) = @@ -119,5 +137,5 @@ struct EigenHingeLossGrad { template struct EigenHingeLoss; template struct EigenHingeLossGrad; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/loss.cu b/paddle/pten/kernels/funcs/eigen/loss.cu similarity index 69% rename from paddle/fluid/operators/eigen/loss.cu rename to paddle/pten/kernels/funcs/eigen/loss.cu index 02341202a2b..484bae4c224 100644 --- a/paddle/fluid/operators/eigen/loss.cu +++ b/paddle/pten/kernels/funcs/eigen/loss.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,10 +11,10 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenRankLoss { @@ -22,8 +22,10 @@ struct EigenRankLoss { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, - const InType& label, const InType& left, + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& label, + const InType& left, const InType& right) { out.device(dev) = (1.0f + (left - right).exp()).log() - label * (left - right); @@ -37,15 +39,21 @@ struct EigenRankLossGrad { using OutType = Eigen::TensorMap>; - static void EvalLeft(const Eigen::GpuDevice& dev, OutType dleft, - const InType& dout, const InType& label, - const InType& left, const InType& right) { + static void EvalLeft(const Eigen::GpuDevice& dev, + OutType dleft, + const InType& dout, + const InType& label, + const InType& left, + const InType& right) { dleft.device(dev) = dout * (1.0f / (1.0f + (right - left).exp()) - label); } - static void EvalRight(const Eigen::GpuDevice& dev, OutType dright, - const InType& dout, const InType& label, - const InType& left, const InType& right) { + static void EvalRight(const Eigen::GpuDevice& dev, + OutType dright, + const InType& dout, + const InType& label, + const InType& left, + const InType& right) { dright.device(dev) = -dout * (1.0f / (1.0f + (right - left).exp()) - label); } }; @@ -59,8 +67,11 @@ struct EigenLogLoss { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& pred, - const InType& label, const T& epsilon) { + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& pred, + const InType& label, + const T& epsilon) { out.device(dev) = (-(label * (pred + epsilon).log()) - ((static_cast(1) - label) * (static_cast(1) - pred + epsilon).log())); @@ -73,8 +84,11 @@ struct EigenLogLossGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType dpred, - const InType& dloss, const InType& pred, const InType& label, + static void Eval(const Eigen::GpuDevice& dev, + OutType dpred, + const InType& dloss, + const InType& pred, + const InType& label, const T& epsilon) { dpred.device(dev) = dloss * @@ -92,8 +106,10 @@ struct EigenHingeLoss { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType loss, - const InType& pred, const InType& label) { + static void Eval(const Eigen::GpuDevice& dev, + OutType loss, + const InType& pred, + const InType& label) { loss.device(dev) = (static_cast(1) - pred * (static_cast(2) * label - static_cast(1))) .cwiseMax(static_cast(0)); @@ -106,8 +122,10 @@ struct EigenHingeLossGrad { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType dpred, - const InType& dloss, const InType& pred, + static void Eval(const Eigen::GpuDevice& dev, + OutType dpred, + const InType& dloss, + const InType& pred, const InType& label) { auto alt_labels = static_cast(2) * label - static_cast(1); dpred.device(dev) = @@ -119,5 +137,5 @@ struct EigenHingeLossGrad { template struct EigenHingeLoss; template struct EigenHingeLossGrad; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/pad.cc b/paddle/pten/kernels/funcs/eigen/pad.cc similarity index 73% rename from paddle/fluid/operators/eigen/pad.cc rename to paddle/pten/kernels/funcs/eigen/pad.cc index 9db4571357a..ed4b1c0643a 100644 --- a/paddle/fluid/operators/eigen/pad.cc +++ b/paddle/pten/kernels/funcs/eigen/pad.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,11 +11,11 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/complex.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenPad { @@ -32,13 +32,18 @@ struct EigenPad { Eigen::TensorMap, Eigen::Aligned>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& in, const Array& padding, const T value) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& in, + const Array& padding, + const T value) { out.device(dev) = in.pad(padding, value); } - static void Eval(const Eigen::DefaultDevice& dev, OutType32BitIndex out, - const InType32BitIndex& in, const Array32Bit& padding, + static void Eval(const Eigen::DefaultDevice& dev, + OutType32BitIndex out, + const InType32BitIndex& in, + const Array32Bit& padding, const T value) { out.device(dev) = in.pad(padding, value); } @@ -56,9 +61,9 @@ INSTANTIATION(EigenPad, int); INSTANTIATION(EigenPad, int64_t); INSTANTIATION(EigenPad, float); INSTANTIATION(EigenPad, double); -INSTANTIATION(EigenPad, platform::complex); -INSTANTIATION(EigenPad, platform::complex); +INSTANTIATION(EigenPad, dtype::complex); +INSTANTIATION(EigenPad, dtype::complex); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/pad.cu b/paddle/pten/kernels/funcs/eigen/pad.cu similarity index 68% rename from paddle/fluid/operators/eigen/pad.cu rename to paddle/pten/kernels/funcs/eigen/pad.cu index e028a8aef18..6d40adce877 100644 --- a/paddle/fluid/operators/eigen/pad.cu +++ b/paddle/pten/kernels/funcs/eigen/pad.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,13 +11,13 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/bfloat16.h" -#include "paddle/fluid/platform/complex.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/bfloat16.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenPad { @@ -34,13 +34,18 @@ struct EigenPad { Eigen::TensorMap, Eigen::Aligned>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& in, - const Array& padding, const T value) { + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& in, + const Array& padding, + const T value) { out.device(dev) = in.pad(padding, value); } - static void Eval(const Eigen::GpuDevice& dev, OutType32BitIndex out, - const InType32BitIndex& in, const Array32Bit& padding, + static void Eval(const Eigen::GpuDevice& dev, + OutType32BitIndex out, + const InType32BitIndex& in, + const Array32Bit& padding, const T value) { out.device(dev) = in.pad(padding, value); } @@ -58,11 +63,11 @@ INSTANTIATION(EigenPad, int); INSTANTIATION(EigenPad, int64_t); INSTANTIATION(EigenPad, float); INSTANTIATION(EigenPad, double); -INSTANTIATION(EigenPad, platform::float16); -INSTANTIATION(EigenPad, platform::bfloat16); -INSTANTIATION(EigenPad, platform::complex); -INSTANTIATION(EigenPad, platform::complex); +INSTANTIATION(EigenPad, dtype::float16); +INSTANTIATION(EigenPad, dtype::bfloat16); +INSTANTIATION(EigenPad, dtype::complex); +INSTANTIATION(EigenPad, dtype::complex); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/reverse.cc b/paddle/pten/kernels/funcs/eigen/reverse.cc similarity index 81% rename from paddle/fluid/operators/eigen/reverse.cc rename to paddle/pten/kernels/funcs/eigen/reverse.cc index 02044479db9..9e77ae4fba5 100644 --- a/paddle/fluid/operators/eigen/reverse.cc +++ b/paddle/pten/kernels/funcs/eigen/reverse.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,10 +11,10 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenReverse { @@ -23,8 +23,10 @@ struct EigenReverse { Eigen::Tensor>; using OutType = Eigen::TensorMap< Eigen::Tensor>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& in, const Array& reverse) { + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& in, + const Array& reverse) { out.device(dev) = in.reverse(reverse); } }; @@ -44,5 +46,5 @@ INSTANTIATION(EigenReverse, float); INSTANTIATION(EigenReverse, double); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/reverse.cu b/paddle/pten/kernels/funcs/eigen/reverse.cu similarity index 83% rename from paddle/fluid/operators/eigen/reverse.cu rename to paddle/pten/kernels/funcs/eigen/reverse.cu index 9b769489ce7..fc6c3b29ab8 100644 --- a/paddle/fluid/operators/eigen/reverse.cu +++ b/paddle/pten/kernels/funcs/eigen/reverse.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,10 +11,10 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenReverse { @@ -23,7 +23,9 @@ struct EigenReverse { Eigen::Tensor>; using OutType = Eigen::TensorMap< Eigen::Tensor>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& in, + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& in, const Array& reverse) { out.device(dev) = in.reverse(reverse); } @@ -44,5 +46,5 @@ INSTANTIATION(EigenReverse, float); INSTANTIATION(EigenReverse, double); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/scale.cc b/paddle/pten/kernels/funcs/eigen/scale.cc similarity index 67% rename from paddle/fluid/operators/eigen/scale.cc rename to paddle/pten/kernels/funcs/eigen/scale.cc index d9fbb878e35..cd34cd6e700 100644 --- a/paddle/fluid/operators/eigen/scale.cc +++ b/paddle/pten/kernels/funcs/eigen/scale.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,12 +11,12 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/bfloat16.h" -#include "paddle/fluid/platform/complex.h" +#include "paddle/pten/common/bfloat16.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenScale { @@ -24,8 +24,11 @@ struct EigenScale { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& in, const T scale, const T bias, + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& in, + const T scale, + const T bias, const bool bias_after_scale) { if (bias_after_scale) { out.device(dev) = scale * in + bias; @@ -37,14 +40,14 @@ struct EigenScale { template struct EigenScale; template struct EigenScale; -template struct EigenScale; +template struct EigenScale; template struct EigenScale; template struct EigenScale; template struct EigenScale; template struct EigenScale; template struct EigenScale; -template struct EigenScale>; -template struct EigenScale>; +template struct EigenScale>; +template struct EigenScale>; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/scale.cu b/paddle/pten/kernels/funcs/eigen/scale.cu similarity index 64% rename from paddle/fluid/operators/eigen/scale.cu rename to paddle/pten/kernels/funcs/eigen/scale.cu index 5e485799af5..f1cbbd6a9bc 100644 --- a/paddle/fluid/operators/eigen/scale.cu +++ b/paddle/pten/kernels/funcs/eigen/scale.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,12 +11,12 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/complex.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenScale { @@ -24,8 +24,12 @@ struct EigenScale { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& in, - const T scale, const T bias, const bool bias_after_scale) { + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& in, + const T scale, + const T bias, + const bool bias_after_scale) { if (bias_after_scale) { out.device(dev) = scale * in + bias; } else { @@ -41,9 +45,9 @@ template struct EigenScale; template struct EigenScale; template struct EigenScale; template struct EigenScale; -template struct EigenScale; -template struct EigenScale>; -template struct EigenScale>; +template struct EigenScale; +template struct EigenScale>; +template struct EigenScale>; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/sign.cc b/paddle/pten/kernels/funcs/eigen/sign.cc similarity index 77% rename from paddle/fluid/operators/eigen/sign.cc rename to paddle/pten/kernels/funcs/eigen/sign.cc index 4a4445f6569..99ecfadea35 100644 --- a/paddle/fluid/operators/eigen/sign.cc +++ b/paddle/pten/kernels/funcs/eigen/sign.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,10 +11,10 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenSign { @@ -22,7 +22,8 @@ struct EigenSign { Eigen::Tensor>; using OutType = Eigen::TensorMap>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, const InType& in) { out.device(dev) = in.sign(); } @@ -31,5 +32,5 @@ struct EigenSign { template struct EigenSign; template struct EigenSign; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/sign.cu b/paddle/pten/kernels/funcs/eigen/sign.cu similarity index 73% rename from paddle/fluid/operators/eigen/sign.cu rename to paddle/pten/kernels/funcs/eigen/sign.cu index 52c8d3c80dd..aad73c917cc 100644 --- a/paddle/fluid/operators/eigen/sign.cu +++ b/paddle/pten/kernels/funcs/eigen/sign.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,12 +11,12 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/eigen_ext.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" +#include "paddle/pten/kernels/funcs/eigen/extensions.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenSign { @@ -31,7 +31,7 @@ struct EigenSign { template struct EigenSign; template struct EigenSign; -template struct EigenSign; +template struct EigenSign; -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/slice.cc b/paddle/pten/kernels/funcs/eigen/slice.cc similarity index 72% rename from paddle/fluid/operators/eigen/slice.cc rename to paddle/pten/kernels/funcs/eigen/slice.cc index 2579b5f07eb..e838137a761 100644 --- a/paddle/fluid/operators/eigen/slice.cc +++ b/paddle/pten/kernels/funcs/eigen/slice.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,13 +11,13 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/bfloat16.h" -#include "paddle/fluid/platform/complex.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/bfloat16.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenSlice { @@ -34,14 +34,18 @@ struct EigenSlice { Eigen::TensorMap, Eigen::Aligned>; - static void Eval(const Eigen::DefaultDevice& dev, OutType out, - const InType& in, const Array& offsets, + static void Eval(const Eigen::DefaultDevice& dev, + OutType out, + const InType& in, + const Array& offsets, const Array& extents) { out.device(dev) = in.slice(offsets, extents); } - static void Eval(const Eigen::DefaultDevice& dev, OutType32BitIndex out, - const InType32BitIndex& in, const Array32Bit& offsets, + static void Eval(const Eigen::DefaultDevice& dev, + OutType32BitIndex out, + const InType32BitIndex& in, + const Array32Bit& offsets, const Array32Bit& extents) { out.device(dev) = in.slice(offsets, extents); } @@ -65,11 +69,11 @@ INSTANTIATION(EigenSlice, int16_t); INSTANTIATION(EigenSlice, int64_t); INSTANTIATION(EigenSlice, float); INSTANTIATION(EigenSlice, double); -INSTANTIATION(EigenSlice, platform::float16); -INSTANTIATION(EigenSlice, platform::bfloat16); -INSTANTIATION(EigenSlice, platform::complex); -INSTANTIATION(EigenSlice, platform::complex); +INSTANTIATION(EigenSlice, dtype::float16); +INSTANTIATION(EigenSlice, dtype::bfloat16); +INSTANTIATION(EigenSlice, dtype::complex); +INSTANTIATION(EigenSlice, dtype::complex); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten diff --git a/paddle/fluid/operators/eigen/slice.cu b/paddle/pten/kernels/funcs/eigen/slice.cu similarity index 68% rename from paddle/fluid/operators/eigen/slice.cu rename to paddle/pten/kernels/funcs/eigen/slice.cu index 3dfd0500cc9..b68a556f9c3 100644 --- a/paddle/fluid/operators/eigen/slice.cu +++ b/paddle/pten/kernels/funcs/eigen/slice.cu @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +/* Copyright (c) 2022 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. @@ -11,13 +11,13 @@ 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. */ -#include "paddle/fluid/operators/eigen/eigen_function.h" -#include "paddle/fluid/platform/bfloat16.h" -#include "paddle/fluid/platform/complex.h" -#include "paddle/fluid/platform/float16.h" +#include "paddle/pten/common/bfloat16.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/kernels/funcs/eigen/eigen_function.h" -namespace paddle { -namespace operators { +namespace pten { +namespace funcs { template struct EigenSlice { @@ -34,13 +34,18 @@ struct EigenSlice { Eigen::TensorMap, Eigen::Aligned>; - static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& in, - const Array& offsets, const Array& extents) { + static void Eval(const Eigen::GpuDevice& dev, + OutType out, + const InType& in, + const Array& offsets, + const Array& extents) { out.device(dev) = in.slice(offsets, extents); } - static void Eval(const Eigen::GpuDevice& dev, OutType32BitIndex out, - const InType32BitIndex& in, const Array32Bit& offsets, + static void Eval(const Eigen::GpuDevice& dev, + OutType32BitIndex out, + const InType32BitIndex& in, + const Array32Bit& offsets, const Array32Bit& extents) { out.device(dev) = in.slice(offsets, extents); } @@ -58,11 +63,11 @@ INSTANTIATION(EigenSlice, int); INSTANTIATION(EigenSlice, int64_t); INSTANTIATION(EigenSlice, float); INSTANTIATION(EigenSlice, double); -INSTANTIATION(EigenSlice, platform::float16); -INSTANTIATION(EigenSlice, platform::bfloat16); -INSTANTIATION(EigenSlice, platform::complex); -INSTANTIATION(EigenSlice, platform::complex); +INSTANTIATION(EigenSlice, dtype::float16); +INSTANTIATION(EigenSlice, dtype::bfloat16); +INSTANTIATION(EigenSlice, dtype::complex); +INSTANTIATION(EigenSlice, dtype::complex); #undef INSTANTIATION -} // namespace operators -} // namespace paddle +} // namespace funcs +} // namespace pten -- GitLab