This is an archive of the discontinued LLVM Phabricator instance.

[mlir][openacc] Add conversion pass OpenACC to LLVM with initial acc.enter_data conversion
AbandonedPublic

Authored by clementval on Apr 16 2021, 12:21 PM.

Details

Summary

This patch begins to lower acc.enter_data operation to call to tgt runtime call.
It currently only lower create operands of memref type. This acts as a basis to add support
for FIR types in the Flang/OpenACC support. It follows more or less a similar path than clang
with omp target enter data map directives.

OpenACC support in Flang will rely on the current OpenMP runtime where 1:1 lowering can be
applied. Some extension will be added where features are not available yet.

Big part of this code will be shared for other standalone data operations in the OpenACC
dialect such as acc.exit_data and acc.update.

It is likely that parts of the lowering can also be shared later with the ops for
standalone data directives in the OpenMP dialect when they are introduced.

This is an initial lowering and it probably needs more work.

Diff Detail

Event Timeline

clementval created this revision.Apr 16 2021, 12:21 PM
clementval requested review of this revision.Apr 16 2021, 12:21 PM
clementval edited the summary of this revision. (Show Details)Apr 16 2021, 12:25 PM
clementval added inline comments.Apr 16 2021, 12:27 PM
mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
96

The global name is obviously just a temporary placeholder. Would it be a good idea to enable unnamed GlobalOp? @ftynse

109

Same here, the name doesn't really matter so unnamed GlobalOp would be nice.

clementval edited the summary of this revision. (Show Details)Apr 16 2021, 12:36 PM
jdoerfert requested changes to this revision.Apr 19 2021, 9:24 AM

I left some comments to show how this duplicates/exposes things that it should not.

Basically, we fist need the OpenMPIRBuilder entry points for the __tgt_XXX functions and then we can call them during the conversion.

mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
52

This should never be needed. ident_t is an implementation artifact of the runtime that should not leak into the user space.

77

Not necessary, see use below.

79–145
161

Again, implementation detail, subject to change.

241

This duplicates what
OpenMPIRBuilder::getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_target_data_begin_mapper);
does but with drawbacks.

This revision now requires changes to proceed.Apr 19 2021, 9:24 AM

I left some comments to show how this duplicates/exposes things that it should not.

Basically, we fist need the OpenMPIRBuilder entry points for the __tgt_XXX functions and then we can call them during the conversion.

Thanks for the pointer in the OpenMPIRBuilder. For sure it makes sense to reuse what is there. I guess it means that instead of a conversion this will has to be moved to a translation.

clementval added inline comments.Apr 19 2021, 12:18 PM
mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
79–145

Fully agree with this if we are in the translation. Currently I don't think there is a way to have the OMPBuilder in the conversion step. I don't say that we should find a way for that but probably the global location creation should be at least deferred until the translation phase in order to make correct use of the OMPBuilder. Just thinking out loud :-)

@mehdi_amini or @ftynse do you have any insight how this could be handled properly?

161

Surely the creation of the global can be done in OMPBuilder but the information in the flags array needs to be collected from the MLIR information.

clementval edited the summary of this revision. (Show Details)Apr 19 2021, 12:55 PM

Great to see that we are now making progress in the LLVM codegen for OpenACC. Clarity here will help the OpenMP device side work as well. I have a general question inline.

mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
79–145

Yes, I think we cannot use the OpenMP IRBuilder while converting to LLVM Dialect. It has to be during the translation phase.

I believe you were investigating using the OpenMP IRBuilder and considering extending it. Did you face issues there or in interfacing at the translation level with the OpenMP IRBuilder. Or are you pointing out that the conversion to LLVM dialect requires special handling irrespective of whether OpenMP IRBuilder is used or not.

clementval added inline comments.Apr 20 2021, 11:28 AM
mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
79–145

Yeah that's correct. The OpenMP IR Builder works directly on the translated module so there is no way to use it in a conversion pass.

There is no problem using/extending the OpenMP IRBuilder but as you mentioned it has to be used at the translation level. This patch was trying to achieve the lowering with a conversion pass to LLVM dialect. I'm planing to rewrite this lowering at the translation level and so directly targeting LLVM IR. That's the only way to reuse the OpenMP IRBuilder code unless we find another way around.

clementval abandoned this revision.Apr 28 2021, 6:11 PM

Patch D101504 is taking the new approach by doing a direct translation to LLVM IR with the use of the OpenMPIRBuilder.