Skip to content

Conversation

nickgg
Copy link
Contributor

@nickgg nickgg commented Apr 13, 2020

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;
*/

@nickgg nickgg requested a review from apaszke as a code owner April 13, 2020 23:56
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 13, 2020
@nickgg nickgg force-pushed the fixReorderedReduceInit branch from 342c0ce to 04ae0bc Compare April 13, 2020 23:56
@dr-ci
Copy link

dr-ci bot commented Apr 13, 2020

💊 Build failures summary and remediations

As of commit 5ae30e4 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

See how this bot performed.

This comment has been revised 19 times.

@nickgg nickgg force-pushed the fixReorderedReduceInit branch 5 times, most recently from 89658c4 to ac0f9e7 Compare April 15, 2020 19:59
@nickgg nickgg changed the title [TensorExpr] add axis reordering (WIP) [TensorExpr] Add support for Axis reordering in LoopNest Apr 15, 2020
Copy link

@ZolotukhinM ZolotukhinM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I didn't follow all the logic but I trust your tests :) I left some questions inline - they are not to request changes but rather to double check my own understanding.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you feel this methods will generally be helpful in other use-cases? If not, I'd rather make it a local helper method rather than pulling it into the For class itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did use it in the ReductionExpander as well - but they're both in loopnest.cpp so for now could be local (could be complicated if we pull the mutators out of loopnest). I think this is generally a useful helper though, I think we'll reuse it again.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: according to std convention, it's probably better to change nparams to return size_t.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. That would touch quite a few different places in the code though so rather not roll into this diff.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why do we clone here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root_stmt returns the internal pointer, which is modified by reorderAxis below. We need to clone to preserve the original behaviour.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really use the tensor here, only its loops: maybe take std::vector<For*> as the first parameter instead (on the callsite we'll get it by l.getLoopStmtsFor(t))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. It would save the extra call to getLoopStatementsFor but it's not longer really a loopNest thing. Prefer to refactor when we pull this and maybe rfactor/split out

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about it mostly from the data we're accessing here: we pass the tensor, but only use part of it that's responsible for the corresponding loops. That made me think that we should pass only the loops since we're not using anything else from the tensor. I don't have a strong preference on it though since we don't have clear guidelines on it yet anyways :)

@nickgg nickgg force-pushed the fixReorderedReduceInit branch from ac0f9e7 to 5ae30e4 Compare April 16, 2020 16:26
@nickgg
Copy link
Contributor Author

nickgg commented Apr 16, 2020

addressed comments

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nickgg is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@nickgg merged this pull request in ee3d046.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants