Skip to content

Commit 2187cbf

Browse files
committed
[OpenMP][libomptarget] Add __tgt_target_return_t enum for __tgt_target_XXX return int
The defintion of OFFLOAD_SUCCESS and OFFLOAD_FAIL used in plugin APIs and libomptarget public APIs are not consistent. Create __tgt_target_return_t for libomptarget public APIs. Differential Revision: https://reviews.llvm.org/D109304
1 parent 99ea8ac commit 2187cbf

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

openmp/libomptarget/include/omptarget.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
// Don't format out enums and structs.
2929
// clang-format off
3030

31+
/// return flags of __tgt_target_XXX public APIs
32+
enum __tgt_target_return_t : int {
33+
/// successful offload executed on a target device
34+
OMP_TGT_SUCCESS = 0,
35+
/// offload may not execute on the requested target device
36+
/// this scenario can be caused by the device not available or unsupported
37+
/// as described in the Execution Model in the specifcation
38+
/// this status may not be used for target device execution failure
39+
/// which should be handled internally in libomptarget
40+
OMP_TGT_FAIL = ~0
41+
};
42+
3143
/// Data attributes for each data reference used in an OpenMP target region.
3244
enum tgt_map_type {
3345
// No flags

openmp/libomptarget/src/interface.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ EXTERN int __tgt_target_mapper(ident_t *loc, int64_t device_id, void *host_ptr,
284284
DPxPTR(host_ptr), device_id);
285285
if (checkDeviceAndCtors(device_id, loc)) {
286286
DP("Not offloading to device %" PRId64 "\n", device_id);
287-
return OFFLOAD_FAIL;
287+
return OMP_TGT_FAIL;
288288
}
289289

290290
if (getInfoLevel() & OMP_INFOTYPE_KERNEL_ARGS)
@@ -307,7 +307,8 @@ EXTERN int __tgt_target_mapper(ident_t *loc, int64_t device_id, void *host_ptr,
307307
if (rc == OFFLOAD_SUCCESS)
308308
rc = AsyncInfo.synchronize();
309309
handleTargetOutcome(rc == OFFLOAD_SUCCESS, loc);
310-
return rc;
310+
assert(rc == OFFLOAD_SUCCESS && "__tgt_target_mapper unexpected failure!");
311+
return OMP_TGT_SUCCESS;
311312
}
312313

313314
EXTERN int __tgt_target_nowait_mapper(
@@ -357,7 +358,7 @@ EXTERN int __tgt_target_teams_mapper(ident_t *loc, int64_t device_id,
357358
DPxPTR(host_ptr), device_id);
358359
if (checkDeviceAndCtors(device_id, loc)) {
359360
DP("Not offloading to device %" PRId64 "\n", device_id);
360-
return OFFLOAD_FAIL;
361+
return OMP_TGT_FAIL;
361362
}
362363

363364
if (getInfoLevel() & OMP_INFOTYPE_KERNEL_ARGS)
@@ -380,7 +381,9 @@ EXTERN int __tgt_target_teams_mapper(ident_t *loc, int64_t device_id,
380381
if (rc == OFFLOAD_SUCCESS)
381382
rc = AsyncInfo.synchronize();
382383
handleTargetOutcome(rc == OFFLOAD_SUCCESS, loc);
383-
return rc;
384+
assert(rc == OFFLOAD_SUCCESS &&
385+
"__tgt_target_teams_mapper unexpected failure!");
386+
return OMP_TGT_SUCCESS;
384387
}
385388

386389
EXTERN int __tgt_target_teams_nowait_mapper(

0 commit comments

Comments
 (0)