diff --git a/paddle/fluid/framework/data_type.h b/paddle/fluid/framework/data_type.h index 791e9a83fa09cb946377059ceddc0170380a1dd8..dbde9aa24ff02474a5f231e7f5d556d4af6e8836 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 f8a27da00ba2b84e9e60b26f4171053b91f03095..d18ff6f6bfe2f0b04966af9e80bc40f3bebfc593 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 8b64e35b93526eb7edbe7f723832126ef7f0e0a6..0000000000000000000000000000000000000000 --- 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 9a3be7ca439b9aead2e931c7fa3036128400b057..a460e4c04c5f9bedf6fb1d914cf0dcc9096d1332 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 5e3c1fc202d595cf7406841cae716d3ddcb59d02..03610d4589058e074f64940741df34bd8f66e379 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 6d98522d752196690a110922a3c41c0bf60c7476..9a3eaa66caa8e870f2692c67aea29535dbd7492a 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 dc2d3aa73ba601362b071cf5aa23edd97cbc70b0..cac9767dc2948fb1c272f20a5593dc4d3a499cc0 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 4d13161e94faf910829fd93543e6c18990ea7813..05171495a88320c36a87d09de1551759ec4bdfce 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 b46d1b7b271d78fd436682fa2a5ffae974e61326..8f1dea1044677b3f1f49a5220b1d7a890e54ecbf 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 56633a35116719b617ac7b2dbc6aeac381a251d6..b1132952e72824877b4f83b348be1bca71fe90d9 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 8be774441fe7c00a7d01c198df409ab269ff850a..7a047d790abdc06710659e4388323fd0bf87dba5 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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8b64e35b93526eb7edbe7f723832126ef7f0e0a6 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 dab25f95493726a1b9a459ea0f6f3f33ad7bb22e..8d6c6c1e82bf0a1ac5ccc9ca3aa4d2328002df0b 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 63e244d393a9bcbbc4537fadd7c8bc996643e43f..5a9c26358a3e51a0ea9c138fa51a9db41c5818ea 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 45b03ccbf10043ad142c7de15d7cdf110e134f9a..5eb25f9bb9a858e585a54cd192d0ab41d8488bd9 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 cf4a2917f7d36f817b53aa892ff1b43b347086c8..c33da70e6a0daf88aa26bc84e85b0ec93be4ae8a 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 0000000000000000000000000000000000000000..75ba543dd9ce5d816c44f8ccbc8583f6f46b6313 --- /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 bedecfe5c224feda5126050be1f80843db5b0a87..700bd1363c95d452e2251780e1cabe54adfe6ba8 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 a750a06284f5e44fa71440820e2c40c0868f4e6f..999046b74a99d4fc84c5afaffef123bf7edf4abd 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 6c2c734c97769418fa9316150c606909acf33eba..1ebb9f84846d38fcf1d268c5c5609d6b9e3a6062 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 632205bdcbf7efaf6004e071ea078739742a417f..1971f5abbce2de16d36ff15c33bd438fe8eee78b 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 872a6cf062eeff01e2725e8d8ea64058438be114..a67b3268f09469da0d68f2633f32d9ac97bfee9a 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 e7ed60f76662eb7907f4884d93149f6f49bc0bc8..37d06b7879ff0eede34139ee5050e435738e722b 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 a27cd7ae6b7898d8d7fe4001cdfd447d02e19cb7..00156597dc538d0c8f5bbcf2ac6844b1ef85361e 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 469456537d9aa20564cf9abe2bf1ece735534be3..2a762fadd8110748692e30bc82f04f2fdbf9253d 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 02341202a2b4f18acc79f7bd4d4c69a69a039eca..484bae4c224e276e35cdce1dec141abe4e30ee5a 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 9db4571357a78781669951d4c672344d2555cde4..ed4b1c0643a906e592a66f31b75f3e5f97001ea9 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 e028a8aef18cfc62c1541cc1931f95b772df8768..6d40adce877173cd9c00fb5b5cd8faa47a483ccc 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 02044479db952ff27c06148ca39c4a2a3e36330a..9e77ae4fba529d8d96dabb147060339141a2451e 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 9b769489ce723678b2cc1440bf6c3d374e3a55d6..fc6c3b29ab86ed088e5270be977fd65e87b87ac7 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 d9fbb878e35ea77638aad7ef98e20979852a5881..cd34cd6e700ea8fa84c29f80e1c76b51f7612dad 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 5e485799af52c674c37a781ccac534e9b1083014..f1cbbd6a9bc78b1e1ac8a81f2c75ddba026ea402 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 4a4445f6569d388a4181eec1bed2faf190aeb729..99ecfadea35aa5208b8d33eb9842395bb24e4e96 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 52c8d3c80dd2c5d0d64e9a92ae596d7b69e70476..aad73c917ccdf209e3f0aad0a4804ba33e7569f8 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 2579b5f07eb27817f5488d8065fa05f409d1163f..e838137a76179fe2e17b6aa766684fbbec40c2ca 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 3dfd0500cc954f3990ed12d2be5b1a653c733d74..b68a556f9c30454a7f073e202f5d0b1ecd9f6474 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