This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][OpenMPIRBuilder] Add kernel launch codegen to emitTargetCall
ClosedPublic

Authored by jsjodin on Jul 18 2023, 1:06 PM.

Details

Summary

This patch adds code emission in emitTargetCall to call the OpenMP runtime to launch an kernel, and to call the fallback host implementation if the launch fails.

Diff Detail

Event Timeline

jsjodin created this revision.Jul 18 2023, 1:06 PM
Herald added a project: Restricted Project. · View Herald Transcript
jsjodin requested review of this revision.Jul 18 2023, 1:06 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
jsjodin updated this revision to Diff 542009.Jul 19 2023, 7:07 AM

Remove llvm::

jdoerfert added inline comments.Jul 26 2023, 8:50 AM
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4390

Is the AllocaIP expected to be used later?

4403

Is this NumThreads or ThreadLimit, I assume the latter.

4419
jsjodin updated this revision to Diff 544780.Jul 27 2023, 7:57 AM
jsjodin marked an inline comment as done.

Fixes from review feedback. Rebase.

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4390

Even if it is, it should not be part of this patch. I will remove it. Good catch.

4403

It should be the equivalent of llvm::Value *NumThreads = OMPRuntime->emitNumThreadsForTargetDirective(CGF, D); in clang, which looks a bit involved, but is essentially ThreadLimit from what I can tell.

Ping for review. If someone can take a look at this patch I would appreciate it.

This patch adds code emission in emitTargetCall to call the OpenMP runtime to launch an kernel, and to call the fallback host implementation if the launch fails.

This is not visible in the IR generated from MLIR. Could you add a test?

Also could @TIFitis review this patch?

TIFitis added inline comments.Aug 9 2023, 8:31 AM
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4411

Expand type here.

4416

This allows debug info to be accurately generated.

4452–4455

No need to explicitly specify OpenMPIRBuilder namespace here.

4453

Same, remove explicit namespace.

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
5077–5078

Maybe we can replace this with OMPBuilder.getOrCreateDefaultSrcLocStr?

Also it is fine to leave the Names empty if not available.

5084

Can you please check if this works with function arguments?

AFAIK getTypeAllocSize doesn't work on function arguments, in that case we might want to move this function as a callback to MLIR.

TIFitis added inline comments.Aug 11 2023, 6:35 AM
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
5066–5073

Given the args are added by this tests themselves, I think this condition is not needed.

5084

Sorry, forgot this function is inside test. Please ignore above comment.

jsjodin updated this revision to Diff 549426.Aug 11 2023, 8:57 AM

Updated test to check new kernel launch codegen. Fixed nits.

jsjodin marked 5 inline comments as done.Aug 11 2023, 9:00 AM

Marked fixed items, one more to do that I didn't get to.

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
5066–5073

Given the args are added by this tests themselves, I think this condition is not needed.

Sure, I will remove the if.

5077–5078

I'm leaving it for now since it doesn't affect the test.

jsjodin updated this revision to Diff 549432.Aug 11 2023, 9:12 AM
jsjodin marked an inline comment as done.

Removed useless condition in test.

jsjodin marked an inline comment as done.Aug 11 2023, 9:12 AM

Finished addressing feedback.

TIFitis accepted this revision.Aug 14 2023, 7:07 AM

LGTM

This revision is now accepted and ready to land.Aug 14 2023, 7:07 AM

@kiranchandramohan did you have any more feedback about the patch?

@kiranchandramohan did you have any more feedback about the patch?

I have not gone through the patch in detail. If you feel the patch is in good shape and @jdoerfert has not further comments you may go ahead.

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
5137–5154

Nit: leftover debug?

jsjodin added inline comments.Aug 14 2023, 2:02 PM
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
5137–5154

Nit: leftover debug?

Yes, thank you for finding that. I will remove this and update the parameter names CreateDefaultMapInfos.

This revision was landed with ongoing or failed builds.Aug 15 2023, 7:08 AM
This revision was automatically updated to reflect the committed changes.