Go to the documentation of this file.
25 #ifndef MSHADOW_EXTENSION_IMPLICIT_GEMM_H_
26 #define MSHADOW_EXTENSION_IMPLICIT_GEMM_H_
28 #include "../extension.h"
29 #include "../packet-inl.h"
39 template<
typename LhsExp,
typename RhsExp,
typename DType>
41 public Exp<ImplicitGEMMExp<LhsExp, RhsExp, DType>,
42 DType, type::kChainer> {
62 template<
typename LhsExp,
typename RhsExp,
typename DType,
int e1,
int e2>
63 inline ImplicitGEMMExp<LhsExp, RhsExp, DType>
67 ::Error_Expression_Does_Not_Meet_Dimension_Req();
74 template<
typename LhsExp,
typename RhsExp,
typename DType>
80 prod_size_(e.prod_size_),
86 Packet sum = Packet::Fill(0);
88 const size_t packetSize = Packet::size;
89 DType lhs_temp[packetSize], rhs_temp[packetSize];
91 for (
index_t i = 0; i < prod_size_lower_align_; i += packetSize) {
93 for (
index_t j = 0; j < packetSize; ++j) {
94 lhs_temp[j] = lhs_.Eval(y, i + j);
96 for (
index_t j = 0; j < packetSize; ++j) {
97 rhs_temp[j] = rhs_.Eval(i + j, x);
99 sum = sum + Packet::LoadUnAligned(lhs_temp) * Packet::LoadUnAligned(rhs_temp);
101 DType ret_result = sum.Sum();
103 for (
index_t i = prod_size_lower_align_; i < prod_size_; ++i) {
104 ret_result += lhs_.Eval(y, i) * rhs_.Eval(i, x);
113 const index_t prod_size_lower_align_;
116 template<
typename LhsExp,
typename RhsExp,
typename DType>
117 inline Plan<ImplicitGEMMExp<LhsExp, RhsExp, DType>, DType>
123 template<
int dim,
typename LhsExp,
typename RhsExp,
typename DType>
128 <<
"ImplicitGEMMExp only support 2 dimension";
131 CHECK_EQ(shape1[1], shape2[0])
132 <<
"implicit_dot The matrix shape do not match";
137 template<
typename LhsExp,
typename RhsExp,
typename DType>
145 #endif // MSHADOW_EXTENSION_IMPLICIT_GEMM_H_
static const int kDevMask
Definition: expr_engine-inl.h:264
const SubType & self(void) const
Definition: expression.h:82
index_t prod_size_
internal production size
Definition: implicit_gemm.h:48
used to help static type check
Definition: expr_engine-inl.h:330
ImplicitGEMMExp(const LhsExp &lhs, const RhsExp &rhs)
constructor
Definition: implicit_gemm.h:52
Generic packet type.
Definition: packet-inl.h:59
const RhsExp & rhs_
rhs operand
Definition: implicit_gemm.h:46
#define MSHADOW_XINLINE
Definition: base.h:228
index_t LowerAlign(index_t size)
get lower bound of aligned index of size
Definition: packet-inl.h:146
runtime shape checking template get the shape of an expression, report error if shape mismatch
Definition: expr_engine-inl.h:364
static Shape< dim > Check(const E &t)
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:262
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:239
static Shape< dim > Check(const ImplicitGEMMExp< LhsExp, RhsExp, DType > &t)
Definition: implicit_gemm.h:126
static const int kDim
Definition: expr_engine-inl.h:263
int32_t index_t
type that will be used for index
Definition: base.h:328
Definition: expr_engine-inl.h:58
Shape< 2 > shape_
the shape of this expression
Definition: implicit_gemm.h:50
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
ImplicitGEMMExp< LhsExp, RhsExp, DType > implicit_dot(const Exp< LhsExp, DType, e1 > &lhs, const Exp< RhsExp, DType, e2 > &rhs)
Definition: implicit_gemm.h:64
overloaded + operator between half_t and bf16_t
Definition: base.h:319
const LhsExp & lhs_
lhs operand
Definition: implicit_gemm.h:44
MSHADOW_XINLINE Shape< 2 > Shape2(index_t s0, index_t s1)
construct a two dimension shape, stride will equal s0
Definition: tensor.h:230
Plan(const ImplicitGEMMExp< LhsExp, RhsExp, DType > &e)
Definition: implicit_gemm.h:77
Matrix multiplication.
Definition: implicit_gemm.h:40
#define MSHADOW_DEFAULT_PACKET
Definition: packet-inl.h:47
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: implicit_gemm.h:84