Skip to content

Test unaligned temp storage#9746

Merged
bernhardmgruber merged 2 commits into
NVIDIA:mainfrom
bernhardmgruber:temp_storage_alignment
Jul 10, 2026
Merged

Test unaligned temp storage#9746
bernhardmgruber merged 2 commits into
NVIDIA:mainfrom
bernhardmgruber:temp_storage_alignment

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Follow-up to: #9742

@bernhardmgruber bernhardmgruber requested a review from a team as a code owner July 8, 2026 10:04
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 8, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 8, 2026
Comment on lines +191 to +195
// randomly offset the temporary storage address by one byte
const int offset = GENERATE(random(0, 1));
c2h::device_vector<std::uint8_t> temp_storage(temp_storage_bytes + offset, thrust::no_init);

error = action(thrust::raw_pointer_cast(temp_storage.data()), temp_storage_bytes, args...);
error = action(thrust::raw_pointer_cast(temp_storage.data()) + offset, temp_storage_bytes, args...);

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.

🍿

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 don't mind this, but my issue with it is you may have a case where we don't test the regression this PR aims to fix. It might be better to add an explicit test case for scan that has unaligned temp storage

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.

I deem the probability of ALL calls to cub::DeviceScan across all unit tests across all CI jobs generating ONLY an offset of 0 so low that I believe it's almost certain we are going to cover it ;)

@bernhardmgruber bernhardmgruber Jul 9, 2026

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.

The reason I didn't add it for scan explicitly is, that we do actually need this test for every CUB device-scope algorithm. And for a second I considered asking claude to add those, until I noticed that every CUB device-scope algorithm goes through the launch helper, so there is a single point where we could test this for every algorithm at essentially no additional compile and runtime cost (there is no new scan instantiation and no additional test, we just perturb the existing tests a bit). I found that elegant.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e2ddaf85-658f-4823-abcf-c34b883c2b12

📥 Commits

Reviewing files that changed from the base of the PR and between 9d54f77 and 1a33c68.

📒 Files selected for processing (1)
  • cub/test/catch2_test_launch_helper.h

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Improved host-launched test coverage by varying temporary storage alignment during test execution.
    • Preserved existing CUDA error checking and device synchronization behavior.

Walkthrough

The host-side test launch helper now randomly offsets temporary storage by zero or one byte before invoking the action, while preserving existing CUDA error checks and synchronization.

Changes

Misaligned temporary storage coverage

Layer / File(s) Summary
Test helper exercises misaligned buffers
cub/test/catch2_test_launch_helper.h
The host-launched path allocates one additional byte when needed and passes the temporary-storage pointer shifted by the random offset.

Assessment against linked issues

Objective Addressed Explanation
Ensure lookahead scan handles temporary storage that is not 16-byte aligned [#9742] This change only modifies the test helper; no dispatch or lookahead scan implementation is updated to realign the temporary-storage pointer.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cub/cub/device/dispatch/dispatch_scan.cuh (1)

502-506: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

critical: DispatchScan still underreports temp storage here. aligned_temp_storage = ::cuda::align_up(...) can advance by up to alignment - 1 bytes, so allocating exactly temp_storage_bytes can overrun the buffer. Add the same padding used in invoke_lookahead.

🧹 Nitpick comments (1)
cub/cub/device/dispatch/dispatch_scan.cuh (1)

526-526: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: aligned_temp_storage is never reassigned; declare it const auto. As per coding guidelines: "All variables that are not modified must be declared const".

Also applies to: 1131-1131

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d4810340-1fc7-45c5-9e1b-d1a8dd25f73b

📥 Commits

Reviewing files that changed from the base of the PR and between ff80b87 and cee5da8.

📒 Files selected for processing (2)
  • cub/cub/device/dispatch/dispatch_scan.cuh
  • cub/test/catch2_test_launch_helper.h

Comment thread cub/cub/device/dispatch/dispatch_scan.cuh Outdated
Comment thread cub/test/catch2_test_launch_helper.h
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bernhardmgruber

bernhardmgruber commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Since #9565 also solved this issue, this PR becomes obsolete for main. However, we cannot backport #9565 because it has too many other dependencies. I hoped this PR would land before it, so we could backport.

I will retarget this PR to the 3.4 branch now.

I will limit this PR to the temporary storage test and open a new PR with a targeted fix for 3.4: #9781

@bernhardmgruber bernhardmgruber force-pushed the temp_storage_alignment branch from 9d54f77 to 1a33c68 Compare July 10, 2026 08:17
@bernhardmgruber bernhardmgruber changed the title Temp storage alignment fixes Test unaligned temp storage Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 36m: Pass: 100%/242 | Total: 11d 13h | Max: 2h 35m | Hits: 16%/915581

See results here.

@bernhardmgruber bernhardmgruber merged commit c3b50f0 into NVIDIA:main Jul 10, 2026
264 of 265 checks passed
@bernhardmgruber bernhardmgruber deleted the temp_storage_alignment branch July 10, 2026 12:56
@github-actions

Copy link
Copy Markdown
Contributor

Successfully created backport PR for branch/3.4.x:

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants