Repository navigation
fix(rocshmem): make Anvil SDMA usable on MI300X CPX and QPX, DPX up to two OAMs #12841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dlamd1dai
merged 11 commits into
develop
from
users/dondai/aicomrccl-2387-rocshmem-anvil-cpx
Oct 18, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bb683b6
fix(rocshmem): make Anvil SDMA usable on MI300X CPX partitions
dlamd1dai 904f4ba
Expose pciFunctionBus and the queue budget for testing
dlamd1dai 2526438
ci: retrigger math-ci after a Docker Hub registry timeout
dlamd1dai 61c5ab9
Address Argus review on the Anvil CPX change
dlamd1dai c87f376
Test the CPX engine fold and harden AnvilLib inputs
dlamd1dai 97738bf
Scope SDMA init teardown and test the queue budget
dlamd1dai 2a40260
Scope sdmaHostStop teardown to the peers it wired
dlamd1dai f1742de
Fail fast on an SDMA connect failure in rocSHMEM init
dlamd1dai aad8f6b
Keep Anvil partition logs quiet and copy the engine map into RCCL
dlamd1dai b47b4f7
fix(rocshmem): keep Anvil queues on safe SDMA engines
dlamd1dai 77d8723
Merge branch 'develop' into users/dondai/aicomrccl-2387-rocshmem-anvi…
dlamd1dai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /****************************************************************************** | ||
| * Copyright (c) Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to | ||
| * deal in the Software without restriction, including without limitation the | ||
| * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| * sell copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| * IN THE SOFTWARE. | ||
| *****************************************************************************/ | ||
| #ifndef LIBRARY_SRC_SDMA_ANVIL_ENGINE_MAP_HPP_ | ||
| #define LIBRARY_SRC_SDMA_ANVIL_ENGINE_MAP_HPP_ | ||
|
|
||
| // Pure engine-selection and queue-budget helpers for AnvilLib. Kept free of HSA/KFD headers so the | ||
| // unit tests can build them without USE_SDMA. | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
|
|
||
| namespace sdma_anvil { | ||
|
|
||
| // Every queue slot on an even-numbered MI300 SDMA engine is reachable by a GPU-written doorbell. | ||
| // Slots 0-3 on odd engines are not (ROCM-32598), and this code cannot choose a slot, so use only | ||
| // even engines until the slot-aware workaround can inspect and park unusable queues. | ||
| inline bool isUsableSdmaEngine(int engineId) { return engineId >= 0 && engineId % 2 == 0; } | ||
|
|
||
| // Number of even engines in a node-local engine range. A zero total means the count is unknown. | ||
| inline uint32_t usableSdmaEngines(uint32_t numSdmaEnginesTotal) { | ||
| return (numSdmaEnginesTotal + 1) / 2; | ||
| } | ||
|
|
||
| // Select an even engine from an HSA preferred-copy-engine mask. Prefer an even bit from the mask; | ||
| // if it contains only odd engines, use the paired even engine immediately below the lowest one. | ||
| // Return -1 for an empty mask. | ||
| inline int preferredUsableEngine(uint32_t preferredMask) { | ||
| if (preferredMask == 0) return -1; | ||
| const uint32_t evenMask = preferredMask & 0x55555555u; | ||
| return evenMask != 0 ? __builtin_ctz(evenMask) : (__builtin_ctz(preferredMask) & ~1); | ||
| } | ||
|
|
||
| // A CPX/DPX partition owns host SDMA engines but no xGMI engines. Callers pass a total of 0 when | ||
| // the engine counts could not be queried, so a failed query is never read as a partition. | ||
| inline bool isSdmaPartition(uint32_t numSdmaXgmiEngines, uint32_t numSdmaEnginesTotal) { | ||
| return numSdmaXgmiEngines == 0 && numSdmaEnginesTotal > 0; | ||
| } | ||
|
|
||
| // True when the doubled OAM-map id cannot be used as-is. A partition (no xGMI | ||
| // engines) folds even when the doubled id is in range: same-device peers share | ||
| // the map diagonal and would otherwise all land on engine 0. An id past the | ||
| // engines this node reports folds too. numSdmaEnginesTotal == 0 never folds, | ||
| // so the modulo below is not asked to divide by zero. | ||
| inline bool oamMapEngineNeedsFold(uint32_t numSdmaXgmiEngines, uint32_t numSdmaEnginesTotal, | ||
| int doubledEngineId) { | ||
| const bool partition = isSdmaPartition(numSdmaXgmiEngines, numSdmaEnginesTotal); | ||
| const bool outOfRange = | ||
| numSdmaEnginesTotal > 0 && static_cast<uint32_t>(doubledEngineId) >= numSdmaEnginesTotal; | ||
| return partition || outOfRange; | ||
| } | ||
|
|
||
| // Fold the undoubled OAM-map value and both PCI functions onto an even engine this node reports. | ||
| // numEnginesTotal must be > 0. An unreadable function (-1) counts as 0 and therefore collides with | ||
| // function 0. | ||
| inline int foldOamMapEngine(int oamEngine, int srcFn, int dstFn, uint32_t numEnginesTotal) { | ||
| const int src = srcFn < 0 ? 0 : srcFn; | ||
| const int dst = dstFn < 0 ? 0 : dstFn; | ||
| return 2 * ((oamEngine + src + dst) % | ||
| static_cast<int>(usableSdmaEngines(numEnginesTotal))); | ||
| } | ||
|
|
||
| // PCI function and the function-0 BDF of the same device. function is -1 when the tail is not a | ||
| // function digit, so an unreadable id is not treated as function 0. The physical BDF is rewritten | ||
| // only in that case; a bad tail is left unchanged. | ||
| struct PciFunctionBus { | ||
| std::string busId; | ||
| std::string physBusId; | ||
| int function; | ||
| }; | ||
|
|
||
| // Split a BDF into its function digit and the function-0 BDF of the same device. Pure, and beside | ||
| // the two helpers above because it decides the same fallback they do: a tail outside '0'-'7' | ||
| // leaves function at -1 and physBusId equal to busId, which collapses getOamId's candidate list to | ||
| // one entry so the physical-BDF read never runs. PCI function numbers are three bits, so '0'-'7' | ||
| // is the whole range. | ||
| inline PciFunctionBus pciFunctionBus(const std::string& busId) { | ||
| PciFunctionBus loc; | ||
| loc.busId = busId; | ||
| loc.physBusId = busId; | ||
| loc.function = -1; | ||
| if (busId.empty()) return loc; | ||
| const char c = busId.back(); | ||
| if (c >= '0' && c <= '7') { | ||
| loc.function = c - '0'; | ||
| loc.physBusId.back() = '0'; | ||
| } | ||
| return loc; | ||
| } | ||
|
|
||
| // True when taking `requested` more queues would exceed the queue budget, counted across the | ||
| // engines the caller can safely use. Either count being 0 means the budget is unknown, which is | ||
| // never reported as exhausted. | ||
| inline bool queueBudgetExceeded(uint32_t used, int requested, uint32_t numEnginesTotal, | ||
| uint32_t queuesPerEngine) { | ||
| const uint32_t budget = numEnginesTotal * queuesPerEngine; | ||
| return requested > 0 && budget > 0 && used + static_cast<uint32_t>(requested) > budget; | ||
| } | ||
|
|
||
| } // namespace sdma_anvil | ||
|
|
||
| #endif // LIBRARY_SRC_SDMA_ANVIL_ENGINE_MAP_HPP_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.