================
@@ -422,6 +427,19 @@ uint32_t GenericKernelTy::getEffectiveNumBlocks(
       // will execute one iteration of the loop; rounded up to the nearest
       // integer. However, if that results in too few blocks, we artificially
       // reduce the thread count per block to increase the outer parallelism.
+
+      // Favor fewer, larger teams for cross-team reductions. As a heuristic, 
we
+      // aim for double the default number of threads and half the default
+      // number of blocks.
+      if (isCrossTeamReduction()) {
+        // Never launch more teams than the trip count needs.
+        uint64_t NumBlocks =
----------------
dhruvachak wrote:

Your change halves the number of blocks even if the blocksize could not be 
increased for some reason. To guard against that problem, guard it like below. 
Additionally, instead of a hardcoded 2, use a scale-factor. 

```
if (isCrossTeamReduction() && EffectiveNumThreads > PreferredNumThreads) {
  uint64_t Scaled = std::max<uint64_t>(
      (uint64_t(DefaultNumBlocks) * PreferredNumThreads) / EffectiveNumThreads, 
1);
  uint64_t NumBlocks = std::min<uint64_t>(
      Scaled, ((LoopTripCount - 1) / EffectiveNumThreads) + 1);
  return std::min(NumBlocks, 
uint64_t(GenericDevice.getBlockLimit(EffectiveNumThreads)));
}
```

https://github.com/llvm/llvm-project/pull/208253
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to