|
|
@ -19,25 +19,20 @@ namespace paddle {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* \brief The tensor evaluator classes.
|
|
|
|
* \brief The tensor evaluator classes.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template<typename Derived, class T>
|
|
|
|
template <typename Derived, class T>
|
|
|
|
class TensorApply {
|
|
|
|
class TensorApply {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit INLINE TensorApply(const Derived& p)
|
|
|
|
explicit INLINE TensorApply(const Derived& p)
|
|
|
|
: data_(p.data_), stride_(p.stride_),
|
|
|
|
: data_(p.data_),
|
|
|
|
height_(p.height_), width_(p.width_), useGpu_(p.useGpu_) {}
|
|
|
|
stride_(p.stride_),
|
|
|
|
|
|
|
|
height_(p.height_),
|
|
|
|
|
|
|
|
width_(p.width_),
|
|
|
|
|
|
|
|
useGpu_(p.useGpu_) {}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
|
INLINE T apply(int i, int j) const { return data_[i * stride_ + j]; }
|
|
|
|
return data_[i * stride_ + j];
|
|
|
|
INLINE T apply(int index) const { return data_[index]; }
|
|
|
|
}
|
|
|
|
INLINE T& applyRef(int i, int j) { return data_[i * stride_ + j]; }
|
|
|
|
INLINE T apply(int index) const {
|
|
|
|
INLINE T& applyRef(int index) { return data_[index]; }
|
|
|
|
return data_[index];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE T& applyRef(int i, int j) {
|
|
|
|
|
|
|
|
return data_[i * stride_ + j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE T& applyRef(int index) {
|
|
|
|
|
|
|
|
return data_[index];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INLINE size_t getWidth() const { return width_; }
|
|
|
|
INLINE size_t getWidth() const { return width_; }
|
|
|
|
INLINE size_t getHeight() const { return height_; }
|
|
|
|
INLINE size_t getHeight() const { return height_; }
|
|
|
@ -53,22 +48,20 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* \brief The tensor evaluator classes.
|
|
|
|
* \brief The tensor evaluator classes.
|
|
|
|
*
|
|
|
|
|
|
|
|
* evaluator for rvalues
|
|
|
|
* evaluator for rvalues
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template<typename Derived, class T>
|
|
|
|
template <typename Derived, class T>
|
|
|
|
class TensorApply<const Derived, T> {
|
|
|
|
class TensorApply<const Derived, T> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit INLINE TensorApply(const Derived& p)
|
|
|
|
explicit INLINE TensorApply(const Derived& p)
|
|
|
|
: data_(p.data_), stride_(p.stride_),
|
|
|
|
: data_(p.data_),
|
|
|
|
height_(p.height_), width_(p.width_), useGpu_(p.useGpu_) {}
|
|
|
|
stride_(p.stride_),
|
|
|
|
|
|
|
|
height_(p.height_),
|
|
|
|
|
|
|
|
width_(p.width_),
|
|
|
|
|
|
|
|
useGpu_(p.useGpu_) {}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
|
INLINE T apply(int i, int j) const { return data_[i * stride_ + j]; }
|
|
|
|
return data_[i * stride_ + j];
|
|
|
|
INLINE T apply(int index) const { return data_[index]; }
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE T apply(int index) const {
|
|
|
|
|
|
|
|
return data_[index];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INLINE size_t getWidth() const { return width_; }
|
|
|
|
INLINE size_t getWidth() const { return width_; }
|
|
|
|
INLINE size_t getHeight() const { return height_; }
|
|
|
|
INLINE size_t getHeight() const { return height_; }
|
|
|
@ -82,18 +75,14 @@ public:
|
|
|
|
bool useGpu_;
|
|
|
|
bool useGpu_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Derived, class T>
|
|
|
|
template <typename Derived, class T>
|
|
|
|
class TensorApply<const TensorExpression<Derived, T>, T> {
|
|
|
|
class TensorApply<const TensorExpression<Derived, T>, T> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit TensorApply(const TensorExpression<Derived, T>& expr)
|
|
|
|
explicit TensorApply(const TensorExpression<Derived, T>& expr)
|
|
|
|
: expr_(expr.derived()) {}
|
|
|
|
: expr_(expr.derived()) {}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
|
INLINE T apply(int i, int j) const { return expr_.apply(i, j); }
|
|
|
|
return expr_.apply(i, j);
|
|
|
|
INLINE T apply(int index) const { return expr_.apply(index); }
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE T apply(int index) const {
|
|
|
|
|
|
|
|
return expr_.apply(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INLINE size_t getWidth() const { return expr_.getWidth(); }
|
|
|
|
INLINE size_t getWidth() const { return expr_.getWidth(); }
|
|
|
|
INLINE size_t getHeight() const { return expr_.getHeight(); }
|
|
|
|
INLINE size_t getHeight() const { return expr_.getHeight(); }
|
|
|
@ -106,18 +95,14 @@ public:
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* \brief The unary expression evaluator classes.
|
|
|
|
* \brief The unary expression evaluator classes.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template<class OP, typename ArgType, class T>
|
|
|
|
template <class OP, typename ArgType, class T>
|
|
|
|
class TensorApply<const TensorUnaryOp<OP, ArgType, T>, T> {
|
|
|
|
class TensorApply<const TensorUnaryOp<OP, ArgType, T>, T> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit INLINE TensorApply(const TensorUnaryOp<OP, ArgType, T>& expr)
|
|
|
|
explicit INLINE TensorApply(const TensorUnaryOp<OP, ArgType, T>& expr)
|
|
|
|
: op_(expr.op_), expr_(expr.expr_) {}
|
|
|
|
: op_(expr.op_), expr_(expr.expr_) {}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
|
INLINE T apply(int i, int j) const { return op_(expr_.apply(i, j)); }
|
|
|
|
return op_(expr_.apply(i, j));
|
|
|
|
INLINE T apply(int index) const { return op_(expr_.apply(index)); }
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE T apply(int index) const {
|
|
|
|
|
|
|
|
return op_(expr_.apply(index));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INLINE size_t getWidth() const { return expr_.getWidth(); }
|
|
|
|
INLINE size_t getWidth() const { return expr_.getWidth(); }
|
|
|
|
INLINE size_t getHeight() const { return expr_.getHeight(); }
|
|
|
|
INLINE size_t getHeight() const { return expr_.getHeight(); }
|
|
|
@ -131,17 +116,17 @@ public:
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* \brief The binary expression evaluator classes.
|
|
|
|
* \brief The binary expression evaluator classes.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template<class OP, typename LhsType, typename RhsType, class T>
|
|
|
|
template <class OP, typename LhsType, typename RhsType, class T>
|
|
|
|
class TensorApply<const TensorBinaryOp<OP, LhsType, RhsType, T>, T> {
|
|
|
|
class TensorApply<const TensorBinaryOp<OP, LhsType, RhsType, T>, T> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit INLINE TensorApply(
|
|
|
|
explicit INLINE TensorApply(
|
|
|
|
const TensorBinaryOp<OP, LhsType, RhsType, T>& expr)
|
|
|
|
const TensorBinaryOp<OP, LhsType, RhsType, T>& expr)
|
|
|
|
: op_(expr.op_), lhs_(expr.lhs_), rhs_(expr.rhs_) {
|
|
|
|
: op_(expr.op_), lhs_(expr.lhs_), rhs_(expr.rhs_) {
|
|
|
|
#ifndef __CUDA_ARCH__
|
|
|
|
#ifndef __CUDA_ARCH__
|
|
|
|
CHECK_EQ(lhs_.getWidth(), rhs_.getWidth());
|
|
|
|
CHECK_EQ(lhs_.getWidth(), rhs_.getWidth());
|
|
|
|
CHECK_EQ(lhs_.getHeight(), rhs_.getHeight());
|
|
|
|
CHECK_EQ(lhs_.getHeight(), rhs_.getHeight());
|
|
|
|
CHECK_EQ(lhs_.useGpu(), rhs_.useGpu());
|
|
|
|
CHECK_EQ(lhs_.useGpu(), rhs_.useGpu());
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
@ -166,20 +151,20 @@ public:
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* \brief The ternary expression evaluator classes.
|
|
|
|
* \brief The ternary expression evaluator classes.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template<typename ArgType1, typename ArgType2, typename ArgType3, class T>
|
|
|
|
template <typename ArgType1, typename ArgType2, typename ArgType3, class T>
|
|
|
|
class TensorApply<const TensorTernaryOp<ArgType1, ArgType2, ArgType3, T>, T> {
|
|
|
|
class TensorApply<const TensorTernaryOp<ArgType1, ArgType2, ArgType3, T>, T> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit INLINE TensorApply(
|
|
|
|
explicit INLINE TensorApply(
|
|
|
|
const TensorTernaryOp<ArgType1, ArgType2, ArgType3, T>& expr)
|
|
|
|
const TensorTernaryOp<ArgType1, ArgType2, ArgType3, T>& expr)
|
|
|
|
: expr1_(expr.expr1_), expr2_(expr.expr2_), expr3_(expr.expr3_) {
|
|
|
|
: expr1_(expr.expr1_), expr2_(expr.expr2_), expr3_(expr.expr3_) {
|
|
|
|
#ifndef __CUDA_ARCH__
|
|
|
|
#ifndef __CUDA_ARCH__
|
|
|
|
CHECK_EQ(expr1_.getWidth(), expr2_.getWidth());
|
|
|
|
CHECK_EQ(expr1_.getWidth(), expr2_.getWidth());
|
|
|
|
CHECK_EQ(expr1_.getWidth(), expr3_.getWidth());
|
|
|
|
CHECK_EQ(expr1_.getWidth(), expr3_.getWidth());
|
|
|
|
CHECK_EQ(expr1_.getHeight(), expr2_.getHeight());
|
|
|
|
CHECK_EQ(expr1_.getHeight(), expr2_.getHeight());
|
|
|
|
CHECK_EQ(expr1_.getHeight(), expr3_.getHeight());
|
|
|
|
CHECK_EQ(expr1_.getHeight(), expr3_.getHeight());
|
|
|
|
CHECK_EQ(expr1_.useGpu(), expr2_.useGpu());
|
|
|
|
CHECK_EQ(expr1_.useGpu(), expr2_.useGpu());
|
|
|
|
CHECK_EQ(expr1_.useGpu(), expr3_.useGpu());
|
|
|
|
CHECK_EQ(expr1_.useGpu(), expr3_.useGpu());
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
@ -192,8 +177,8 @@ public:
|
|
|
|
INLINE size_t getWidth() const { return expr1_.getWidth(); }
|
|
|
|
INLINE size_t getWidth() const { return expr1_.getWidth(); }
|
|
|
|
INLINE size_t getHeight() const { return expr1_.getHeight(); }
|
|
|
|
INLINE size_t getHeight() const { return expr1_.getHeight(); }
|
|
|
|
INLINE bool isContiguous() const {
|
|
|
|
INLINE bool isContiguous() const {
|
|
|
|
return expr1_.isContiguous() &&
|
|
|
|
return expr1_.isContiguous() && expr2_.isContiguous() &&
|
|
|
|
expr2_.isContiguous() && expr3_.isContiguous();
|
|
|
|
expr3_.isContiguous();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
INLINE bool useGpu() const { return expr1_.useGpu(); }
|
|
|
|
INLINE bool useGpu() const { return expr1_.useGpu(); }
|
|
|
|
|
|
|
|
|
|
|
@ -205,18 +190,14 @@ public:
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* \brief The const expression evaluator classes.
|
|
|
|
* \brief The const expression evaluator classes.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template<class OP, typename ArgType, class T>
|
|
|
|
template <class OP, typename ArgType, class T>
|
|
|
|
class TensorApply<const TensorConstant<OP, ArgType, T>, T> {
|
|
|
|
class TensorApply<const TensorConstant<OP, ArgType, T>, T> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit INLINE TensorApply(const TensorConstant<OP, ArgType, T>& expr)
|
|
|
|
explicit INLINE TensorApply(const TensorConstant<OP, ArgType, T>& expr)
|
|
|
|
: op_(expr.op_), expr_(expr.expr_) {}
|
|
|
|
: op_(expr.op_), expr_(expr.expr_) {}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE T apply(int i, int j) const {
|
|
|
|
INLINE T apply(int i, int j) const { return op_(i, j); }
|
|
|
|
return op_(i, j);
|
|
|
|
INLINE T apply(int index) const { return op_(index); }
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE T apply(int index) const {
|
|
|
|
|
|
|
|
return op_(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INLINE size_t getWidth() const { return expr_.getWidth(); }
|
|
|
|
INLINE size_t getWidth() const { return expr_.getWidth(); }
|
|
|
|
INLINE size_t getHeight() const { return expr_.getHeight(); }
|
|
|
|
INLINE size_t getHeight() const { return expr_.getHeight(); }
|
|
|
|