Skip to content

Commit 1345041

Browse files
committed
Ensure correct number of threads for offloaded regions
1 parent 8a4be72 commit 1345041

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

tools/flang2/flang2exe/expsmp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
10941094
iltb.callfg = 1;
10951095
chk_block(ili);
10961096
}
1097-
ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg, OPENMP);
1097+
ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg, OPENMP, -1);
10981098
iltb.callfg = 1;
10991099
chk_block(ili);
11001100

@@ -1175,7 +1175,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
11751175
wr_block();
11761176
cr_block();
11771177
exp_label(par_label);
1178-
ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg, OPENMP);
1178+
ili = ll_make_kmpc_fork_call(sptr, 1, &iliarg, OPENMP, -1);
11791179
iltb.callfg = 1;
11801180
chk_block(ili);
11811181

tools/flang2/flang2exe/kmpcutil.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,31 @@ KMPC_GENERIC_P_2I(ll_make_kmpc_cancellationpoint, KMPC_API_CANCELLATIONPOINT,
693693

694694
/* arglist is 1 containing the uplevel pointer */
695695
int
696-
ll_make_kmpc_fork_call(SPTR sptr, int argc, int *arglist, RegionType rt)
696+
ll_make_kmpc_fork_call(SPTR sptr, int argc, int *arglist, RegionType rt, int ngangs_ili)
697697
{
698-
int argili, args[4];
699-
DTYPE arg_types[] = {DT_CPTR, DT_INT, DT_CPTR, DT_NONE};
698+
int argili, args[5];
699+
DTYPE arg_types[] = {DT_CPTR, DT_INT, DT_CPTR, DT_NONE, DT_NONE};
700700
arg_types[3] = DT_CPTR;
701-
args[3] = gen_null_arg(); /* ident */
702-
args[2] = ad_icon(argc);
701+
702+
int call_pgi_kmpc_fork_call = (rt == OPENACC);
703+
call_pgi_kmpc_fork_call = 0;
704+
705+
if (call_pgi_kmpc_fork_call) {
706+
// In case we call pgi_kmpc_fork_call, we must also pass in the
707+
// number of gangs. Because the function takes varargs, the num_gangs
708+
// argument needs to appear before end of argument list - thus shift
709+
// arguments over to make room for num_gangs argument.
710+
arg_types[4] = arg_types[3];
711+
arg_types[3] = arg_types[2];
712+
arg_types[2] = DT_INT; // num_gangs is integer argument
713+
args[4] = gen_null_arg();
714+
args[3] = ad_icon(argc);
715+
args[2] = ngangs_ili;
716+
} else {
717+
args[3] = gen_null_arg(); /* ident */
718+
args[2] = ad_icon(argc);
719+
}
720+
703721
args[1] = ad1ili(IL_ACON, get_acon(sptr, 0));
704722
args[0] = *arglist;
705723
return mk_kmpc_api_call(KMPC_API_FORK_CALL, 4, arg_types, args);

tools/flang2/flang2exe/kmpcutil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ int ll_make_kmpc_flush(void);
278278
/**
279279
\brief ...
280280
*/
281-
int ll_make_kmpc_fork_call(SPTR sptr, int argc, int *arglist, RegionType rt);
281+
int ll_make_kmpc_fork_call(SPTR sptr, int argc, int *arglist, RegionType rt, int ngangs_ili);
282282

283283
/**
284284
\brief ...

0 commit comments

Comments
 (0)