Skip to content

Commit bdb854e

Browse files
doru1004ronlieb
authored andcommitted
[libomptarget] Move AMD system checks for host globals in separate function.
This patch is supposed to land before Joseph's upstream patch: llvm#77150 Change-Id: I71cddcdeb7181caa02361ce19873bbbf5bde9578
1 parent 57d4d14 commit bdb854e

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

openmp/libomptarget/include/Shared/PluginAPI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ bool __tgt_rtl_requested_prepopulate_gpu_page_table();
246246
// Check if image is incompatible due to XNACK mismatch.
247247
void __tgt_rtl_check_invalid_image(__tgt_device_image *Image);
248248

249+
bool __tgt_rtl_can_use_host_globals();
250+
249251
bool __tgt_rtl_is_system_supporting_managed_memory();
250252

251253
int32_t __tgt_rtl_launch_kernel_sync(int32_t, void *, void **, ptrdiff_t *,

openmp/libomptarget/include/Shared/PluginAPI.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ PLUGIN_API_HANDLE(data_notify_unmapped, false);
4848
PLUGIN_API_HANDLE(set_device_offset, false);
4949
PLUGIN_API_HANDLE(initialize_record_replay, false);
5050
PLUGIN_API_HANDLE(check_invalid_image, true);
51+
PLUGIN_API_HANDLE(can_use_host_globals, true);
5152
PLUGIN_API_HANDLE(has_apu_device, true);
5253
PLUGIN_API_HANDLE(has_USM_capable_dGPU, true);
5354
PLUGIN_API_HANDLE(are_allocations_for_maps_on_apus_disabled, true);

openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,6 +4179,31 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
41794179
return;
41804180
}
41814181

4182+
bool canUseHostGlobals() {
4183+
// Check if the HSA_XNACK and OMPX_APU_MAPS are enabled. If unified memory is
4184+
// not enabled but both HSA_XNACK and OMPX_APU_MAPS are enabled then we can
4185+
// also use globals directly from the host.
4186+
bool EnableHostGlobals = false;
4187+
bool IsZeroCopyOnAPU = Plugin::get().AreAllocationsForMapsOnApusDisabled();
4188+
BoolEnvar HSAXnack = BoolEnvar("HSA_XNACK", false);
4189+
4190+
if (IsZeroCopyOnAPU && HSAXnack.get())
4191+
EnableHostGlobals = true;
4192+
4193+
// Check if we are on a system that has an APU or on a non-APU system
4194+
// where unified shared memory can be enabled:
4195+
bool IsUsmSystem =
4196+
Plugin::get().hasAPUDevice() || Plugin::get().hasDGpuWithUsmSupport();
4197+
4198+
// Warn user if there is a mismatch between the request and the system
4199+
// architecture:
4200+
if (EnableHostGlobals && !IsUsmSystem)
4201+
fprintf(stderr, "OMPX_APU_MAPS and HSA_XNACK enabled on system that"
4202+
" does not support unified shared memory");
4203+
4204+
return IsUsmSystem && EnableHostGlobals;
4205+
}
4206+
41824207
bool isDataExchangable(int32_t SrcDeviceId, int32_t DstDeviceId) override {
41834208
return true;
41844209
}

openmp/libomptarget/plugins-nextgen/common/include/PluginInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,10 @@ struct GenericPluginTy {
11821182
/// Indicate whether the plugin supports empty images.
11831183
virtual bool supportsEmptyImages() const { return false; }
11841184

1185+
/// Return true if host globals can be enabled on a system that supprots
1186+
/// unified shared memory.
1187+
virtual bool canUseHostGlobals() const {}
1188+
11851189
protected:
11861190
/// Indicate whether a device id is valid.
11871191
bool isValidDeviceId(int32_t DeviceId) const {

openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,30 +1116,8 @@ Error GenericDeviceTy::registerGlobalOffloadEntry(
11161116
// can either be link or to. This means that once unified
11171117
// memory is activated via the requires directive, the variable
11181118
// can be used directly from the host in both cases.
1119-
1120-
// Check if the HSA_XNACK and OMPX_APU_MAPS are enabled. If unified memory is
1121-
// not enabled but both HSA_XNACK and OMPX_APU_MAPS are enabled then we can
1122-
// also use globals directly from the host.
1123-
bool EnableHostGlobals = false;
1124-
bool IsZeroCopyOnAPU = Plugin::get().AreAllocationsForMapsOnApusDisabled();
1125-
BoolEnvar HSAXnack = BoolEnvar("HSA_XNACK", false);
1126-
1127-
if (IsZeroCopyOnAPU && HSAXnack.get())
1128-
EnableHostGlobals = true;
1129-
1130-
// Check if we are on a system that has an APU or on a non-APU system
1131-
// where unified shared memory can be enabled:
1132-
bool IsUsmSystem =
1133-
Plugin::get().hasAPUDevice() || Plugin::get().hasDGpuWithUsmSupport();
1134-
1135-
// Fail if there is a mismatch between the user request and the system
1136-
// architecture:
1137-
if (EnableHostGlobals && !IsUsmSystem)
1138-
return Plugin::error("OMPX_APU_MAPS and HSA_XNACK enabled on system that"
1139-
" does not support unified shared memory");
1140-
11411119
if (Plugin.getRequiresFlags() & OMP_REQ_UNIFIED_SHARED_MEMORY ||
1142-
(IsUsmSystem && EnableHostGlobals)) {
1120+
Plugin.canUseHostGlobals()) {
11431121
// If unified memory is present any target link or to variables
11441122
// can access host addresses directly. There is no longer a
11451123
// need for device copies.
@@ -1828,6 +1806,10 @@ void __tgt_rtl_check_invalid_image(__tgt_device_image *InvalidImage) {
18281806
Plugin::get().checkInvalidImage(InvalidImage);
18291807
}
18301808

1809+
bool __tgt_rtl_can_use_host_globals() {
1810+
return Plugin::get().canUseHostGlobals();
1811+
}
1812+
18311813
int32_t __tgt_rtl_supports_empty_images() {
18321814
return Plugin::get().supportsEmptyImages();
18331815
}

0 commit comments

Comments
 (0)