[llvm] [mlir] [flang][OpenMP] Support `target enter|update|exit .. nowait` (PR #113305)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 06:00:08 PDT 2024
================
@@ -7153,21 +7170,44 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
bool HasDependencies = Dependencies.size() > 0;
bool RequiresOuterTargetTask = HasNoWait || HasDependencies;
+ OpenMPIRBuilder::TargetKernelArgs KArgs;
+
+ auto TaskBodyCB = [&](Value *DeviceID, Value *RTLoc,
+ IRBuilderBase::InsertPoint TargetTaskAllocaIP) {
+ if (OutlinedFnID) {
+ // emitKernelLaunch makes the necessary runtime call to offload the
+ // kernel. We then outline all that code into a separate function
+ // ('kernel_launch_function' in the pseudo code above). This function is
+ // then called by the target task proxy function (see
+ // '@.omp_target_task_proxy_func' in the pseudo code above)
+ // "@.omp_target_task_proxy_func' is generated by
+ // emitTargetTaskProxyFunction.
+ Builder.restoreIP(OMPBuilder.emitKernelLaunch(
+ Builder, OutlinedFnID, EmitTargetCallFallbackCB, KArgs, DeviceID,
+ RTLoc, TargetTaskAllocaIP));
+ } else {
+ // When OutlinedFnID is set to nullptr, then it's not an offloading
+ // call. In this case, we execute the host implementation directly.
+ OMPBuilder.Builder.restoreIP(
+ EmitTargetCallFallbackCB(OMPBuilder.Builder.saveIP()));
+ }
+ };
+
// If we don't have an ID for the target region, it means an offload entry
// wasn't created. In this case we just run the host fallback directly.
if (!OutlinedFnID) {
if (RequiresOuterTargetTask) {
// Arguments that are intended to be directly forwarded to an
// emitKernelLaunch call are pased as nullptr, since OutlinedFnID=nullptr
// results in that call not being done.
- OpenMPIRBuilder::TargetKernelArgs KArgs;
- Builder.restoreIP(OMPBuilder.emitTargetTask(
- OutlinedFn, /*OutlinedFnID=*/nullptr, EmitTargetCallFallbackCB, KArgs,
- /*DeviceID=*/nullptr, /*RTLoc=*/nullptr, AllocaIP, Dependencies,
- HasNoWait));
+ Builder.restoreIP(OMPBuilder.emitTargetTask(TaskBodyCB,
+ /*DeviceID=*/nullptr,
+ /*RTLoc=*/nullptr, AllocaIP,
+ Dependencies, HasNoWait));
} else {
Builder.restoreIP(EmitTargetCallFallbackCB(Builder.saveIP()));
}
+
----------------
Meinersbur wrote:
```suggestion
```
[nit] unrelated change
https://github.com/llvm/llvm-project/pull/113305
More information about the llvm-commits
mailing list