Skip to content

Commit

Permalink
[libomptarget] Fix environment variable checks when initializing devices
Browse files Browse the repository at this point in the history
Change-Id: Ib8f934b861762bb178e8abf28440a0f628509d36
  • Loading branch information
doru1004 authored and ronlieb committed Mar 6, 2024
1 parent 7e1efa2 commit be5eca3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
6 changes: 0 additions & 6 deletions openmp/libomptarget/include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ struct DeviceTy {
/// Controlled via environment flag OMPX_FORCE_SYNC_REGIONS
bool ForceSynchronousTargetRegions = false;

/// Flag that indicates whether the user requested eager zero-copy maps
/// to execute their application. Even if true, this is only valid on certain
/// architectures and configurations, which is checked upon device
/// initialization.
bool EagerZeroCopyMaps = false;

DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID);
// DeviceTy is not copyable
DeviceTy(const DeviceTy &D) = delete;
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/src/OpenMP/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ TargetPointerResultTy MappingInfoTy::getTargetPointer(
// If we are here, it means that we are either in auto zero-copy or USM.
// Enable GPU page table prefaulting if selected by the user. This feature
// is only enabled for APUs.
if (Device.EagerZeroCopyMaps) {
if (PM->getRequirements() & OMPX_REQ_EAGER_ZERO_COPY_MAPS) {
Device.RTL->prepopulate_page_table(Device.DeviceID, HstPtrBegin, Size);
INFO(OMP_INFOTYPE_MAPPING_CHANGED, Device.DeviceID,
"Prefaulted " DPxMOD " Size=%" PRId64 " on GPU page table\n",
Expand Down
19 changes: 8 additions & 11 deletions openmp/libomptarget/src/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ void PluginAdaptorTy::initDevices(PluginManager &PM) {
// The following properties must have the same value for all devices.
// They are surfaced per-device because the related properties
// are computed as such in the plugins.
bool EagerMapsRequested = false;
bool IsAPU = false;
bool SupportsUnifiedMemory = false;
for (int32_t PDevI = 0, UserDevId = DeviceOffset; PDevI < NumPD; PDevI++) {
auto Device = std::make_unique<DeviceTy>(this, UserDevId, PDevI);
if (auto Err = Device->init()) {
Expand All @@ -150,23 +147,24 @@ void PluginAdaptorTy::initDevices(PluginManager &PM) {
continue;
}
UseAutoZeroCopy = UseAutoZeroCopy && Device->useAutoZeroCopy();
SupportsUnifiedMemory =
SupportsUnifiedMemory && Device->supportsUnifiedMemory();

ExclusiveDevicesAccessor->push_back(std::move(Device));
++NumberOfUserDevices;
++UserDevId;
}

// IsAPU and EagerMapsRequested are properties associated
// with devices but they must be the same for all devices.
// We do not mix APUs with discrete GPUs and eager maps
// is set by an host environment variable.
// IsAPU, EagerMapsRequested and SupportsUnifiedMemory are properties
// associated with devices but they must be the same for all devices.
// We do not mix APUs with discrete GPUs. Eager maps is set by a host
// environment variable.
bool IsAPU = false;
bool SupportsUnifiedMemory = false;
if (ExclusiveDevicesAccessor->size() > 0) {
auto &Device = *(*ExclusiveDevicesAccessor)[0];
IsAPU = Device.checkIfAPU();
EagerMapsRequested = Device.EagerZeroCopyMaps;
SupportsUnifiedMemory = Device.supportsUnifiedMemory();
}
bool EagerMapsRequested = BoolEnvar("OMPX_EAGER_ZERO_COPY_MAPS", false).get();

// Auto Zero-Copy can only be currently triggered when the system is an
// homogeneous APU architecture without attached discrete GPUs.
Expand All @@ -185,7 +183,6 @@ void PluginAdaptorTy::initDevices(PluginManager &PM) {
}

// sanity checks for zero-copy depend on specific devices: request it here
// TODO: check if there are no devices and bail if so.
if ((ExclusiveDevicesAccessor->size() > 0) &&
((PM.getRequirements() & OMP_REQ_UNIFIED_SHARED_MEMORY) ||
(PM.getRequirements() & OMPX_REQ_AUTO_ZERO_COPY))) {
Expand Down
4 changes: 0 additions & 4 deletions openmp/libomptarget/src/omptarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ static int initLibrary(DeviceTy &Device) {
static BoolEnvar FSTEnvVar = BoolEnvar("OMPX_FORCE_SYNC_REGIONS", false);
Device.ForceSynchronousTargetRegions = FSTEnvVar.get();

static BoolEnvar OMPX_EagerMaps =
BoolEnvar("OMPX_EAGER_ZERO_COPY_MAPS", false);
Device.EagerZeroCopyMaps = OMPX_EagerMaps.get();

return OFFLOAD_SUCCESS;
}

Expand Down

0 comments on commit be5eca3

Please sign in to comment.