Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Relay] WithFields method for Call, Function, Var, TupleGetItem, If, Let, RefCreate, RefRead, RefWrite, Match, and Clause #9569

Merged
merged 2 commits into from
Nov 25, 2021

Conversation

electriclilies
Copy link
Contributor

In this PR, I implement the WithFields method for Call, Function, Var, TupleGetItem, If, Let, RefCreate, RefRead, RefWrite, Match and Clause. It is a continuation of work in #9533, where I implement WithFields for Tuples.
Additionally, I remove the explicit COW logic from the visitors in expr_functor.cc for these classes. In future work, I'll use these methods to replace most explicit reconstructions of these classes in visitors.
@mbs-octoml @mikepapadim PTAL! I would especially appreciate typo checks in the documentation, I did a lot of copy-pasting and probably missed some things there.
cc @tqchen in case you are interested -- I've kept the API consistent with what we discussed for WithFields for tuples

Copy link
Contributor

@mikepapadim mikepapadim left a comment

Choose a reason for hiding this comment

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

LGTM, maybe add a cpp tests for new Clause.

@@ -615,6 +615,8 @@ class PartialEvaluator : public ExprFunctor<PStatic(const Expr& e, LetList* ll)>
value.push_back(ps);
expr.push_back(ps->dynamic);
}
// Note: The partial evaluator seems to do some weird stuff with sharing. Changing Tuple(expr)
// to WithFields(op, expr) causes some strange failures.
return HasStatic(MkSTuple(value), ll->Push(Tuple(expr)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get capture these failures with some unit-test?

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 was seeing some failures in the partial evaluator tests, but also in other places. I'll update the comment to clarify, I don't think I need to add another unittest here though

Expr tuple = opt_tuple.value_or(tuple_get_item->tuple);
int index =
opt_index.value_or(tuple_get_item->index)
->value; // Is it OK that this is an Integer instead of int? this lets me use Optional
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Integer is fine here. Still need this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch, thanks!

Copy link
Contributor

@mbs-octoml mbs-octoml left a comment

Choose a reason for hiding this comment

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

Look great, thank you.

For bonus points you could replace the explicit ctors in device_planner.cc with WithField.

Optional<Array<Expr>> opt_args = Optional<Array<Expr>>(),
Optional<Attrs> opt_attrs = Optional<Attrs>(),
Optional<Array<Type>> opt_type_args = Optional<Array<Type>>(),
Optional<Span> opt_span = Optional<Span>(nullptr));
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need the nullptr arg apparently

Copy link
Member

@jroesch jroesch left a comment

Choose a reason for hiding this comment

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

Changes look great, thanks Lily! Just minor question about moving const references.

return Clause(pat, VisitExpr(c->rhs));
Clause VisitClause(const Clause& clause) final {
Pattern lhs = VisitPattern(clause->lhs);
return WithFields(std::move(clause), std::move(lhs), VisitExpr(clause->rhs));
Copy link
Member

Choose a reason for hiding this comment

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

@mbs-octoml I don't know if we actually need these moves, for const reference does this matter? I can't actually remember what the spec says about value vs move semantics for const &.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, didn't even notice it was const. I was just std::moving everything that was named that we were not using again

@electriclilies
Copy link
Contributor Author

electriclilies commented Nov 24, 2021

@mbs-octoml Changed the explicit constructions in the device planner to copy except for one Tuple, since I don't have WithFields for tuples in this PR (waiting on #9533).

@electriclilies
Copy link
Contributor Author

@Mousius or @manupa-arm could you merge? It’s a holiday weekend here and I’d like to get this in before there are any merge conflicts. Thanks!

Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

LGTM. Getting this in for now.
Lets follow up if needed

@manupak manupak merged commit 8ca8e38 into apache:main Nov 25, 2021
dchauhan-arm pushed a commit to dchauhan-arm/tvm that referenced this pull request Nov 29, 2021
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 12, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
…Let, RefCreate, RefRead, RefWrite, Match, and Clause (apache#9569)

* Implement WithFields for Relay exprs

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants