diff options
author | Joseph Huber <jhuber6@vols.utk.edu> | 2023-03-01 14:02:40 -0600 |
---|---|---|
committer | Joseph Huber <jhuber6@vols.utk.edu> | 2023-03-01 14:12:46 -0600 |
commit | 656378085e7f52d67581245617474c5ce530dac4 (patch) | |
tree | edcbe844d474ef5e8bfe85953c7c0cda39bf34ea /openmp | |
parent | c9843af5785600731bb09736b990de183c9a05e5 (diff) | |
download | llvm-656378085e7f52d67581245617474c5ce530dac4.tar.gz |
[Libomptarget] Fix block and thread limit environment variables not being respected
The next-gen plugins did not properly set the values from
`OMP_NUM_TEAMS` and `OMP_TEAMS_THREAD_LIMIT`. This is because these
maximum values are set by each plugin to its hardware maximum. This
happens *after* the previous initialization. Move it to the correct
place and then add a test.
Fixes https://github.com/llvm/llvm-project/issues/61082
Reviewed By: tianshilei1992
Differential Revision: https://reviews.llvm.org/D145105
Diffstat (limited to 'openmp')
-rw-r--r-- | openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp | 21 | ||||
-rw-r--r-- | openmp/libomptarget/test/api/omp_env_vars.c | 12 |
2 files changed, 23 insertions, 10 deletions
diff --git a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp index c8c4a60d0bdf..1d4d906bec4e 100644 --- a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp +++ b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp @@ -352,15 +352,7 @@ GenericDeviceTy::GenericDeviceTy(int32_t DeviceId, int32_t NumDevices, OMPX_InitialNumEvents("LIBOMPTARGET_NUM_INITIAL_EVENTS", 32), DeviceId(DeviceId), GridValues(OMPGridValues), PeerAccesses(NumDevices, PeerAccessState::PENDING), PeerAccessesLock(), - PinnedAllocs(*this) { - if (OMP_NumTeams > 0) - GridValues.GV_Max_Teams = - std::min(GridValues.GV_Max_Teams, uint32_t(OMP_NumTeams)); - - if (OMP_TeamsThreadLimit > 0) - GridValues.GV_Max_WG_Size = - std::min(GridValues.GV_Max_WG_Size, uint32_t(OMP_TeamsThreadLimit)); -} + PinnedAllocs(*this) {} Error GenericDeviceTy::init(GenericPluginTy &Plugin) { if (auto Err = initImpl(Plugin)) @@ -385,6 +377,16 @@ Error GenericDeviceTy::init(GenericPluginTy &Plugin) { return HeapSizeEnvarOrErr.takeError(); OMPX_TargetHeapSize = std::move(*HeapSizeEnvarOrErr); + // Update the maximum number of teams and threads after the device + // initialization sets the corresponding hardware limit. + if (OMP_NumTeams > 0) + GridValues.GV_Max_Teams = + std::min(GridValues.GV_Max_Teams, uint32_t(OMP_NumTeams)); + + if (OMP_TeamsThreadLimit > 0) + GridValues.GV_Max_WG_Size = + std::min(GridValues.GV_Max_WG_Size, uint32_t(OMP_TeamsThreadLimit)); + // Enable the memory manager if required. auto [ThresholdMM, EnableMM] = MemoryManagerTy::getSizeThresholdFromEnv(); if (EnableMM) @@ -1191,7 +1193,6 @@ __tgt_target_table *__tgt_rtl_load_binary(int32_t DeviceId, GenericPluginTy &Plugin = Plugin::get(); GenericDeviceTy &Device = Plugin.getDevice(DeviceId); - auto TableOrErr = Device.loadBinary(Plugin, TgtImage); if (!TableOrErr) { auto Err = TableOrErr.takeError(); diff --git a/openmp/libomptarget/test/api/omp_env_vars.c b/openmp/libomptarget/test/api/omp_env_vars.c new file mode 100644 index 000000000000..2e78bb115bee --- /dev/null +++ b/openmp/libomptarget/test/api/omp_env_vars.c @@ -0,0 +1,12 @@ +// RUN: %libomptarget-compile-generic +// RUN: env OMP_NUM_TEAMS=1 OMP_TEAMS_THREAD_LIMIT=1 LIBOMPTARGET_INFO=16 \ +// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic + +#define N 256 + +int main() { + // CHECK: Launching kernel [[KERNEL:.+_main_.+]] with 1 blocks and 1 threads +#pragma omp target teams +#pragma omp parallel + {} +} |