This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP][OMPIRBuilder] Add lowering of TargetOp for device codegen
ClosedPublic

Authored by skatrak on Apr 10 2023, 7:07 AM.

Details

Summary

This patch adds support in the OpenMPIRBuilder for generating working
device code for OpenMP target regions. It generates and handles the
result of a call to __kmpc_target_init() at the beginning of the
function resulting from outlining each target region, and it also
generates the matching __kmpc_target_deinit() call before returning.

It relies on the implementation of target region outlining for host
codegen to handle the production of the new function and the lowering of
its body based on the contents of the associated target region.

Depends on D147172

Diff Detail

Event Timeline

skatrak created this revision.Apr 10 2023, 7:07 AM
Herald added a project: Restricted Project. · View Herald Transcript
skatrak requested review of this revision.Apr 10 2023, 7:07 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
skatrak updated this revision to Diff 517604.Apr 27 2023, 9:27 AM

Update after landing parent host codegen for target regions patch. This patch is now ready for review.

Ping for reviews!

jsjodin accepted this revision.May 16 2023, 7:16 AM

LGTM

This revision is now accepted and ready to land.May 16 2023, 7:16 AM

Thank you for the review, Jan! I'll wait a day or two before landing the patch in case anybody else has any further comments.

jsjodin added a comment.EditedMay 17 2023, 10:40 AM

Is there a way we can create a MLIR->LLVM IR test with a target region and use the --offload-device-only flag to check that we get the device function generated? It would be nice to have.

skatrak updated this revision to Diff 523324.May 18 2023, 4:02 AM

Rebase and add one more unit test.

Is there a way we can create a MLIR->LLVM IR test with a target region and use the --offload-device-only flag to check that we get the device function generated? It would be nice to have.

I just added a unit test to look at the translation from MLIR to LLVM IR of a target region for the device. It doesn't use the --offload-device-only flag, but I think that might be redundant, since that is a driver-only flag. In flang/test/Driver/omp-driver-offload.f90 there is a test that makes sure that, if that option is set, the proper triples for the offloading invocation are added. The new test I just added makes sure that the device function is generated from MLIR if omp.is_device is set and there's an OpenMP target region, and there are other tests making sure that omp.is_device and omp.target are generated in the proper cases. So I think the whole flow involving that command line option and code generation for the device function is tested already.

If this is something that you still think we should have, let me know.