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

[Unity][Transform] Extract partial-tuple-usage from FuseTIR #16120

Merged

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, the FuseTIR pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel. The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
FuseTIR.

This commit implements the same functionality in terms of the
ExpandTupleArguments and RemoveUnusedParameters transforms,
introduced in #16115 and
#16116 respectively. By using these
passes before the main FuseOps changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by FuseTIR. This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.

@Lunderberg
Copy link
Contributor Author

This PR is marked as a draft, until the pre-requisite PRs #16115, #16116, #16117, and #16118 land.

@Lunderberg Lunderberg force-pushed the unity_transform_refactor_fuse_tir branch from 4b60b69 to f5ac463 Compare December 1, 2023 21:51
@Lunderberg Lunderberg marked this pull request as ready for review December 1, 2023 21:51
@Lunderberg Lunderberg changed the title [Draft][Unity][Transform] Extract partial-tuple-usage from FuseTIR [Unity][Transform] Extract partial-tuple-usage from FuseTIR Dec 1, 2023
@Lunderberg
Copy link
Contributor Author

All pre-requisite PRs have landed, and this is now ready for review.

Prior to this commit, the `FuseTIR` pass explicitly tracked usage of
tuple arguments, to minimize the set of arguments provided to each
kernel.  The additional tgracking and handling of partially-used
tuples makes it difficult to follow the primary changes being made by
`FuseTIR`.

This commit implements the same functionality in terms of the
`ExpandTupleArguments` and `RemoveUnusedParameters` transforms,
introduced in apache#16115 and
apache#16116 respectively.  By using these
passes before the main `FuseOps` changes, partial tuple usage is
already handled at that point.

This commit is intended to minimize any changes to user-facing
behavior, and so these pre-process passes are currently used
internally by `FuseOps`.  This may be avoided in the future by pulling
this internal delegation out into a lowering pipeline.
@Lunderberg Lunderberg force-pushed the unity_transform_refactor_fuse_tir branch from d202a49 to 6656fb6 Compare December 19, 2023 18:47
@Lunderberg
Copy link
Contributor Author

Rebased onto unity to avoid stale CI results.

for (const auto& var : shape_expr->values.value()) {
ICHECK(var->IsInstance<tir::VarNode>());
params.push_back(Downcast<tir::Var>(var));
out->push_back(Downcast<tir::Var>(var));
}
} else {
ICHECK(false) << "TypeError: The param type of PrimFunc is expected to be Tensor, Tuple or "
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: tuples are no longer accepted, so the message is inaccurate (though a tuple would have been caught above).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, and updated to remove Tuple from the list, and add PrimValue as it is now handled.

}

// Move all scalar params after buffer params.
std::stable_sort(prim_func_params.begin(), prim_func_params.end(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume it's important for the relative ordering to be preserved (hence the stable sort), might be good to call that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, and updated the comment. It's mainly to make sure that the order is consistent and predictable for unit tests, not for any correctness of the output.

Copy link
Contributor

@slyubomirsky slyubomirsky left a comment

Choose a reason for hiding this comment

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

The changes seem to make sense. I'm not fully versed on FuseTIR so I'm not aware of all of the broader context, but the expansion of tuples makes this code a lot a simpler and the tests all pass. I had a couple of commenting nitpicks to make, but they shouldn't be blockers. Great work.

@Lunderberg Lunderberg merged commit ec542da into apache:unity Jan 3, 2024
14 checks passed
@Lunderberg Lunderberg deleted the unity_transform_refactor_fuse_tir branch January 3, 2024 17:09
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.

None yet

2 participants