# Sm90: setmaxnreg will change Occupancy dynamically?

**URL:** <https://forums.developer.nvidia.com/t/sm90-setmaxnreg-will-change-occupancy-dynamically/302068>\
**Category:** Nsight Compute\
**Created:** [August 2, 2024, 9:13am UTC](https://forums.developer.nvidia.com/t/sm90-setmaxnreg-will-change-occupancy-dynamically/302068 "2024-08-02T09:13:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![202476410arsmart](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@202476410arsmart](https://forums.developer.nvidia.com/u/202476410arsmart)\
**Post date:** [August 2, 2024, 9:13am UTC](https://forums.developer.nvidia.com/t/sm90-setmaxnreg-will-change-occupancy-dynamically/302068/1 "2024-08-02T09:13:54Z")

</div>

setmaxnreg is a new feature since Hopper. I noticed this in cutlass:

> <https://github.com/NVIDIA/cutlass/blob/eee0cab26c8eedea447eb3b58b3498eeba2294da/include/cutlass/gemm/kernel/sm90_gemm_tma_warpspecialized_cooperative.hpp#L446>

From above, the consumer register is 232, the producer register is 40.  
Different warp can use different register number??? This will affect Occupancy.  
Also, we can dynamicaly modify register during kernel running? This will affect Occupancy.  
Using NCU, I find a static register number 168, not 232, not 40. Anything wrong？

 ![56874582e553d9cf4bcd455b9332988](https://global.discourse-cdn.com/nvidia/original/4X/7/7/c/77cdd5c1e49ce6af21eaf2ed2065ba6972c25eeb.png)

---

<div class="post-metadata">

**Author:** ![202476410arsmart](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@202476410arsmart](https://forums.developer.nvidia.com/u/202476410arsmart)\
**Post date:** [August 2, 2024, 10:00am UTC](https://forums.developer.nvidia.com/t/sm90-setmaxnreg-will-change-occupancy-dynamically/302068/2 "2024-08-02T10:00:17Z")

</div>

Here we have a producer(128 threads with 40 regs each, but only 1 warp for mainloop is active), two consumers(256 threads with 232 regs each)  
So (40 \* 32+256 \* 232)/384=158!!?? ≈168???

---

<div class="post-metadata">

**Author:** ![Greg](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/greg/32/14043_2.png) [@Greg](https://forums.developer.nvidia.com/u/Greg)\
**Post date:** [August 2, 2024, 4:18pm UTC](https://forums.developer.nvidia.com/t/sm90-setmaxnreg-will-change-occupancy-dynamically/302068/3 "2024-08-02T16:18:55Z")

</div>

A CUDA grid launch specifies the number of registers per warp. All warps in the CTA (thread block) launch with the same number of registers. The PTX instruction setmaxnreg allows a warp (e.g. producer warp) to return registers to the CTA register pool (setmaxnreg.dec) and other warps to acquire registers from the CTA register pool (setmaxnreg.inc). The total number of registers allocated to the CTA does not change. The total number of registers allocated to all warps in the CTA cannot exceed the initial CTA launch. Due to this constraint SM warp occupancy is not changed.

Registers allocated to warps are freed on warp complete (EXIT).  
Registers returned to the CTA pool are freed on CTA complete after all warps complete.

NCU captures the number of registers per warp at grid launch. The use of setmaxnreg is a dynamic operation at runtime. NCU does not have a method to trace the changes. A given warp could go through many different warp counts during execution of a grid.

For more details see [PTX ISA 8.5](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#miscellaneous-instructions-setmaxnreg) section on setmaxnreg.

---

<div class="post-metadata">

**Author:** ![202476410arsmart](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@202476410arsmart](https://forums.developer.nvidia.com/u/202476410arsmart)\
**Post date:** [August 4, 2024, 9:39am UTC](https://forums.developer.nvidia.com/t/sm90-setmaxnreg-will-change-occupancy-dynamically/302068/4 "2024-08-04T09:39:30Z")

</div>

> Here we have a producer(128 threads with 40 regs each, but only 1 warp for mainloop is active), two consumers(256 threads with 232 regs each)  
> So (40 \* 32+256 \* 232)/384=158!!?? ≈168???

Seems this make sense?

> The total number of registers allocated to all warps in the CTA cannot exceed the initial CTA launch. Due to this constraint SM warp occupancy is not changed.

This means, the register from NCU might not be correct(because it is changing), but the Occupancy is still correct and useful, right?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [August 18, 2024, 9:39am UTC](https://forums.developer.nvidia.com/t/sm90-setmaxnreg-will-change-occupancy-dynamically/302068/5 "2024-08-18T09:39:33Z")

</div>

Closed on August 18, 2024, 9:39am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
