Skip to content

Extend op attrs with commutattive annotation#9479

Closed
mikepapadim wants to merge 2 commits intoapache:mainfrom
mikepapadim:pattern_commutative_scopes
Closed

Extend op attrs with commutattive annotation#9479
mikepapadim wants to merge 2 commits intoapache:mainfrom
mikepapadim:pattern_commutative_scopes

Conversation

@mikepapadim
Copy link
Contributor

This PR extends the op attrs with commutativity.
This is required for the ongoing work to use the pattern language to express more general patterns.

@mbs-octoml @mbrookhart @jroesch @electriclilies

@mikepapadim mikepapadim force-pushed the pattern_commutative_scopes branch from 6cf56f6 to db634cf Compare November 10, 2021 13:30
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.

Suggestion to default the attrib to false and explicitly set to true at registration site for add & mul. Adding more if op == "add" etc logic seems to be going against the grain.

/*!
* \brief Mark the operator as commutative to allow expr simplifications.
*/
using CommutativeOp = bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: TCommutativeOp

}
return false;
};
auto is_commutative_op = [&get_op_node](const CallPatternNode* op_node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was expecting this to look at the TCommutativeOp attribute of op_node.

.add_type_rel("Identity", IdentityRel) \
.set_attr<TOpPattern>("TOpPattern", kElemWise) \
.set_attr<TOpIsStateful>("TOpIsStateful", false) \
.set_attr<CommutativeOp>("CommutativeOp", false) \
Copy link
Contributor

Choose a reason for hiding this comment

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

well, I guess so...

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to put the commutativity property on unary and ops with 3+ arity?
I guess the downside is that then you'd need to check that arity == 2 before looking at the CommutativeOp attribute, or that the CommutativeOp attr is actually on the op.

.add_type_rel("Broadcast", BroadcastRel) \
.set_attr<TOpPattern>("TOpPattern", kBroadcast) \
.set_attr<TOpIsStateful>("TOpIsStateful", false) \
.set_attr<CommutativeOp>("CommutativeOp", isCommutativeOp(OpName)) \
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it's non-comm by default (so no attrib binding), and the registration of (for now) add & multiply explicitly set it to true.

@areusch
Copy link
Contributor

areusch commented Apr 8, 2022

closing due to inactivity, feel free to reopen if you'd like to merge

@areusch areusch closed this Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants