Skip to content

Commit 357275d

Browse files
committed
Flang OpenMP GPU offload fixes
1 parent 70a00dc commit 357275d

File tree

10 files changed

+210
-157
lines changed

10 files changed

+210
-157
lines changed

include/flang/Error/errmsg-in.n

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,3 +1516,4 @@ A DO CONCURRENT variable with LOCAL_INIT locality must have a host variable of t
15161516
.MS S 1203 "OpenMP GPU - Directive target exit data is used, map type [$] cannot be used. It should be one of 'from', 'release', or 'delete'"
15171517
.MS S 1204 "OpenMP GPU - Directive target data is used, map type [$] cannot be used. It should be one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'"
15181518
.MS S 1205 "OpenMP GPU - Directive target enter data is used, map type [$] cannot be used. It should be one of 'to', or 'alloc'"
1519+
.MS W 1206 "OpenMP GPU - Using [map] clause is used with an array section for $ array is not supported, mapping will be done on entire array."

tools/flang1/flang1exe/semsmp.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,6 +4841,16 @@ semsmp(int rednum, SST *top)
48414841
* <accel data> ::= <accel data name> ( <accel sub list> ) |
48424842
*/
48434843
case ACCEL_DATA1:
4844+
#ifdef OMP_OFFLOAD_LLVM
4845+
if (SST_IDG(RHS(1)) == S_IDENT || SST_IDG(RHS(1)) == S_DERIVED) {
4846+
sptr = SST_SYMG(RHS(1));
4847+
} else {
4848+
sptr = SST_LSYMG(RHS(1));
4849+
}
4850+
error(1206, ERR_Warning, gbl.lineno, sptr ? SYMNAME(sptr) : CNULL, CNULL);
4851+
goto accel_data2;
4852+
break;
4853+
#endif
48444854
accel_data1:
48454855
if (SST_IDG(RHS(1)) == S_IDENT || SST_IDG(RHS(1)) == S_DERIVED) {
48464856
sptr = SST_SYMG(RHS(1));

tools/flang2/flang2exe/expsmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,7 @@ exp_smp(ILM_OP opc, ILM *ilmp, int curilm)
27812781
#ifdef OMP_OFFLOAD_LLVM
27822782
case IM_MP_MAP:
27832783
if (flg.omptarget) {
2784-
exp_ompaccel_map(ilmp, curilm);
2784+
exp_ompaccel_map(ilmp, curilm, outlinedCnt);
27852785
}
27862786
break;
27872787
case IM_MP_TARGETLOOPTRIPCOUNT:

tools/flang2/flang2exe/llassem.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,16 +1029,21 @@ ompaccel_write_sharedvars(void)
10291029
}
10301030

