Skip to content

Commit

Permalink
[TensorExpr] Add LoopNest::simplify. (#50850)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #50850

Test Plan: Imported from OSS

Reviewed By: Chillee

Differential Revision: D25985085

Pulled By: ZolotukhinM

fbshipit-source-id: e51709423c2c12b37b449a9d7bb22be04cda7ef1
  • Loading branch information
Mikhail Zolotukhin authored and facebook-github-bot committed Jan 22, 2021
1 parent 2ba2ab9 commit 5f07b53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions torch/csrc/jit/tensorexpr/loopnest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,11 @@ bool LoopNest::hasLoopBodyFor(Tensor* t) const {
return getLoopBodyFor(t) != nullptr;
}

Stmt* LoopNest::simplify() {
root_stmt_ = IRSimplifier::simplify(root_stmt_);
return root_stmt_;
}

Stmt* FlattenIndexes(Stmt* s) {
IndexFlattener idx_flattener;
return idx_flattener.flatten(s);
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/tensorexpr/loopnest.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TORCH_API LoopNest {
bool hasLoopBodyFor(Tensor*) const;

static void vectorize(For*);
Stmt* simplify();

bool computeInline(Stmt* s);
bool computeInline(const Buf* b);
Expand Down
13 changes: 13 additions & 0 deletions torch/csrc/jit/tensorexpr/tensorexpr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,23 @@ void initTensorExprBindings(PyObject* module) {
self.rfactor(r, v.node(), &ins_point);
},
py::return_value_policy::reference)
.def(
"flatten",
[](const tensorexpr::LoopNest& self,
const std::vector<tensorexpr::For*>& loops) {
tensorexpr::For* flattened;
self.flatten(loops, &flattened);
return flattened;
},
py::return_value_policy::reference)
.def(
"reorder",
&tensorexpr::LoopNest::reorderAxis,
py::return_value_policy::reference)
.def(
"simplify",
&tensorexpr::LoopNest::simplify,
py::return_value_policy::reference)
.def(
"__str__",
[](const tensorexpr::LoopNest& self) {
Expand Down

0 comments on commit 5f07b53

Please sign in to comment.