← Back to Pull requests

fix (rocprim): Update lookback scan and ordered_block_id optimizations to include gfx1250 and gfx1250-strict #11620

Merged
stanleytsang-amd merged 8 files (84 lines) on Sep 24, 2026 15:38 UTC
View on GitHub
stanleytsang-amd stanleytsang-amd commented on Sep 02, 2026 17:06 UTC
Author

Motivation

PR has been modified since creation to include gfx1250-strict support.

The same technical conditions which necessitated having the slow threadfence workaround in lookback_scan and ordered_block_id with atomics for maximum performance on MI300-series GPUs also exist on MI400-series GPUs.

In the process of carrying forward the workaround for MI455x/gfx1250, I realized that we did not properly support it in rocPRIM. gfx1250 was grouped together with RDNA4 (perhaps because gfx1200/gfx1201 are RNDA4) - this is wrong, gfx1250 is CDNA5. I have added CDNA5 support to rocPRIM.

Technical Details

Update the aforementioned optimizations to also be in effect for gfx1250.

Test Plan

Ran device_partition which uses lookback_scan on gfx1250 to verify it is in effect. Built and ran full test suite on gfx1200 to ensure I did not break compatibility with RDNA4. Built tests on gfx1201, gfx1250 to check it is .

Test Result

The above checks passed.

Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
  • JIRA ID: ROCM-28420

    Diff: 84 lines (+65 / -19) across 8 files Reviewer: amd-hsong Review duration: 31591m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.40) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 84 lines diff across 8 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 5 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.266
    Real PR Conversation Timeline
    21 items
    therock-pr-bot[bot] therock-pr-bot[bot] commented on Sep 02, 2026 17:12 UTC
    Bot

    <!-- therock-pr-bot-policy-check -->

    ✅ All Checks Passed — Ready for Review

    | Check | Status | Details |
    |---|:---:|---|
    | 📝 PR Description | ✅ Pass | — |
    | ⛔ Forbidden Files | ✅ Pass | — |
    | 🧪 Unit Test | ⚠️ Warning | Error: Source/code files changed without an accompanying unit test.<br>Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).<br>Current: code file(s) changed: projects/rocprim/rocprim/include/rocprim/config.hpp, projects/rocprim/rocprim/include/rocprim/device/config_types.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/lookback_scan_state.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/ordered_block_id.hpp, projects/rocprim/rocprim/include/rocprim/intrinsics/atomic.hpp (+2 more); no test file found |
    | 🔎 pre-commit | ✅ Pass | — |
    | 🚫 Draft PR | 🔜 To Be Enabled | — |
    | 🚩 Feature Flag | 🔜 To Be Enabled | — |
    | 📊 Code Coverage | 🔜 To Be Enabled | — |
    | 🤖 therock-pr-bot | ✅ Pass | — |

    🎉 All checks passed! This PR is ready for review.

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

    🙋 Wish to Override Policy?

    therock-pr-bot[bot] therock-pr-bot[bot] commented on Sep 02, 2026 17:12 UTC
    Bot

    <!-- therock-pr-bot-fix-policies -->
    🎉 All checks passed! This PR is ready for review.

    NguyenNhuDi NguyenNhuDi commented on Sep 02, 2026 20:56 UTC
    Contributor

    @stanleytsang-amd there seems to be some compile errors related to the changes:
    https://github.com/ROCm/rocm-libraries/actions/runs/33659735785/job/100357235705?pr=11620#step:15:6302.

    To fix this you need to add the target in rocprim/rocprim/include/rocprim/device/config_types.hpp

    amd-hsong amd-hsong commented on code on Sep 08, 2026 19:21 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/device/detail/lookback_scan_state.hpp:1
    @@ -46,7 +46,7 @@
     // Global coherence of prefixes_*_values is ensured by atomic_load/atomic_store that bypass
     // cache.
     #ifndef ROCPRIM_DETAIL_LOOKBACK_SCAN_STATE_WITHOUT_SLOW_FENCES
    -    #if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx942__) || defined(__gfx950__) || defined(__gfx9_4_generic__))
    +    #if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx942__) || defined(__gfx950__) || defined(__gfx9_4_generic__)) || defined(__gfx1250__)

    Should "|| defined(__gfx1250__)" be inside the second pair of parentheses? Like
    #if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx942__) || defined(__gfx950__) || defined(__gfx9_4_generic__) || defined(__gfx1250__))

    amd-hsong amd-hsong commented on code on Sep 08, 2026 19:23 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/intrinsics/atomic.hpp:1
    @@ -375,8 +375,8 @@ namespace detail
         ROCPRIM_DEVICE ROCPRIM_INLINE void atomic_fence_release_vmem_order_only()
         {
             __builtin_amdgcn_fence(__ATOMIC_RELEASE, "workgroup");
    -#if ROCPRIM_TARGET_RDNA4
    -        // RDNA4 (gfx12) splits waitcnt: wait for all store counts to complete
    +#if ROCPRIM_TARGET_CDNA5
    +        // CDNA5 (gfx1250) splits waitcnt: wait for all store counts to complete

    What will happen to #if ROCPRIM_TARGET_RDNA4, now that it is removed from the condition?

    amd-hsong amd-hsong commented on code on Sep 08, 2026 19:23 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/intrinsics/atomic.hpp:1
    @@ -395,8 +395,8 @@ namespace detail
         /// developers that know what they are doing.
         ROCPRIM_DEVICE ROCPRIM_INLINE void atomic_fence_acquire_order_only()
         {
    -#if ROCPRIM_TARGET_RDNA4
    -        // RDNA4 (gfx12) splits waitcnt: wait for all load counts to complete
    +#if ROCPRIM_TARGET_CDNA5
    +        // CDNA5 (gfx1250) splits waitcnt: wait for all load counts to complete

    What will happen to #if ROCPRIM_TARGET_RDNA4?

    stanleytsang-amd stanleytsang-amd commented on code on Sep 10, 2026 18:30 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/device/detail/lookback_scan_state.hpp:1
    @@ -46,7 +46,7 @@
     // Global coherence of prefixes_*_values is ensured by atomic_load/atomic_store that bypass
     // cache.
     #ifndef ROCPRIM_DETAIL_LOOKBACK_SCAN_STATE_WITHOUT_SLOW_FENCES
    -    #if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx942__) || defined(__gfx950__) || defined(__gfx9_4_generic__))
    +    #if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx942__) || defined(__gfx950__) || defined(__gfx9_4_generic__)) || defined(__gfx1250__)

    Yes, you're right. Sorry, I should move this PR to draft state, it's still in a WIP.

    stanleytsang-amd stanleytsang-amd commented on code on Sep 14, 2026 17:35 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/intrinsics/atomic.hpp:1
    @@ -375,8 +375,8 @@ namespace detail
         ROCPRIM_DEVICE ROCPRIM_INLINE void atomic_fence_release_vmem_order_only()
         {
             __builtin_amdgcn_fence(__ATOMIC_RELEASE, "workgroup");
    -#if ROCPRIM_TARGET_RDNA4
    -        // RDNA4 (gfx12) splits waitcnt: wait for all store counts to complete
    +#if ROCPRIM_TARGET_CDNA5
    +        // CDNA5 (gfx1250) splits waitcnt: wait for all store counts to complete

    RDNA4 never "needed" this in the first place, it was me incorrectly labelling gfx1250 (which needs this) as RDNA4. Interestingly enough, when compiling for gfx1200 and gfx1201 (RDNA4), it seems to be happy with either asm volatile("s_wait_storecnt 0x0" : : : "memory"); or __builtin_amdgcn_s_waitcnt(/vmcnt/ 0 | (/exp_cnt/ 0x7 << 4) | (/lgkmcnt/ 0xf << 8));.

    stanleytsang-amd stanleytsang-amd commented on code on Sep 14, 2026 17:36 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/intrinsics/atomic.hpp:1
    @@ -395,8 +395,8 @@ namespace detail
         /// developers that know what they are doing.
         ROCPRIM_DEVICE ROCPRIM_INLINE void atomic_fence_acquire_order_only()
         {
    -#if ROCPRIM_TARGET_RDNA4
    -        // RDNA4 (gfx12) splits waitcnt: wait for all load counts to complete
    +#if ROCPRIM_TARGET_CDNA5
    +        // CDNA5 (gfx1250) splits waitcnt: wait for all load counts to complete

    RDNA4 will go the default __builtin_amdgcn_s_waitcnt(/vmcnt/ 0 | (/exp_cnt/ 0x7 << 4) | (/lgkmcnt/ 0xf << 8)); call like all other architectures.

    amd-hsong amd-hsong commented on code on Sep 14, 2026 22:14 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/device/detail/lookback_scan_state.hpp:1
    @@ -46,7 +46,8 @@
     // Global coherence of prefixes_*_values is ensured by atomic_load/atomic_store that bypass
     // cache.
     #ifndef ROCPRIM_DETAIL_LOOKBACK_SCAN_STATE_WITHOUT_SLOW_FENCES
    -    #if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx942__) || defined(__gfx950__) || defined(__gfx9_4_generic__) || defined(__gfx1250__)) 
    +    #if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx942__) || defined(__gfx950__) || defined(__gfx9_4_generic__) ||
    +        defined(__gfx1250__) || defined(__gfx1250-strict__))

    defined(__gfx1250-strict__) => defined(__gfx1250_strict__)? see https://github.com/ROCm/rocm-systems/pull/11551/changes

    amd-hsong amd-hsong commented on code on Sep 14, 2026 22:15 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/config.hpp:1
    @@ -120,7 +120,7 @@
     #undef ROCPRIM_TARGET_UNKNOWN
     
     // See https://llvm.org/docs/AMDGPUUsage.html#instructions
    -#if defined(__gfx1250__)
    +#if defined(__gfx1250__) || defined(__gfx1250-strict__)

    defined(__gfx1250-strict__) => defined(__gfx1250_strict__)

    amd-hsong amd-hsong commented on Sep 14, 2026 22:19 UTC
    Reviewer

    Looks like the new target is spelled as __gfx1250_strict__

    stanleytsang-amd stanleytsang-amd commented on code on Sep 14, 2026 22:44 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/config.hpp:1
    @@ -120,7 +120,7 @@
     #undef ROCPRIM_TARGET_UNKNOWN
     
     // See https://llvm.org/docs/AMDGPUUsage.html#instructions
    -#if defined(__gfx1250__)
    +#if defined(__gfx1250__) || defined(__gfx1250-strict__)

    Done

    amd-hsong amd-hsong commented on code on Sep 14, 2026 22:58 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/config.hpp:1
    @@ -197,6 +204,16 @@
              || __builtin_amdgcn_processor_is("gfx10-1-generic") \
              || __builtin_amdgcn_processor_is("gfx12-generic"))
     #else
    +    #if defined(ROCPRIM_TARGET_CDNA5)
    +        #define ROCPRIM_IS_CDNA5() 1
    +    #else
    +        #define ROCPRIM_IS_CDNA5() 0
    +    #endif
    +    #if defined(ROCPRIM_TARGET_CDNA3)

    Should this be #if defined(ROCPRIM_TARGET_CDNA4)? Then the lines below become

            #define ROCPRIM_IS_CDNA4() 1
        #else
            #define ROCPRIM_IS_CDNA4() 0
        #endif
    

    amd-jmahovsky amd-jmahovsky commented on code on Sep 14, 2026 23:02 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/device/config_types.hpp:1
    @@ -328,6 +335,8 @@ constexpr target_arch get_target_arch_from_name(const char* const arch_name, con
         ROCPRIM_RETURN_IF_ARCH(gfx1153);
         ROCPRIM_RETURN_IF_ARCH(gfx1200);
         ROCPRIM_RETURN_IF_ARCH(gfx1201);
    +    ROCPRIM_RETURN_IF_ARCH(gfx1250);
    +    ROCPRIM_RETURN_IF_ARCH(gfx1250-strict);

    should this be gfx1250_strict?

    amd-hsong amd-hsong commented on Sep 14, 2026 23:06 UTC
    Reviewer

    Sorry, I have one more question - see above.

    amd-hsong amd-hsong commented on code on Sep 14, 2026 23:07 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/device/config_types.hpp:1
    @@ -328,6 +335,8 @@ constexpr target_arch get_target_arch_from_name(const char* const arch_name, con
         ROCPRIM_RETURN_IF_ARCH(gfx1153);
         ROCPRIM_RETURN_IF_ARCH(gfx1200);
         ROCPRIM_RETURN_IF_ARCH(gfx1201);
    +    ROCPRIM_RETURN_IF_ARCH(gfx1250);
    +    ROCPRIM_RETURN_IF_ARCH(gfx1250-strict);

    Looks like they spell the offload target as gfx1250-strict.

    scchan scchan commented on Sep 18, 2026 16:32 UTC
    Reviewer

    Reviewed at high-level for gfx1250-strict, LGTM

    stanleytsang-amd stanleytsang-amd commented on code on Sep 18, 2026 16:37 UTC
    Code Review
    projects/rocprim/rocprim/include/rocprim/config.hpp:1
    @@ -197,6 +204,16 @@
              || __builtin_amdgcn_processor_is("gfx10-1-generic") \
              || __builtin_amdgcn_processor_is("gfx12-generic"))
     #else
    +    #if defined(ROCPRIM_TARGET_CDNA5)
    +        #define ROCPRIM_IS_CDNA5() 1
    +    #else
    +        #define ROCPRIM_IS_CDNA5() 0
    +    #endif
    +    #if defined(ROCPRIM_TARGET_CDNA3)

    Sorry I didn't see your comment earlier - yes you are right, I will fix this now. Thank you

    amd-hsong amd-hsong approved these changes on Sep 18, 2026 17:06 UTC
    Approved Reviewer

    LGTM. Thanks.

    Reviewers
    Assignees
    stanleytsang-amd stanleytsang-amd
    Labels
    risk: low confidence: 90.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.6% · Lower = rushed or shallow review
    90.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.7% · Safe to merge
    3.7%