7 #ifndef MSHADOW_EXTENSION_IMPLICIT_GEMM_H_ 8 #define MSHADOW_EXTENSION_IMPLICIT_GEMM_H_ 10 #include "../extension.h" 11 #include "../packet-inl.h" 21 template<
typename LhsExp,
typename RhsExp,
typename DType>
23 public Exp<ImplicitGEMMExp<LhsExp, RhsExp, DType>,
24 DType, type::kChainer> {
35 : lhs_(lhs), rhs_(rhs) {
44 template<
typename LhsExp,
typename RhsExp,
typename DType,
int e1,
int e2>
49 ::Error_Expression_Does_Not_Meet_Dimension_Req();
56 template<
typename LhsExp,
typename RhsExp,
typename DType>
68 Packet sum = Packet::Fill(0);
70 const size_t packetSize = Packet::size;
71 DType lhs_temp[packetSize], rhs_temp[packetSize];
73 for (
index_t i = 0; i < prod_size_lower_align_; i += packetSize) {
75 for (
index_t j = 0; j < packetSize; ++j) {
76 lhs_temp[j] =
lhs_.Eval(y, i + j);
78 for (
index_t j = 0; j < packetSize; ++j) {
79 rhs_temp[j] =
rhs_.Eval(i + j, x);
81 sum = sum + Packet::LoadUnAligned(lhs_temp) * Packet::LoadUnAligned(rhs_temp);
83 DType ret_result = sum.Sum();
86 ret_result +=
lhs_.Eval(y, i) *
rhs_.Eval(i, x);
95 const index_t prod_size_lower_align_;
98 template<
typename LhsExp,
typename RhsExp,
typename DType>
105 template<
int dim,
typename LhsExp,
typename RhsExp,
typename DType>
110 <<
"ImplicitGEMMExp only support 2 dimension";
113 CHECK_EQ(shape1[1], shape2[0])
114 <<
"implicit_dot The matrix shape do not match";
119 template<
typename LhsExp,
typename RhsExp,
typename DType>
121 static const int kDim = 2;
127 #endif // MSHADOW_EXTENSION_IMPLICIT_GEMM_H_ ImplicitGEMMExp(const LhsExp &lhs, const RhsExp &rhs)
constructor
Definition: implicit_gemm.h:34
ImplicitGEMMExp< LhsExp, RhsExp, DType > implicit_dot(const Exp< LhsExp, DType, e1 > &lhs, const Exp< RhsExp, DType, e2 > &rhs)
Definition: implicit_gemm.h:46
static Shape< dim > Check(const ImplicitGEMMExp< LhsExp, RhsExp, DType > &t)
Definition: implicit_gemm.h:108
index_t prod_size_
internal production size
Definition: implicit_gemm.h:30
Definition: expr_engine-inl.h:40
used to help static type check
Definition: expr_engine-inl.h:312
const RhsExp & rhs_
rhs operand
Definition: implicit_gemm.h:28
static Shape< dim > Check(const E &t)
#define MSHADOW_XINLINE
Definition: base.h:204
Shape< 2 > shape_
the shape of this expression
Definition: implicit_gemm.h:32
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:244
int32_t index_t
type that will be used for index
Definition: base.h:291
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:346
MSHADOW_XINLINE Shape< 2 > Shape2(index_t s0, index_t s1)
construct a two dimension shape, stride will equal s0
Definition: tensor.h:198
index_t LowerAlign(index_t size)
get lower bound of aligned index of size
Definition: packet-inl.h:124
const LhsExp & lhs_
lhs operand
Definition: implicit_gemm.h:26
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:61
const SubType & 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
namespace for mshadow
Definition: base.h:282
Plan(const ImplicitGEMMExp< LhsExp, RhsExp, DType > &e)
Definition: implicit_gemm.h:59
Matrix multiplication.
Definition: implicit_gemm.h:22
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: implicit_gemm.h:66
#define MSHADOW_DEFAULT_PACKET
Definition: packet-inl.h:29
Generic packet type.
Definition: packet-inl.h:41