Skip to content

perf(rocprim): reduce false sharing in lookback scan - #11702

Closed
Naraenda wants to merge 19 commits into
developfrom
users/naraenda/rocprim-lookback-false-sharing
Closed

Naraenda wants to merge 19 commits into
developfrom
users/naraenda/rocprim-lookback-false-sharing

Conversation

@Naraenda

@Naraenda Naraenda commented Sep 4, 2026

Copy link
Copy Markdown
Member

Motivation

Look-back scan is an integral part of many primitive algorithms. It relies heavily on atomic load/store operations. These operate on cachelines, and may cause issues akin to false sharing. This PR introduces a tunable mechanism to pad atomic flags to reduce this false sharing.

Partially addresses the following tickets:

JIRA ID : EXSWSTRHPC-330
JIRA ID : EXSWSTRHPC-331

Technical Details

  • Padding is a compile-time mechanism.
    This is added as a template parameter to lookback_scan_state.
  • On the host-side we must resolve the required lookback scan state which we only can know on runtime.
    This is solved by leveraging the config launching mechanism, were use a visitor pattern to get compile time access to the config.
  • The padding is introduced by wrapping the (packed) flag type.
  • The padding parameter is added to the device scan config.
  • No additional tuning is done.
    • Manually modifying some of the configs did result in a performance increase.

Test Plan

Performance should not change, as configs should be generated in a later PR.

Test Result

Verified no change in kernels before and after these changes:

# Compile benchmark_device_scan with --save-temps
grep -v '^[[:space:]]*[^[:alpha:]]' *.s.old | md5sum
# 4ae345b846f0b8074204d72151e3d1e7 -- gfx908, hash may very if rebased.
grep -v '^[[:space:]]*[^[:alpha:]]' *.s.new | md5sum
# 4ae345b846f0b8074204d72151e3d1e7 -- gfx908, hash may very if rebased.

Submission Checklist

@therock-pr-bot

therock-pr-bot Bot commented Sep 4, 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/rocprim/rocprim/include/rocprim/device/config_types.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/device_config_helper.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/lookback_scan_state.hpp, projects/rocprim/rocprim/include/rocprim/device/device_scan.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

therock-pr-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

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

@assistant-librarian assistant-librarian Bot added the organization: streamhpc contributors from streamhpc label Sep 4, 2026
@Naraenda Naraenda changed the title Users/naraenda/rocprim lookback false sharing perf(rocprim): reduce false sharing in lookback scan Sep 4, 2026
@Naraenda Naraenda self-assigned this Sep 9, 2026
@Naraenda
Naraenda force-pushed the users/naraenda/rocprim-lookback-false-sharing branch from 3c82a3c to e0b503a Compare September 17, 2026 09:50
@Naraenda

Copy link
Copy Markdown
Member Author

Rebased.

@amd-jmahovsky amd-jmahovsky 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.

Some comments. We might also want to add a test that uses non-zero alignment to ensure correct output.

@Naraenda
Naraenda force-pushed the users/naraenda/rocprim-lookback-false-sharing branch from e0b503a to 728de81 Compare September 24, 2026 09:03

@amd-jmahovsky amd-jmahovsky 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

@amd-jmahovsky

Copy link
Copy Markdown
Contributor

@Naraenda This is legitimately failing CI with a compile error:

[hipCUB] /__w/rocm-libraries/rocm-libraries/external-rocm-libraries/projects/hipcub/hipcub/include/hipcub/agent/../backend/rocprim/agent/single_pass_scan_operators.hpp:226:38: error: too many template arguments for class template 'lookback_scan_state'
[hipCUB]   226 |     using NativeT = rocprim::detail::lookback_scan_state<T, true, 0, SINGLE_WORD>;
[hipCUB]       |                                      ^                               ~~~~~~~~~~~~

plus other errors that follow.

@Naraenda

Copy link
Copy Markdown
Member Author

@Naraenda This is legitimately failing CI with a compile error:

