Skip to content

fix(ck): [CK] LCOPMILER-2487: Remove erroneous __restrict__ qualifier - #10229

Merged
shumway merged 1 commit into
developfrom
users/zgoldtho/ck/lcompiler-2487
Aug 3, 2026
Merged

fix(ck): [CK] LCOPMILER-2487: Remove erroneous __restrict__ qualifier#10229
shumway merged 1 commit into
developfrom
users/zgoldtho/ck/lcompiler-2487

Conversation

@zGoldthorpe

Copy link
Copy Markdown
Contributor

Motivation

Memory referenced via __restrict__-qualified pointers may not be modified in any way other than through said pointer so long as that pointer is alive.
This is ambiguated in the context of multiple threads, but insofar as it is modeled by noalias in LLVM, accessing memory through a __restrict__ pointer in one thread after having it modified by another thread violates this contract.

JIRA ID: https://amd-hub.atlassian.net/browse/LCOMPILER-2487

Technical Details

This is analogous to #9629.
The semantics for LLVM's noalias between threads was clarified in llvm/llvm-project#211507 to also prohibit modifications through the same pointer from other threads. Unless __restrict__ adopts a weaker guarantee in the future, p_shared_block is in violation of this contract.

Test Plan

Build and run: test_gemm_splitk

Test Result

Before:

[----------] Global test environment tear-down
[==========] 32 tests from 8 test suites ran. (77718 ms total)
[  PASSED  ] 29 tests.
[  FAILED  ] 3 tests, listed below:
[  FAILED  ] TestGemmSplitK_MK_NK/0.SmallM, where TypeParam = std::tuple<_Float16,_Float16,_Float16>
[  FAILED  ] TestGemmSplitK_MK_NK/0.MidLargeM, where TypeParam = std::tuple<_Float16,_Float16,_Float16>
[  FAILED  ] TestGemmSplitK_MK_NK/0.Regular, where TypeParam = std::tuple<_Float16,_Float16,_Float16>

 3 FAILED TESTS

With this patch, all tests pass.

Submission Checklist

@therock-pr-bot

therock-pr-bot Bot commented Jul 31, 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_xdlops_v2r4r2.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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, @shumway to do final approval

@michaelselehov michaelselehov 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.

LGTM too. Hopefully one day we can bring the __restrict__ back.

@shumway
shumway merged commit a1c4cbd into develop Aug 3, 2026
67 of 74 checks passed
@shumway
shumway deleted the users/zgoldtho/ck/lcompiler-2487 branch August 3, 2026 14:35
assistant-librarian Bot pushed a commit to ROCm/composable_kernel that referenced this pull request Aug 3, 2026
fix(ck): [CK] LCOPMILER-2487: Remove erroneous `__restrict__`
 qualifier (#10229)

## Motivation

<!-- Explain the purpose of this PR and the goals it aims to achieve.
-->
Memory referenced via `__restrict__`-qualified pointers may not be
modified in any way other than through said pointer so long as that
pointer is alive.
This is ambiguated in the context of multiple threads, but insofar as it
is modeled by `noalias` in LLVM, accessing memory through a
`__restrict__` pointer in one thread after having it modified by another
thread violates this contract.

JIRA ID: https://amd-hub.atlassian.net/browse/LCOMPILER-2487

## Technical Details

<!-- Explain the changes along with any relevant GitHub links. -->
This is analogous to #9629.
The semantics for LLVM's `noalias` between threads was clarified in
llvm/llvm-project#211507 to also prohibit modifications through the same
pointer from other threads. Unless `__restrict__` adopts a weaker
guarantee in the future, `p_shared_block` is in violation of this
contract.

## Test Plan

<!-- Explain any relevant testing done to verify this PR. -->
Build and run: `test_gemm_splitk`

## Test Result

<!-- Briefly summarize test outcomes. -->
Before:

```
[----------] Global test environment tear-down
[==========] 32 tests from 8 test suites ran. (77718 ms total)
[  PASSED  ] 29 tests.
[  FAILED  ] 3 tests, listed below:
[  FAILED  ] TestGemmSplitK_MK_NK/0.SmallM, where TypeParam = std::tuple<_Float16,_Float16,_Float16>
[  FAILED  ] TestGemmSplitK_MK_NK/0.MidLargeM, where TypeParam = std::tuple<_Float16,_Float16,_Float16>
[  FAILED  ] TestGemmSplitK_MK_NK/0.Regular, where TypeParam = std::tuple<_Float16,_Float16,_Float16>

 3 FAILED TESTS
```

With this patch, all tests pass.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
ntrost57 added a commit that referenced this pull request Aug 5, 2026
…mory (#10270)

## Motivation

`segmented_blockreduce()` in `csrmm_device_nnz_split.h` takes two
pointers into block-shared LDS, and both were marked `__restrict__`.
Each thread reads `vals[tid - j]`, which another thread wrote. The
attribute therefore does not hold.

Clang lowers `__restrict__` to LLVM `noalias`. LangRef states that
`noalias` also covers accesses from other threads, see
llvm/llvm-project#211507. The compiler is free to forward the LDS reads
across `__syncthreads()`. The reduction then drops the contributions of
the neighbour threads and returns wrong values.

The attribute also buys nothing here. The helper is force-inlined, and
its two arguments are distinct `__shared__` arrays, so alias analysis
already proves that they do not alias.

JIRA ID : LCOMPILER-2518

## Technical Details

This is analogous to #10229 and #9629.

The failure appears with a compiler that contains c3628c7f125b "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. An LDS array declared
inside a kernel is such an object. Together with the invalid
`__restrict__`, this lets the compiler drop the cross-thread partial
sums.

I confirmed both sides on MI300X (gfx942):

| compiler | source | result |
| --- | --- | --- |
| current weekly | `__restrict__` present | 40 pass, 8 fail |
| current weekly | `__restrict__` removed | 48 pass |
| same commit, AA change disabled | `__restrict__` present | 48 pass |

## Test Plan

Build and run, on MI300X:

```
hipsparse-test --gtest_filter='*nightly/spmm_csc.generic*'
```

The failing cases use the Chebyshev4 matrix, `transA = T`, and `f64_r`.

## Test Result

Before:

```
[==========] 48 tests from 1 test suite ran.
[  PASSED  ] 40 tests.
[  FAILED  ] 8 tests
```

With this patch, all 48 tests pass.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests

---------

Co-authored-by: Nico <31079890+ntrost57@users.noreply.github.com>
Co-authored-by: Daniel So <dso@amd.com>
shumway pushed a commit to ROCm/composable_kernel that referenced this pull request Aug 18, 2026
fix(ck): [CK] LCOPMILER-2487: Remove erroneous `__restrict__` qualifier

## Motivation

<!-- Explain the purpose of this PR and the goals it aims to achieve.
-->
Memory referenced via `__restrict__`-qualified pointers may not be
modified in any way other than through said pointer so long as that
pointer is alive.
This is ambiguated in the context of multiple threads, but insofar as it
is modeled by `noalias` in LLVM, accessing memory through a
`__restrict__` pointer in one thread after having it modified by another
thread violates this contract.

JIRA ID: https://amd-hub.atlassian.net/browse/LCOMPILER-2487

## Technical Details

<!-- Explain the changes along with any relevant GitHub links. -->
This is analogous to #9629.
The semantics for LLVM's `noalias` between threads was clarified in
llvm/llvm-project#211507 to also prohibit modifications through the same
pointer from other threads. Unless `__restrict__` adopts a weaker
guarantee in the future, `p_shared_block` is in violation of this
contract.

## Test Plan

<!-- Explain any relevant testing done to verify this PR. -->
Build and run: `test_gemm_splitk`

## Test Result

<!-- Briefly summarize test outcomes. -->
Before:

```
[----------] Global test environment tear-down
[==========] 32 tests from 8 test suites ran. (77718 ms total)
[  PASSED  ] 29 tests.
[  FAILED  ] 3 tests, listed below:
[  FAILED  ] TestGemmSplitK_MK_NK/0.SmallM, where TypeParam = std::tuple<_Float16,_Float16,_Float16>
[  FAILED  ] TestGemmSplitK_MK_NK/0.MidLargeM, where TypeParam = std::tuple<_Float16,_Float16,_Float16>
[  FAILED  ] TestGemmSplitK_MK_NK/0.Regular, where TypeParam = std::tuple<_Float16,_Float16,_Float16>

 3 FAILED TESTS
```

With this patch, all tests pass.


## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
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.

4 participants