Replace hardcoded CU/SM values with dynamic detection using HIP runtime #198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The codebase had hardcoded values for the number of Compute Units (CUs) / Streaming Multiprocessors (SMs) throughout examples and benchmark scripts:
These hardcoded values prevented the code from working optimally on different GPU architectures without manual modification.
Solution
Replaced hardcoded values with dynamic SM allocation logic inlined at each call site. The logic uses
get_cu_count()
from the HIP runtime API and applies algorithm-specific calculations:1.
all_scatter
algorithm: Uses total CU count2.
wg_specialized
algorithm: Uses next smaller power of 23.
all_reduce
algorithm: Reserves ~1/3 of leftover CUs for communicationChanges
Updated 11 files across the repository:
None
, with inlined runtime detection logic in worker functionsAll command-line arguments still support manual override for tuning and testing purposes.
Implementation
The SM calculation logic is inlined at each call site rather than using a helper function, making the allocation strategy explicit and localized:
Testing
Verified that formulas produce expected results:
MI300X (304 CUs):
MI250 (104 CUs):
All files pass ruff linting and Python syntax validation.
Benefits
Fixes #197
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.