[hipCUB] /__w/rocm-libraries/rocm-libraries/external-rocm-libraries/projects/hipcub/hipcub/include/hipcub/agent/../backend/rocprim/agent/single_pass_scan_operators.hpp:226:38: error: too many template arguments for class template 'lookback_scan_state'
[hipCUB]   226 |     using NativeT = rocprim::detail::lookback_scan_state<T, true, 0, SINGLE_WORD>;
[hipCUB]       |                                      ^                               ~~~~~~~~~~~~

plus other errors that follow.

AFAIK, this happens because TheRockCI does not handle depedent builds well. E.g. for hipCUB it will use the rocPRIM from develop, and not from source.

I do think I can find a workaround for this.

@Naraenda
Naraenda force-pushed the users/naraenda/rocprim-lookback-false-sharing branch from 67dab51 to f25f562 Compare September 25, 2026 07:31
@amd-jmahovsky

Copy link
Copy Markdown
Contributor

@Naraenda You mentioned finding a workaround for the failing CI. Any update on this? I suppose I can have this gardened and just have it merged in, but will it then break TheRock?

@Naraenda

Copy link
Copy Markdown
Member Author

@Naraenda You mentioned finding a workaround for the failing CI. Any update on this? I suppose I can have this gardened and just have it merged in, but will it then break TheRock?

It's already included: f25f562

@amd-jmahovsky

Copy link
Copy Markdown
Contributor

Closing because there is a newer PR: #12972

