Skip to content

Commit b437014

Browse files
[OpenMPIRBuilder] Do not call host runtime for GPU teams codegen (#79984)
Patch ensures that host runtime functions are not called for handling OpenMP teams clause on the device. GPU code for pragma `omp target teams distribute parallel do` will require only one call to OpenMP loop-worksharing GPU runtime. Support for it will be added later. This patch does not include changes required for handling `omp target teams` for the host side.
1 parent 3f5fcb5 commit b437014

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6251,8 +6251,10 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
62516251
BasicBlock *AllocaBB =
62526252
splitBB(Builder, /*CreateBranch=*/true, "teams.alloca");
62536253

6254+
bool SubClausesPresent =
6255+
(NumTeamsLower || NumTeamsUpper || ThreadLimit || IfExpr);
62546256
// Push num_teams
6255-
if (NumTeamsLower || NumTeamsUpper || ThreadLimit || IfExpr) {
6257+
if (!Config.isTargetDevice() && SubClausesPresent) {
62566258
assert((NumTeamsLower == nullptr || NumTeamsUpper != nullptr) &&
62576259
"if lowerbound is non-null, then upperbound must also be non-null "
62586260
"for bounds on num_teams");
@@ -6305,7 +6307,8 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
63056307
OI.ExcludeArgsFromAggregate.push_back(createFakeIntVal(
63066308
Builder, OuterAllocaIP, ToBeDeleted, AllocaIP, "tid", true));
63076309

6308-
OI.PostOutlineCB = [this, Ident, ToBeDeleted](Function &OutlinedFn) mutable {
6310+
auto HostPostOutlineCB = [this, Ident,
6311+
ToBeDeleted](Function &OutlinedFn) mutable {
63096312
// The stale call instruction will be replaced with a new call instruction
63106313
// for runtime call with the outlined function.
63116314

@@ -6342,6 +6345,9 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
63426345
}
63436346
};
63446347

6348+
if (!Config.isTargetDevice())
6349+
OI.PostOutlineCB = HostPostOutlineCB;
6350+
63456351
addOutlineInfo(std::move(OI));
63466352

63476353
Builder.SetInsertPoint(ExitBB, ExitBB->begin());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
2+
3+
// The aim of the test is to check the LLVM IR codegen for the device
4+
// for omp teams construct
5+
6+
module attributes {omp.is_target_device = true} {
7+
llvm.func @foo(i32)
8+
llvm.func @omp_target_teams_shared_simple(%arg0 : i32) {
9+
omp.teams {
10+
llvm.call @foo(%arg0) : (i32) -> ()
11+
omp.terminator
12+
}
13+
llvm.return
14+
}
15+
}
16+
17+
// CHECK-LABEL: @omp_target_teams_shared_simple
18+
// CHECK-SAME: (i32 [[ARG0:%.+]])
19+
// CHECK: call void @[[OUTLINED_FN:.*]](
20+
// CHECK-NOT: call {{.+}} @__kmpc_fork_teams
21+
// CHECK: ret void
22+
23+
//CHECK: define internal void @[[OUTLINED_FN]](
24+
//CHECK: call void @foo(i32 %[[FOO_ARG:.*]])
25+
//CHECK: ret void

0 commit comments

Comments
 (0)