Skip to content

fix(ck): [CK] LCOMPILER-2577: Remove erroneous __restrict__ qualifier - #10574

Open
michaelselehov wants to merge 7 commits into
ROCm:developfrom
michaelselehov:users/michaelselehov/ck/lcompiler-2577
Open

fix(ck): [CK] LCOMPILER-2577: Remove erroneous __restrict__ qualifier#10574
michaelselehov wants to merge 7 commits into
ROCm:developfrom
michaelselehov:users/michaelselehov/ck/lcompiler-2577

Conversation

@michaelselehov

Copy link
Copy Markdown
Contributor

Motivation

The gridwise GEMM kernels take a pointer to block-shared LDS memory. Every thread of the block writes into that memory, and other threads then read it after block_sync_lds(). The __restrict__ qualifier does not hold for such a pointer.

Clang lowers __restrict__ to LLVM noalias. LangRef states that noalias also prohibits modifications through other threads, see llvm/llvm-project#211507. The compiler is therefore free to keep an LDS value in a register across the barrier. The kernel then reads stale data and produces wrong results.

JIRA ID: LCOMPILER-2577

Technical Details

This is analogous to #10229 and #9629.

The failing test is TestGroupedConvndBwdData2d/9.Test2D. The kernel that fails the numerical check is DeviceGroupedConvBwdDataMultipleD_Xdl_CShuffle_v1<256, 64, 16, 16, 4, 4, Default, 16, 16, 1, 1, 4, 1, 1, 1>. It uses gridwise_gemm_multiple_d_xdl_cshuffle.hpp and gridwise_gemm_xdlops_v2r3.hpp. This patch removes __restrict__ from p_shared in both headers, 4 places in total.

I confirmed all sides on MI300X (gfx942):

compiler source result
current staging __restrict__ present FAILED, max err 130
current staging __restrict__ removed PASSED
baseline with the AA change reverted __restrict__ present PASSED

The baseline compiler contains a revert of llvm/llvm-project#196923 "Reapply [AA] No synchronization effects for never-escaping identified local". That commit tells alias analysis that a synchronizing operation cannot affect an object that never escapes the function. Together with the invalid __restrict__, this lets the compiler drop the values that other threads wrote into LDS.

Test Plan

Build and run, on MI300X:

test_grouped_convnd_bwd_data --gtest_filter='TestGroupedConvndBwdData2d/9.*'

Test Result

Before:

max err: 130, number of errors: 137150, 22.78% wrong values
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestGroupedConvndBwdData2d/9.Test2D, where TypeParam = std::tuple<float,ck::tensor_layout::convolution::NHWGK,ck::tensor_layout::convolution::GKYXC,ck::tensor_layout::convolution::NHWGC>

 1 FAILED TEST

With this patch:

[       OK ] TestGroupedConvndBwdData2d/9.Test2D (3223 ms)
[  PASSED  ] 1 test.

Submission Checklist

The gridwise GEMM kernels take a pointer to block-shared LDS memory. Every
thread of the block writes into that memory, and other threads then read it
after `block_sync_lds()`. The `__restrict__` qualifier does not hold here.

Clang lowers `__restrict__` to LLVM `noalias`. LangRef states that `noalias`
also prohibits modifications through other threads, see
llvm/llvm-project#211507. The compiler is therefore free to keep an LDS value
in a register across the barrier, and the kernel reads stale data.

This is analogous to ROCm#10229 and ROCm#9629.

JIRA ID: LCOMPILER-2577
@therock-pr-bot

therock-pr-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

✅ 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.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/composablekernel/include/ck/tensor_operation/gpu/grid/gridwise_gemm_multiple_d_xdl_cshuffle.hpp, projects/composablekernel/include/ck/tensor_operation/gpu/grid/gridwise_gemm_xdlops_v2r3.hpp; 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

Copy link
Copy Markdown

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

@ronlieb

ronlieb commented Aug 12, 2026

Copy link
Copy Markdown

@shumway ok to land ?

@michaelselehov

Copy link
Copy Markdown
Contributor Author

I stopped re-running the failed CI jobs. This error repeats over and over again:

subprocess.CalledProcessError: Command '['/opt/python/cp312-cp312/bin/python', '-m', 'pip', 'install', '--force-reinstall', '--pre', 'rocm[libraries,devel]==10.1.0.dev0+f5a34f5ee296a8c235d4a25694aec3befbc657fd']' returned non-zero exit status 1.
Error: Error: failed to run script step: command terminated with non-zero exit code: error executing command [sh -e /__w/_temp/e3bc6a40-97ca-11f1-8415-69b9f438896e.sh], exit code 1

@ronlieb

ronlieb commented Aug 19, 2026

Copy link
Copy Markdown

@shumway can this be landed now ? we need a code owner to approve

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.

3 participants