Skip to content

feat(kfdtest): Cu mask enablement PR AILIKFD-28 - #9738

Merged
amd-justchen merged 7 commits into
developfrom
users/asierrag-amd/develop_wip
Sep 1, 2026
Merged

amd-justchen merged 7 commits into
developfrom
users/asierrag-amd/develop_wip

Conversation

@asierrag-amd

@asierrag-amd asierrag-amd commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

#AILIKFD-28
BasicCuMaskingLinear assumes mask bit i selects the i-th CU on the engine
that runs the dispatch, which breaks on a multi-XCC node (e.g. gfx12.1.0
in SPX mode) in two ways.

The driver spreads the linear mask across XCCs (bit i -> XCC i % NumXcc),
but the PM4 queue runs on a single XCC, so most enabled bits never grow
the executing XCC's CU count. Stride the mask by NumXcc and cap the sweep
at ActiveCU / NumXcc so every enabled CU lands on XCC0.

Within that XCC the mask fills round-robin across shader engines, so
parallelism grows only in steps of SEsPerXcc. Compare against this
SE-balanced effective CU count instead of the raw count.

For single-XCC parts (NumXcc == 1) this reduces to the original
contiguous mask, so behavior is unchanged.

@therock-pr-bot

therock-pr-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

❌ PR Check — Action Required

Check Status Details
📝 PR Description ❌ Fail Error: PR description must reference a JIRA ID, ISSUE ID, or a GitHub closing keyword.
Expected: include a JIRA ID / ISSUE ID line (separator : or -, or omitted; value may be a JIRA key, a number with/without #, or a link), OR a closing keyword + issue reference. Accepted examples:
• JIRA ID : TESTAUTO-6039
• JIRA ID - #330
• JIRA ID #330
• JIRA ID (on separate line)
ROCM-25757
• ISSUE ID : TESTUTO-3334
• ISSUE ID #3334
• ISSUE ID - TESTAUTO-3433
• ISSUE ID (on separate line)
AIRUNTIME-2352
• ISSUE ID : https://github.com/<org_name>/<repo_name>/issues/1234
• Closes #10
• Fixes octo-org/octo-repo#100
• Resolves: #123
• #123
• https://github.com/<org_name>/<repo_name>/issues/123
Current: no valid JIRA/ISSUE/closing-keyword reference found
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rocr-runtime/libhsakmt/tests/kfdtest/src/BaseQueue.cpp, projects/rocr-runtime/libhsakmt/tests/kfdtest/src/BaseQueue.hpp, projects/rocr-runtime/libhsakmt/tests/kfdtest/src/KFDQMTest.cpp, projects/rocr-runtime/libhsakmt/tests/kfdtest/src/KFDQMTest.hpp, projects/rocr-runtime/libhsakmt/tests/kfdtest/src/ShaderStore.cpp; no test file found
🔎 pre-commit ⏳ Pending ⏳ Still running…
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

⚠️ 1 policy check(s) failed. Please address the issues above before this PR can be Reviewed.

🚫 Please fix the failed policies

  • ❌ PR Description

The Not ready to Review label was added to this PR. Once all policies pass, the label is removed automatically.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ PR Description

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

@dayatsin-amd dayatsin-amd changed the title kfdtest Cu mask enablement feat(kfdtest): Cu mask enablement Aug 5, 2026
@dayatsin-amd

Copy link
Copy Markdown
Contributor

In the future please use this format for the PR descriptions:
feat(kfdtest): Cu mask enablement

@asierrag-amd asierrag-amd changed the title feat(kfdtest): Cu mask enablement feat(kfdtest): Cu mask enablement PR AILIKFD-28 Aug 7, 2026
}

/*
* Check and record any inactive WPGs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo - WPGs - should be WGPs - Workgroup Processors - I know its outside your patch but just noticed.

@asierrag-amd asierrag-amd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shwetagkhatri , just replied to your comments.

@shwetagkhatri
shwetagkhatri self-requested a review August 13, 2026 14:38

@cfreeamd cfreeamd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI-assisted pre-review (for @cfreeamd)

kfdtest.exclude restructuring, adjustMaskXcc, cuMaskSetUnit refactoring, and ShaderStore gfx12.5 SE-inject all look correct and consistent. No concerns in the kfdtest.exclude blacklist refactor or the mask_config_t extension.

One finding to flag (in addition to what shwetagkhatri raised):

extendedCuMaskingXcc() — In the random subset loop, wgpMask is uint32_t and the loop uses (1u << u) where u can reach 35 on gfx1250 (gridWgpPerXcc=36). 1u << 32 is UB in C++; on x86 GCC's SHL masks the count to 5 bits, so units 32–35 silently re-check bits 0–3. These WGPs are covered by the linear and combination tests, but the random path can never select them. Fix: uint64_t wgpMask and 1ULL << u. (shwetagkhatri caught the truncation side of this independently.)

ShaderStore.cpp — Minor: comment says MSG_RTN_GET_SE_AID_ID[3:0] but the mask is 0x3 which keeps only bits [1:0].

@asierrag-amd asierrag-amd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shwetagkhatri could you please provide your comments

@shwetagkhatri shwetagkhatri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont want to block approval on KFDTests. Approving along with the following -

Non-blocking nit - the test passes correctly, so this isn't a merge blocker.
But 1u << u at line 1453 is undefined behavior for u = 32..35 (grid is 36). On x86 it happens to wrap onto bits 0–3, so units 32–35 (the 9th WGP of each column) still get toggled, just correlated to units 0–3 rather than independently; unit 31 is effectively never set since rand() is 31-bit.

If you can fix this - the clean form would be:
uint64_t r = ((uint64_t)rand() << 31) | (uint32_t)rand();
uint64_t wgpMask = (r % ((1ULL << gridWgpPerXcc) - 1)) + 1;
for (uint32_t u = 0; u < gridWgpPerXcc; u++)
if (wgpMask & (1ULL << u))
cuMaskSetUnit(mask, cfg, u);

@kentrussell kentrussell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really love the exclude format change, but don't have a suggestion to improve it. Especially if we're intending to move the blacklist logic into the binary itself (future plan)

BasicCuMaskingLinear assumes mask bit i selects the i-th CU on the engine
that runs the dispatch, which breaks on a multi-XCC node (e.g. gfx12.1.0
in SPX mode) in two ways.

The driver spreads the linear mask across XCCs (bit i -> XCC i % NumXcc),
but the PM4 queue runs on a single XCC, so most enabled bits never grow
the executing XCC's CU count. Stride the mask by NumXcc and cap the sweep
at ActiveCU / NumXcc so every enabled CU lands on XCC0.

Within that XCC the mask fills round-robin across shader engines, so
parallelism grows only in steps of SEsPerXcc. Compare against this
SE-balanced effective CU count instead of the raw count.

For single-XCC parts (NumXcc == 1) this reduces to the original
contiguous mask, so behavior is unchanged.
On gfx12.1 the CU mask ABI is one bit per WGP, interleaved across XCCs
(unit u of XCC x is at x + u*numXcc), and a PM4 dispatch runs on a single
XCC. The old flat-SE, two-bit-per-WGP flow mis-maps every mask on such
parts (e.g. gfx1250), marking all CUs outside XCC0 inactive.

Add a per-XCC path (gated on NumXcc > 1 within FAMILY_GFX12):

- Let a PM4 queue select its target XCC via BaseQueue::Create; existing
  callers are unchanged.
- Extend mask_config_t with numXcc/targetXcc; numXcc <= 1 keeps the
  legacy encoding so pre-gfx12.1 parts are unaffected.
- Make setCUMask/adjustMask honour the one-bit-per-WGP interleaved
  encoding and drive/validate each XCC's WGPs in isolation.
- Treat KFD topology as WGP-granular (drop the CU<->WGP factor of two)
  so the per-XCC WGP count and mask size are not halved.

Also fix SE readback on gfx12.5+, where HW_ID1 no longer carries SE: the
shader reads it from MSG_RTN_GET_SE_AID_ID. Rewrite adjustMaskXcc to
mirror KFD's interleaved enumeration and compaction of inactive WGPs,
handling asymmetric WGP-per-SA layouts (e.g. SA0=9, SA1=8 on gfx1250).

Signed-off-by: Alex Sierra <alex.sierra@amd.com>
Run the CU masking tests on gfx1250 now that they are multi-XCC aware
and expected to pass on this ASIC:

- Drop KFDQMTest.ExtendedCuMasking from the gfx1250 exclude profile.
- Split the CU masking tests (BasicCuMaskingLinear, BasicCuMaskingEven)
  out of PERMANENT_BLACKLIST_ALL_ASICS into CU_MASKING_BLACKLIST, and add
  a BLACKLIST_ALL_ASICS_NO_CU_MASK base that omits them. gfx1250 builds
  on this base so the tests are executed, while all other profiles keep
  excluding them via BLACKLIST_ALL_ASICS (unchanged behavior).
On gfx12.1 the CU mask ABI is one bit per WGP, interleaved across XCCs
(unit u of XCC x is at x + u*numXcc), and a PM4 dispatch runs on a single
XCC. The old flat-SE, two-bit-per-WGP flow mis-maps every mask on such
parts (e.g. gfx1250), marking all CUs outside XCC0 inactive.

Add a per-XCC path (gated on NumXcc > 1 within FAMILY_GFX12):

- Let a PM4 queue select its target XCC via BaseQueue::Create; existing
  callers are unchanged.
- Extend mask_config_t with numXcc/targetXcc; numXcc <= 1 keeps the
  legacy encoding so pre-gfx12.1 parts are unaffected.
- Make setCUMask/adjustMask honour the one-bit-per-WGP interleaved
  encoding and drive/validate each XCC's WGPs in isolation.
- Treat KFD topology as WGP-granular (drop the CU<->WGP factor of two)
  so the per-XCC WGP count and mask size are not halved.

Also fix SE readback on gfx12.5+, where HW_ID1 no longer carries SE: the
shader reads it from MSG_RTN_GET_SE_AID_ID. Rewrite adjustMaskXcc to
mirror KFD's interleaved enumeration and compaction of inactive WGPs,
handling asymmetric WGP-per-SA layouts (e.g. SA0=9, SA1=8 on gfx1250).

Signed-off-by: Alex Sierra <alex.sierra@amd.com>
@asierrag-amd
asierrag-amd force-pushed the users/asierrag-amd/develop_wip branch from 613730a to 54c8e26 Compare August 26, 2026 21:34

@cfreeamd cfreeamd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI-assisted pre-review (for @cfreeamd) — follow-up after gating approvals

Both rocrtst gating co-owners (@shwetagkhatri and @kentrussell) have now approved, which clears the gate. Noting for completeness that the earlier [Optional] item is not yet fixed: in extendedCuMaskingXcc() the random-subset loop is still uint32_t wgpMask = (rand() % ((1ULL << gridWgpPerXcc) - 1)) + 1; with 1u << u, so on gfx1250 (gridWgpPerXcc=36) 1u << u is UB for u>=32 and units 32-35 never appear in random subsets. This is a random-path coverage gap only — the linear and combination sweeps cover those units — so it is non-blocking. A uint64_t wgpMask / 1ULL << u cleanup would close it if you touch this again.

@amd-justchen

Copy link
Copy Markdown
Contributor

Noticed possible infra build flakes, also pulled in develop to get windows fix in ( #10951 )

@amd-justchen

amd-justchen commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Will merge given code owner approval.
The TheRock CI failures are only known infra/flake issues, unrelated to the kfdtest Cu-mask change (the diff is entirely under projects/rocr-runtime/libhsakmt/tests/kfdtest/):

  • Linux (gfx94X-dcgpu) / Test hip-tests (shard 4 of 4): 1 of 1235 tests failed - Unit_hipMemPrefetchAsync_v2_HostNuma_HostNumaCurrent, a runner NUMA-topology-dependent test in projects/hip-tests/catch/unit/memory/; a kfdtest-only change cannot affect it (environment flake)
  • Linux (gfx94X-dcgpu) / Test rocgdb-gpu (xfail): expected-fail advisory lane
  • Linux MI455 Test / Test Sanity Check: first failing step is Initialize containers (container provisioning) = infra

All four Build Packages jobs (Linux gfx94X, gfx950, MI455, Windows) are green, and the other required gate HIP NVIDIA CI Summary passed.

Additional notes:

For this one rocm-systems's TheRock ref needs to be bumped to something recent, like today's. I expect things will pass then, like in TheRock main.

Waiting for this bump #11050

@amd-justchen
amd-justchen merged commit b1ba58b into develop Sep 1, 2026
38 of 43 checks passed
@amd-justchen
amd-justchen deleted the users/asierrag-amd/develop_wip branch September 1, 2026 23:19
amd-justchen added a commit that referenced this pull request Sep 2, 2026
Bump the pinned `ROCm/TheRock` ref from `b45a060` (2026-08-26) to
`648a501` (2026-09-02) across the TheRock CI workflows.

Per Luis Machado's recommendation on #9738: rocm-systems' TheRock ref
needs bumping to something recent so those builds pass as they do on
TheRock `main`.

`648a501` is the current TheRock `main` tip and includes
[ROCm/TheRock#7820](ROCm/TheRock#7820) (guard
Unix-only `fcntl` import in the Windows driver/GPU sanity check), so
this newer ref does not break the Windows test lane.

Updates all 15 workflow files that share the develop TheRock pin (21
occurrences: checkout `ref:` lines and rccl `therock_ref` input
defaults). The intentionally separate multi-arch pin (`3c4ec01`) is left
unchanged.

Ref: #9738
@systems-assistant

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants