10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H 23 template<
typename CustomUnaryFunc,
typename XprType>
26 typedef typename XprType::Scalar Scalar;
27 typedef typename XprType::StorageKind StorageKind;
28 typedef typename XprType::Index
Index;
29 typedef typename XprType::Nested Nested;
35 template<
typename CustomUnaryFunc,
typename XprType>
41 template<
typename CustomUnaryFunc,
typename XprType>
51 template<
typename CustomUnaryFunc,
typename XprType>
57 typedef typename XprType::CoeffReturnType CoeffReturnType;
63 : m_expr(expr), m_func(func) {}
66 const CustomUnaryFunc& func()
const {
return m_func; }
70 expression()
const {
return m_expr; }
73 typename XprType::Nested m_expr;
74 const CustomUnaryFunc m_func;
79 template<
typename CustomUnaryFunc,
typename XprType,
typename Device>
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorEvaluator(
const ArgType& op,
const Device& device)
101 : m_op(op), m_device(device), m_result(NULL)
103 m_dimensions = op.func().dimensions(op.expression());
106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
108 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(CoeffReturnType* data) {
113 m_result =
static_cast<CoeffReturnType*
>(
114 m_device.allocate(dimensions().TotalSize() *
sizeof(Scalar)));
120 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
121 if (m_result != NULL) {
122 m_device.deallocate(m_result);
127 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const {
128 return m_result[index];
131 template<
int LoadMode>
132 EIGEN_DEVICE_FUNC PacketReturnType packet(Index index)
const {
133 return internal::ploadt<PacketReturnType, LoadMode>(m_result + index);
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorOpCost costPerCoeff(
bool vectorized)
const {
138 return TensorOpCost(
sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
141 EIGEN_DEVICE_FUNC CoeffReturnType* data()
const {
return m_result; }
144 EIGEN_DEVICE_FUNC
void evalTo(Scalar* data) {
147 m_op.func().eval(m_op.expression(), result, m_device);
150 Dimensions m_dimensions;
152 const Device& m_device;
153 CoeffReturnType* m_result;
166 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
170 typename RhsXprType::Scalar>::ret Scalar;
172 typename RhsXprType::CoeffReturnType>::ret CoeffReturnType;
177 typedef typename LhsXprType::Nested LhsNested;
178 typedef typename RhsXprType::Nested RhsNested;
185 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
191 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
201 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
212 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorCustomBinaryOp(
const LhsXprType& lhs,
const RhsXprType& rhs,
const CustomBinaryFunc&
func)
214 : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_func(func) {}
217 const CustomBinaryFunc& func()
const {
return m_func; }
221 lhsExpression()
const {
return m_lhs_xpr; }
225 rhsExpression()
const {
return m_rhs_xpr; }
228 typename LhsXprType::Nested m_lhs_xpr;
229 typename RhsXprType::Nested m_rhs_xpr;
230 const CustomBinaryFunc m_func;
235 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType,
typename Device>
242 typedef typename XprType::Scalar Scalar;
256 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorEvaluator(
const XprType& op,
const Device& device)
257 : m_op(op), m_device(device), m_result(NULL)
259 m_dimensions = op.func().dimensions(op.lhsExpression(), op.rhsExpression());
262 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
264 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(CoeffReturnType* data) {
269 m_result =
static_cast<Scalar *
>(m_device.allocate(dimensions().TotalSize() *
sizeof(Scalar)));
275 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
276 if (m_result != NULL) {
277 m_device.deallocate(m_result);
282 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const {
283 return m_result[index];
286 template<
int LoadMode>
287 EIGEN_DEVICE_FUNC PacketReturnType packet(Index index)
const {
288 return internal::ploadt<PacketReturnType, LoadMode>(m_result + index);
291 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorOpCost costPerCoeff(
bool vectorized)
const {
293 return TensorOpCost(
sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
296 EIGEN_DEVICE_FUNC CoeffReturnType* data()
const {
return m_result; }
299 EIGEN_DEVICE_FUNC
void evalTo(Scalar* data) {
301 m_op.func().eval(m_op.lhsExpression(), m_op.rhsExpression(), result, m_device);
304 Dimensions m_dimensions;
306 const Device& m_device;
307 CoeffReturnType* m_result;
313 #endif // EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H Tensor custom class.
Definition: TensorCustomOp.h:52
Tensor custom class.
Definition: TensorCustomOp.h:202
Definition: TensorCostModel.h:25
Definition: XprHelper.h:158
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Definition: GenericPacketMath.h:96
template <class> class MakePointer_ is added to convert the host pointer to the device pointer...
Definition: TensorForwardDeclarations.h:25
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
The tensor base class.
Definition: TensorBase.h:827
Definition: benchGeometry.cpp:23
Definition: BandTriangularSolver.h:13
Definition: TensorTraits.h:170
The type used to identify a dense storage.
Definition: Constants.h:491
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Definition: ForwardDeclarations.h:17
Definition: XprHelper.h:312