10311031
static void
1032-
write_tgtrt_statics(SPTR sptr, char *gname, char *typed, int gblsym,
1032+
write_libomptarget_statics(SPTR sptr, char *gname, char *typed, int gblsym,
10331033
DSRT *dsrtp)
10341034
{
10351035
char *linkage_type;
1036+
10361037
linkage_type = "internal";
10371038
sprintf(gname, "struct%s", getsname(sptr));
10381039
get_typedef_ag(gname, typed);
10391040
free(typed);
10401041
gblsym = find_ag(gname);
10411042
typed = AG_TYPENAME(gblsym);
1043+
1044+
process_ftn_dtype_struct(DTYPEG(sptr), typed, false);
1045+
write_struct_defs();
1046+
10421047
#ifdef WEAKG
10431048
if (WEAKG(sptr))
10441049
linkage_type = "weak";
@@ -1055,20 +1060,25 @@ write_tgtrt_statics(SPTR sptr, char *gname, char *typed, int gblsym,
10551060
fputc('\n', ASMFIL);
10561061
}
10571062

1058-
static bool isLibomptargetInit = false;
1063+
static bool isOmptargetInitialized = false;
1064+
10591065
void
10601066
write_libomtparget(void)
10611067
{
1062-
if (isLibomptargetInit)
1063-
return;
1064-
fprintf(ASMFIL, "\n; OpenMP GPU Offload Init\n\
1065-
@.omp_offloading.img_end.nvptx64-nvidia-cuda = external constant i8 \n\
1066-
@.omp_offloading.img_start.nvptx64-nvidia-cuda = external constant i8 \n\
1067-
@.omp_offloading.entries_end = external constant %%struct.__tgt_offload_entry \n\
1068-
@.omp_offloading.entries_begin = external constant %%struct.__tgt_offload_entry \n\
1069-
@.omp_offloading.device_images = internal unnamed_addr constant [1 x %%struct.__tgt_device_image] [%%struct.__tgt_device_image { i8* @.omp_offloading.img_start.nvptx64-nvidia-cuda, i8* @.omp_offloading.img_end.nvptx64-nvidia-cuda, %%struct.__tgt_offload_entry* @.omp_offloading.entries_begin, %%struct.__tgt_offload_entry* @.omp_offloading.entries_end }], align 8\n\
1070-
@.omp_offloading.descriptor_ = internal constant %%struct.__tgt_bin_desc { i64 1, %%struct.__tgt_device_image* getelementptr inbounds ([1 x %%struct.__tgt_device_image], [1 x %%struct.__tgt_device_image]* @.omp_offloading.device_images, i32 0, i32 0), %%struct.__tgt_offload_entry* @.omp_offloading.entries_begin, %%struct.__tgt_offload_entry* @.omp_offloading.entries_end }, align 8\n\n");
1071-
isLibomptargetInit = true;
1068+
/* These structs should be created just right after the first target region. */
1069+
if (!isOmptargetInitialized) {
1070+
if(!strcmp(SYMNAME(gbl.currsub), "ompaccel.register"))
1071+
{
1072+
fprintf(ASMFIL, "\n; OpenMP GPU Offload Init\n\
1073+
@.omp_offloading.img_end.nvptx64-nvidia-cuda = external constant i8 \n\
1074+
@.omp_offloading.img_start.nvptx64-nvidia-cuda = external constant i8 \n\
1075+
@.omp_offloading.entries_end = external constant %%struct.__tgt_offload_entry_ \n\
1076+
@.omp_offloading.entries_begin = external constant %%struct.__tgt_offload_entry_ \n\
1077+
@.omp_offloading.device_images = internal unnamed_addr constant [1 x %%struct.__tgt_device_image] [%%struct.__tgt_device_image { i8* @.omp_offloading.img_start.nvptx64-nvidia-cuda, i8* @.omp_offloading.img_end.nvptx64-nvidia-cuda, %%struct.__tgt_offload_entry_* @.omp_offloading.entries_begin, %%struct.__tgt_offload_entry_* @.omp_offloading.entries_end }], align 8\n\
1078+
@.omp_offloading.descriptor_ = internal constant %%struct.__tgt_bin_desc { i64 1, %%struct.__tgt_device_image* getelementptr inbounds ([1 x %%struct.__tgt_device_image], [1 x %%struct.__tgt_device_image]* @.omp_offloading.device_images, i32 0, i32 0), %%struct.__tgt_offload_entry_* @.omp_offloading.entries_begin, %%struct.__tgt_offload_entry_* @.omp_offloading.entries_end }, align 8\n\n");
1079+
isOmptargetInitialized = true;
1080+
}
1081+
}
10721082
}
10731083

10741084
#endif
@@ -1617,7 +1627,7 @@ write_statics(void)
16171627
typed = get_struct_from_dsrt(sptr, dsrtp, SIZEG(sptr), &align8, true, 0);
16181628
#ifdef OMP_OFFLOAD_LLVM
16191629
if (OMPACCSTRUCTG(sptr)) {
1620-
write_tgtrt_statics(sptr, gname, typed, gblsym, dsrtp);
1630+
write_libomptarget_statics(sptr, gname, typed, gblsym, dsrtp);
16211631
count--;
16221632
continue;
16231633
}
@@ -3715,13 +3725,6 @@ getsname(SPTR sptr)
37153725
sprintf(name, "%s", SYMNAME(sptr));
37163726
p = name;
37173727
}
3718-
#ifdef OMP_OFFLOAD_LLVM
3719-
if (gbl.isnvvmcodegen && STYPEG(sptr) == ST_PROC &&
3720-
strncmp(SYMNAME(sptr), "omp_get_", 8) == 0) {
3721-
sprintf(name, "%s", SYMNAME(sptr));
3722-
return name;
3723-
}
3724-
#endif
37253728
else if (gbl.internal && CONTAINEDG(sptr)) {
37263729
p = name;
37273730
if (gbl.outersub) {

tools/flang2/flang2exe/main.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ process_input(char *argv0, bool *need_cuda_constructor)
194194
interr("main: malloc_verify failsA", errno, ERR_Fatal);
195195
#endif
196196
reinit();
197+
198+
197199
#if DEBUG & sun
198200
if (DBGBIT(7, 4))
199201
if (malloc_verify() != 1)
@@ -243,12 +245,11 @@ process_input(char *argv0, bool *need_cuda_constructor)
243245
} else {
244246
#ifdef OMP_OFFLOAD_LLVM
245247
if (flg.omptarget) {
248+
init_test();
246249
ompaccel_initsyms();
247-
if (ompaccel_tinfo_has(gbl.currsub))
248-
gbl.inomptarget = true;
249-
else
250-
gbl.inomptarget = false;
251-
ompaccel_create_globalctor();
250+
gbl.inomptarget = ompaccel_tinfo_has(gbl.currsub);
251+
if(!DTYPEG(gbl.currsub))
252+
ompaccel_create_globalctor();
252253
ompaccel_create_reduction_wrappers();
253254
}
254255
#endif
@@ -319,9 +320,6 @@ process_input(char *argv0, bool *need_cuda_constructor)
319320
#ifdef OMP_OFFLOAD_LLVM
320321
if (DBGBIT(61, 1) && flg.omptarget)
321322
dumpomptarget(ompaccel_tinfo_current_get());
322-
/* todo ompaccel we do not have host fallback mechanism.
323-
* all codes are in the target region will be generated ONLY for device.
324-
*/
325323
if (flg.omptarget && ompaccel_tinfo_has(gbl.currsub))
326324
gbl.isnvvmcodegen = true;
327325
#endif

0 commit comments

Comments
 (0)