stanleytsang-amd added a commit that referenced this pull request Oct 6, 2026
…to hipccl3) (#12972)

Port of #11702 (by @Naraenda) to the hipccl3 layout, so the change lands
in `projects/hipccl/hipccl3/` instead of the retired `projects/`
location. The original PR will be closed once this one is accepted.

## Original description

## Motivation

Look-back scan is an integral part of many primitive algorithms. It
relies heavily on atomic load/store operations. These operate on
cachelines, and may cause issues akin to false sharing. This PR
introduces a tunable mechanism to pad atomic flags to reduce this false
sharing.

Partially addresses the following tickets:

JIRA ID : EXSWSTRHPC-330
JIRA ID : EXSWSTRHPC-331

## Technical Details

* Padding is a compile-time mechanism.
  This is added as a template parameter to `lookback_scan_state`.
* On the host-side we must resolve the required lookback scan state
which we only can know on runtime.
This is solved by leveraging the config launching mechanism, were use a
visitor pattern to get compile time access to the config.
* The padding is introduced by wrapping the (packed) flag type.
* The padding parameter is added to the device scan config.
* **No additional tuning is done.**
* Manually modifying some of the configs did result in a performance
increase.

## Test Plan

Performance should not change, as configs should be generated in a later
PR.

## Test Result

Verified no change in kernels before and after these changes:

```sh
# Compile benchmark_device_scan with --save-temps
grep -v '^[[:space:]]*[^[:alpha:]]' *.s.old | md5sum
# 4ae345b846f0b8074204d72151e3d1e7 -- gfx908, hash may very if rebased.
grep -v '^[[:space:]]*[^[:alpha:]]' *.s.new | md5sum
# 4ae345b846f0b8074204d72151e3d1e7 -- gfx908, hash may very if rebased.
```

## Submission Checklist

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

## About this port

- Commits are the original 13 commit(s), with their authors and messages
unchanged. Only the paths were remapped (`projects/<name>/` ->
`projects/hipccl/hipccl3/<name>/`). The commit IDs differ from the
originals, as they must.
- Result: 4 files changed, 414 insertions(+), 261 deletions(-).
- `git am --3way` applied it cleanly on top of `develop`.
- **Not built or tested here.** No CI covers `projects/hipccl` yet, so
the checks on this PR do not exercise the change. Please build the
affected hipccl3 component and run its relevant tests before merging.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Nara Prasetya <nara@streamhpc.com>
Co-authored-by: amd-jmahovsky <jeffrey.mahovsky@amd.com>
amd-jmahovsky added a commit that referenced this pull request Oct 9, 2026
## Motivation

#11702 did add optimizations,
but did not include them to the tuning mechanisms. This PR addresses
that and tunes said algorithms for MI300X.

JIRA ID : EXSWSTRHPC-330
JIRA ID : EXSWSTRHPC-331

## Technical Details

* 345fe33:
#11702 (should be dropped)
* 96b6d8f: adds the new parameters to
the search space
* 36cee5f: allows tuning with
mismatching default parameters
* 3fd8430: the resulting configs

## Test Plan

* Tests pass. 
* Performance improved.

## Test Result

* CI passes.
* Performance verified on MI300X node.

## Submission Checklist

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

---------

Co-authored-by: amd-jmahovsky <jeffrey.mahovsky@amd.com>
@amd-jmahovsky amd-jmahovsky reopened this Oct 15, 2026
NguyenNhuDi added a commit that referenced this pull request Oct 15, 2026
## Motivation

#11702 did add optimizations,
but did not include them to the tuning mechanisms. This PR addresses
that and tunes said algorithms for MI300X.

This PR should not be merged before
#11702. After the
aforementioned PR is merged, commit
345fe33
should be dropped from this PR.

JIRA ID : EXSWSTRHPC-330
JIRA ID : EXSWSTRHPC-331

## Technical Details


345fe33:
#11702 (should be dropped)

96b6d8f:
adds the new parameters to the search space

36cee5f:
allows tuning with mismatching default parameters

3fd8430:
the resulting configs

## Test Plan

Tests pass.
Performance improved.

## Test Result

CI passes.
Performance verified on MI300X node.

## Submission Checklist

- [ ] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

---------

Co-authored-by: Ed D'Azevedo <98369794+EdDAzevedo@users.noreply.github.com>
Co-authored-by: Mark Gates <mark.gates@amd.com>
Co-authored-by: Mahovsky <jmahovsk@amd.com>
Co-authored-by: Daming Feng <dmfeng8898@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
NguyenNhuDi added a commit that referenced this pull request Oct 15, 2026
## Motivation

#11702 did add optimizations,
but did not include them to the tuning mechanisms. This PR addresses
that and tunes said algorithms for MI300X.

This PR should not be merged before
#11702. After the
aforementioned PR is merged, commit
345fe33
should be dropped from this PR.

JIRA ID : EXSWSTRHPC-330
JIRA ID : EXSWSTRHPC-331

## Technical Details


345fe33:
#11702 (should be dropped)

96b6d8f:
adds the new parameters to the search space

36cee5f:
allows tuning with mismatching default parameters

3fd8430:
the resulting configs

## Test Plan

Tests pass.
Performance improved.

## Test Result

CI passes.
Performance verified on MI300X node.

## Submission Checklist

- [ ] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

---------

Co-authored-by: Ed D'Azevedo <98369794+EdDAzevedo@users.noreply.github.com>
Co-authored-by: Mark Gates <mark.gates@amd.com>
Co-authored-by: Mahovsky <jmahovsk@amd.com>
Co-authored-by: Daming Feng <dmfeng8898@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
@NguyenNhuDi

Copy link
Copy Markdown
Contributor

closing in favour of #13756

stanleytsang-amd pushed a commit that referenced this pull request Oct 15, 2026
## Motivation

#11702 did add optimizations,
but did not include them to the tuning mechanisms. This PR addresses
that and tunes said algorithms for MI300X.

This PR should not be merged before
#11702. After the
aforementioned PR is merged, commit
345fe33
should be dropped from this PR.

JIRA ID : EXSWSTRHPC-330
JIRA ID : EXSWSTRHPC-331

## Technical Details


345fe33:
#11702 (should be dropped)

96b6d8f:
adds the new parameters to the search space

36cee5f:
allows tuning with mismatching default parameters

3fd8430:
the resulting configs

## Test Plan

Tests pass.
Performance improved.

## Test Result

CI passes.
Performance verified on MI300X node.

## Submission Checklist

- [ ] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

---------

Co-authored-by: Ed D'Azevedo <98369794+EdDAzevedo@users.noreply.github.com>
Co-authored-by: Mark Gates <mark.gates@amd.com>
Co-authored-by: Mahovsky <jmahovsk@amd.com>
Co-authored-by: Daming Feng <dmfeng8898@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
@NguyenNhuDi
NguyenNhuDi deleted the users/naraenda/rocprim-lookback-false-sharing branch October 16, 2026 19:24
@NguyenNhuDi
NguyenNhuDi restored the users/naraenda/rocprim-lookback-false-sharing branch October 16, 2026 19:24
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