Skip to content

Commit 44f3022

Browse files
committed
[OpenMP][NFC] Pass a DeviceTy, not the device number to target
This unifies the API of `target` relative to `targetUpdateData` and such. Reviewed By: tianshilei1992, grokos Differential Revision: https://reviews.llvm.org/D96429
1 parent ea93957 commit 44f3022

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

openmp/libomptarget/src/interface.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ EXTERN int __tgt_target_mapper(ident_t *loc, int64_t device_id, void *host_ptr,
407407
}
408408
#endif
409409

410-
int rc = target(loc, device_id, host_ptr, arg_num, args_base, args, arg_sizes,
410+
DeviceTy &Device = PM->Devices[device_id];
411+
int rc = target(loc, Device, host_ptr, arg_num, args_base, args, arg_sizes,
411412
arg_types, arg_names, arg_mappers, 0, 0, false /*team*/);
412413
HandleTargetOutcome(rc == OFFLOAD_SUCCESS, loc);
413414
return rc;
@@ -487,7 +488,8 @@ EXTERN int __tgt_target_teams_mapper(ident_t *loc, int64_t device_id,
487488
}
488489
#endif
489490

490-
int rc = target(loc, device_id, host_ptr, arg_num, args_base, args, arg_sizes,
491+
DeviceTy &Device = PM->Devices[device_id];
492+
int rc = target(loc, Device, host_ptr, arg_num, args_base, args, arg_sizes,
491493
arg_types, arg_names, arg_mappers, team_num, thread_limit,
492494
true /*team*/);
493495
HandleTargetOutcome(rc == OFFLOAD_SUCCESS, loc);

openmp/libomptarget/src/omptarget.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ static int InitLibrary(DeviceTy &Device) {
159159
DP("Has pending ctors... call now\n");
160160
for (auto &entry : lib.second.PendingCtors) {
161161
void *ctor = entry;
162-
int rc =
163-
target(nullptr, device_id, ctor, 0, nullptr, nullptr, nullptr,
164-
nullptr, nullptr, nullptr, 1, 1, true /*team*/);
162+
int rc = target(nullptr, Device, ctor, 0, nullptr, nullptr, nullptr,
163+
nullptr, nullptr, nullptr, 1, 1, true /*team*/);
165164
if (rc != OFFLOAD_SUCCESS) {
166165
REPORT("Running ctor " DPxMOD " failed.\n", DPxPTR(ctor));
167166
Device.PendingGlobalsMtx.unlock();
@@ -1238,11 +1237,11 @@ static int processDataAfter(ident_t *loc, int64_t DeviceId, void *HostPtr,
12381237
/// performs the same action as data_update and data_end above. This function
12391238
/// returns 0 if it was able to transfer the execution to a target and an
12401239
/// integer different from zero otherwise.
1241-
int target(ident_t *loc, int64_t DeviceId, void *HostPtr, int32_t ArgNum,
1240+
int target(ident_t *loc, DeviceTy &Device, void *HostPtr, int32_t ArgNum,
12421241
void **ArgBases, void **Args, int64_t *ArgSizes, int64_t *ArgTypes,
12431242
map_var_info_t *ArgNames, void **ArgMappers, int32_t TeamNum,
12441243
int32_t ThreadLimit, int IsTeamConstruct) {
1245-
DeviceTy &Device = PM->Devices[DeviceId];
1244+
int32_t DeviceId = Device.DeviceID;
12461245

12471246
TableMap *TM = getTableMap(HostPtr);
12481247
// No map for this host pointer found!

openmp/libomptarget/src/private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef _OMPTARGET_PRIVATE_H
1414
#define _OMPTARGET_PRIVATE_H
1515

16+
#include "device.h"
1617
#include <Debug.h>
1718
#include <SourceInfo.h>
1819
#include <omptarget.h>
@@ -36,7 +37,7 @@ extern int targetDataUpdate(ident_t *loc, DeviceTy &Device, int32_t arg_num,
3637
void **arg_mappers,
3738
__tgt_async_info *async_info_ptr = nullptr);
3839

39-
extern int target(ident_t *loc, int64_t DeviceId, void *HostPtr, int32_t ArgNum,
40+
extern int target(ident_t *loc, DeviceTy &Device, void *HostPtr, int32_t ArgNum,
4041
void **ArgBases, void **Args, int64_t *ArgSizes,
4142
int64_t *ArgTypes, map_var_info_t *arg_names,
4243
void **ArgMappers, int32_t TeamNum, int32_t ThreadLimit,

openmp/libomptarget/src/rtl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,8 @@ void RTLsTy::UnregisterLib(__tgt_bin_desc *desc) {
401401
Device.PendingGlobalsMtx.lock();
402402
if (Device.PendingCtorsDtors[desc].PendingCtors.empty()) {
403403
for (auto &dtor : Device.PendingCtorsDtors[desc].PendingDtors) {
404-
int rc =
405-
target(nullptr, Device.DeviceID, dtor, 0, nullptr, nullptr,
406-
nullptr, nullptr, nullptr, nullptr, 1, 1, true /*team*/);
404+
int rc = target(nullptr, Device, dtor, 0, nullptr, nullptr, nullptr,
405+
nullptr, nullptr, nullptr, 1, 1, true /*team*/);
407406
if (rc != OFFLOAD_SUCCESS) {
408407
DP("Running destructor " DPxMOD " failed.\n", DPxPTR(dtor));
409408
}

0 commit comments

Comments
 (0)