未验证 提交 a1e40dc6 编写于 作者: F Feiyu Chan 提交者: GitHub

[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
上级 f783b846
......@@ -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 {
......
......@@ -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)
......
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()
......@@ -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 <typename EigenDevice, typename T, int Rank>
struct EigenBroadcast {
using Array = Eigen::DSizes<Eigen::DenseIndex, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using InType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<const T, Rank, Eigen::RowMajor, int>,
Eigen::Aligned>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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<EigenDevice, T, Rank>;
template <typename EigenDevice, typename T, int Rank>
struct EigenBroadcastGrad {
using Array = Eigen::DSizes<Eigen::DenseIndex, Rank>;
using Array2 = Eigen::DSizes<Eigen::DenseIndex, Rank * 2>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, InType in,
const Array& reduce_dims, const Array2& reshape_dims);
};
using EigenBroadcastGrad =
pten::funcs::EigenBroadcastGrad<EigenDevice, T, Rank>;
template <typename EigenDevice, typename T, int Rank>
struct EigenConstant {
using Type = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, Type out, const T value);
};
using EigenConstant = pten::funcs::EigenConstant<EigenDevice, T, Rank>;
template <typename EigenDevice, typename T>
struct EigenSign {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in);
};
using EigenSign = pten::funcs::EigenSign<EigenDevice, T>;
template <typename EigenDevice, typename T, int Rank>
struct EigenReverse {
using Array = Eigen::DSizes<bool, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in,
const Array& reverse);
};
using EigenReverse = pten::funcs::EigenReverse<EigenDevice, T, Rank>;
template <typename EigenDevice, typename T>
struct EigenAdd {
using InType = Eigen::TensorMap<Eigen::TensorFixedSize<
const T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<
T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in,
const T value);
};
using EigenAdd = pten::funcs::EigenAdd<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenSub {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& left,
const InType& right);
};
using EigenSub = pten::funcs::EigenSub<EigenDevice, T>;
template <typename EigenDevice, typename T, int Rank>
struct EigenSlice {
using Array = Eigen::DSizes<Eigen::DenseIndex, Rank>;
using Array32Bit = Eigen::DSizes<int, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using InType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<const T, Rank, Eigen::RowMajor, int>,
Eigen::Aligned>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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<EigenDevice, T, Rank>;
template <typename EigenDevice, typename T, int Rank>
struct EigenPad {
using Array = std::array<std::pair<int64_t, int64_t>, Rank>;
using Array32Bit = std::array<std::pair<int, int>, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using InType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<const T, Rank, Eigen::RowMajor, int>,
Eigen::Aligned>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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<EigenDevice, T, Rank>;
template <typename EigenDevice, typename T>
struct EigenScale {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenErf {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in);
};
using EigenErf = pten::funcs::EigenErf<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenErfGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType din, const InType& in,
const InType& dout);
};
using EigenErfGrad = pten::funcs::EigenErfGrad<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenRankLoss {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& label,
const InType& left, const InType& right);
};
using EigenRankLoss = pten::funcs::EigenRankLoss<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenRankLossGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenLogLoss {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& pred,
const InType& label, const T& epsilon);
};
using EigenLogLoss = pten::funcs::EigenLogLoss<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenLogLossGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenHingeLoss {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType loss, const InType& pred,
const InType& label);
};
using EigenHingeLoss = pten::funcs::EigenHingeLoss<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenHingeLossGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType dpred, const InType& dloss,
const InType& pred, const InType& label);
};
using EigenHingeLossGrad = pten::funcs::EigenHingeLossGrad<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenL1Norm {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<
T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in);
};
using EigenL1Norm = pten::funcs::EigenL1Norm<EigenDevice, T>;
template <typename EigenDevice, typename T>
struct EigenL1NormGrad {
using Array = Eigen::DSizes<Eigen::DenseIndex, 1>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType din, const InType& dout,
const InType& in, const Array& bcast);
};
using EigenL1NormGrad = pten::funcs::EigenL1NormGrad<EigenDevice, T>;
} // namespace operators
} // namespace paddle
......@@ -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 {
......
......@@ -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 {
......
......@@ -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"
......
......@@ -14,7 +14,7 @@
#include "paddle/fluid/platform/complex.h"
#include <complex>
#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<float> *************
complex<float> a;
a.real = float(INFINITY);
a.real = static_cast<float>(INFINITY);
EXPECT_EQ(std::isinf(a), true);
a.imag = float(INFINITY);
a.imag = static_cast<float>(INFINITY);
EXPECT_EQ(std::isinf(a), true);
complex<float> b = float(INFINITY);
complex<float> b = static_cast<float>(INFINITY);
EXPECT_EQ(std::isinf(b), true);
complex<float> c(float(INFINITY), 0);
complex<float> c(static_cast<float>(INFINITY), 0);
EXPECT_EQ(std::isinf(c), true);
// *********** complex<double> *************
complex<double> a1;
a1.real = double(INFINITY);
a1.real = static_cast<double>(INFINITY);
EXPECT_EQ(std::isinf(a1), true);
a1.imag = double(INFINITY);
a1.imag = static_cast<double>(INFINITY);
EXPECT_EQ(std::isinf(a1), true);
complex<double> b1 = double(INFINITY);
complex<double> b1 = static_cast<double>(INFINITY);
EXPECT_EQ(std::isinf(b1), true);
complex<double> c1(double(INFINITY), 0);
complex<double> c1(static_cast<double>(INFINITY), 0);
EXPECT_EQ(std::isinf(c1), true);
}
TEST(complex, isnan) {
// *********** complex<float> *************
complex<float> a;
a.real = float(NAN);
a.real = static_cast<float>(NAN);
EXPECT_EQ(std::isnan(a), true);
a.imag = float(NAN);
a.imag = static_cast<float>(NAN);
EXPECT_EQ(std::isnan(a), true);
complex<float> b = float(NAN);
complex<float> b = static_cast<float>(NAN);
EXPECT_EQ(std::isnan(b), true);
complex<float> c(float(NAN), 0);
complex<float> c(static_cast<float>(NAN), 0);
EXPECT_EQ(std::isnan(c), true);
// *********** complex<double> *************
complex<double> a1;
a1.real = double(NAN);
a1.real = static_cast<double>(NAN);
EXPECT_EQ(std::isnan(a1), true);
a1.imag = double(NAN);
a1.imag = static_cast<double>(NAN);
EXPECT_EQ(std::isnan(a1), true);
complex<double> b1 = double(NAN);
complex<double> b1 = static_cast<double>(NAN);
EXPECT_EQ(std::isnan(b1), true);
complex<double> c1(double(NAN), 0);
complex<double> c1(static_cast<double>(NAN), 0);
EXPECT_EQ(std::isnan(c1), true);
}
......
......@@ -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<float> *************
complex<float> a;
a.real = float(INFINITY);
a.real = static_cast<float>(INFINITY);
EXPECT_EQ(std::isinf(a), true);
a.imag = float(INFINITY);
a.imag = static_cast<float>(INFINITY);
EXPECT_EQ(std::isinf(a), true);
complex<float> b = float(INFINITY);
complex<float> b = static_cast<float>(INFINITY);
EXPECT_EQ(std::isinf(b), true);
complex<float> c(float(INFINITY), 0);
complex<float> c(static_cast<float>(INFINITY), 0);
EXPECT_EQ(std::isinf(c), true);
// *********** complex<double> *************
complex<double> a1;
a1.real = double(INFINITY);
a1.real = static_cast<double>(INFINITY);
EXPECT_EQ(std::isinf(a1), true);
a1.imag = double(INFINITY);
a1.imag = static_cast<double>(INFINITY);
EXPECT_EQ(std::isinf(a1), true);
complex<double> b1 = double(INFINITY);
complex<double> b1 = static_cast<double>(INFINITY);
EXPECT_EQ(std::isinf(b1), true);
complex<double> c1(double(INFINITY), 0);
complex<double> c1(static_cast<double>(INFINITY), 0);
EXPECT_EQ(std::isinf(c1), true);
}
TEST(complex, isnan) {
// *********** complex<float> *************
complex<float> a;
a.real = float(NAN);
a.real = static_cast<float>(NAN);
EXPECT_EQ(std::isnan(a), true);
a.imag = float(NAN);
a.imag = static_cast<float>(NAN);
EXPECT_EQ(std::isnan(a), true);
complex<float> b = float(NAN);
complex<float> b = static_cast<float>(NAN);
EXPECT_EQ(std::isnan(b), true);
complex<float> c(float(NAN), 0);
complex<float> c(static_cast<float>(NAN), 0);
EXPECT_EQ(std::isnan(c), true);
// *********** complex<double> *************
complex<double> a1;
a1.real = double(NAN);
a1.real = static_cast<double>(NAN);
EXPECT_EQ(std::isnan(a1), true);
a1.imag = double(NAN);
a1.imag = static_cast<double>(NAN);
EXPECT_EQ(std::isnan(a1), true);
complex<double> b1 = double(NAN);
complex<double> b1 = static_cast<double>(NAN);
EXPECT_EQ(std::isnan(b1), true);
complex<double> c1(double(NAN), 0);
complex<double> c1(static_cast<double>(NAN), 0);
EXPECT_EQ(std::isnan(c1), true);
}
} // namespace platform
} // namespace paddle
#endif
\ No newline at end of file
#endif
......@@ -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 {
......
......@@ -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) { \
......
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()
/* 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 <typename T, int Rank>
struct EigenBroadcast<Eigen::DefaultDevice, T, Rank> {
......@@ -31,13 +31,17 @@ struct EigenBroadcast<Eigen::DefaultDevice, T, Rank> {
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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::DefaultDevice, T, Rank> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::DefaultDevice, T, Rank> {
template struct FUNCTOR<Eigen::DefaultDevice, T, 5>; \
template struct FUNCTOR<Eigen::DefaultDevice, T, 6>
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<Eigen::DefaultDevice, int, 0>;
template struct EigenBroadcastGrad<Eigen::DefaultDevice, int64_t, 0>;
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T, int Rank>
struct EigenBroadcast<Eigen::GpuDevice, T, Rank> {
......@@ -31,13 +31,17 @@ struct EigenBroadcast<Eigen::GpuDevice, T, Rank> {
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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::GpuDevice, T, Rank> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::GpuDevice, T, Rank> {
template struct FUNCTOR<Eigen::GpuDevice, T, 5>; \
template struct FUNCTOR<Eigen::GpuDevice, T, 6>
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<Eigen::GpuDevice, float, 0>;
template struct EigenBroadcastGrad<Eigen::GpuDevice, platform::float16, 0>;
template struct EigenBroadcastGrad<Eigen::GpuDevice, dtype::float16, 0>;
template struct EigenBroadcastGrad<Eigen::GpuDevice, double, 0>;
template struct EigenBroadcastGrad<Eigen::GpuDevice, int, 0>;
template struct EigenBroadcastGrad<Eigen::GpuDevice, int64_t, 0>;
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
......@@ -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 <typename T, int Rank>
struct EigenConstant<Eigen::DefaultDevice, T, Rank> {
......@@ -27,5 +27,5 @@ struct EigenConstant<Eigen::DefaultDevice, T, Rank> {
template struct EigenConstant<Eigen::DefaultDevice, float, 1>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T, int Rank>
struct EigenConstant<Eigen::GpuDevice, T, Rank> {
......@@ -27,5 +27,5 @@ struct EigenConstant<Eigen::GpuDevice, T, Rank> {
template struct EigenConstant<Eigen::GpuDevice, float, 1>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename EigenDevice, typename T, int Rank>
struct EigenBroadcast {
using Array = Eigen::DSizes<Eigen::DenseIndex, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using InType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<const T, Rank, Eigen::RowMajor, int>,
Eigen::Aligned>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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 <typename EigenDevice, typename T, int Rank>
struct EigenBroadcastGrad {
using Array = Eigen::DSizes<Eigen::DenseIndex, Rank>;
using Array2 = Eigen::DSizes<Eigen::DenseIndex, Rank * 2>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType out,
InType in,
const Array& reduce_dims,
const Array2& reshape_dims);
};
template <typename EigenDevice, typename T, int Rank>
struct EigenConstant {
using Type = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, Type out, const T value);
};
template <typename EigenDevice, typename T>
struct EigenSign {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in);
};
template <typename EigenDevice, typename T, int Rank>
struct EigenReverse {
using Array = Eigen::DSizes<bool, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType out,
const InType& in,
const Array& reverse);
};
template <typename EigenDevice, typename T>
struct EigenAdd {
using InType = Eigen::TensorMap<Eigen::TensorFixedSize<const T,
Eigen::Sizes<>,
Eigen::RowMajor,
Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<T,
Eigen::Sizes<>,
Eigen::RowMajor,
Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType out,
const InType& in,
const T value);
};
template <typename EigenDevice, typename T>
struct EigenSub {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType out,
const InType& left,
const InType& right);
};
template <typename EigenDevice, typename T, int Rank>
struct EigenSlice {
using Array = Eigen::DSizes<Eigen::DenseIndex, Rank>;
using Array32Bit = Eigen::DSizes<int, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using InType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<const T, Rank, Eigen::RowMajor, int>,
Eigen::Aligned>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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 <typename EigenDevice, typename T, int Rank>
struct EigenPad {
using Array = std::array<std::pair<int64_t, int64_t>, Rank>;
using Array32Bit = std::array<std::pair<int, int>, Rank>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using InType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<const T, Rank, Eigen::RowMajor, int>,
Eigen::Aligned>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType32BitIndex =
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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 <typename EigenDevice, typename T>
struct EigenScale {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType out,
const InType& in,
const T scale,
const T bias,
const bool bias_after_scale);
};
template <typename EigenDevice, typename T>
struct EigenErf {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in);
};
template <typename EigenDevice, typename T>
struct EigenErfGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType din,
const InType& in,
const InType& dout);
};
template <typename EigenDevice, typename T>
struct EigenRankLoss {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType out,
const InType& label,
const InType& left,
const InType& right);
};
template <typename EigenDevice, typename T>
struct EigenRankLossGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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 <typename EigenDevice, typename T>
struct EigenLogLoss {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType out,
const InType& pred,
const InType& label,
const T& epsilon);
};
template <typename EigenDevice, typename T>
struct EigenLogLossGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType dpred,
const InType& dloss,
const InType& pred,
const InType& label,
const T& epsilon);
};
template <typename EigenDevice, typename T>
struct EigenHingeLoss {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType loss,
const InType& pred,
const InType& label);
};
template <typename EigenDevice, typename T>
struct EigenHingeLossGrad {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType dpred,
const InType& dloss,
const InType& pred,
const InType& label);
};
template <typename EigenDevice, typename T>
struct EigenL1Norm {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<T,
Eigen::Sizes<>,
Eigen::RowMajor,
Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev, OutType out, const InType& in);
};
template <typename EigenDevice, typename T>
struct EigenL1NormGrad {
using Array = Eigen::DSizes<Eigen::DenseIndex, 1>;
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const EigenDevice& dev,
OutType din,
const InType& dout,
const InType& in,
const Array& bcast);
};
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenAdd<Eigen::DefaultDevice, T> {
using InType = Eigen::TensorMap<Eigen::TensorFixedSize<
const T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<
T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const Eigen::DefaultDevice& dev, OutType out,
const InType& in, const T value) {
using InType = Eigen::TensorMap<Eigen::TensorFixedSize<const T,
Eigen::Sizes<>,
Eigen::RowMajor,
Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<T,
Eigen::Sizes<>,
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::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::DefaultDevice, float>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenAdd<Eigen::GpuDevice, T> {
using InType = Eigen::TensorMap<Eigen::TensorFixedSize<
const T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<
T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const Eigen::GpuDevice& dev, OutType out, const InType& in,
using InType = Eigen::TensorMap<Eigen::TensorFixedSize<const T,
Eigen::Sizes<>,
Eigen::RowMajor,
Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<T,
Eigen::Sizes<>,
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::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::GpuDevice, T> {
template struct EigenSub<Eigen::GpuDevice, float>;
} // namespace operators
} // namespace paddle
} // namespace fucns
} // namespace pten
/* 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 <typename T>
struct EigenErf<Eigen::DefaultDevice, T> {
......@@ -24,7 +24,8 @@ struct EigenErf<Eigen::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(M_2_SQRTPI) * (-(in.square())).exp();
}
......@@ -46,10 +49,10 @@ struct EigenErfGrad<Eigen::DefaultDevice, T> {
#define INSTANTIATION(FUNCTOR) \
template struct FUNCTOR<Eigen::DefaultDevice, float>; \
template struct FUNCTOR<Eigen::DefaultDevice, double>; \
template struct FUNCTOR<Eigen::DefaultDevice, platform::float16>
template struct FUNCTOR<Eigen::DefaultDevice, dtype::float16>
INSTANTIATION(EigenErf);
INSTANTIATION(EigenErfGrad);
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenErf<Eigen::GpuDevice, T> {
......@@ -38,7 +38,9 @@ struct EigenErfGrad<Eigen::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(M_2_SQRTPI) * (-(in.square())).exp();
......@@ -48,10 +50,10 @@ struct EigenErfGrad<Eigen::GpuDevice, T> {
#define INSTANTIATION(FUNCTOR) \
template struct FUNCTOR<Eigen::GpuDevice, float>; \
template struct FUNCTOR<Eigen::GpuDevice, double>; \
template struct FUNCTOR<Eigen::GpuDevice, platform::float16>
template struct FUNCTOR<Eigen::GpuDevice, dtype::float16>
INSTANTIATION(EigenErf);
INSTANTIATION(EigenErfGrad);
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
// 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 <typename T>
using complex = paddle::platform::complex<T>;
using complex = pten::dtype::complex<T>;
template <typename T>
struct NumTraits;
template <>
struct NumTraits<paddle::platform::bfloat16>
: GenericNumTraits<paddle::platform::bfloat16> {
struct NumTraits<pten::dtype::bfloat16>
: GenericNumTraits<pten::dtype::bfloat16> {
enum {
IsSigned = true,
IsInteger = false,
......@@ -40,23 +40,23 @@ struct NumTraits<paddle::platform::bfloat16>
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<float16> : GenericNumTraits<float16> {
};
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<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 exp(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::expf(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 expm1(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::expm1f(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 expm1(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::expm1f(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 erf(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::erff(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 erf(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::erff(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 log(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::logf(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 log(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::logf(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 tanh(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::tanhf(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 tanh(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::tanhf(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 sqrt(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::sqrtf(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 sqrt(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::sqrtf(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 ceil(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::ceilf(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 ceil(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::ceilf(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 floor(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::floorf(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 floor(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::floorf(static_cast<float>(a)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 round(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::roundf(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 round(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::roundf(static_cast<float>(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<float>(a), static_cast<float>(b)));
}
template <>
HOSTDEVICE inline paddle::platform::bfloat16 abs(
const paddle::platform::bfloat16& a) {
return paddle::platform::bfloat16(::fabs(static_cast<float>(a)));
HOSTDEVICE inline pten::dtype::bfloat16 abs(const pten::dtype::bfloat16& a) {
return pten::dtype::bfloat16(::fabs(static_cast<float>(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<float>& a) {
return (paddle::platform::isnan)(a);
return (pten::dtype::isnan)(a);
}
template <>
HOSTDEVICE inline bool(isinf)(const complex<float>& a) {
return (paddle::platform::isinf)(a);
return (pten::dtype::isinf)(a);
}
template <>
HOSTDEVICE inline bool(isfinite)(const complex<float>& a) {
return (paddle::platform::isfinite)(a);
return (pten::dtype::isfinite)(a);
}
template <>
......@@ -256,17 +246,17 @@ HOSTDEVICE inline complex<float> exp(const complex<float>& a) {
template <>
HOSTDEVICE inline complex<float> log(const complex<float>& a) {
return paddle::platform::log(a);
return pten::dtype::log(a);
}
template <>
HOSTDEVICE inline complex<float> tanh(const complex<float>& a) {
return paddle::platform::tanh(a);
return pten::dtype::tanh(a);
}
template <>
HOSTDEVICE inline complex<float> sqrt(const complex<float>& a) {
return paddle::platform::sqrt(a);
return pten::dtype::sqrt(a);
}
template <>
......@@ -287,29 +277,29 @@ HOSTDEVICE inline complex<float> round(const complex<float>& a) {
template <>
HOSTDEVICE inline complex<float> pow(const complex<float>& a,
const complex<float>& b) {
return paddle::platform::pow(a, b);
return pten::dtype::pow(a, b);
}
template <>
HOSTDEVICE inline float abs(const complex<float>& a) {
return paddle::platform::abs(a);
return pten::dtype::abs(a);
}
//////////// complex<double> methods /////////////
template <>
HOSTDEVICE inline bool(isnan)(const complex<double>& a) {
return (paddle::platform::isnan)(a);
return (pten::dtype::isnan)(a);
}
template <>
HOSTDEVICE inline bool(isinf)(const complex<double>& a) {
return (paddle::platform::isinf)(a);
return (pten::dtype::isinf)(a);
}
template <>
HOSTDEVICE inline bool(isfinite)(const complex<double>& a) {
return (paddle::platform::isfinite)(a);
return (pten::dtype::isfinite)(a);
}
template <>
......@@ -322,17 +312,17 @@ HOSTDEVICE inline complex<double> exp(const complex<double>& a) {
template <>
HOSTDEVICE inline complex<double> log(const complex<double>& a) {
return paddle::platform::log(a);
return pten::dtype::log(a);
}
template <>
HOSTDEVICE inline complex<double> tanh(const complex<double>& a) {
return paddle::platform::tanh(a);
return pten::dtype::tanh(a);
}
template <>
HOSTDEVICE inline complex<double> sqrt(const complex<double>& a) {
return paddle::platform::sqrt(a);
return pten::dtype::sqrt(a);
}
template <>
......@@ -353,29 +343,29 @@ HOSTDEVICE inline complex<double> round(const complex<double>& a) {
template <>
HOSTDEVICE inline complex<double> pow(const complex<double>& a,
const complex<double>& b) {
return paddle::platform::pow(a, b);
return pten::dtype::pow(a, b);
}
template <>
HOSTDEVICE inline double abs(const complex<double>& 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 <>
......
/* 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 <typename T>
struct EigenL1Norm<Eigen::DefaultDevice, T> {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<
T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
static void Eval(const Eigen::DefaultDevice& dev, OutType out,
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<T,
Eigen::Sizes<>,
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::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::DefaultDevice, T> {
template struct EigenL1Norm<Eigen::DefaultDevice, float>;
template struct EigenL1NormGrad<Eigen::DefaultDevice, float>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenL1Norm<Eigen::GpuDevice, T> {
using InType = Eigen::TensorMap<
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<
T, Eigen::Sizes<>, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<Eigen::TensorFixedSize<T,
Eigen::Sizes<>,
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::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::GpuDevice, T> {
template struct EigenL1Norm<Eigen::GpuDevice, float>;
template struct EigenL1NormGrad<Eigen::GpuDevice, float>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenRankLoss<Eigen::DefaultDevice, T> {
......@@ -22,8 +22,10 @@ struct EigenRankLoss<Eigen::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::DefaultDevice, T> {
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(1) - label) *
(static_cast<T>(1) - pred + epsilon).log()));
......@@ -73,8 +84,11 @@ struct EigenLogLossGrad<Eigen::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(1) -
pred * (static_cast<T>(2) * label - static_cast<T>(1)))
.cwiseMax(static_cast<T>(0));
......@@ -106,8 +122,10 @@ struct EigenHingeLossGrad<Eigen::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(2) * label - static_cast<T>(1);
dpred.device(dev) =
......@@ -119,5 +137,5 @@ struct EigenHingeLossGrad<Eigen::DefaultDevice, T> {
template struct EigenHingeLoss<Eigen::DefaultDevice, float>;
template struct EigenHingeLossGrad<Eigen::DefaultDevice, float>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenRankLoss<Eigen::GpuDevice, T> {
......@@ -22,8 +22,10 @@ struct EigenRankLoss<Eigen::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::GpuDevice, T> {
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(1) - label) *
(static_cast<T>(1) - pred + epsilon).log()));
......@@ -73,8 +84,11 @@ struct EigenLogLossGrad<Eigen::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(1) -
pred * (static_cast<T>(2) * label - static_cast<T>(1)))
.cwiseMax(static_cast<T>(0));
......@@ -106,8 +122,10 @@ struct EigenHingeLossGrad<Eigen::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<T>(2) * label - static_cast<T>(1);
dpred.device(dev) =
......@@ -119,5 +137,5 @@ struct EigenHingeLossGrad<Eigen::GpuDevice, T> {
template struct EigenHingeLoss<Eigen::GpuDevice, float>;
template struct EigenHingeLossGrad<Eigen::GpuDevice, float>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T, int Rank>
struct EigenPad<Eigen::DefaultDevice, T, Rank> {
......@@ -32,13 +32,18 @@ struct EigenPad<Eigen::DefaultDevice, T, Rank> {
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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<float>);
INSTANTIATION(EigenPad, platform::complex<double>);
INSTANTIATION(EigenPad, dtype::complex<float>);
INSTANTIATION(EigenPad, dtype::complex<double>);
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T, int Rank>
struct EigenPad<Eigen::GpuDevice, T, Rank> {
......@@ -34,13 +34,18 @@ struct EigenPad<Eigen::GpuDevice, T, Rank> {
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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<float>);
INSTANTIATION(EigenPad, platform::complex<double>);
INSTANTIATION(EigenPad, dtype::float16);
INSTANTIATION(EigenPad, dtype::bfloat16);
INSTANTIATION(EigenPad, dtype::complex<float>);
INSTANTIATION(EigenPad, dtype::complex<double>);
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T, int Rank>
struct EigenReverse<Eigen::DefaultDevice, T, Rank> {
......@@ -23,8 +23,10 @@ struct EigenReverse<Eigen::DefaultDevice, T, Rank> {
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
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
/* 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 <typename T, int Rank>
struct EigenReverse<Eigen::GpuDevice, T, Rank> {
......@@ -23,7 +23,9 @@ struct EigenReverse<Eigen::GpuDevice, T, Rank> {
Eigen::Tensor<const T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType = Eigen::TensorMap<
Eigen::Tensor<T, Rank, Eigen::RowMajor, Eigen::DenseIndex>>;
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
/* 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 <typename T>
struct EigenScale<Eigen::DefaultDevice, T> {
......@@ -24,8 +24,11 @@ struct EigenScale<Eigen::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::DefaultDevice, T> {
template struct EigenScale<Eigen::DefaultDevice, float>;
template struct EigenScale<Eigen::DefaultDevice, double>;
template struct EigenScale<Eigen::DefaultDevice, platform::bfloat16>;
template struct EigenScale<Eigen::DefaultDevice, dtype::bfloat16>;
template struct EigenScale<Eigen::DefaultDevice, uint8_t>;
template struct EigenScale<Eigen::DefaultDevice, int8_t>;
template struct EigenScale<Eigen::DefaultDevice, int16_t>;
template struct EigenScale<Eigen::DefaultDevice, int>;
template struct EigenScale<Eigen::DefaultDevice, int64_t>;
template struct EigenScale<Eigen::DefaultDevice, platform::complex<float>>;
template struct EigenScale<Eigen::DefaultDevice, platform::complex<double>>;
template struct EigenScale<Eigen::DefaultDevice, dtype::complex<float>>;
template struct EigenScale<Eigen::DefaultDevice, dtype::complex<double>>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenScale<Eigen::GpuDevice, T> {
......@@ -24,8 +24,12 @@ struct EigenScale<Eigen::GpuDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::GpuDevice, int8_t>;
template struct EigenScale<Eigen::GpuDevice, int16_t>;
template struct EigenScale<Eigen::GpuDevice, int>;
template struct EigenScale<Eigen::GpuDevice, int64_t>;
template struct EigenScale<Eigen::GpuDevice, platform::float16>;
template struct EigenScale<Eigen::GpuDevice, platform::complex<float>>;
template struct EigenScale<Eigen::GpuDevice, platform::complex<double>>;
template struct EigenScale<Eigen::GpuDevice, dtype::float16>;
template struct EigenScale<Eigen::GpuDevice, dtype::complex<float>>;
template struct EigenScale<Eigen::GpuDevice, dtype::complex<double>>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenSign<Eigen::DefaultDevice, T> {
......@@ -22,7 +22,8 @@ struct EigenSign<Eigen::DefaultDevice, T> {
Eigen::Tensor<const T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
using OutType =
Eigen::TensorMap<Eigen::Tensor<T, 1, Eigen::RowMajor, Eigen::DenseIndex>>;
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<Eigen::DefaultDevice, T> {
template struct EigenSign<Eigen::DefaultDevice, float>;
template struct EigenSign<Eigen::DefaultDevice, double>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T>
struct EigenSign<Eigen::GpuDevice, T> {
......@@ -31,7 +31,7 @@ struct EigenSign<Eigen::GpuDevice, T> {
template struct EigenSign<Eigen::GpuDevice, float>;
template struct EigenSign<Eigen::GpuDevice, double>;
template struct EigenSign<Eigen::GpuDevice, platform::float16>;
template struct EigenSign<Eigen::GpuDevice, dtype::float16>;
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T, int Rank>
struct EigenSlice<Eigen::DefaultDevice, T, Rank> {
......@@ -34,14 +34,18 @@ struct EigenSlice<Eigen::DefaultDevice, T, Rank> {
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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<float>);
INSTANTIATION(EigenSlice, platform::complex<double>);
INSTANTIATION(EigenSlice, dtype::float16);
INSTANTIATION(EigenSlice, dtype::bfloat16);
INSTANTIATION(EigenSlice, dtype::complex<float>);
INSTANTIATION(EigenSlice, dtype::complex<double>);
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
/* 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 <typename T, int Rank>
struct EigenSlice<Eigen::GpuDevice, T, Rank> {
......@@ -34,13 +34,18 @@ struct EigenSlice<Eigen::GpuDevice, T, Rank> {
Eigen::TensorMap<Eigen::Tensor<T, Rank, Eigen::RowMajor, int>,
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<float>);
INSTANTIATION(EigenSlice, platform::complex<double>);
INSTANTIATION(EigenSlice, dtype::float16);
INSTANTIATION(EigenSlice, dtype::bfloat16);
INSTANTIATION(EigenSlice, dtype::complex<float>);
INSTANTIATION(EigenSlice, dtype::complex<double>);
#undef INSTANTIATION
} // namespace operators
} // namespace paddle
} // namespace funcs
} // namespace pten
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册