Commit Graph

16 Commits

Author SHA1 Message Date
Nick Gibson
4e2ea6e013 [TensorExpr] Remove the Tensor argument from loopnest.reorderAxis (#37873)
Summary:
Remove the requirement for the axes provided to reorderAxis to come from a Tensor. We were using that to determine the relevant loops, but we can alternatively determine it by traversing the parents of each provided For.

resistor does this work for you?
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37873

Differential Revision: D21428016

Pulled By: nickgg

fbshipit-source-id: b16b2f41cb443dfc2c6548b7980731d1e7d89a35
2020-05-06 12:02:15 -07:00
Mikhail Zolotukhin
1c0bad25f3 [TensorExpr] Add dtype to class Buf. (#36611)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/36611

Currently Buf represents underlying storage but it didn't have dtype.
That resulted in specifying dtypes in different places and there was no
mechanism to enforce its consistency: e.g. one could've created a kFloat
expression and use a kInt buffer to store its result. Now we're
centralizing where the logic regarding the storage is located and we can
start enforcing semantics rules.

Follow-ups: we can merge Buffer and BufHandle classes as the former is
now a mere wrapper over the latter.

Test Plan: Imported from OSS

Differential Revision: D21027356

Pulled By: ZolotukhinM

fbshipit-source-id: c06aa2c4077fdcde3bb4ca622d324aece79b5a9c
2020-05-05 15:04:37 -07:00
Owen Anderson
564de515f5 Add an iterator to Block. (#37542)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/37542

Differential Revision: D21314421

Pulled By: resistor

fbshipit-source-id: e54d7a8a5c9c1186be59f69b5b8af030fc054b32
2020-05-01 15:12:49 -07:00
Mikhail Zolotukhin
799793f279 [TensorExpr] Cleanup IRPrinter implementation for statements. (#37050)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37050

With this change curly braces are printed as a part of Block rather than
a part of the enclosing statement. It allows us, for instance, to more
easily see nested blocks: now they will be printed each in its own
curly-braced scope.

As a side effect, I had to change how we print loop options. Previously
we did it like this:
```
for (...) { // <loop options>
  <loop body (Block)>
}
```

Now, since everything in between { and } is a part of the block, we have
to do it the following way:
```
for (...) /* <loop options> */ {
  <loop body (Block)>
}
```
Note the change from '//' to '/* .. */' for the loop option comments.

Test Plan: Imported from OSS

Differential Revision: D21171851

Pulled By: ZolotukhinM

fbshipit-source-id: 39f51a9e15aec03b6527b0634fd4b9e01a912cda
2020-04-21 23:20:18 -07:00
Mikhail Zolotukhin
b8e2d797c0 [TensorExpr] Insert allocations for temporary buffer at the innermost valid scope. (#36836)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36836

Test Plan: Imported from OSS

Differential Revision: D21099913

Pulled By: ZolotukhinM

fbshipit-source-id: 8faf5f1d55b60bdd4f4b2b909977aeb7abaa95b4
2020-04-21 22:51:46 -07:00
Mike Ruberry
b45b9673a1 Fixes clang format (#36787)
Summary:
Fixes clang format.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/36787

Differential Revision: D21084603

Pulled By: mruberry

fbshipit-source-id: 7e29da135f9a2aa126cb68640e33c1914fd570e3
2020-04-17 00:42:51 -07:00
Owen Anderson
1fc3556ec9 Teach the tensorexpr vectorizer to handle nested For loops. (#36467)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36467

Differential Revision: D21013179

Pulled By: resistor

fbshipit-source-id: aa4f3da58cf16934f11e0cf4252a300cbac98f21
2020-04-16 15:40:44 -07:00
Nick Gibson
ee3d046f87 [TensorExpr] Add support for Axis reordering in LoopNest (#36540)
Summary:
Adds a capability for reordering axes in the LoopNest. This was fairly straightforward except when handling Reduction initializers which required more changes, UPDATE: actually the complicated bit was preserving the ordering of statements in the loopnest which should not be reordered.

Usage looks something like this:

```
Tensor* tensor = Compute(
    "f", {{2, "x"}, {3, "y"}}, [](const VarHandle& x, const VarHandle& y) {
      return ExprHandle(1.0f) + cast<float>(x) * x + cast<float>(y) * y;
    });
LoopNest l({tensor});

/* LoopNest looks like:
  for x in ...
    for y  in ...
       f[x,y] = 1 + x * x + y * y;
*/

auto loops = l.getLoopStmtsFor(tensor);
l.reorderAxis(tensor, loops[0], loops[1])

/* LoopNest looks like:
  for y in ...
    for x  in ...
       f[x,y] = 1 + x * x + y * y;
*/
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/36540

Differential Revision: D21068143

Pulled By: nickgg

fbshipit-source-id: f02c29004376df4f5a9bedff366c075772726618
2020-04-16 13:42:47 -07:00
Mikhail Zolotukhin
317f598103 [TensorExpr] Clang-format test/cpp/tensorexpr/*. (#36615)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36615

Test Plan: Imported from OSS

Differential Revision: D21027733

Pulled By: ZolotukhinM

fbshipit-source-id: e19cd85c1634f4e40805814ac71eec719d6587f8
2020-04-14 19:08:18 -07:00
Mikhail Zolotukhin
d5ba39c25d [TensorExpr] Postpone insertion of Alloc/Free statements in computeAt. (#36526)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36526

Test Plan: Imported from OSS

Differential Revision: D21004740

Pulled By: ZolotukhinM

fbshipit-source-id: 8ac8db0d4e31065e4fbd3e0cc27f15a15dcb141c
2020-04-13 22:30:00 -07:00
Mikhail Zolotukhin
df5f0a04ff [TensorExpr] Implement LoopNest::computeAt (#36112)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36112

Differential Revision: D20885662

Test Plan: Imported from OSS

Pulled By: ZolotukhinM

fbshipit-source-id: 4ea6293b249562fca46739dc36c5483d912e5838
2020-04-11 04:01:14 -07:00
Mikhail Zolotukhin
397aa46a3e [TensorExpr] Bounds inference (#35120)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/35120

Differential Revision: D20567926

Test Plan: Imported from OSS

Pulled By: ZolotukhinM

fbshipit-source-id: 89a2afcddaf23a5c6259c15e4f7194e8649c1c4d
2020-04-11 03:59:34 -07:00
Mikhail Zolotukhin
3ef5ff6012 [TensorExpr] Make Load and Store multi-dimensional. (#35800)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/35800

This PR includes the following changes:
* Introduce a new `Expr` type `Buf`: it plays a similar to `Var` role, but also has dimensions.
* Use the new `Buf` class in `Store` and `Load` instead of `Var` for specifying where to store to or load from. `Buf` contains the dimensions info of the buffer we're loading/storing to and hence we are able to keep N-d indexes without flattening them into a 1-d index ([x,y] vs [x+y*W]).
* Flattening of the indexes is now a separate pass that is executed in `LoopNest::prepareForCodegen` - backends still expect indexes to be flattened, and this PR preserves that.
* `Tensor` now contains a `Buf` instead of `Var`, and thus Tensor now has the dimensions info (previously it was a property of a `Function`, not a `Tensor`). This brings us closer to Tensor being a combination of Buffer + Function, where Buffer specifies iteration domain and the Function defines a computation.

TODOs:
* Consider merging `Buffer` with `Buf` or `BufHandle`. It seems that we don't need all of them.
* Harden the logic of how we create buffers in fuser pass. Currently it seems that sometimes we don't set dimensions.
* Use `Buf` in `Allocate` and `Free`.
* Make it clearer that `Function` doesn't "own" dimensions info and that dimensions are a property of a Tensor, not a Function.

Differential Revision: D20789005

Test Plan: Imported from OSS

Reviewed By: zheng-xq

Pulled By: ZolotukhinM

fbshipit-source-id: e04188d1d297f195f1c46669c614557d6bb6cde4
2020-04-02 11:18:28 -07:00
Mikhail Zolotukhin
ceb4ed3733 [TensorExpr] Methods name cleanup in LoopNest class. (#35174)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/35174

Differential Revision: D20585575

Test Plan: Imported from OSS

Pulled By: ZolotukhinM

fbshipit-source-id: 0fa8e1e85e1502b9a86cf34608cb791ffb23d395
2020-03-25 11:51:11 -07:00
Mikhail Zolotukhin
95ad94c75b [TensorExpr] Nuke tensorexpr::schedule namespace. (#35126)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/35126

Test Plan: Imported from OSS

Differential Revision: D20569364

Pulled By: ZolotukhinM

fbshipit-source-id: c0d51ecadf411918641cdbdc6d8cb06e207d2c9b
2020-03-20 23:39:14 -07:00
Mikhail Zolotukhin
65cea95777 [TensorExpr] Rename schedule.{cpp,h} to loopnest.{cpp,h}. (#35119)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/35119

Differential Revision: D20567927

Test Plan: Imported from OSS

Pulled By: ZolotukhinM

fbshipit-source-id: 1fb6d03bd4c6e66aca62140d2b537692577f261d
2020-03-20 23:37:51 -07:00