[Openmp-commits] [llvm] [openmp] [OpenMP][offload] Trade threads for blocks in Generic-SPMD kernels (PR #234191)
Alex Duran via Openmp-commits
openmp-commits at lists.llvm.org
Fri Oct 23 06:48:45 PDT 2026
================
@@ -733,19 +745,38 @@ static uint32_t getEffectiveNumThreads(const DeviceGeometryPropsTy &Props,
: KernelEnv.PreferredNumThreads);
}
+/// Get the number of teams the user set with OMP_NUM_TEAMS, or zero.
+static uint32_t getOMPNumTeams() {
+ static Int32Envar OMP_NumTeams("OMP_NUM_TEAMS");
+ return OMP_NumTeams > 0 ? uint32_t(OMP_NumTeams) : 0;
+}
+
/// Get the maximum number of blocks the device can launch for a kernel using
/// \p NumThreads threads per block, further limited by OMP_NUM_TEAMS if the
/// user set it.
static uint32_t getDeviceBlockLimit(GenericDeviceTy &GenericDevice,
uint32_t NumThreads) {
- static Int32Envar OMP_NumTeams("OMP_NUM_TEAMS");
-
uint32_t BlockLimit = GenericDevice.getBlockLimit(NumThreads);
- if (OMP_NumTeams > 0)
- return std::min(BlockLimit, uint32_t(OMP_NumTeams));
+ if (uint32_t NumTeams = getOMPNumTeams())
+ return std::min(BlockLimit, NumTeams);
return BlockLimit;
}
+/// Get the default number of blocks for a kernel in Generic-SPMD mode.
+static uint32_t
+getDefaultNumBlocksGenericSPMD(const DeviceGeometryPropsTy &Props) {
+ // Envar to set the default number of blocks per compute unit for a kernel in
+ // Generic-SPMD mode on AMDGPU devices. Zero uses the default number of blocks
+ // of other kernels.
+ static UInt32Envar OMPX_GenericSPMDTeamsPerCU(
+ "LIBOMPTARGET_AMDGPU_GENERIC_SPMD_TEAMS_PER_CU", 6);
----------------
adurang wrote:
ah right, in the next condition... might be clearer doing that check first.
you didn't answer about whether is OpenMP specific though :)
https://github.com/llvm/llvm-project/pull/234191
More information about the Openmp-commits
mailing list