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

[Flang][OpenMP] Lower host_eval clauses during target lowering #200

Merged

Conversation

skatrak
Copy link

@skatrak skatrak commented Nov 6, 2024

Previously, the approach taken to deal with host-evaluated clauses for operations nested inside of omp.target was to use the HostClausesInsertionGuard. This class moved the MLIR insertion point outside the omp.target operation, so that clause lowering would produce code to be evaluated in the host device.

However, this approach resulted in the use of MLIR values defined only inside of the target region outside of it. Then, some fix-up work was performed to replace these uses with the equivalent values outside, which had to consider multiple corner cases based on the types and the origin of these values.

This patch replaces that approach with another in which these host-evaluated clauses are lowered as part of the processing of omp.target clauses, so the created MLIR operations are correct from the beginning, without the need for a fix-up pass.

For that, evaluations related to a target construct are analyzed and processed independently of the established lowering process, also checking nested evaluations for the code patterns for which host_eval operands have to be introduced into the omp.target operation under construction. If one of these patterns is found, the relevant clauses are evaluated and stored in a global structure.

This global structure is checked and used when lowering clauses for operations that can potentially be evaluated in the host, rather than immediately prior to that operation. If it has already been evaluated in the host, the corresponding omp.target region block argument is passed as an operand to that operation. Otherwise, it is evaluated as usual.

@skatrak skatrak changed the title [Flang][OpenMP] Lower host_eval clauses at the right spot [Flang][OpenMP] Lower host_eval clauses during target lowering Nov 6, 2024
@skatrak skatrak force-pushed the users/skatrak/target-passthrough-04-flang branch from fab6db4 to e29a641 Compare November 6, 2024 16:10
@skatrak skatrak force-pushed the users/skatrak/target-passthrough-05-insertionguard branch from 0f2c7da to e6c553a Compare November 6, 2024 16:18
@skatrak skatrak force-pushed the users/skatrak/target-passthrough-04-flang branch from e29a641 to 5f080c6 Compare November 7, 2024 10:54
Base automatically changed from users/skatrak/target-passthrough-04-flang to amd-trunk-dev November 7, 2024 10:54
@skatrak skatrak force-pushed the users/skatrak/target-passthrough-05-insertionguard branch from e6c553a to 7a73464 Compare November 7, 2024 10:57
Copy link

@TIFitis TIFitis left a comment

Choose a reason for hiding this comment

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

I am happy with the patch, but don't understand it in enough depth for a definitive approval. Hopefully someone else can give it a thumbs up as well :)

Previously, the approach taken to deal with host-evaluated clauses for
operations nested inside of `omp.target` was to use the
`HostClausesInsertionGuard`. This class moved the MLIR insertion point outside
the `omp.target` operation, so that clause lowering would produce code to be
evaluated in the host device.

However, this approach resulted in the use of MLIR values defined only inside
of the target region outside of it. Then, some fix-up work was performed to
replace these uses with the equivalent values outside, which had to consider
multiple corner cases based on the types and the origin of these values.

This patch replaces that approach with another in which these host-evaluated
clauses are lowered as part of the processing of `omp.target` clauses, so the
created MLIR operations are correct from the beginning, without the need for a
fix-up pass.

For that, evaluations related to a target construct are analyzed and processed
independently of the established lowering process, also checking nested
evaluations for the code patterns for which `host_eval` operands have to be
introduced for the `omp.target` operation under construction. If one of these
patterns is found, the relevant clauses are evaluated and stored in a global
structure.

This global structure is checked and used when lowering clauses for operations
that can potentially be evaluated in the host, rather than immediately prior to
that operation. If it has already been evaluated in the host, the corresponding
`omp.target` region block argument is passed as an operand to that operation.
Otherwise, it is evaluated as usual.

This patch also updates the MLIR to LLVM IR translation pass to make sure
default values are properly processed regardless of whether it's host or device
compilation.
@skatrak skatrak force-pushed the users/skatrak/target-passthrough-05-insertionguard branch from 7a73464 to 98f2560 Compare November 15, 2024 15:35
@skatrak skatrak merged commit 62fa744 into amd-trunk-dev Nov 15, 2024
2 of 4 checks passed
@skatrak skatrak deleted the users/skatrak/target-passthrough-05-insertionguard branch November 15, 2024 15:53
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.

2 participants