7 #ifndef MSHADOW_EXPR_ENGINE_INL_H_ 8 #define MSHADOW_EXPR_ENGINE_INL_H_ 11 #include "./logging.h" 24 template<
typename SubType,
typename SrcExp,
int dim,
typename DType>
26 :
public Exp<MakeTensorExp<SubType, SrcExp, dim, DType>,
27 DType, type::kChainer> {
32 return *
static_cast<const SubType*
>(
this);
39 template<
typename ExpType,
typename DType>
49 template <
typename Device,
int dim,
typename DType>
53 : dptr_(t.dptr_), stride_(t.stride_) {}
56 return dptr_[y * stride_ + x];
60 return dptr_[y * stride_ + x];
68 template <
typename Device,
typename DType>
83 template<
typename DType>
95 template<
typename DstDType,
typename SrcDType,
96 typename EType,
int etype>
101 return DstDType(src_.Eval(y, x));
109 template<
typename OP,
typename TA,
typename TB,
typename TC,
int etype,
typename DType>
114 : item1_(item1), item2_(item2), item3_(item3) {}
116 return OP::Map(item1_.Eval(y, x), item2_.Eval(y, x), item3_.Eval(y, x));
125 template<
typename OP,
typename TA,
typename TB,
int etype,
typename DType>
129 : lhs_(lhs), rhs_(rhs) {}
131 return OP::Map(lhs_.Eval(y, x), rhs_.Eval(y, x));
139 template<
typename OP,
typename TA,
int etype,
typename DType>
144 return OP::Map(src_.Eval(y, x));
151 template<
typename SubType,
typename SrcExp,
int dim,
typename DType>
156 return src_.Eval(y, x);
163 template<
typename EType,
typename DType>
168 return src_.Eval(x, y);
177 template<
typename OP,
typename TA,
typename TB,
typename DType,
int etype>
181 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int etype>
185 template<
typename DType>
190 template<
typename DstDType,
typename SrcDType,
typename EType,
int etype>
193 return Plan<TypecastExp<DstDType, SrcDType, EType, etype>, DstDType>(
MakePlan(e.
exp));
196 template<
typename T,
typename DType>
201 template<
typename T,
typename DType>
204 return Plan<TransposeExp<T, DType>, DType>(
MakePlan(e.
exp));
207 template<
typename T,
typename SrcExp,
int dim,
typename DType>
213 template<
typename OP,
typename TA,
typename DType,
int etype>
216 return Plan<UnaryMapExp<OP, TA, DType, etype>, DType>(
MakePlan(e.
src_));
219 template<
typename OP,
typename TA,
typename TB,
typename DType,
int etype>
220 inline Plan<BinaryMapExp<OP, TA, TB, DType, etype>, DType>
222 return Plan<BinaryMapExp<OP, TA, TB, DType, etype>,
227 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int etype>
228 inline Plan<TernaryMapExp<OP, TA, TB, TC, DType, etype>, DType>
230 return Plan<TernaryMapExp<OP, TA, TB, TC, DType, etype>,
245 static const int kDim = -1;
246 static const int kDevMask = 0;
248 template<
typename DType>
250 static const int kDim = 0;
251 static const int kDevMask = 0xffff;
253 template<
typename E,
typename DType>
258 template<
typename DstDType,
typename SrcDType,
typename EType,
int etype>
263 template<
typename Device,
int dim,
typename DType>
265 static const int kDim = dim;
266 static const int kDevMask = Device::kDevMask;
268 template<
typename T,
typename SrcExp,
int dim,
typename DType>
271 static const int kDim = kDimSrc >= 0 ? dim : -1;
274 template<
typename OP,
typename TA,
typename DType,
int etype>
279 template<
typename OP,
typename TA,
typename TB,
typename DType,
int etype>
283 static const int kDim = (kDimLhs >= 0 && kDimRhs >= 0) ?\
286 ((kDimRhs == 0 || kDimLhs == kDimRhs) ? kDimLhs : -1)) : -1;
289 template<
typename OP,
typename TA,
typename TB,
typename TC,
typename DType,
int etype>
294 static const int kDim = kDimItem1;
299 template<
typename Device,
int dim,
typename DType,
typename E>
306 static const bool kMapPass = (kExpDim == 0 || kExpDim == dim) && kDevPass;
308 static const bool kRedPass = (kExpDim > dim) && kDevPass;
326 template<
typename Device,
typename E>
330 template<
int dim,
typename Device,
typename DType>
345 template<
int dim,
typename E>
349 template<
int dim,
typename DType>
354 for (
int i = 0; i < dim; ++i) {
360 template<
int dim,
typename DstDType,
typename SrcDType,
typename EType,
int etype>
367 template<
int dim,
typename E,
typename DType>
372 std::swap(s[0], s[1]);
376 template<
int dim,
typename Device,
typename DType>
382 template<
int dim,
typename SrcExp,
typename T,
typename DType>
389 template<
int dim,
typename OP,
typename TA,
typename DType,
int etype>
397 template<
int dim,
typename OP,
typename TA,
typename TB,
398 typename DType,
int etype>
404 if (shape1[0] == 0)
return shape2;
405 if (shape2[0] == 0)
return shape1;
406 CHECK_EQ(shape1, shape2) <<
"BinaryMapExp: Shapes of operands are not the same, " <<
407 "Shape1=" << shape1 <<
", Shape2=" << shape2;
412 template<
int dim,
typename OP,
typename TA,
typename TB,
typename TC,
413 typename DType,
int etype>
420 bool same = (shape1 == shape2) && (shape2 == shape3);
421 CHECK(same) <<
"TernaryMapExp: Shapes of operands are not the same, " <<
422 "Shape1=" << shape1 <<
", Shape2=" << shape2 <<
", Shape3=" << shape3;
436 template<
typename SV,
typename RV,
typename E,
typename DType>
438 inline static void Eval(RV *dst,
const E &exp);
441 template<
typename SV,
typename RV,
typename DType>
444 inline static void Eval(RV *dst,
446 MapExp<SV>(dst, exp);
449 inline static void Eval(RV *dst,
451 MapExp<SV>(dst, exp);
454 inline static void Eval(RV *dst,
456 MapExp<SV>(dst, exp);
459 inline static void Eval(RV *dst,
464 template<
typename SV,
typename Device,
int dim,
int ldim,
465 int rdim,
bool ltrans,
bool rtrans,
typename DType>
467 Tensor<Device, dim, DType>,
469 Tensor<Device, rdim, DType>,
470 ltrans, rtrans, DType>,
475 ltrans, rtrans, DType> &exp) {
477 ltrans, rtrans, DType>::Eval(dst, exp.lhs_, exp.rhs_, exp.scale_);
482 #endif // MSHADOW_EXPR_ENGINE_INL_H_ Plan(const Plan< TA, DType > &src)
Definition: expr_engine-inl.h:142
static Shape< dim > Check(const UnaryMapExp< OP, TA, DType, etype > &t)
Definition: expr_engine-inl.h:391
static void Eval(RV *dst, const Exp< E, DType, type::kRValue > &exp)
Definition: expr_engine-inl.h:454
static Shape< dim > Check(const MakeTensorExp< T, SrcExp, dim, DType > &t)
Definition: expr_engine-inl.h:385
static Shape< dim > Check(const Tensor< Device, dim, DType > &t)
Definition: expr_engine-inl.h:378
ScalarExp< DType > scalar(DType s)
create an scalar expression
Definition: expression.h:85
static Shape< dim > Check(const BinaryMapExp< OP, TA, TB, DType, etype > &t)
Definition: expr_engine-inl.h:401
Definition: expr_engine-inl.h:40
Plan(const Tensor< Device, 1, DType > &t)
Definition: expr_engine-inl.h:71
used to help static type check
Definition: expr_engine-inl.h:312
template to do type check
Definition: expr_engine-inl.h:300
const TB & rhs_
right operand
Definition: expression.h:321
Plan(const Tensor< Device, dim, DType > &t)
Definition: expr_engine-inl.h:52
Shape< dimension > shape_
shape of the tensor
Definition: tensor.h:418
ternary map expression
Definition: expression.h:261
static void Error_All_Tensor_in_Exp_Must_Have_Same_Type(void)
Definition: expr_engine-inl.h:318
binary map expression lhs [op] rhs
Definition: expression.h:316
Plan(DType scalar)
Definition: expr_engine-inl.h:86
mshadow::expr::ExpComplexEngine< SV, Tensor< Device, dim, DType >, DotExp< Tensor< Device, ldim, DType >, Tensor< Device, rdim, DType >, ltrans, rtrans, DType >, DType >::Eval static void Eval(Tensor< Device, dim, DType > *dst, const DotExp< Tensor< Device, ldim, DType >, Tensor< Device, rdim, DType >, ltrans, rtrans, DType > &exp)
Definition: expr_engine-inl.h:472
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:155
static void Eval(RV *dst, const E &exp)
base class of all rvalues
Definition: expression.h:130
Definition: dot_engine-inl.h:52
DType scalar_
scalar value
Definition: expression.h:79
MSHADOW_XINLINE DType & REval(index_t y, index_t x)
Definition: expr_engine-inl.h:55
const EType & exp
expression to be transposed
Definition: expression.h:116
static void Error_TypeCheck_Not_Pass_For_Reduce_Exp(void)
Definition: expr_engine-inl.h:319
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:115
MSHADOW_XINLINE const DType & Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:59
static Shape< dim > Check(const E &t)
static void Eval(RV *dst, const Exp< E, DType, type::kChainer > &exp)
Definition: expr_engine-inl.h:449
#define MSHADOW_XINLINE
Definition: base.h:204
const TB & item2_
second operand
Definition: expression.h:266
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:244
Definition: expr_engine-inl.h:327
definitions of abstract expressions and expressions template
static void Eval(RV *dst, const Exp< E, DType, type::kComplex > &exp)
Definition: expr_engine-inl.h:459
static Shape< dim > Check(const TernaryMapExp< OP, TA, TB, TC, DType, etype > &t)
Definition: expr_engine-inl.h:416
static void Error_Expression_Does_Not_Meet_Dimension_Req(void)
Definition: expr_engine-inl.h:320
MSHADOW_XINLINE const DType & Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:75
int32_t index_t
type that will be used for index
Definition: base.h:291
Plan(const Plan< EType, DType > &src)
Definition: expr_engine-inl.h:166
static Shape< dim > Check(const TypecastExp< DstDType, SrcDType, EType, etype > &exp)
Definition: expr_engine-inl.h:363
Plan(const Plan< TA, DType > &item1, const Plan< TB, DType > &item2, const Plan< TC, DType > &item3)
Definition: expr_engine-inl.h:112
const TA & item1_
first operand
Definition: expression.h:264
typecast expression, cast the type of elements
Definition: expression.h:96
static Shape< dim > Check(const ScalarExp< DType > &exp)
Definition: expr_engine-inl.h:351
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:346
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:143
represent a transpose expression of a container
Definition: expression.h:113
some engine that evaluate complex expression
Definition: expr_engine-inl.h:437
const TA & src_
source expression
Definition: expression.h:389
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:167
unary map expression op(src)
Definition: expression.h:386
matrix multiplication expression dot(lhs[.T], rhs[.T])
Definition: expression.h:206
Plan(const Plan< EType, SrcDType > &src)
Definition: expr_engine-inl.h:99
scalar expression
Definition: expression.h:77
Plan(const Plan< SubType, DType > &src)
Definition: expr_engine-inl.h:154
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:61
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:87
const EType & exp
expression to be typecasted
Definition: expression.h:100
const Container & self(void) const
Definition: expression.h:64
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:221
const TC & item3_
third operand
Definition: expression.h:268
MSHADOW_XINLINE DstDType Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:100
const SubType & real_self(void) const
true self of subtype
Definition: expr_engine-inl.h:31
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: expr_engine-inl.h:130
a general class that allows extension that makes tensors of some shape
Definition: expr_engine-inl.h:25
const TA & lhs_
left operand
Definition: expression.h:319
namespace for mshadow
Definition: base.h:282
static Shape< dim > Check(const TransposeExp< E, DType > &e)
Definition: expr_engine-inl.h:369
the engine that dispatches simple operations
Definition: expr_engine-inl.h:442
Shape< dim > shape_
the shape of this expression
Definition: expr_engine-inl.h:29
general tensor
Definition: tensor.h:402
static void Eval(RV *dst, const Exp< E, DType, type::kMapper > &exp)
Definition: expr_engine-inl.h:444
Stream< Device > * stream_
stream where the computation lies stream is a device dependency concept where each computation ...
Definition: tensor.h:428
definitions of how Matrix Multiplications can be evaluated
Plan(const Plan< TA, DType > &lhs, const Plan< TB, DType > &rhs)
Definition: expr_engine-inl.h:128
MSHADOW_XINLINE DType & REval(index_t y, index_t x)
Definition: expr_engine-inl.h:72
static Stream< Device > * Get(const Tensor< Device, dim, DType > &t)
Definition: expr_engine-inl.h:332
computaion stream structure, used for asynchronous computations
Definition: tensor.h:365