forked from jiuyuan/InfiniTensor
Rename: Expr construction helpers
This commit is contained in:
parent
c6c445991a
commit
29071ddcac
|
@ -386,13 +386,16 @@ class FuncNode : public ExprNode {
|
|||
};
|
||||
|
||||
// Wrappers for type deduction
|
||||
Subscript makeSubscript(const Expr &tensor, const VecExpr &subscripts);
|
||||
RangeOp makeRangeOperator(const vector<VarRangePair> &_loopIters,
|
||||
const vector<VarRangePair> &_sumIters, Expr _summand,
|
||||
const vector<int> &paddings = {});
|
||||
Tensor makeTensor(const string &name, const vector<int> &shape,
|
||||
const vector<int> &paddings = {},
|
||||
const Routine &source = nullptr);
|
||||
|
||||
// make subscript
|
||||
Subscript mSub(const Expr &tensor, const VecExpr &subscripts);
|
||||
// make range operator
|
||||
RangeOp mL(const vector<VarRangePair> &_loopIters,
|
||||
const vector<VarRangePair> &_sumIters, Expr _summand,
|
||||
const vector<int> &paddings = {});
|
||||
// make tensor
|
||||
Tensor mT(const string &name, const vector<int> &shape,
|
||||
const vector<int> &paddings = {}, const Routine &source = nullptr);
|
||||
|
||||
// Pretty output for dbg with shared_ptr
|
||||
template <typename T, typename std::enable_if_t<std::is_base_of_v<ExprNode, T>>
|
||||
|
|
|
@ -7,7 +7,9 @@ namespace infini {
|
|||
*
|
||||
*/
|
||||
class SliceObj : public OperatorObj {
|
||||
template <class T> struct range_t { T start, end, step; };
|
||||
template <class T> struct range_t {
|
||||
T start, end, step;
|
||||
};
|
||||
vector<range_t<int>> axes;
|
||||
|
||||
public:
|
||||
|
|
|
@ -12,12 +12,11 @@ void MatchMemBoundKernel::transform(Formula &origin, int depth, Expr &rCur) {
|
|||
const auto &inputs = InputVisitor().getInputs(rangeOp);
|
||||
auto source =
|
||||
make_ref<ElementWiseNode>(rangeOp, inputs, rangeOp->getOutputShape());
|
||||
auto tensor =
|
||||
makeTensor(newTensorName(), rangeOp->getOutputShape(), {}, source);
|
||||
auto tensor = mT(newTensorName(), rangeOp->getOutputShape(), {}, source);
|
||||
// The original code directly appends candidate. But it seems should be done
|
||||
// by the search.
|
||||
// appendCanddiate(as<TensorNode>(tensor), depth);
|
||||
nextStep(origin, depth, rCur, tensor);
|
||||
}
|
||||
|
||||
} // namespace nnet
|
||||
} // namespace nnet
|
||||
|
|
|
@ -38,11 +38,10 @@ void Rule3StageSplit::transform(Formula &origin, int depth, Expr &rCur) {
|
|||
|
||||
// if no sum iterator, the stage is redundant
|
||||
assert(!innerSumVars.empty());
|
||||
auto inner =
|
||||
makeRangeOperator(innerLoopVars, innerSumVars, cur->getSummand());
|
||||
auto inner = mL(innerLoopVars, innerSumVars, cur->getSummand());
|
||||
auto subscriptedInner = make_ref<SubscriptNode>(inner, indexForInner);
|
||||
auto outer = makeRangeOperator(cur->getLoopVarRanges(), outerSumVars,
|
||||
subscriptedInner);
|
||||
auto outer =
|
||||
mL(cur->getLoopVarRanges(), outerSumVars, subscriptedInner);
|
||||
outer->setPaddings(cur->getPaddings());
|
||||
|
||||
// next searching step
|
||||
|
@ -79,4 +78,4 @@ Rule3StageSplit::getSplitSummationIters(RangeOp rangeOp) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
} // namespace nnet
|
||||
} // namespace nnet
|
||||
|
|
|
@ -50,8 +50,8 @@ VecExpr Rule6KenerlMatching::matchElementWise(const RangeOp &rangeOp) {
|
|||
const auto &inputs = InputVisitor().getInputs(rangeOp);
|
||||
auto source =
|
||||
make_ref<ElementWiseNode>(rangeOp, inputs, rangeOp->getOutputShape());
|
||||
auto newTensor = makeTensor(newTensorName(), newShape, {}, source);
|
||||
auto newTensor = mT(newTensorName(), newShape, {}, source);
|
||||
return {newTensor};
|
||||
}
|
||||
|
||||
} // namespace nnet
|
||||
} // namespace nnet
|
||||
|
|
|
@ -265,10 +265,9 @@ Expr Rule8GuidedDLT::guidedDLTMoreVar2(const RangeOp &cur,
|
|||
const auto sourceRoutine = make_ref<ElementWiseNode>(
|
||||
sourceExpr, vector<Tensor>{originalTensor}, newShape);
|
||||
// build stage connections
|
||||
const auto newTensor =
|
||||
makeTensor(newTensorName(), newShape, {}, sourceRoutine);
|
||||
const auto &newSub = makeSubscript(
|
||||
newTensor, VecExpr(tensorDimAxes.begin(), tensorDimAxes.end()));
|
||||
const auto newTensor = mT(newTensorName(), newShape, {}, sourceRoutine);
|
||||
const auto &newSub =
|
||||
mSub(newTensor, VecExpr(tensorDimAxes.begin(), tensorDimAxes.end()));
|
||||
// TODO [1124]: get variable mapping and reorder L according to it
|
||||
// dbg(cur, originalSub, newSub, newVarRanges, replace.toReadable(),
|
||||
// tensorDimAxes, newShape);
|
||||
|
@ -311,7 +310,7 @@ Expr Rule8GuidedDLT::buildGuidedDLTSource(const Subscript &originalSub,
|
|||
vector<VarRangePair> loopVarRangePairs;
|
||||
for (size_t i = 0; i < tensorDimAxes.size(); ++i)
|
||||
loopVarRangePairs.emplace_back(tensorDimAxes[i], pair(0, newShape[i]));
|
||||
return makeRangeOperator(loopVarRangePairs, {}, newSub);
|
||||
return mL(loopVarRangePairs, {}, newSub);
|
||||
}
|
||||
|
||||
} // namespace nnet
|
||||
} // namespace nnet
|
||||
|
|
|
@ -47,8 +47,8 @@ Rule90TwoStageElementWise::matchTwoStageElementWise(const RangeOp &rangeOp) {
|
|||
const auto &inputs = InputVisitor().getInputs(rangeOp);
|
||||
auto source =
|
||||
make_ref<ElementWiseNode>(rangeOp, inputs, rangeOp->getOutputShape());
|
||||
auto newTensor = makeTensor(newTensorName(), newShape, {}, source);
|
||||
auto newTensor = mT(newTensorName(), newShape, {}, source);
|
||||
return {newTensor};
|
||||
}
|
||||
|
||||
} // namespace nnet
|
||||
} // namespace nnet
|
||||
|
|
|
@ -45,27 +45,26 @@ VecExpr MatmulTransposeMutator::transpose(const Tensor &tensor) {
|
|||
auto _va = make_ref<VarNode>("transA");
|
||||
auto _vb = make_ref<VarNode>("transB");
|
||||
auto _vc = make_ref<VarNode>("swapAB");
|
||||
auto fakeSub = makeSubscript(matmul->getExpr(), {_va, _vb});
|
||||
auto fakeRangeWrapperForHackHash =
|
||||
makeRangeOperator({{_va, {0, Atrans + 100}},
|
||||
{_vb, {0, Btrans + 100}},
|
||||
{_vc, {0, ABswap + 100}}},
|
||||
{}, fakeSub);
|
||||
auto fakeSub = mSub(matmul->getExpr(), {_va, _vb});
|
||||
auto fakeRangeWrapperForHackHash = mL({{_va, {0, Atrans + 100}},
|
||||
{_vb, {0, Btrans + 100}},
|
||||
{_vc, {0, ABswap + 100}}},
|
||||
{}, fakeSub);
|
||||
Matmul newMatmul =
|
||||
make_ref<MatmulNode>(fakeRangeWrapperForHackHash, inputs[0],
|
||||
inputs[1], b, m, n, k, transa, transb);
|
||||
auto newTensor = makeTensor(derivator.newTensorName(), newShape,
|
||||
newPaddings, newMatmul);
|
||||
auto newTensor =
|
||||
mT(derivator.newTensorName(), newShape, newPaddings, newMatmul);
|
||||
// build output transpose
|
||||
if (ABswap) {
|
||||
vector<Var> vars{derivator.getNewVar(), derivator.getNewVar()};
|
||||
auto sub = makeSubscript(newTensor, {vars[1], vars[0]});
|
||||
auto sub = mSub(newTensor, {vars[1], vars[0]});
|
||||
vector<VarRangePair> loopVRs;
|
||||
// Sicne inputs array may be swaped, use the orignal tensor shape
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
loopVRs.emplace_back(vars[i], Range(0, tensor->getShape(i)));
|
||||
}
|
||||
auto rangeOp = makeRangeOperator(loopVRs, {}, sub);
|
||||
auto rangeOp = mL(loopVRs, {}, sub);
|
||||
ret.emplace_back(rangeOp);
|
||||
} else
|
||||
ret.emplace_back(newTensor);
|
||||
|
@ -85,8 +84,8 @@ optional<Tensor> MatmulTransposeMutator::transposeInput(const Tensor &tensor) {
|
|||
assert(!rangeOp->hasPaddings());
|
||||
// auto paddings = rangeOp->getPaddings();
|
||||
// std::swap(paddings[0], paddings[1]);
|
||||
auto sub = makeSubscript(rangeOp, {loopVRs[1].first, loopVRs[0].first});
|
||||
auto newRangeOp = makeRangeOperator(loopVRs, {}, sub);
|
||||
auto sub = mSub(rangeOp, {loopVRs[1].first, loopVRs[0].first});
|
||||
auto newRangeOp = mL(loopVRs, {}, sub);
|
||||
// ElementWise newElementWise = make_ref<ElementWiseNode>(*ew);
|
||||
auto outputShape = ew->getOutputShape();
|
||||
std::swap(outputShape[0], outputShape[1]);
|
||||
|
@ -97,8 +96,8 @@ optional<Tensor> MatmulTransposeMutator::transposeInput(const Tensor &tensor) {
|
|||
auto tensorPaddings = tensor->getPaddings();
|
||||
std::swap(tensorShape[0], tensorShape[1]);
|
||||
std::swap(tensorPaddings[0], tensorPaddings[1]);
|
||||
ret = makeTensor(derivator.newTensorName(), tensorShape, tensorPaddings,
|
||||
newElementWise);
|
||||
ret = mT(derivator.newTensorName(), tensorShape, tensorPaddings,
|
||||
newElementWise);
|
||||
// } else if (!tensor->getSource()) {
|
||||
} else {
|
||||
nnet_unimplemented_continue();
|
||||
|
@ -107,4 +106,4 @@ optional<Tensor> MatmulTransposeMutator::transposeInput(const Tensor &tensor) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
} // namespace nnet
|
||||
} // namespace nnet
|
||||
|
|
|
@ -32,8 +32,7 @@ RangeOp PatternMatcher::getOffsetCur() {
|
|||
}
|
||||
auto newSummand = ReplaceKit::replaceMultipleExprs(
|
||||
originalCur->getSummand(), itersFromNonZero, psis);
|
||||
return makeRangeOperator(newLoopVarRanges, originalCur->getSumVarRanges(),
|
||||
newSummand);
|
||||
return mL(newLoopVarRanges, originalCur->getSumVarRanges(), newSummand);
|
||||
}
|
||||
|
||||
VecExpr PatternMatcher::matchKernel(const Pattern &pattern,
|
||||
|
@ -106,9 +105,9 @@ VecExpr PatternMatcher::applyWrapper(const VecExpr &exprs) {
|
|||
}
|
||||
}
|
||||
for (auto &expr : exprs) {
|
||||
auto newSub = makeSubscript(expr, indexes);
|
||||
ret.emplace_back(makeRangeOperator(originalCur->getLoopVarRanges(), {},
|
||||
newSub, originalCur->getPaddings()));
|
||||
auto newSub = mSub(expr, indexes);
|
||||
ret.emplace_back(mL(originalCur->getLoopVarRanges(), {}, newSub,
|
||||
originalCur->getPaddings()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ Expr Serializer::buildExprTree(string key) {
|
|||
}
|
||||
auto summand = buildExprTree(j[key]["summand"]);
|
||||
auto paddings = j[key]["paddings"].get<std::vector<int>>();
|
||||
auto rangeOp = makeRangeOperator(loopIters, sumIters, summand);
|
||||
auto rangeOp = mL(loopIters, sumIters, summand);
|
||||
rangeOp->setPaddings(paddings);
|
||||
return rangeOp;
|
||||
}
|
||||
|
|
|
@ -83,12 +83,11 @@ optional<Expr> DLT::apply(const RangeOp &rangeOp, const Subscript &subscript,
|
|||
// HACK [important] fix this fake tensor.
|
||||
auto elementRoutine = make_ref<ElementWiseNode>(
|
||||
// FIXME: implement transpose
|
||||
// makeTensor(newTensorName + "_DLT", {}), vector<Tensor>{tensor},
|
||||
// mT(newTensorName + "_DLT", {}), vector<Tensor>{tensor},
|
||||
// shape0);
|
||||
makeTensor("__DLT", {}), vector<Tensor>{tensor}, shape0);
|
||||
auto dltedTensor =
|
||||
makeTensor(newTensorName, shape0, dltedPaddings, elementRoutine);
|
||||
auto dltedSubscript = makeSubscript(dltedTensor, index0);
|
||||
mT("__DLT", {}), vector<Tensor>{tensor}, shape0);
|
||||
auto dltedTensor = mT(newTensorName, shape0, dltedPaddings, elementRoutine);
|
||||
auto dltedSubscript = mSub(dltedTensor, index0);
|
||||
return optional<Expr>(std::in_place, dltedSubscript);
|
||||
}
|
||||
|
||||
|
|
|
@ -368,19 +368,19 @@ Expr operator/(const Expr &lhs, const int rhs) {
|
|||
}
|
||||
|
||||
// Wrappers for type deduction
|
||||
Subscript makeSubscript(const Expr &tensor, const VecExpr &subscripts) {
|
||||
Subscript mSub(const Expr &tensor, const VecExpr &subscripts) {
|
||||
return make_ref<SubscriptNode>(tensor, subscripts);
|
||||
}
|
||||
|
||||
RangeOp makeRangeOperator(const vector<VarRangePair> &_loopIters,
|
||||
const vector<VarRangePair> &_sumIters, Expr _summand,
|
||||
const vector<int> &paddings) {
|
||||
RangeOp mL(const vector<VarRangePair> &_loopIters,
|
||||
const vector<VarRangePair> &_sumIters, Expr _summand,
|
||||
const vector<int> &paddings) {
|
||||
return make_ref<RangeOpNode>(_loopIters, _sumIters, _summand, paddings);
|
||||
}
|
||||
|
||||
// Wrappers for type deduction
|
||||
Tensor makeTensor(const string &name, const vector<int> &shape,
|
||||
const vector<int> &paddings, const Routine &source) {
|
||||
Tensor mT(const string &name, const vector<int> &shape,
|
||||
const vector<int> &paddings, const Routine &source) {
|
||||
if (paddings.size() == 0)
|
||||
return make_ref<TensorNode>(name, shape,
|
||||
vector<int>((int)shape.size(), 0), source);
|
||||
|
|
|
@ -296,10 +296,9 @@ const Pattern &MatmulPattern::getMatmulPattern() {
|
|||
auto k = make_ref<VarNode>("_Matmul_k");
|
||||
auto A = make_ref<TensorNode>("_Matmul_A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("_Matmul_B", vector<int>({N, K}));
|
||||
auto subA = makeSubscript(A, {m, k});
|
||||
auto subB = makeSubscript(B, {n, k});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {m, k});
|
||||
auto subB = mSub(B, {n, k});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
auto success = exprIT.analyzeExpr(range);
|
||||
assert(success);
|
||||
exprIT.buildTable({0, 1});
|
||||
|
@ -317,11 +316,10 @@ const Pattern &ConvPattern::getPattern() {
|
|||
// auto n = make_ref<VarNode>("_Matmul_n");
|
||||
auto A = make_ref<TensorNode>("_Conv_A", vector<int>({N, C, H, W}));
|
||||
auto B = make_ref<TensorNode>("_Conv_K", vector<int>({F, C, R, S}));
|
||||
auto subA = makeSubscript(A, {n, c, h + r, w + s});
|
||||
auto subB = makeSubscript(B, {f, c, r, s});
|
||||
auto range = makeRangeOperator(
|
||||
{{n, {0, 0}}, {f, {0, 0}}, {h, {0, 0}}, {w, {0, 0}}},
|
||||
{{c, {0, 0}}, {r, {0, 0}}, {s, {0, 0}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, c, h + r, w + s});
|
||||
auto subB = mSub(B, {f, c, r, s});
|
||||
auto range = mL({{n, {0, 0}}, {f, {0, 0}}, {h, {0, 0}}, {w, {0, 0}}},
|
||||
{{c, {0, 0}}, {r, {0, 0}}, {s, {0, 0}}}, subA * subB);
|
||||
auto success = exprIT.analyzeExpr(range);
|
||||
assert(success);
|
||||
exprIT.buildTable({0, 1});
|
||||
|
@ -404,11 +402,10 @@ const Pattern &Sg2bmmPattern::getPattern() {
|
|||
// auto n = make_ref<VarNode>("_Matmul_n");
|
||||
auto A = make_ref<TensorNode>("_Sg2bmm_A", vector<int>{Batch, M, K});
|
||||
auto B = make_ref<TensorNode>("_Sg2bmm_B", vector<int>{Batch, M, K});
|
||||
auto subA = makeSubscript(A, {b, m, k});
|
||||
auto subB = makeSubscript(B, {b, m + w, k});
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {w, {-W, W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, k});
|
||||
auto subB = mSub(B, {b, m + w, k});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {w, {-W, W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
auto success = exprIT.analyzeExpr(range);
|
||||
assert(success);
|
||||
exprIT.buildTableWithDefaultMap();
|
||||
|
@ -458,11 +455,10 @@ const Pattern &LongformerGBMMPattern::getPattern() {
|
|||
auto A =
|
||||
make_ref<TensorNode>("_lo_A", vector<int>{Batch, M, 2 * W + 1});
|
||||
auto B = make_ref<TensorNode>("_lo_B", vector<int>{Batch, M, N});
|
||||
auto subA = makeSubscript(A, {b, m, w});
|
||||
auto subB = makeSubscript(B, {b, m + w, n});
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {n, {0, M}}},
|
||||
{{w, {-W, W + 1}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, w});
|
||||
auto subB = mSub(B, {b, m + w, n});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {n, {0, M}}},
|
||||
{{w, {-W, W + 1}}}, subA * subB);
|
||||
auto success = exprIT.analyzeExpr(range);
|
||||
assert(success);
|
||||
exprIT.buildTableWithDefaultMap();
|
||||
|
@ -536,11 +532,10 @@ Expr ConvPattern::getExpr(Tensor A, Tensor K, int N, int C, int H, int W, int F,
|
|||
DEFINE_VAR(f);
|
||||
DEFINE_VAR(r);
|
||||
DEFINE_VAR(s);
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subB = makeSubscript(K, {f, c, r, s});
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subB = mSub(K, {f, c, r, s});
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subB);
|
||||
return range;
|
||||
}
|
||||
|
||||
|
@ -572,13 +567,13 @@ Expr ConvTransPattern::getExpr(Tensor A, Tensor K, int N, int C, int H, int W,
|
|||
// vector<int>{0, padding, padding, 0});
|
||||
// auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subA = mSub(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK =
|
||||
// makeSubscript(K, {(R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, f, c});
|
||||
makeSubscript(K, {f, (R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, c});
|
||||
// mSub(K, {(R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, f, c});
|
||||
mSub(K, {f, (R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, c});
|
||||
// x1=(h+1)//2, x2=(h+1)%2, y1=(w+1)//2
|
||||
|
||||
auto range1 = makeRangeOperator(
|
||||
auto range1 = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{c, {0, C}},
|
||||
|
@ -588,10 +583,10 @@ Expr ConvTransPattern::getExpr(Tensor A, Tensor K, int N, int C, int H, int W,
|
|||
{y2, {0, 2}},
|
||||
},
|
||||
{{f, {0, F}}, {r, {0, R / 2}}, {s, {0, S / 2}}}, subA * subK);
|
||||
auto sub0 = makeSubscript(
|
||||
auto sub0 = mSub(
|
||||
range1, {n, c, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2});
|
||||
auto range0 = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
auto range0 =
|
||||
mL({{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
return range0;
|
||||
}
|
||||
|
||||
|
@ -606,11 +601,10 @@ pair<Expr, pair<Tensor, Tensor>> Sg2bmmPattern::getExpr(int Batch, int M, int K,
|
|||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, D * W, 0});
|
||||
|
||||
auto subA = makeSubscript(A, {b, m, k});
|
||||
auto subB = makeSubscript(B, {b, m + D * (w - W), k});
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, k});
|
||||
auto subB = mSub(B, {b, m + D * (w - W), k});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
return {range, {A, B}};
|
||||
}
|
||||
|
||||
|
@ -624,10 +618,10 @@ LongformerGBMMPattern::getExpr(int Batch, int M, int W, int K, int dilation) {
|
|||
vector<int>{0, 0, 0});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, dilation * W, 0});
|
||||
auto subA = makeSubscript(A, {b, m, w});
|
||||
auto subB = makeSubscript(B, {b, m + dilation * w - dilation * W, n});
|
||||
auto range = makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, w});
|
||||
auto subB = mSub(B, {b, m + dilation * w - dilation * W, n});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
return {range, {A, B}};
|
||||
}
|
||||
|
||||
|
@ -642,10 +636,10 @@ pair<Expr, pair<Tensor, Tensor>> MatmulPattern::getExpr(bool transA,
|
|||
vector<int>{0, 0, 0});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, K, N}),
|
||||
vector<int>{0, 0, 0});
|
||||
auto subA = makeSubscript(A, {b, m, k});
|
||||
auto subB = makeSubscript(B, {b, k, n});
|
||||
auto range = makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {n, {0, N}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, k});
|
||||
auto subB = mSub(B, {b, k, n});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
return {range, {A, B}};
|
||||
}
|
||||
|
||||
|
|
|
@ -288,9 +288,9 @@ pair<nnet::Expr, NMutator::NameNToTensorT> NMutator::extractOp(Operator opT) {
|
|||
if (!(sh == 1 && sw == 1 && dh == 1 && dw == 1))
|
||||
return {};
|
||||
assert(sh == 1 && sw == 1 && dh == 1 && dw == 1);
|
||||
const auto A = nnet::makeTensor("A", AT->getDims(),
|
||||
std::vector<int>{0, 0, ph, pw});
|
||||
const auto K = nnet::makeTensor("K", KT->getDims());
|
||||
const auto A =
|
||||
nnet::mT("A", AT->getDims(), std::vector<int>{0, 0, ph, pw});
|
||||
const auto K = nnet::mT("K", KT->getDims());
|
||||
return {nnet::ConvPattern::getExpr(A, K, n, c, h, w, f, r, s),
|
||||
{{"A", AT}, {"K", KT}}};
|
||||
} else if (auto convOp = as<ConvTransposed2dNHWCObj>(opT)) {
|
||||
|
@ -309,9 +309,9 @@ pair<nnet::Expr, NMutator::NameNToTensorT> NMutator::extractOp(Operator opT) {
|
|||
// https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html
|
||||
// Real padding = dilation * (kernel_size - 1) - padding
|
||||
int padding = dh * (r - 1) - ph;
|
||||
const auto A = nnet::makeTensor(
|
||||
"A", AT->getDims(), std::vector<int>{0, padding, padding, 0});
|
||||
const auto K = nnet::makeTensor("K", KT->getDims());
|
||||
const auto A = nnet::mT("A", AT->getDims(),
|
||||
std::vector<int>{0, padding, padding, 0});
|
||||
const auto K = nnet::mT("K", KT->getDims());
|
||||
return {nnet::ConvTransPattern::getExpr(A, K, n, c, h, w, f, r, s),
|
||||
{{"A", AT}, {"K", KT}}};
|
||||
} else if (auto g2bmmOp = as<G2BMMObj>(opT)) {
|
||||
|
@ -1146,22 +1146,21 @@ NMutator::generateUnaryExpr(const Operator &op) {
|
|||
for (size_t i = 0; i < shape.size(); ++i) {
|
||||
indices.emplace_back(make_ref<VarNode>("i" + std::to_string(i)));
|
||||
}
|
||||
auto sub = makeSubscript(T, indices);
|
||||
auto sub = mSub(T, indices);
|
||||
auto func = nnet::make_ref<FuncNode>(sub, type);
|
||||
vector<VarRangePair> varRanges;
|
||||
for (size_t i = 0; i < shape.size(); ++i) {
|
||||
varRanges.emplace_back(nnet::as<VarNode>(indices[i]),
|
||||
Range{0, shape[i]});
|
||||
}
|
||||
return {makeRangeOperator(varRanges, {}, func),
|
||||
NameNToTensorT{{"T", op->getInputs()[0]}}};
|
||||
return {mL(varRanges, {}, func), NameNToTensorT{{"T", op->getInputs()[0]}}};
|
||||
}
|
||||
|
||||
pair<nnet::Expr, vector<nnet::Tensor>> NMutator::generateRevert(Tensor in) {
|
||||
using namespace nnet;
|
||||
using infini::make_ref;
|
||||
const Shape &orignalShape = in->getDims();
|
||||
auto tensor = makeTensor("T", in->getDims());
|
||||
auto tensor = mT("T", in->getDims());
|
||||
VecExpr iters;
|
||||
for (size_t i = 0; i < orignalShape.size(); ++i) {
|
||||
iters.emplace_back(make_ref<VarNode>("i" + std::to_string(i)));
|
||||
|
@ -1169,13 +1168,13 @@ pair<nnet::Expr, vector<nnet::Tensor>> NMutator::generateRevert(Tensor in) {
|
|||
|
||||
Shape newShape = orignalShape;
|
||||
std::reverse(newShape.begin(), newShape.end());
|
||||
auto sub = makeSubscript(tensor, iters);
|
||||
auto sub = mSub(tensor, iters);
|
||||
vector<VarRangePair> loopIters;
|
||||
for (int i = orignalShape.size() - 1; i >= 0; --i) {
|
||||
loopIters.emplace_back(infini::as<VarNode>(iters[i]),
|
||||
Range{0, orignalShape[i]});
|
||||
}
|
||||
auto range = makeRangeOperator(loopIters, {}, sub);
|
||||
auto range = mL(loopIters, {}, sub);
|
||||
return {range, {tensor}};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ RangeOp ReplaceKit::replaceRangeOpIterator(const RangeOp &rangeOp,
|
|||
replace.oldIters.size() +
|
||||
replace.newIters.size());
|
||||
// Check the number of loop iterators
|
||||
return makeRangeOperator(newVarRangePairs, rangeOp->getSumVarRanges(),
|
||||
replacedSummand);
|
||||
return mL(newVarRangePairs, rangeOp->getSumVarRanges(),
|
||||
replacedSummand);
|
||||
} else if (replace.iteratorType == IterationType::Sum) {
|
||||
for (const auto &[var, range] : rangeOp->getSumVarRanges()) {
|
||||
if (!replace.isReplaced(var))
|
||||
|
@ -27,8 +27,8 @@ RangeOp ReplaceKit::replaceRangeOpIterator(const RangeOp &rangeOp,
|
|||
assert(newVarRangePairs.size() == rangeOp->getSumVarRanges().size() -
|
||||
replace.oldIters.size() +
|
||||
replace.newIters.size());
|
||||
return makeRangeOperator(rangeOp->getLoopVarRanges(), newVarRangePairs,
|
||||
replacedSummand, rangeOp->getPaddings());
|
||||
return mL(rangeOp->getLoopVarRanges(), newVarRangePairs,
|
||||
replacedSummand, rangeOp->getPaddings());
|
||||
}
|
||||
assert(false);
|
||||
return nullptr;
|
||||
|
@ -55,7 +55,7 @@ Subscript ReplaceKit::buildSubscirptForLoopVarReplace(const RangeOp &inner,
|
|||
// } else
|
||||
// subs.emplace_back(inner->getLoopVar(i));
|
||||
// }
|
||||
return makeSubscript(inner, subs);
|
||||
return mSub(inner, subs);
|
||||
}
|
||||
|
||||
RangeOp
|
||||
|
@ -89,4 +89,4 @@ Expr ReplaceKit::replaceExpr(const Expr &cur, const Expr &pattern,
|
|||
return ret;
|
||||
}
|
||||
|
||||
} // namespace nnet
|
||||
} // namespace nnet
|
||||
|
|
|
@ -20,15 +20,13 @@ TEST(Activation, Relu) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, 0, 0});
|
||||
|
||||
auto subA = makeSubscript(A, {b, m, k});
|
||||
auto innerRange = makeRangeOperator(
|
||||
{{b, {0, Batch}}, {m, {0, M}}, {k, {0, K}}}, {}, subA);
|
||||
auto outerSub = makeSubscript(innerRange, {b, m, k});
|
||||
// auto subB = makeSubscript(B, {b, m + dilation * (w - W), k});
|
||||
auto subA = mSub(A, {b, m, k});
|
||||
auto innerRange = mL({{b, {0, Batch}}, {m, {0, M}}, {k, {0, K}}}, {}, subA);
|
||||
auto outerSub = mSub(innerRange, {b, m, k});
|
||||
// auto subB = mSub(B, {b, m + dilation * (w - W), k});
|
||||
auto relu = make_ref<FuncNode>(subA, FuncType::Relu);
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, relu);
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, relu);
|
||||
dbg(range);
|
||||
|
||||
auto g = new tpm::Graph();
|
||||
|
|
|
@ -18,9 +18,9 @@ TEST(TransposeOp2Expr, Basic) {
|
|||
auto k = make_ref<VarNode>("k");
|
||||
auto l = make_ref<VarNode>("l");
|
||||
auto AN = make_ref<TensorNode>("A", vector<int>({2, 4, 6, 8}));
|
||||
auto subA = makeSubscript(AN, {l, j, k, i});
|
||||
auto ans = makeRangeOperator(
|
||||
{{i, {0, 16}}, {j, {0, 4}}, {k, {0, 8}}, {l, {0, 2}}}, {}, subA);
|
||||
auto subA = mSub(AN, {l, j, k, i});
|
||||
auto ans =
|
||||
mL({{i, {0, 16}}, {j, {0, 4}}, {k, {0, 8}}, {l, {0, 2}}}, {}, subA);
|
||||
ASSERT_TRUE(HashVisitor().getHash(ans) ==
|
||||
HashVisitor().getHash(tpm::transposeOpToExpression(op)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,12 @@ TEST(Interpreter, SingleStage) {
|
|||
DEFINE_VAR(k);
|
||||
DEFINE_VAR(i3);
|
||||
DEFINE_VAR(i4);
|
||||
auto A = makeTensor("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = makeTensor("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = makeSubscript(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB = makeSubscript(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = makeRangeOperator(
|
||||
{{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
auto A = mT("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = mT("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = mSub(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB = mSub(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = mL({{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
cout << range->toReadable() << endl;
|
||||
|
||||
auto dataA = make_ref<vector<int>>(8 * 10000 * 512);
|
||||
|
@ -49,17 +48,16 @@ TEST(Interpreter, DoubleNestedStages) {
|
|||
DEFINE_VAR(i3);
|
||||
DEFINE_VAR(i4);
|
||||
DEFINE_VAR(i45);
|
||||
auto A = makeTensor("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = makeTensor("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = makeSubscript(A, {b, i45, k});
|
||||
auto subB = makeSubscript(B, {b, (i45 + w), k});
|
||||
auto innerRange =
|
||||
makeRangeOperator({{i45, {0, 10000}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
auto subOuter = makeSubscript(innerRange, {(i3 + (2500 * i4)), b, w});
|
||||
auto outerRange = makeRangeOperator(
|
||||
{{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}}, {},
|
||||
subOuter);
|
||||
auto A = mT("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = mT("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = mSub(A, {b, i45, k});
|
||||
auto subB = mSub(B, {b, (i45 + w), k});
|
||||
auto innerRange = mL({{i45, {0, 10000}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
auto subOuter = mSub(innerRange, {(i3 + (2500 * i4)), b, w});
|
||||
auto outerRange =
|
||||
mL({{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}}, {},
|
||||
subOuter);
|
||||
cout << outerRange->toReadable() << endl;
|
||||
|
||||
auto dataA = make_ref<vector<int>>(8 * 10000 * 512);
|
||||
|
@ -82,25 +80,23 @@ TEST(Interpreter, CompareTwoExprs) {
|
|||
DEFINE_VAR(i3);
|
||||
DEFINE_VAR(i4);
|
||||
DEFINE_VAR(i45);
|
||||
auto A = makeTensor("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = makeTensor("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto A = mT("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = mT("B", {8, 10000, 512}, {0, 128, 0});
|
||||
// singleStage
|
||||
auto subA1 = makeSubscript(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB1 = makeSubscript(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = makeRangeOperator(
|
||||
{{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA1 * subB1);
|
||||
auto subA1 = mSub(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB1 = mSub(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = mL({{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA1 * subB1);
|
||||
cout << range->toReadable() << endl;
|
||||
// doubleStages
|
||||
auto subA2 = makeSubscript(A, {b, i45, k});
|
||||
auto subB2 = makeSubscript(B, {b, (i45 + w), k});
|
||||
auto innerRange =
|
||||
makeRangeOperator({{i45, {0, 10000}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA2 * subB2);
|
||||
auto subOuter = makeSubscript(innerRange, {(i3 + (2500 * i4)), b, w});
|
||||
auto outerRange = makeRangeOperator(
|
||||
{{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}}, {},
|
||||
subOuter);
|
||||
auto subA2 = mSub(A, {b, i45, k});
|
||||
auto subB2 = mSub(B, {b, (i45 + w), k});
|
||||
auto innerRange = mL({{i45, {0, 10000}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA2 * subB2);
|
||||
auto subOuter = mSub(innerRange, {(i3 + (2500 * i4)), b, w});
|
||||
auto outerRange =
|
||||
mL({{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}}, {},
|
||||
subOuter);
|
||||
cout << outerRange->toReadable() << endl;
|
||||
|
||||
auto dataA = make_ref<vector<int>>(8 * 10000 * 512);
|
||||
|
@ -136,24 +132,22 @@ TEST(Interpreter, TransConv) {
|
|||
DEFINE_VAR(f);
|
||||
DEFINE_VAR(r);
|
||||
DEFINE_VAR(s);
|
||||
auto A = makeTensor("A", {1, 4, 4, 448}, {0, 2, 2, 0});
|
||||
auto K = makeTensor("K", {4, 4, 448, 256}, {0, 0, 0, 0});
|
||||
auto subA = makeSubscript(A, {n, ((x1 + r) + (-1)), ((y1 + s) + (-1)), f});
|
||||
auto subK =
|
||||
makeSubscript(K, {((2 - (2 * r)) + x2), ((2 - (2 * s)) + y2), f, c});
|
||||
auto innerRange = makeRangeOperator(
|
||||
{{n, {0, 1}},
|
||||
{c, {0, 256}},
|
||||
{x1, {0, 3}},
|
||||
{x2, {0, 2}},
|
||||
{y1, {0, 3}},
|
||||
{y2, {0, 2}}},
|
||||
{{f, {0, 448}}, {r, {0, 2}}, {s, {0, 2}}}, subA * subK);
|
||||
auto subOuter =
|
||||
makeSubscript(innerRange, {n, c, ((h + 1) / 2), ((h + 1) % 2),
|
||||
((w + 1) / 2), ((w + 1) % 2)});
|
||||
auto outerRange = makeRangeOperator(
|
||||
{{n, {0, 1}}, {h, {0, 4}}, {w, {0, 4}}, {c, {0, 256}}}, {}, subOuter);
|
||||
auto A = mT("A", {1, 4, 4, 448}, {0, 2, 2, 0});
|
||||
auto K = mT("K", {4, 4, 448, 256}, {0, 0, 0, 0});
|
||||
auto subA = mSub(A, {n, ((x1 + r) + (-1)), ((y1 + s) + (-1)), f});
|
||||
auto subK = mSub(K, {((2 - (2 * r)) + x2), ((2 - (2 * s)) + y2), f, c});
|
||||
auto innerRange =
|
||||
mL({{n, {0, 1}},
|
||||
{c, {0, 256}},
|
||||
{x1, {0, 3}},
|
||||
{x2, {0, 2}},
|
||||
{y1, {0, 3}},
|
||||
{y2, {0, 2}}},
|
||||
{{f, {0, 448}}, {r, {0, 2}}, {s, {0, 2}}}, subA * subK);
|
||||
auto subOuter = mSub(innerRange, {n, c, ((h + 1) / 2), ((h + 1) % 2),
|
||||
((w + 1) / 2), ((w + 1) % 2)});
|
||||
auto outerRange = mL({{n, {0, 1}}, {h, {0, 4}}, {w, {0, 4}}, {c, {0, 256}}},
|
||||
{}, subOuter);
|
||||
cout << outerRange->toReadable() << endl;
|
||||
|
||||
auto dataA = make_ref<vector<int>>(1 * 4 * 4 * 448);
|
||||
|
|
|
@ -80,12 +80,11 @@ TEST_F(OpSearch, Conv3x3) {
|
|||
// auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = makeSubscript(K, {r, s, f, c});
|
||||
auto subA = mSub(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = mSub(K, {r, s, f, c});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
// Derivation
|
||||
Formula conv_3x3_nhwc_rsfc(range, 0);
|
||||
|
@ -136,12 +135,11 @@ RangeOp buildTConv4x4_NHWF_RSFC(const int N, const int C, const int H,
|
|||
vector<int>{0, padding, padding, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK =
|
||||
makeSubscript(K, {(R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, f, c});
|
||||
auto subA = mSub(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = mSub(K, {(R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, f, c});
|
||||
// x1=(h+1)//2, x2=(h+1)%2, y1=(w+1)//2
|
||||
|
||||
auto range1 = makeRangeOperator(
|
||||
auto range1 = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{c, {0, C}},
|
||||
|
@ -152,10 +150,10 @@ RangeOp buildTConv4x4_NHWF_RSFC(const int N, const int C, const int H,
|
|||
},
|
||||
{{f, {0, F}}, {r, {0, R / 2}}, {s, {0, S / 2}}}, subA * subK);
|
||||
dbg(range1);
|
||||
auto sub0 = makeSubscript(
|
||||
auto sub0 = mSub(
|
||||
range1, {n, c, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2});
|
||||
auto range0 = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
auto range0 =
|
||||
mL({{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
return range0;
|
||||
}
|
||||
|
||||
|
@ -198,12 +196,11 @@ TEST_F(OpSearch, Conv5x5) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
Formula conv_9x9(range, 0);
|
||||
Derivator derivator(maxDepth, useHash, mode, passMode, printAndExit);
|
||||
|
@ -236,11 +233,10 @@ TEST_F(OpSearch, G2BMM) {
|
|||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, dilation * W, 0});
|
||||
|
||||
auto subA = makeSubscript(A, {b, m, k});
|
||||
auto subB = makeSubscript(B, {b, m + dilation * (w - W), k});
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, k});
|
||||
auto subB = mSub(B, {b, m + dilation * (w - W), k});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
|
||||
// Derivation: this work without padding check in stage merging
|
||||
Formula dialted_g2bmm(range, 0);
|
||||
|
|
|
@ -15,15 +15,13 @@ Expr buildAnsPosPos() {
|
|||
DEFINE_VAR(y);
|
||||
DEFINE_VAR(t1);
|
||||
DEFINE_VAR(i3);
|
||||
auto A = makeTensor("A", {8});
|
||||
auto B = makeTensor("B", {8});
|
||||
auto subA = makeSubscript(A, {i3});
|
||||
auto subB = makeSubscript(B, {t1});
|
||||
auto innerRange =
|
||||
makeRangeOperator({{i3, {0, 8}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
auto subInner = makeSubscript(innerRange, {x + 2 * y});
|
||||
auto outerRange =
|
||||
makeRangeOperator({{x, {0, 2}}, {y, {0, 4}}}, {}, subInner);
|
||||
auto A = mT("A", {8});
|
||||
auto B = mT("B", {8});
|
||||
auto subA = mSub(A, {i3});
|
||||
auto subB = mSub(B, {t1});
|
||||
auto innerRange = mL({{i3, {0, 8}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
auto subInner = mSub(innerRange, {x + 2 * y});
|
||||
auto outerRange = mL({{x, {0, 2}}, {y, {0, 4}}}, {}, subInner);
|
||||
return outerRange;
|
||||
}
|
||||
|
||||
|
@ -53,12 +51,11 @@ TEST(Rule2, PosPos) {
|
|||
DEFINE_VAR(x);
|
||||
DEFINE_VAR(y);
|
||||
DEFINE_VAR(t1);
|
||||
auto A = makeTensor("A", {8});
|
||||
auto B = makeTensor("B", {8});
|
||||
auto subA = makeSubscript(A, {a * x + b * y});
|
||||
auto subB = makeSubscript(B, {t1});
|
||||
auto range = makeRangeOperator({{x, {0, 2}}, {y, {0, 4}}}, {{t1, {0, 5}}},
|
||||
subA * subB);
|
||||
auto A = mT("A", {8});
|
||||
auto B = mT("B", {8});
|
||||
auto subA = mSub(A, {a * x + b * y});
|
||||
auto subB = mSub(B, {t1});
|
||||
auto range = mL({{x, {0, 2}}, {y, {0, 4}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
realTest(range, buildAnsPosPos());
|
||||
}
|
||||
|
||||
|
@ -70,15 +67,13 @@ Expr buildAnsPosNeg() {
|
|||
DEFINE_VAR(y);
|
||||
DEFINE_VAR(t1);
|
||||
DEFINE_VAR(i3);
|
||||
auto A = makeTensor("A", {8});
|
||||
auto B = makeTensor("B", {8});
|
||||
auto subA = makeSubscript(A, {i3});
|
||||
auto subB = makeSubscript(B, {t1});
|
||||
auto innerRange =
|
||||
makeRangeOperator({{i3, {0, 8}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
auto subInner = makeSubscript(innerRange, {x - 2 * y + 6});
|
||||
auto outerRange =
|
||||
makeRangeOperator({{x, {0, 2}}, {y, {0, 4}}}, {}, subInner);
|
||||
auto A = mT("A", {8});
|
||||
auto B = mT("B", {8});
|
||||
auto subA = mSub(A, {i3});
|
||||
auto subB = mSub(B, {t1});
|
||||
auto innerRange = mL({{i3, {0, 8}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
auto subInner = mSub(innerRange, {x - 2 * y + 6});
|
||||
auto outerRange = mL({{x, {0, 2}}, {y, {0, 4}}}, {}, subInner);
|
||||
return outerRange;
|
||||
}
|
||||
|
||||
|
@ -87,12 +82,11 @@ TEST(Rule2, PosNeg) {
|
|||
DEFINE_VAR(x);
|
||||
DEFINE_VAR(y);
|
||||
DEFINE_VAR(t1);
|
||||
auto A = makeTensor("A", {8});
|
||||
auto B = makeTensor("B", {8});
|
||||
auto subA = makeSubscript(A, {a * x + b * y + 6});
|
||||
auto subB = makeSubscript(B, {t1});
|
||||
auto range = makeRangeOperator({{x, {0, 2}}, {y, {0, 4}}}, {{t1, {0, 5}}},
|
||||
subA * subB);
|
||||
auto A = mT("A", {8});
|
||||
auto B = mT("B", {8});
|
||||
auto subA = mSub(A, {a * x + b * y + 6});
|
||||
auto subB = mSub(B, {t1});
|
||||
auto range = mL({{x, {0, 2}}, {y, {0, 4}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
realTest(range, buildAnsPosNeg());
|
||||
}
|
||||
|
||||
|
@ -104,15 +98,13 @@ Expr buildAnsNegNeg() {
|
|||
DEFINE_VAR(y);
|
||||
DEFINE_VAR(t1);
|
||||
DEFINE_VAR(i3);
|
||||
auto A = makeTensor("A", {8});
|
||||
auto B = makeTensor("B", {8});
|
||||
auto subA = makeSubscript(A, {i3});
|
||||
auto subB = makeSubscript(B, {t1});
|
||||
auto innerRange =
|
||||
makeRangeOperator({{i3, {0, 8}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
auto subInner = makeSubscript(innerRange, {(-1) * x - 2 * y + 7});
|
||||
auto outerRange =
|
||||
makeRangeOperator({{x, {0, 2}}, {y, {0, 4}}}, {}, subInner);
|
||||
auto A = mT("A", {8});
|
||||
auto B = mT("B", {8});
|
||||
auto subA = mSub(A, {i3});
|
||||
auto subB = mSub(B, {t1});
|
||||
auto innerRange = mL({{i3, {0, 8}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
auto subInner = mSub(innerRange, {(-1) * x - 2 * y + 7});
|
||||
auto outerRange = mL({{x, {0, 2}}, {y, {0, 4}}}, {}, subInner);
|
||||
return outerRange;
|
||||
}
|
||||
|
||||
|
@ -121,11 +113,10 @@ TEST(Rule2, NegNeg) {
|
|||
DEFINE_VAR(x);
|
||||
DEFINE_VAR(y);
|
||||
DEFINE_VAR(t1);
|
||||
auto A = makeTensor("A", {8});
|
||||
auto B = makeTensor("B", {8});
|
||||
auto subA = makeSubscript(A, {a * x + b * y + 7});
|
||||
auto subB = makeSubscript(B, {t1});
|
||||
auto range = makeRangeOperator({{x, {0, 2}}, {y, {0, 4}}}, {{t1, {0, 5}}},
|
||||
subA * subB);
|
||||
auto A = mT("A", {8});
|
||||
auto B = mT("B", {8});
|
||||
auto subA = mSub(A, {a * x + b * y + 7});
|
||||
auto subB = mSub(B, {t1});
|
||||
auto range = mL({{x, {0, 2}}, {y, {0, 4}}}, {{t1, {0, 5}}}, subA * subB);
|
||||
realTest(range, buildAnsNegNeg());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ TEST(Conv2conv, TConv4x4_NHWC_innerStage_RuleBased) {
|
|||
vector<int>{0, padding, padding, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, R, S, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = makeSubscript(
|
||||
auto subA = mSub(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = mSub(
|
||||
K, {f, -2 * r + (-1) * x2 + (R - 1), -2 * s + (-1) * y2 + (S - 1), c});
|
||||
|
||||
auto range = makeRangeOperator(
|
||||
auto range = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{c, {0, C}},
|
||||
|
@ -61,16 +61,16 @@ TEST(Conv2conv, TConv4x4_NHWC_RuleBased) {
|
|||
vector<int>{0, padding, padding, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, R, S, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = makeSubscript(
|
||||
auto subA = mSub(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = mSub(
|
||||
K, {f, -2 * r + (-1) * x2 + (R - 1), -2 * s + (-1) * y2 + (S - 1), c});
|
||||
|
||||
// auto range =
|
||||
// makeRangeOperator({{n, {0, N}}, {c, {0, H}}, {w, {0, W}}, {f, {0,
|
||||
// mL({{n, {0, N}}, {c, {0, H}}, {w, {0, W}}, {f, {0,
|
||||
// F}}},
|
||||
// {{f, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA *
|
||||
// subK);
|
||||
auto range = makeRangeOperator(
|
||||
auto range = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{x1, {0, OH / 2 + 1}},
|
||||
|
@ -80,9 +80,9 @@ TEST(Conv2conv, TConv4x4_NHWC_RuleBased) {
|
|||
{c, {0, C}},
|
||||
},
|
||||
{{f, {0, F}}, {r, {0, R / 2}}, {s, {0, S / 2}}}, subA * subK);
|
||||
auto subOuter = makeSubscript(
|
||||
range, {n, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2, c});
|
||||
auto outerRange = makeRangeOperator(
|
||||
auto subOuter =
|
||||
mSub(range, {n, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2, c});
|
||||
auto outerRange = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{h, {0, OH}},
|
||||
|
@ -124,16 +124,16 @@ TEST(Conv2conv, TConv4x4_BS16_NHWC_RuleBased) {
|
|||
vector<int>{0, padding, padding, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, R, S, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = makeSubscript(
|
||||
auto subA = mSub(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = mSub(
|
||||
K, {f, -2 * r + (-1) * x2 + (R - 1), -2 * s + (-1) * y2 + (S - 1), c});
|
||||
|
||||
// auto range =
|
||||
// makeRangeOperator({{n, {0, N}}, {c, {0, H}}, {w, {0, W}}, {f, {0,
|
||||
// mL({{n, {0, N}}, {c, {0, H}}, {w, {0, W}}, {f, {0,
|
||||
// F}}},
|
||||
// {{f, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA *
|
||||
// subK);
|
||||
auto range = makeRangeOperator(
|
||||
auto range = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{x1, {0, OH / 2 + 1}},
|
||||
|
@ -143,9 +143,9 @@ TEST(Conv2conv, TConv4x4_BS16_NHWC_RuleBased) {
|
|||
{c, {0, C}},
|
||||
},
|
||||
{{f, {0, F}}, {r, {0, R / 2}}, {s, {0, S / 2}}}, subA * subK);
|
||||
auto subOuter = makeSubscript(
|
||||
range, {n, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2, c});
|
||||
auto outerRange = makeRangeOperator(
|
||||
auto subOuter =
|
||||
mSub(range, {n, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2, c});
|
||||
auto outerRange = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{h, {0, OH}},
|
||||
|
@ -192,12 +192,11 @@ RangeOp buildTConv4x4_NHWF_FRSC(const int N, const int C, const int H,
|
|||
vector<int>{0, padding, padding, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, R, S, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK =
|
||||
makeSubscript(K, {f, (R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, c});
|
||||
auto subA = mSub(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = mSub(K, {f, (R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, c});
|
||||
// x1=(h+1)//2, x2=(h+1)%2, y1=(w+1)//2
|
||||
|
||||
auto range1 = makeRangeOperator(
|
||||
auto range1 = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{c, {0, C}},
|
||||
|
@ -208,10 +207,10 @@ RangeOp buildTConv4x4_NHWF_FRSC(const int N, const int C, const int H,
|
|||
},
|
||||
{{f, {0, F}}, {r, {0, R / 2}}, {s, {0, S / 2}}}, subA * subK);
|
||||
dbg(range1);
|
||||
auto sub0 = makeSubscript(
|
||||
auto sub0 = mSub(
|
||||
range1, {n, c, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2});
|
||||
auto range0 = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
auto range0 =
|
||||
mL({{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
return range0;
|
||||
}
|
||||
|
||||
|
@ -234,12 +233,11 @@ RangeOp buildTConv4x4_NHWF_RSFC(const int N, const int C, const int H,
|
|||
vector<int>{0, padding, padding, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK =
|
||||
makeSubscript(K, {(R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, f, c});
|
||||
auto subA = mSub(A, {n, x1 + r - 1, y1 + s - 1, f});
|
||||
auto subK = mSub(K, {(R - 2) - 2 * r + x2, (S - 2) - 2 * s + y2, f, c});
|
||||
// x1=(h+1)//2, x2=(h+1)%2, y1=(w+1)//2
|
||||
|
||||
auto range1 = makeRangeOperator(
|
||||
auto range1 = mL(
|
||||
{
|
||||
{n, {0, N}},
|
||||
{c, {0, C}},
|
||||
|
@ -250,10 +248,10 @@ RangeOp buildTConv4x4_NHWF_RSFC(const int N, const int C, const int H,
|
|||
},
|
||||
{{f, {0, F}}, {r, {0, R / 2}}, {s, {0, S / 2}}}, subA * subK);
|
||||
dbg(range1);
|
||||
auto sub0 = makeSubscript(
|
||||
auto sub0 = mSub(
|
||||
range1, {n, c, (h + 1) / 2, (h + 1) % 2, (w + 1) / 2, (w + 1) % 2});
|
||||
auto range0 = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
auto range0 =
|
||||
mL({{n, {0, N}}, {h, {0, OH}}, {w, {0, OW}}, {c, {0, C}}}, {}, sub0);
|
||||
return range0;
|
||||
}
|
||||
|
||||
|
@ -381,9 +379,9 @@ TEST(Conv2conv, InfoGAN_ConvTranspose_3_OOB_Test) {
|
|||
// ConvTranspose_3 in InfoGAN
|
||||
const int n = 1, c = 256, h = 2, w = 2, f = 448, r = 4, s = 4;
|
||||
int padding = 1 * (r - 1) - 1;
|
||||
const auto A = nnet::makeTensor("A", {n, h, w, f},
|
||||
std::vector<int>{0, padding, padding, 0});
|
||||
const auto K = nnet::makeTensor("K", {f, c, r, s});
|
||||
const auto A =
|
||||
nnet::mT("A", {n, h, w, f}, std::vector<int>{0, padding, padding, 0});
|
||||
const auto K = nnet::mT("K", {f, c, r, s});
|
||||
auto expr = ConvTransPattern::getExpr(A, K, n, c, h, w, f, r, s);
|
||||
dbg(expr);
|
||||
Derivator derivator;
|
||||
|
|
|
@ -15,23 +15,21 @@ TEST(Conv2conv, 9x9_RuleBased) {
|
|||
DEFINE_VAR(n);
|
||||
DEFINE_VAR(f);
|
||||
auto T2 = make_ref<TensorNode>("T2", vector<int>({8, 288, 226, 226}));
|
||||
auto S1 = makeRangeOperator(
|
||||
{{i19, {-1, 225}},
|
||||
{i20, {-1, 2}},
|
||||
{i15, {-1, 225}},
|
||||
{i16, {-1, 2}},
|
||||
{n, {0, 8}},
|
||||
{f, {0, 32}}},
|
||||
{}, makeSubscript(T2, {n, 9 * f + 3 * i16 + i20, i15 + 1, i19 + 1}));
|
||||
auto S1 = mL({{i19, {-1, 225}},
|
||||
{i20, {-1, 2}},
|
||||
{i15, {-1, 225}},
|
||||
{i16, {-1, 2}},
|
||||
{n, {0, 8}},
|
||||
{f, {0, 32}}},
|
||||
{}, mSub(T2, {n, 9 * f + 3 * i16 + i20, i15 + 1, i19 + 1}));
|
||||
S1->setPaddings({2, 0, 2, 0, 0, 0});
|
||||
DEFINE_VAR(h);
|
||||
DEFINE_VAR(w);
|
||||
DEFINE_VAR(i13);
|
||||
DEFINE_VAR(i3);
|
||||
auto S2 = makeRangeOperator(
|
||||
{{n, {0, 8}}, {h, {0, 224}}, {w, {0, 224}}, {f, {0, 32}}},
|
||||
{{i13, {-1, 2}}, {i3, {-1, 2}}},
|
||||
makeSubscript(S1, {w + 3 * i13, i13, h + 3 * i3, i3, n, f}));
|
||||
auto S2 = mL({{n, {0, 8}}, {h, {0, 224}}, {w, {0, 224}}, {f, {0, 32}}},
|
||||
{{i13, {-1, 2}}, {i3, {-1, 2}}},
|
||||
mSub(S1, {w + 3 * i13, i13, h + 3 * i3, i3, n, f}));
|
||||
std::cout << S2->toReadable() << std::endl;
|
||||
|
||||
AsTVMVisitor visitor;
|
||||
|
|
|
@ -20,12 +20,11 @@ Expr buildConv() {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
return range;
|
||||
}
|
||||
|
||||
|
@ -42,4 +41,4 @@ TEST(RangeMagnify, Conv5x5) {
|
|||
sumVarRanges[0].second.first++;
|
||||
rangeOp->setSumIterator(sumVarRanges);
|
||||
EXPECT_FALSE(CompareMultiFormulasVisitor().compare(roots));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,11 @@ TEST(Conv2conv, 9x9_NCHW_FCRS) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
Formula conv_9x9(range, 0);
|
||||
Derivator derivator(8);
|
||||
|
@ -60,13 +59,11 @@ TEST(Conv2conv, 6x6_RuleBased_NCHW_FCRS) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA =
|
||||
makeSubscript(A, {n, c, h + r - (R - 1) / 2, w + s - (S - 1) / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - (R - 1) / 2, w + s - (S - 1) / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
Formula conv_6x6(range, 0);
|
||||
Derivator derivator;
|
||||
|
@ -102,12 +99,11 @@ TEST(Conv2conv, 5x5_RuleBased_NCHW_FCRS) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
Formula conv_9x9(range, 0);
|
||||
Derivator derivator(7);
|
||||
|
@ -126,4 +122,4 @@ TEST(Conv2conv, 5x5_RuleBased_NCHW_FCRS) {
|
|||
derivator.print();
|
||||
derivator.printStatistics();
|
||||
EXPECT_GE(nMatches, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,11 @@ TEST(Conv2gemm, NCHW_FCRS_ruleBased) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
// cout << range->toReadable() << endl;
|
||||
|
||||
// Derivation
|
||||
|
@ -51,12 +50,11 @@ TEST(Conv2gemm, NHWC_RSFC_ruleBased) {
|
|||
// auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = makeSubscript(K, {r, s, f, c});
|
||||
auto subA = mSub(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = mSub(K, {r, s, f, c});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
// cout << range->toReadable() << endl;
|
||||
|
||||
// Derivation
|
||||
|
@ -82,12 +80,11 @@ TEST(Conv2gemm, Derivation_dfs) {
|
|||
vector<int>{0, R / 2, S / 2, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = makeSubscript(K, {r, s, f, c});
|
||||
auto subA = mSub(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = mSub(K, {r, s, f, c});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
// cout << range->toReadable() << endl;
|
||||
|
||||
// Derivation
|
||||
|
@ -107,12 +104,11 @@ void Conv2gemm_NHWC_RSFC_search(int maxDepth, bool enalbeHashPruning) {
|
|||
// auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = makeSubscript(K, {r, s, f, c});
|
||||
auto subA = mSub(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = mSub(K, {r, s, f, c});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
// cout << ange->toReadable() << endl;
|
||||
|
||||
// Derivation
|
||||
|
@ -160,12 +156,11 @@ TEST(Conv2gemm, NCHW_RSFC_search) {
|
|||
vector<int>{0, R / 2, S / 2, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = makeSubscript(K, {r, s, f, c});
|
||||
auto subA = mSub(A, {n, h + r - R / 2, w + s - S / 2, c});
|
||||
auto subK = mSub(K, {r, s, f, c});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
// Derivation
|
||||
Formula conv_3x3_nhwc_rsfc(range, 0);
|
||||
|
@ -195,12 +190,11 @@ TEST(Conv2gemm1x1, NHWC_RSFC_ruleBased) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({N, H, W, C}));
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, h + r, w + s, c});
|
||||
auto subK = makeSubscript(K, {r, s, f, c});
|
||||
auto subA = mSub(A, {n, h + r, w + s, c});
|
||||
auto subK = mSub(K, {r, s, f, c});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
Formula conv_1x1_nhwc_fc(range, 0);
|
||||
Derivator derivator(7);
|
||||
|
@ -224,12 +218,11 @@ TEST(Conv2gemm1x1, NCHW_FCRS_search) {
|
|||
vector<int>{0, R / 2, S / 2, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
// Derivation
|
||||
Formula conv_3x3_nhwc_rsfc(range, 0);
|
||||
|
@ -255,12 +248,11 @@ TEST(Conv2gemm1x7, NCHW_FCRS_search) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
|
||||
// Derivation
|
||||
Formula conv_1x7(range, 0);
|
||||
|
@ -280,4 +272,4 @@ TEST(Conv2gemm1x7, NCHW_FCRS_search) {
|
|||
derivator,
|
||||
"../test/nnet/log/conv2gemm_1x7/Conv2gemm_1x7_NCHW_FCRS_11.expr");
|
||||
EXPECT_GE(nMatches, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,9 @@ TEST(DLT, Simple) {
|
|||
int C = 12, F = 16, R = 9, S = 9;
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {f, c, 3 * p1 + p2, 3 * q1 + q2});
|
||||
auto rangeOp =
|
||||
makeRangeOperator({{p1, {0, 3}}, {q1, {0, 3}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {p2, {0, 3}}, {q2, {0, 3}}}, subA);
|
||||
auto subA = mSub(A, {f, c, 3 * p1 + p2, 3 * q1 + q2});
|
||||
auto rangeOp = mL({{p1, {0, 3}}, {q1, {0, 3}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {p2, {0, 3}}, {q2, {0, 3}}}, subA);
|
||||
DLT dlt;
|
||||
dlt.split(2, 3);
|
||||
auto opt = dlt.apply(rangeOp, subA, "dltedA");
|
||||
|
@ -41,10 +40,9 @@ TEST(DLT, Conv2Conv) {
|
|||
int C = 12, F = 16, R = 9, S = 9;
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {f, c, 3 * p1 + p2, 3 * q1 + q2});
|
||||
auto rangeOp =
|
||||
makeRangeOperator({{p1, {0, 3}}, {q1, {0, 3}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {p2, {0, 3}}, {q2, {0, 3}}}, subA);
|
||||
auto subA = mSub(A, {f, c, 3 * p1 + p2, 3 * q1 + q2});
|
||||
auto rangeOp = mL({{p1, {0, 3}}, {q1, {0, 3}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {p2, {0, 3}}, {q2, {0, 3}}}, subA);
|
||||
DLT dlt;
|
||||
dlt.split(3, 3);
|
||||
dlt.split(2, 3);
|
||||
|
@ -67,10 +65,9 @@ TEST(DLT, Wrong0) {
|
|||
int C = 12, F = 16, R = 9, S = 9;
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {f, c, 3 * p1 + p2, 3 * q1 + q2});
|
||||
auto rangeOp =
|
||||
makeRangeOperator({{p1, {0, 3}}, {q1, {0, 3}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {p2, {0, 4}}, {q2, {0, 3}}}, subA);
|
||||
auto subA = mSub(A, {f, c, 3 * p1 + p2, 3 * q1 + q2});
|
||||
auto rangeOp = mL({{p1, {0, 3}}, {q1, {0, 3}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {p2, {0, 4}}, {q2, {0, 3}}}, subA);
|
||||
DLT dlt;
|
||||
dlt.split(2, 3);
|
||||
auto opt = dlt.apply(rangeOp, subA, "dltedA");
|
||||
|
|
|
@ -19,42 +19,42 @@ TEST(Hash, Conv2gemm) {
|
|||
vector<int>{0, R / 2, S / 2, 0});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({R, S, F, C}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, h + r, w + s, c});
|
||||
auto subK = makeSubscript(K, {r, s, f, c});
|
||||
auto range = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
auto subA = mSub(A, {n, h + r, w + s, c});
|
||||
auto subK = mSub(K, {r, s, f, c});
|
||||
auto range =
|
||||
mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
cout << range->toReadable() << endl;
|
||||
auto hash0 = HashVisitor().getHash(range);
|
||||
cout << hash0 << endl;
|
||||
|
||||
subA = makeSubscript(A, {n, h + s, w + r, c});
|
||||
subK = makeSubscript(K, {s, r, f, c});
|
||||
range = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
subA = mSub(A, {n, h + s, w + r, c});
|
||||
subK = mSub(K, {s, r, f, c});
|
||||
range =
|
||||
mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
cout << range->toReadable() << endl;
|
||||
auto hash1 = HashVisitor().getHash(range);
|
||||
cout << hash1 << endl;
|
||||
|
||||
subA = makeSubscript(A, {n, s + h, w + r, c});
|
||||
subK = makeSubscript(K, {s, r, f, c});
|
||||
range = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
subA = mSub(A, {n, s + h, w + r, c});
|
||||
subK = mSub(K, {s, r, f, c});
|
||||
range =
|
||||
mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
cout << range->toReadable() << endl;
|
||||
auto hash2 = HashVisitor().getHash(range);
|
||||
cout << hash2 << endl;
|
||||
|
||||
subA = makeSubscript(A, {n, s + h, w, c});
|
||||
subK = makeSubscript(K, {s, r, f, c});
|
||||
range = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
subA = mSub(A, {n, s + h, w, c});
|
||||
subK = mSub(K, {s, r, f, c});
|
||||
range =
|
||||
mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
cout << range->toReadable() << endl;
|
||||
auto hash3 = HashVisitor().getHash(range);
|
||||
cout << hash3 << endl;
|
||||
|
|
|
@ -17,11 +17,11 @@ TEST(GBMM, RuleBased) {
|
|||
vector<int>{0, 0, 0});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, dilation * W, 0});
|
||||
auto subA = makeSubscript(A, {b, m, w});
|
||||
// auto subB = makeSubscript(B, {b, m + dilation * (w - W), n});
|
||||
auto subB = makeSubscript(B, {b, m + dilation * w - dilation * W, n});
|
||||
auto range = makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, w});
|
||||
// auto subB = mSub(B, {b, m + dilation * (w - W), n});
|
||||
auto subB = mSub(B, {b, m + dilation * w - dilation * W, n});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
dbg(range);
|
||||
|
||||
// Derivation: this work without padding check in stage merging
|
||||
|
@ -57,11 +57,10 @@ TEST(G2BMM, RuleBased) {
|
|||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, dilation * W, 0});
|
||||
|
||||
auto subA = makeSubscript(A, {b, m, k});
|
||||
auto subB = makeSubscript(B, {b, m + dilation * (w - W), k});
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, k});
|
||||
auto subB = mSub(B, {b, m + dilation * (w - W), k});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, subA * subB);
|
||||
|
||||
// Derivation: this work without padding check in stage merging
|
||||
Formula dialted_g2bmm(range, 0);
|
||||
|
|
|
@ -28,11 +28,10 @@ TEST(GuidedDLT, dimFusion_ConvToGemm_1Tensor) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({N, N, N, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, t1, t2, c});
|
||||
auto subB = makeSubscript(B, {r, c});
|
||||
auto range = makeRangeOperator(
|
||||
{{n, {0, N}}, {t1, {0, N}}, {t2, {0, N}}, {r, {0, N}}}, {{c, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {n, t1, t2, c});
|
||||
auto subB = mSub(B, {r, c});
|
||||
auto range = mL({{n, {0, N}}, {t1, {0, N}}, {t2, {0, N}}, {r, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
Derivator derivator(2);
|
||||
{
|
||||
|
@ -65,15 +64,15 @@ TEST(GuidedDLT, dimFusion_ConvToGemm_1step) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({N, N, N, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, N, N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, t1, t2, c});
|
||||
auto subB = makeSubscript(B, {r, s, f, c});
|
||||
auto range = makeRangeOperator({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, t1, t2, c});
|
||||
auto subB = mSub(B, {r, s, f, c});
|
||||
auto range = mL({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
{
|
||||
Formula matmul(range, 0);
|
||||
|
@ -105,15 +104,15 @@ TEST(GuidedDLT, dimFusion_ConvToGemm_real_2tensors) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({N, N, N, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, N, N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, t1, t2, c});
|
||||
auto subB = makeSubscript(B, {r, s, f, c});
|
||||
auto range = makeRangeOperator({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, t1, t2, c});
|
||||
auto subB = mSub(B, {r, s, f, c});
|
||||
auto range = mL({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
{
|
||||
Formula matmul(range, 0);
|
||||
|
@ -131,23 +130,22 @@ TEST(GuidedDLT, Conv2Conv_KernelDLT) {
|
|||
// auto A =
|
||||
// make_ref<TensorNode>("A", vector<int>({N, C, H, W}),
|
||||
// vector<int>{0, 0, 1, 1});
|
||||
auto A = makeTensor("A", {N, C, H, W}, {0, 0, 3, 3});
|
||||
auto A = mT("A", {N, C, H, W}, {0, 0, 3, 3});
|
||||
auto B = make_ref<TensorNode>("W", vector<int>({F, C, R, S}));
|
||||
// cur =
|
||||
// L<i19:-1:226><i20:-1:2><i15:-1:226><i16:-1:2><n:0:8><f:0:32><pad=2,0,2,0,0,0,>Sum<i14:-1:2><i4:-1:2><c:0:16>
|
||||
// {({A<pad=0,0,4,4>}[n, c, (i15 + i4), (i14 + i19)] * {K}[f, c, ((3 *
|
||||
// i16) + i4), (i14 + (3 * i20))])} (std::shared_ptr<nnet::RangeOpNode>)
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, (j15 + j4 - 1), (j14 - 1 + i19)});
|
||||
auto subB = makeSubscript(B, {f, c, ((3 * j16) + j4), (j14 + (3 * i20))});
|
||||
auto range = makeRangeOperator({{i19, {-1, 226}},
|
||||
{i20, {0, 3}},
|
||||
{j15, {-1, 226}},
|
||||
{j16, {0, 3}},
|
||||
{n, {0, 8}},
|
||||
{f, {0, 32}}},
|
||||
{{j14, {0, 3}}, {j4, {0, 3}}, {c, {0, 16}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {n, c, (j15 + j4 - 1), (j14 - 1 + i19)});
|
||||
auto subB = mSub(B, {f, c, ((3 * j16) + j4), (j14 + (3 * i20))});
|
||||
auto range = mL({{i19, {-1, 226}},
|
||||
{i20, {0, 3}},
|
||||
{j15, {-1, 226}},
|
||||
{j16, {0, 3}},
|
||||
{n, {0, 8}},
|
||||
{f, {0, 32}}},
|
||||
{{j14, {0, 3}}, {j4, {0, 3}}, {c, {0, 16}}}, subA * subB);
|
||||
// Derivation
|
||||
{
|
||||
Formula conv(range, 0);
|
||||
|
@ -187,9 +185,9 @@ TEST(GuidedDLT, Conv2Conv_KernelDLT) {
|
|||
// {L<i101:0:288><i79:-3:227><i55:-3:227><n:0:8>Sum<i14:-1:2><i4:-1:2><c:0:16>
|
||||
// // {({A<pad=0,0,4,4>}[n, c, (i4 + i55), (i14 + i79)] * {T1}[i101, c, i4,
|
||||
// // i14])}}}}}
|
||||
// auto subA = makeSubscript(A, {n, c, (j4 + j55), (j14 + j79)});
|
||||
// auto subB = makeSubscript(B, {j101, c, j4, j14});
|
||||
// auto range = makeRangeOperator(
|
||||
// auto subA = mSub(A, {n, c, (j4 + j55), (j14 + j79)});
|
||||
// auto subB = mSub(B, {j101, c, j4, j14});
|
||||
// auto range = mL(
|
||||
// {{j101, {0, 288}}, {j79, {-3, 227}}, {j55, {-3, 227}}, {n, {0, 8}}},
|
||||
// {{j14, {-1, 2}}, {j4, {-1, 2}}, {c, {0, 16}}}, subA * subB);
|
||||
// // Derivation
|
||||
|
@ -226,15 +224,15 @@ TEST(GuidedDLT, dimFusion_ConvToGemm_2Tensor_ruleBased) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({N, N, N, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, N, N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, t1, t2, c});
|
||||
auto subB = makeSubscript(B, {r, s, f, c});
|
||||
auto range = makeRangeOperator({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, t1, t2, c});
|
||||
auto subB = mSub(B, {r, s, f, c});
|
||||
auto range = mL({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
{
|
||||
|
@ -263,15 +261,15 @@ TEST(GuidedDLT, dimFusion_ConvToGemm_2Tensor_dfs) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({N, N, N, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, N, N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, t1, t2, c});
|
||||
auto subB = makeSubscript(B, {r, s, f, c});
|
||||
auto range = makeRangeOperator({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, t1, t2, c});
|
||||
auto subB = mSub(B, {r, s, f, c});
|
||||
auto range = mL({{r, {0, N}},
|
||||
{s, {0, N}},
|
||||
{n, {0, N}},
|
||||
{t1, {0, N}},
|
||||
{t2, {0, N}},
|
||||
{f, {0, N}}},
|
||||
{{c, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
{
|
||||
|
@ -307,14 +305,14 @@ TEST(GuidedDLT, dimFusion_ConvToGemm_2Tensor_dfs) {
|
|||
// Disabled since forget the answer
|
||||
TEST(GuidedDLT, DISABLED_match_ConvToConv_conv) {
|
||||
DEFINE_VAR(r, s, n, i22, i4, i14, i17, i24, f, c);
|
||||
auto A = makeTensor("A", {1, 1, 224, 224}, {0, 0, 4, 4});
|
||||
auto A = mT("A", {1, 1, 224, 224}, {0, 0, 4, 4});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({576, 1, 3, 3}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, ((i22 + i4) + -4), ((i14 + i17) + -4)});
|
||||
auto subB = makeSubscript(B, {i24, c, i4, i14});
|
||||
auto range = makeRangeOperator(
|
||||
{{i24, {0, 576}}, {i22, {2, 228}}, {i17, {2, 228}}, {n, {0, 1}}},
|
||||
{{i14, {0, 3}}, {i4, {0, 3}}, {c, {0, 1}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, c, ((i22 + i4) + -4), ((i14 + i17) + -4)});
|
||||
auto subB = mSub(B, {i24, c, i4, i14});
|
||||
auto range =
|
||||
mL({{i24, {0, 576}}, {i22, {2, 228}}, {i17, {2, 228}}, {n, {0, 1}}},
|
||||
{{i14, {0, 3}}, {i4, {0, 3}}, {c, {0, 1}}}, subA * subB);
|
||||
dbg(range);
|
||||
// Derivation
|
||||
{
|
||||
|
|
|
@ -63,11 +63,11 @@ TEST(MatchConv, NoBatch) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r, w + s});
|
||||
auto subB = makeSubscript(B, {f, c, r, s});
|
||||
auto rangeOp = makeRangeOperator(
|
||||
{{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2}}, {s, {-S / 2, S / 2}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, c, h + r, w + s});
|
||||
auto subB = mSub(B, {f, c, r, s});
|
||||
auto rangeOp = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2}}, {s, {-S / 2, S / 2}}},
|
||||
subA * subB);
|
||||
|
||||
// Derivation
|
||||
Formula matmul(rangeOp, 0);
|
||||
|
@ -101,11 +101,10 @@ TEST(MatchConv, Wrong0) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r, w + s});
|
||||
auto subB = makeSubscript(B, {c, f, r, s});
|
||||
auto rangeOp =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, c, h + r, w + s});
|
||||
auto subB = mSub(B, {c, f, r, s});
|
||||
auto rangeOp = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subB);
|
||||
|
||||
// Derivation
|
||||
Formula matmul(rangeOp, 0);
|
||||
|
@ -129,11 +128,10 @@ TEST(MatchConv, Wrong1) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + 2 * r, w + s});
|
||||
auto subB = makeSubscript(B, {f, c, r, s});
|
||||
auto rangeOp =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subB);
|
||||
auto subA = mSub(A, {n, c, h + 2 * r, w + s});
|
||||
auto subB = mSub(B, {f, c, r, s});
|
||||
auto rangeOp = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subB);
|
||||
|
||||
// Derivation
|
||||
Formula matmul(rangeOp, 0);
|
||||
|
|
|
@ -20,13 +20,13 @@ TEST(MatchElementWise, NoMatch) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r, w + s});
|
||||
auto subK = makeSubscript(K, {f, c, r + R / 2, s + S / 2});
|
||||
auto subA = mSub(A, {n, c, h + r, w + s});
|
||||
auto subK = mSub(K, {f, c, r + R / 2, s + S / 2});
|
||||
|
||||
auto range = makeRangeOperator(
|
||||
{{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
auto range =
|
||||
mL({{n, {0, N}}, {h, {0, H}}, {w, {0, W}}, {f, {0, F}}},
|
||||
{{c, {0, C}}, {r, {-R / 2, R / 2 + 1}}, {s, {-S / 2, S / 2 + 1}}},
|
||||
subA * subK);
|
||||
// cout << range->toReadable() << endl;
|
||||
|
||||
// Derivation
|
||||
|
@ -56,13 +56,11 @@ TEST(MatchElementWise, TwoStagesWithPadding) {
|
|||
make_ref<TensorNode>("A", vector<int>({N, N}), vector<int>{0, N / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({N, N}));
|
||||
|
||||
auto innerSub = makeSubscript(A, {n, h});
|
||||
auto innerRange =
|
||||
makeRangeOperator({{n, {0, N}}, {h, {0, N}}}, {}, innerSub);
|
||||
auto innerSub = mSub(A, {n, h});
|
||||
auto innerRange = mL({{n, {0, N}}, {h, {0, N}}}, {}, innerSub);
|
||||
innerRange->setPaddings({0, 2});
|
||||
auto outerSub = makeSubscript(innerRange, {r, s + r});
|
||||
auto outerRange =
|
||||
makeRangeOperator({{r, {0, 4}}, {s, {0, 5}}}, {}, outerSub);
|
||||
auto outerSub = mSub(innerRange, {r, s + r});
|
||||
auto outerRange = mL({{r, {0, 4}}, {s, {0, 5}}}, {}, outerSub);
|
||||
// cout << range->toReadable() << endl;
|
||||
|
||||
// Derivation
|
||||
|
@ -85,13 +83,11 @@ TEST(MatchElementWise, TwoStagesWithImperfectedNestedPadding) {
|
|||
vector<int>{0, N / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({100, 100}));
|
||||
|
||||
auto innerSub = makeSubscript(A, {n, h + n});
|
||||
auto innerRange =
|
||||
makeRangeOperator({{n, {0, 8}}, {h, {0, 8}}}, {}, innerSub);
|
||||
auto innerSub = mSub(A, {n, h + n});
|
||||
auto innerRange = mL({{n, {0, 8}}, {h, {0, 8}}}, {}, innerSub);
|
||||
innerRange->setPaddings({0, 2});
|
||||
auto outerSub = makeSubscript(innerRange, {r, s + r});
|
||||
auto outerRange =
|
||||
makeRangeOperator({{r, {0, 4}}, {s, {0, 5}}}, {}, outerSub);
|
||||
auto outerSub = mSub(innerRange, {r, s + r});
|
||||
auto outerRange = mL({{r, {0, 4}}, {s, {0, 5}}}, {}, outerSub);
|
||||
// cout << range->toReadable() << endl;
|
||||
|
||||
// Derivation
|
||||
|
@ -99,4 +95,4 @@ TEST(MatchElementWise, TwoStagesWithImperfectedNestedPadding) {
|
|||
Derivator derivator;
|
||||
derivator.ruleBasedDFS(conv_9x9, 0, {6});
|
||||
EXPECT_EQ(derivator.getNumCandidates(), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,21 +21,18 @@ TEST(MatchMatmul, NoBatch) {
|
|||
// Transpose requires the existance of source for inputs
|
||||
auto _A = make_ref<TensorNode>("A_shadow", vector<int>({M, K}));
|
||||
auto _B = make_ref<TensorNode>("B_shadow", vector<int>({N, K}));
|
||||
auto rangeA = makeRangeOperator({{m, {0, M}}, {k, {0, K}}}, {},
|
||||
makeSubscript(_A, {m, k}));
|
||||
auto rangeB = makeRangeOperator({{n, {0, N}}, {k, {0, K}}}, {},
|
||||
makeSubscript(_A, {n, k}));
|
||||
auto rangeA = mL({{m, {0, M}}, {k, {0, K}}}, {}, mSub(_A, {m, k}));
|
||||
auto rangeB = mL({{n, {0, N}}, {k, {0, K}}}, {}, mSub(_A, {n, k}));
|
||||
auto elemA =
|
||||
make_ref<ElementWiseNode>(rangeA, vector<Tensor>{_A}, _A->getShape());
|
||||
auto elemB =
|
||||
make_ref<ElementWiseNode>(rangeB, vector<Tensor>{_B}, _B->getShape());
|
||||
auto A = makeTensor("A", vector<int>({M, K}), {}, elemA);
|
||||
auto B = makeTensor("B", vector<int>({N, K}), {}, elemB);
|
||||
auto A = mT("A", vector<int>({M, K}), {}, elemA);
|
||||
auto B = mT("B", vector<int>({N, K}), {}, elemB);
|
||||
|
||||
auto subA = makeSubscript(A, {m, k});
|
||||
auto subB = makeSubscript(B, {n, k});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, k});
|
||||
auto subB = mSub(B, {n, k});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
|
@ -73,10 +70,9 @@ TEST(MatchMatmul, Illegal0) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {m, k});
|
||||
auto subB = makeSubscript(B, {k, k});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, k});
|
||||
auto subB = mSub(B, {k, k});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
Derivator derivator;
|
||||
|
@ -93,10 +89,9 @@ TEST(MatchMatmul, Illegal1) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {m, k});
|
||||
auto subB = makeSubscript(B, {n, k});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}, {k, {0, K}}}, {},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, k});
|
||||
auto subB = mSub(B, {n, k});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}, {k, {0, K}}}, {}, subA * subB);
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
Derivator derivator;
|
||||
|
@ -113,10 +108,9 @@ TEST(MatchMatmul, Illegal2) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {m, m + k});
|
||||
auto subB = makeSubscript(B, {n, k});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, m + k});
|
||||
auto subB = mSub(B, {n, k});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
Derivator derivator;
|
||||
|
@ -140,10 +134,9 @@ TEST(MatchMatmul, Illegal3) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {m, n + k});
|
||||
auto subB = makeSubscript(B, {n, k});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, n + k});
|
||||
auto subB = mSub(B, {n, k});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
Derivator derivator;
|
||||
|
@ -168,10 +161,9 @@ TEST(MatchMatmul, Illegal4) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {m, k});
|
||||
auto subB = makeSubscript(B, {k, n});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, k});
|
||||
auto subB = mSub(B, {k, n});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
// Derivation
|
||||
Formula matmul(range, 0);
|
||||
Derivator derivator;
|
||||
|
@ -196,10 +188,9 @@ TEST(MatchMatmul, IteratorTable1) {
|
|||
auto A = make_ref<TensorNode>("_A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("_B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {m, k});
|
||||
auto subB = makeSubscript(B, {n, k});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, k});
|
||||
auto subB = mSub(B, {n, k});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
class IteratorTable exprIT;
|
||||
ASSERT_TRUE(exprIT.analyzeExpr(range));
|
||||
exprIT.buildTable({0, 1});
|
||||
|
@ -244,10 +235,9 @@ TEST(MatchMatmul, IteratorTable2) {
|
|||
auto A = make_ref<TensorNode>("_A", vector<int>({M, K}));
|
||||
auto B = make_ref<TensorNode>("_B", vector<int>({N, K}));
|
||||
|
||||
auto subA = makeSubscript(A, {m, k + m});
|
||||
auto subB = makeSubscript(B, {n, c2 * (k + c2)});
|
||||
auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
subA * subB);
|
||||
auto subA = mSub(A, {m, k + m});
|
||||
auto subB = mSub(B, {n, c2 * (k + c2)});
|
||||
auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}}, subA * subB);
|
||||
class IteratorTable exprIT;
|
||||
ASSERT_TRUE(exprIT.analyzeExpr(range));
|
||||
exprIT.buildTable({0, 1});
|
||||
|
@ -293,19 +283,19 @@ TEST(MatchMatmul, IteratorTable2) {
|
|||
// auto A = make_ref<TensorNode>("A", vector<int>({M, K}));
|
||||
// auto B = make_ref<TensorNode>("B", vector<int>({N, K}));
|
||||
|
||||
// auto subA = makeSubscript(A, {m, k});
|
||||
// auto subB = makeSubscript(B, {n, k});
|
||||
// auto rangeA = makeRangeOperator({{m, {0, M}}, {k, {0, K}}}, {}, subA);
|
||||
// auto rangeB = makeRangeOperator({{n, {0, N}}, {k, {0, K}}}, {}, subB);
|
||||
// auto subA = mSub(A, {m, k});
|
||||
// auto subB = mSub(B, {n, k});
|
||||
// auto rangeA = mL({{m, {0, M}}, {k, {0, K}}}, {}, subA);
|
||||
// auto rangeB = mL({{n, {0, N}}, {k, {0, K}}}, {}, subB);
|
||||
// auto ewA = make_ref<ElementWiseNode>(rangeA, vector<Tensor>{A},
|
||||
// rangeA->getOutputShape());
|
||||
// auto ewB = make_ref<ElementWiseNode>(rangeB, vector<Tensor>{B},
|
||||
// rangeB->getOutputShape());
|
||||
// auto tensorA = makeTensor("TA", A->getShape(), {}, ewA);
|
||||
// auto tensorB = makeTensor("TB", B->getShape(), {}, ewB);
|
||||
// auto subRangeA = makeSubscript(tensorA, {m, k});
|
||||
// auto subRangeB = makeSubscript(tensorB, {n, k});
|
||||
// auto range = makeRangeOperator({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
// auto tensorA = mT("TA", A->getShape(), {}, ewA);
|
||||
// auto tensorB = mT("TB", B->getShape(), {}, ewB);
|
||||
// auto subRangeA = mSub(tensorA, {m, k});
|
||||
// auto subRangeB = mSub(tensorB, {n, k});
|
||||
// auto range = mL({{m, {0, M}}, {n, {0, N}}}, {{k, {0, K}}},
|
||||
// subRangeA * subRangeB);
|
||||
|
||||
// // Derivation
|
||||
|
|
|
@ -10,8 +10,8 @@ using namespace std;
|
|||
TEST(MatchReshape, ElementWise_NHWC) {
|
||||
DEFINE_VAR(i, c);
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({1, 7, 7, 512}));
|
||||
auto subA = makeSubscript(A, {i / 49, i / 7, i % 7, c});
|
||||
auto expr = makeRangeOperator({{i, {0, 49}}, {c, {0, 512}}}, {}, subA);
|
||||
auto subA = mSub(A, {i / 49, i / 7, i % 7, c});
|
||||
auto expr = mL({{i, {0, 49}}, {c, {0, 512}}}, {}, subA);
|
||||
auto matchReshapeVisitor = MatchReshapeVisitor();
|
||||
EXPECT_TRUE(matchReshapeVisitor(expr));
|
||||
}
|
||||
|
@ -19,11 +19,10 @@ TEST(MatchReshape, ElementWise_NHWC) {
|
|||
TEST(MatchReshape, ElementWise_with_Sum) {
|
||||
DEFINE_VAR(n, h, w, f, r, s);
|
||||
auto A = make_ref<TensorNode>("A", vector<int>{49, 512});
|
||||
auto subA = makeSubscript(
|
||||
auto subA = mSub(
|
||||
A, {(49 * n + 7 * (h + r)) + (w + s), ((512 * r) + (512 * s)) + f});
|
||||
auto expr = makeRangeOperator(
|
||||
{{n, {0, 1}}, {h, {0, 7}}, {w, {0, 7}}, {f, {0, 512}}},
|
||||
{{r, {0, 1}}, {s, {0, 1}}}, subA);
|
||||
auto expr = mL({{n, {0, 1}}, {h, {0, 7}}, {w, {0, 7}}, {f, {0, 512}}},
|
||||
{{r, {0, 1}}, {s, {0, 1}}}, subA);
|
||||
auto matchReshapeVisitor = MatchReshapeVisitor();
|
||||
EXPECT_TRUE(matchReshapeVisitor(expr));
|
||||
}
|
||||
|
@ -57,8 +56,8 @@ TEST(MatchReshape, Conv2gemm_1x1_NCHW_K) {
|
|||
// ==> K : Input Tensor shape=[512,512,1,1] pad=[0,0,0,0]
|
||||
DEFINE_VAR(i, c);
|
||||
auto A = make_ref<TensorNode>("K", vector<int>({512, 512, 1, 1}));
|
||||
auto subA = makeSubscript(A, {i, c, i % 1, i % 1});
|
||||
auto expr = makeRangeOperator({{i, {0, 512}}, {c, {0, 512}}}, {}, subA);
|
||||
auto subA = mSub(A, {i, c, i % 1, i % 1});
|
||||
auto expr = mL({{i, {0, 512}}, {c, {0, 512}}}, {}, subA);
|
||||
auto matchReshapeVisitor = MatchReshapeVisitor();
|
||||
EXPECT_TRUE(matchReshapeVisitor(expr));
|
||||
}
|
||||
|
@ -71,8 +70,8 @@ TEST(MatchReshape, Conv2gemm_1x1_NCHW_A_merged) {
|
|||
// ==> A : Input Tensor shape=[1,512,7,7] pad=[0,0,0,0]
|
||||
DEFINE_VAR(i, c);
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({1, 512, 7, 7}));
|
||||
auto subA = makeSubscript(A, {(i / 49), c, (i / 7), (i % 7)});
|
||||
auto expr = makeRangeOperator({{c, {0, 512}}, {i, {0, 49}}}, {}, subA);
|
||||
auto subA = mSub(A, {(i / 49), c, (i / 7), (i % 7)});
|
||||
auto expr = mL({{c, {0, 512}}, {i, {0, 49}}}, {}, subA);
|
||||
auto matchReshapeVisitor = MatchReshapeVisitor();
|
||||
EXPECT_TRUE(matchReshapeVisitor(expr));
|
||||
}
|
||||
|
@ -85,10 +84,10 @@ TEST(MatchReshape, Conv2gemm_1x1_NCHW_A) {
|
|||
// ==> A : Input Tensor shape=[1,512,7,7] pad=[0,0,0,0]
|
||||
DEFINE_VAR(i, c);
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({1, 512, 7, 7}));
|
||||
auto subA = makeSubscript(A, {(i / 49), c, (i / 7), (i % 7)});
|
||||
auto inner = makeRangeOperator({{i, {0, 49}}, {c, {0, 512}}}, {}, subA);
|
||||
auto subInner = makeSubscript(inner, {i, c});
|
||||
auto outer = makeRangeOperator({{c, {0, 512}}, {i, {0, 49}}}, {}, subInner);
|
||||
auto subA = mSub(A, {(i / 49), c, (i / 7), (i % 7)});
|
||||
auto inner = mL({{i, {0, 49}}, {c, {0, 512}}}, {}, subA);
|
||||
auto subInner = mSub(inner, {i, c});
|
||||
auto outer = mL({{c, {0, 512}}, {i, {0, 49}}}, {}, subInner);
|
||||
EXPECT_TRUE(MatchReshapeVisitor()(outer));
|
||||
}
|
||||
|
||||
|
@ -99,11 +98,10 @@ TEST(MatchReshape, Conv2gemm_1x1_NCHW_Output) {
|
|||
// ==> T15 : Matmul{bmnk = 1, 512, 49, 512; AB = T3, T14; transAB = 0, 0}
|
||||
DEFINE_VAR(n, h, w, f, r, s);
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({512, 49}));
|
||||
auto subA = makeSubscript(
|
||||
A, {((f + r) + s), (((49 * n) + (7 * (h + r))) + (w + s))});
|
||||
auto expr = makeRangeOperator(
|
||||
{{n, {0, 1}}, {f, {0, 512}}, {h, {0, 7}}, {w, {0, 7}}},
|
||||
{{r, {0, 1}}, {s, {0, 1}}}, subA);
|
||||
auto subA =
|
||||
mSub(A, {((f + r) + s), (((49 * n) + (7 * (h + r))) + (w + s))});
|
||||
auto expr = mL({{n, {0, 1}}, {f, {0, 512}}, {h, {0, 7}}, {w, {0, 7}}},
|
||||
{{r, {0, 1}}, {s, {0, 1}}}, subA);
|
||||
auto matchReshapeVisitor = MatchReshapeVisitor();
|
||||
EXPECT_TRUE(matchReshapeVisitor(expr));
|
||||
}
|
||||
|
@ -116,11 +114,10 @@ TEST(MatchReshape, Conv2gemm_1x1_NCHW_Output_wrong) {
|
|||
// ==> T7 : Matmul{bmnk = 1, 49, 512, 512; AB = T6, T3; transAB = 1, 1}
|
||||
DEFINE_VAR(n, h, w, f, r, s);
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({49, 512}));
|
||||
auto subA = makeSubscript(
|
||||
A, {(((49 * n) + (6 * (h + r))) + (w + s)), ((f + r) + s)});
|
||||
auto expr = makeRangeOperator(
|
||||
{{n, {0, 1}}, {h, {0, 7}}, {w, {0, 7}}, {f, {0, 512}}},
|
||||
{{r, {0, 1}}, {s, {0, 1}}}, subA);
|
||||
auto subA =
|
||||
mSub(A, {(((49 * n) + (6 * (h + r))) + (w + s)), ((f + r) + s)});
|
||||
auto expr = mL({{n, {0, 1}}, {h, {0, 7}}, {w, {0, 7}}, {f, {0, 512}}},
|
||||
{{r, {0, 1}}, {s, {0, 1}}}, subA);
|
||||
auto matchReshapeVisitor = MatchReshapeVisitor();
|
||||
EXPECT_FALSE(matchReshapeVisitor(expr));
|
||||
}
|
||||
|
@ -140,11 +137,10 @@ TEST(MatchReshape, Conv2gemm_1x7_A) {
|
|||
DEFINE_VAR(i, c);
|
||||
auto A = make_ref<TensorNode>("A", vector<int>({N, C, H, W}),
|
||||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto subA = makeSubscript(A, {(i / 49), c, (i / 7), (i % 7)});
|
||||
auto inner = makeRangeOperator({{i, {0, 49}}, {c, {0, 2048}}}, {}, subA);
|
||||
auto subInner = makeSubscript(inner, {i, c});
|
||||
auto outer =
|
||||
makeRangeOperator({{c, {0, 2048}}, {i, {0, 49}}}, {}, subInner);
|
||||
auto subA = mSub(A, {(i / 49), c, (i / 7), (i % 7)});
|
||||
auto inner = mL({{i, {0, 49}}, {c, {0, 2048}}}, {}, subA);
|
||||
auto subInner = mSub(inner, {i, c});
|
||||
auto outer = mL({{c, {0, 2048}}, {i, {0, 49}}}, {}, subInner);
|
||||
dbg(outer);
|
||||
EXPECT_TRUE(MatchReshapeVisitor()(outer));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,9 +85,8 @@ pair<std::vector<nnet::Tensor>, nnet::Expr> getPReluExpr(int size) {
|
|||
DEFINE_VAR(i);
|
||||
auto A = make_ref<TensorNode>("A", vector{size});
|
||||
auto B = make_ref<TensorNode>("B", vector{size});
|
||||
Expr e = make_ref<FuncNode>(makeSubscript(A, {i}) - makeSubscript(B, {i}),
|
||||
FuncType::PRelu);
|
||||
Expr ret = makeRangeOperator({{i, {0, size}}}, {}, e);
|
||||
Expr e = make_ref<FuncNode>(mSub(A, {i}) - mSub(B, {i}), FuncType::PRelu);
|
||||
Expr ret = mL({{i, {0, size}}}, {}, e);
|
||||
return {{A, B}, ret};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,11 @@ TEST(FuseMembound, Relu) {
|
|||
auto A = make_ref<TensorNode>("A", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, 0, 0});
|
||||
|
||||
auto subA = makeSubscript(A, {b, m, k});
|
||||
auto innerRange = makeRangeOperator(
|
||||
{{b, {0, Batch}}, {m, {0, M}}, {k, {0, K}}}, {}, subA);
|
||||
auto subA = mSub(A, {b, m, k});
|
||||
auto innerRange = mL({{b, {0, Batch}}, {m, {0, M}}, {k, {0, K}}}, {}, subA);
|
||||
auto relu = make_ref<FuncNode>(subA, FuncType::Relu);
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, relu);
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {w, {0, 2 * W + 1}}},
|
||||
{{k, {0, K}}}, relu);
|
||||
cout << MergeMemboundMutator({innerRange, range}).merge()->toReadable()
|
||||
<< endl;
|
||||
}
|
||||
|
@ -38,15 +36,13 @@ TEST(FuseMembound, MemMemFusion) {
|
|||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, K, M}),
|
||||
vector<int>{0, 0, 0});
|
||||
|
||||
auto subA = makeSubscript(B, {b, k, m});
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}}, {{k, {0, K}}}, subA);
|
||||
auto subA = mSub(B, {b, k, m});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}}, {{k, {0, K}}}, subA);
|
||||
auto innerRange =
|
||||
makeRangeOperator({{b, {0, Batch}}, {k, {0, K}}, {m, {0, M}}}, {},
|
||||
makeSubscript(A, {b, m, k}));
|
||||
mL({{b, {0, Batch}}, {k, {0, K}}, {m, {0, M}}}, {}, mSub(A, {b, m, k}));
|
||||
auto merged = MergeMemboundMutator({innerRange, range}).merge();
|
||||
RangeOp ans = makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}},
|
||||
{{k, {0, K}}}, makeSubscript(A, {b, m, k}));
|
||||
RangeOp ans =
|
||||
mL({{b, {0, Batch}}, {m, {0, M}}}, {{k, {0, K}}}, mSub(A, {b, m, k}));
|
||||
EXPECT_EQ(HashVisitor().getHash(merged), HashVisitor().getHash(ans));
|
||||
}
|
||||
|
||||
|
@ -59,15 +55,13 @@ TEST(FuseMembound, mergeNestedStagesInRangeOp) {
|
|||
const int I = 4096, F = 448;
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({448, 4, 4, 256}));
|
||||
|
||||
auto subA = makeSubscript(K, {f, i / 1024, (i / 256) % 4, i % 256});
|
||||
auto range = makeRangeOperator({{i, {0, I}}, {f, {0, F}}}, {}, subA);
|
||||
auto outerRange = makeRangeOperator({{f, {0, F}}, {i, {0, I}}}, {},
|
||||
makeSubscript(range, {i, f}));
|
||||
auto subA = mSub(K, {f, i / 1024, (i / 256) % 4, i % 256});
|
||||
auto range = mL({{i, {0, I}}, {f, {0, F}}}, {}, subA);
|
||||
auto outerRange = mL({{f, {0, F}}, {i, {0, I}}}, {}, mSub(range, {i, f}));
|
||||
auto merged = MergeMemboundMutator({outerRange}).merge();
|
||||
|
||||
// Compare the result with answer
|
||||
RangeOp ans = makeRangeOperator(
|
||||
{{f, {0, F}}, {i, {0, I}}}, {},
|
||||
makeSubscript(K, {f, i / 1024, (i / 256) % 4, i % 256}));
|
||||
RangeOp ans = mL({{f, {0, F}}, {i, {0, I}}}, {},
|
||||
mSub(K, {f, i / 1024, (i / 256) % 4, i % 256}));
|
||||
EXPECT_EQ(HashVisitor().getHash(merged), HashVisitor().getHash(ans));
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ TEST(OOB, noOOB) {
|
|||
vector<int>{0, 0, 0});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, dilation * W, 0});
|
||||
auto subA = makeSubscript(A, {b, m, w});
|
||||
// auto subB = makeSubscript(B, {b, m + dilation * (w - W), n});
|
||||
auto subB = makeSubscript(B, {b, m + dilation * w - dilation * W, n});
|
||||
auto range = makeRangeOperator({{b, {0, Batch}}, {m, {0, M}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, w});
|
||||
// auto subB = mSub(B, {b, m + dilation * (w - W), n});
|
||||
auto subB = mSub(B, {b, m + dilation * w - dilation * W, n});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
dbg(range);
|
||||
|
||||
CheckOOBVisitor oobchecker;
|
||||
|
@ -41,14 +41,13 @@ TEST(OOB, hasOOB) {
|
|||
vector<int>{0, 0, 0});
|
||||
auto B = make_ref<TensorNode>("B", vector<int>({Batch, M, K}),
|
||||
vector<int>{0, 0, 0});
|
||||
auto subA = makeSubscript(A, {b, m, w});
|
||||
// auto subB = makeSubscript(B, {b, m + dilation * (w - W), n});
|
||||
auto subB = makeSubscript(B, {b, m - dilation * (w), n});
|
||||
auto range =
|
||||
makeRangeOperator({{b, {0, Batch}}, {m, {0, M + 1}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
auto subA = mSub(A, {b, m, w});
|
||||
// auto subB = mSub(B, {b, m + dilation * (w - W), n});
|
||||
auto subB = mSub(B, {b, m - dilation * (w), n});
|
||||
auto range = mL({{b, {0, Batch}}, {m, {0, M + 1}}, {n, {0, K}}},
|
||||
{{w, {0, 2 * W + 1}}}, subA * subB);
|
||||
dbg(range);
|
||||
|
||||
CheckOOBVisitor oobchecker;
|
||||
EXPECT_TRUE(oobchecker.checkRangeOp(range));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,12 +21,11 @@ TEST(RangeMagnify, Conv5x5) {
|
|||
vector<int>{0, 0, R / 2, S / 2});
|
||||
auto K = make_ref<TensorNode>("K", vector<int>({F, C, R, S}));
|
||||
|
||||
auto subA = makeSubscript(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = makeSubscript(K, {f, c, r, s});
|
||||
auto subA = mSub(A, {n, c, h + r - R / 2, w + s - S / 2});
|
||||
auto subK = mSub(K, {f, c, r, s});
|
||||
|
||||
auto range =
|
||||
makeRangeOperator({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
auto range = mL({{n, {0, N}}, {f, {0, F}}, {h, {0, H}}, {w, {0, W}}},
|
||||
{{c, {0, C}}, {r, {0, R}}, {s, {0, S}}}, subA * subK);
|
||||
// cout << range->toReadable() << endl;
|
||||
auto ret = RangeMagnifyVisitor().magnify(
|
||||
range, {{c, {0, C}}, {r, {0, R + 1}}, {s, {0, S + 1}}});
|
||||
|
|
|
@ -61,23 +61,23 @@ TEST(Relaxation, NaiveMatch) {
|
|||
DEFINE_VAR(i14);
|
||||
DEFINE_VAR(i4);
|
||||
DEFINE_VAR(c);
|
||||
auto A = makeTensor("A", {8, 16, 224, 224}, {0, 0, 4, 4});
|
||||
auto K = makeTensor("K", {32, 16, 9, 9});
|
||||
auto subA = makeSubscript(A, {n, c, ((i22 + i4) + -4), ((i14 + i17) + -4)});
|
||||
auto subK = makeSubscript(K, {f, c, ((3 * i23) + i4), (i14 + (3 * i18))});
|
||||
auto innerRange = makeRangeOperator(
|
||||
{{i22, {0, 230}},
|
||||
{i23, {0, 3}},
|
||||
{i17, {0, 230}},
|
||||
{i18, {0, 3}},
|
||||
{n, {0, 8}},
|
||||
{f, {0, 32}}},
|
||||
{{i14, {0, 3}}, {i4, {0, 3}}, {c, {0, 16}}}, subA * subK);
|
||||
auto subOuter = makeSubscript(
|
||||
innerRange, {(h + (3 * i3)), i3, (w + (3 * i13)), i13, n, f});
|
||||
auto outerRange = makeRangeOperator(
|
||||
{{n, {0, 8}}, {h, {0, 224}}, {w, {0, 224}}, {f, {0, 32}}},
|
||||
{{i13, {0, 3}}, {i3, {0, 3}}}, subOuter);
|
||||
auto A = mT("A", {8, 16, 224, 224}, {0, 0, 4, 4});
|
||||
auto K = mT("K", {32, 16, 9, 9});
|
||||
auto subA = mSub(A, {n, c, ((i22 + i4) + -4), ((i14 + i17) + -4)});
|
||||
auto subK = mSub(K, {f, c, ((3 * i23) + i4), (i14 + (3 * i18))});
|
||||
auto innerRange =
|
||||
mL({{i22, {0, 230}},
|
||||
{i23, {0, 3}},
|
||||
{i17, {0, 230}},
|
||||
{i18, {0, 3}},
|
||||
{n, {0, 8}},
|
||||
{f, {0, 32}}},
|
||||
{{i14, {0, 3}}, {i4, {0, 3}}, {c, {0, 16}}}, subA * subK);
|
||||
auto subOuter =
|
||||
mSub(innerRange, {(h + (3 * i3)), i3, (w + (3 * i13)), i13, n, f});
|
||||
auto outerRange =
|
||||
mL({{n, {0, 8}}, {h, {0, 224}}, {w, {0, 224}}, {f, {0, 32}}},
|
||||
{{i13, {0, 3}}, {i3, {0, 3}}}, subOuter);
|
||||
Derivator derivator(0);
|
||||
Formula formula(innerRange, 0);
|
||||
Rule5RangeRelaxation pass(derivator);
|
||||
|
@ -88,4 +88,4 @@ TEST(Relaxation, NaiveMatch) {
|
|||
auto rangeOp = as<RangeOpNode>(ret);
|
||||
EXPECT_EQ(rangeOp->getRange(i22), pair(2, 228));
|
||||
EXPECT_EQ(rangeOp->getRange(i17), pair(2, 228));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,12 @@ using namespace std;
|
|||
|
||||
Expr buildSimpleExpr() {
|
||||
DEFINE_VAR(b, w, k, i3, i4);
|
||||
auto A = makeTensor("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = makeTensor("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = makeSubscript(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB = makeSubscript(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = makeRangeOperator(
|
||||
{{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
auto A = mT("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = mT("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = mSub(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB = mSub(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = mL({{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
return range;
|
||||
}
|
||||
|
||||
|
@ -32,9 +31,8 @@ Expr buildNestedExpr() {
|
|||
auto C = make_ref<TensorNode>("C", vector<int>({M, K}));
|
||||
auto D = make_ref<TensorNode>("D", vector<int>({N, K}));
|
||||
auto F = make_ref<TensorNode>("F", vector<int>({N, K}));
|
||||
auto matmulExpr = makeSubscript(C, {j1, j3}) * makeSubscript(D, {j2, j3});
|
||||
Expr expr = makeRangeOperator({{j1, {0, M}}, {j2, {0, N}}}, {{j3, {0, K}}},
|
||||
matmulExpr);
|
||||
auto matmulExpr = mSub(C, {j1, j3}) * mSub(D, {j2, j3});
|
||||
Expr expr = mL({{j1, {0, M}}, {j2, {0, N}}}, {{j3, {0, K}}}, matmulExpr);
|
||||
auto matmul = make_ref<MatmulNode>(expr, C, D, 1, M, N, K, false, false);
|
||||
|
||||
vector<int> shapeE{N, K};
|
||||
|
@ -43,13 +41,12 @@ Expr buildNestedExpr() {
|
|||
auto ele1 = make_ref<ElementWiseNode>(expr, vector{E}, shapeE);
|
||||
|
||||
DEFINE_VAR(b, w, k, i3, i4);
|
||||
auto A = makeTensor("A", {8, 10000, 512}, {0, 0, 0}, matmul);
|
||||
auto B = makeTensor("B", {8, 10000, 512}, {0, 128, 0}, ele1);
|
||||
auto subA = makeSubscript(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB = makeSubscript(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = makeRangeOperator(
|
||||
{{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
auto A = mT("A", {8, 10000, 512}, {0, 0, 0}, matmul);
|
||||
auto B = mT("B", {8, 10000, 512}, {0, 128, 0}, ele1);
|
||||
auto subA = mSub(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto subB = mSub(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = mL({{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, subA * subB);
|
||||
return range;
|
||||
}
|
||||
|
||||
|
@ -61,14 +58,13 @@ TEST(Serializer, Serialization) {
|
|||
|
||||
TEST(Serializer, CompareTwoExprs) {
|
||||
DEFINE_VAR(b, w, k, i3, i4);
|
||||
auto A = makeTensor("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = makeTensor("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = makeSubscript(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto A = mT("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = mT("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto subA = mSub(A, {b, (i3 + (2500 * i4)), k});
|
||||
auto funcA = make_ref<FuncNode>(subA, FuncType::Relu);
|
||||
auto subB = makeSubscript(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = makeRangeOperator(
|
||||
{{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, funcA * subB);
|
||||
auto subB = mSub(B, {b, ((i3 + (2500 * i4)) + w), k});
|
||||
auto range = mL({{i3, {0, 2500}}, {i4, {0, 4}}, {b, {0, 8}}, {w, {0, 65}}},
|
||||
{{k, {0, 512}}}, funcA * subB);
|
||||
Serializer().toFile(range, "./test_serializer.json");
|
||||
auto expr = Serializer().fromFile("./test_serializer.json");
|
||||
dbg(expr);
|
||||
|
@ -89,8 +85,8 @@ TEST(Serializer, Serialization_NestedTensor) {
|
|||
|
||||
TEST(Serializer, Serialization_memboundOp) {
|
||||
auto expr = buildSimpleExpr();
|
||||
auto A = makeTensor("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = makeTensor("B", {8, 10000, 512}, {0, 128, 0});
|
||||
auto A = mT("A", {8, 10000, 512}, {0, 0, 0});
|
||||
auto B = mT("B", {8, 10000, 512}, {0, 128, 0});
|
||||
// using namespace infini;
|
||||
auto runtime = infini::NativeCpuRuntimeObj::getInstance();
|
||||
auto g = infini::make_ref<infini::GraphObj>(runtime);
|
||||
|
|
Loading…
Reference in New Issue