Support configurable number of philox rounds for stochastic rounding#2751
Support configurable number of philox rounds for stochastic rounding#2751ksivaman merged 2 commits intoNVIDIA:mainfrom
Conversation
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Greptile SummaryThis PR introduces a build-time configurable Philox round count for stochastic rounding kernels, replacing the previously hardcoded value of Key changes:
One issue was found: in Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Build: NVTE_BUILD_NUM_PHILOX_ROUNDS env var set?"] -->|"No (empty string)"| B["Default to 10"]
A -->|"Yes"| C{"Matches regex\n^[1-9][0-9]*$?"}
C -->|"No"| D["CMake FATAL_ERROR"]
C -->|"Yes"| E["Pass as -DNVTE_BUILD_NUM_PHILOX_ROUNDS=N\nto compiler (PUBLIC)"]
B --> E
E --> F{"common.h:\n#ifndef NVTE_BUILD_NUM_PHILOX_ROUNDS"}
F -->|"Macro not defined\n(non-CMake build)"| G["#define NVTE_BUILD_NUM_PHILOX_ROUNDS 10"]
F -->|"Macro already defined\nby compiler flag"| H["Use provided value"]
G --> I["static_assert > 0"]
H --> I
I -->|"Pass"| J["philox4x32_native_state<NVTE_BUILD_NUM_PHILOX_ROUNDS>\nin all kernels"]
I -->|"Fail"| K["Compile error"]
style D fill:#f55,color:#fff
style K fill:#f55,color:#fff
style J fill:#5a5,color:#fff
Last reviewed commit: 92caffc |
| if (NOT NVTE_BUILD_NUM_PHILOX_ROUNDS_STR) | ||
| set(NVTE_BUILD_NUM_PHILOX_ROUNDS_STR "10") | ||
| endif() |
There was a problem hiding this comment.
Silent default for value "0" due to CMake falsy evaluation
In CMake, if(NOT variable) evaluates the boolean truthiness of the variable's string value. The string "0" is treated as false in CMake boolean contexts, so NOT "0" is true. This means if a user explicitly sets NVTE_BUILD_NUM_PHILOX_ROUNDS=0, the check on line 306 will silently reset the value to "10" — the regex validation on line 309 is never reached with the original "0", and no error is emitted.
The intent is clearly to default only when the variable is unset (empty), not when it is set to any falsy value. Using STREQUAL "" makes this explicit:
| if (NOT NVTE_BUILD_NUM_PHILOX_ROUNDS_STR) | |
| set(NVTE_BUILD_NUM_PHILOX_ROUNDS_STR "10") | |
| endif() | |
| if (NVTE_BUILD_NUM_PHILOX_ROUNDS_STR STREQUAL "") | |
| set(NVTE_BUILD_NUM_PHILOX_ROUNDS_STR "10") | |
| endif() |
|
/te-ci |
Description
Support configurable number of philox rounds for stochastic rounding.
Type of change
Changes
NVTE_BUILD_NUM_PHILOX_ROUNDSto support configurable number of philox rounds for stochastic rounding.Checklist: