Skip to content

[CUB] Provide pointer traits to cache modified iterators#9623

Open
miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:pointer_traits_cache_modifier
Open

[CUB] Provide pointer traits to cache modified iterators#9623
miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:pointer_traits_cache_modifier

Conversation

@miscco

@miscco miscco commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This provides pointer_traits to the cache modified iterators

Its a bit dangerous, because it essentially drops the cache modifiers on the floor, but at the same time if we want to use a raw pointer anyway we might as well do the thing.

We could also just enable it for the default cases and leave .eg. volatile loads out

@miscco miscco requested a review from a team as a code owner June 29, 2026 08:46
@miscco miscco requested a review from NaderAlAwar June 29, 2026 08:46
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 29, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 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: 5e3b334a-2ac3-46d0-b952-5a41be38c212

📥 Commits

Reviewing files that changed from the base of the PR and between 391a2a5 and bf6cb75.

📒 Files selected for processing (2)
  • cub/cub/iterator/cache_modified_input_iterator.cuh
  • cub/test/catch2_test_iterator.cu
🚧 Files skipped from review as they are similar to previous changes (2)
  • cub/cub/iterator/cache_modified_input_iterator.cuh
  • cub/test/catch2_test_iterator.cu

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added ability to retrieve the underlying raw address from cache-modified input iterators.
    • Improved integration with standard address utilities, with correct behavior for both const and non-const iterators.
  • Tests
    • Re-enabled and expanded coverage for cache-modified iterator behavior.
    • Added assertions validating that address resolution matches the original raw pointer across applicable cache-load modifier variants.

Walkthrough

CacheModifiedInputIterator now exposes __unwrap() and a cuda::std::pointer_traits specialization with to_address() support. The iterator test is enabled and extended with cuda::std::to_address checks for both non-const and const raw-pointer construction.

Changes

CacheModifiedInputIterator pointer_traits support

Layer / File(s) Summary
__unwrap() and pointer_traits specialization
cub/cub/iterator/cache_modified_input_iterator.cuh
Adds __unwrap() plus a cuda::std::pointer_traits specialization that defines to_address() in terms of the wrapped raw pointer.
Enabled cache modified iterator test
cub/test/catch2_test_iterator.cu
Enables the cache-modified iterator test, parameterizes it over cache modifiers, and adds cuda::std::to_address assertions for non-const and const construction.

suggestion: __unwrap() is noexcept, but operator* is not. If the intent is that pointer extraction is always safe, consider documenting that assumption near the accessor.

important: The pointer_traits specialization returns ValueType* even when the iterator is built from const ValueType*. That drops constness for to_address() consumers.

suggestion: The specialization omits rebind. If generic code is expected to use pointer_traits<Iter>::rebind<U>, consider adding it or documenting that it is intentionally unsupported.


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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a053f7a1-b012-455d-a2fc-d6aa17178267

📥 Commits

Reviewing files that changed from the base of the PR and between 0d8f162 and 391a2a5.

📒 Files selected for processing (2)
  • cub/cub/iterator/cache_modified_input_iterator.cuh
  • cub/test/catch2_test_iterator.cu

Comment thread cub/cub/iterator/cache_modified_input_iterator.cuh
Comment thread cub/cub/iterator/cache_modified_input_iterator.cuh
@miscco miscco force-pushed the pointer_traits_cache_modifier branch from 391a2a5 to bf6cb75 Compare June 29, 2026 08:59
Comment on lines +267 to +270
[[nodiscard]] _CCCL_HOST_DEVICE_API static constexpr ValueType* to_address(const pointer iter) noexcept
{
return iter.__unwrap();
}

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.

@miscco should be we return a volatile ValueType* here in case the modifier is LOAD_VOLATILE?

constexpr auto cache_modifier = c2h::get<1, TestType>::value;
constexpr int TEST_VALUES = 11000;

c2h::device_vector<T> d_data(TEST_VALUES);

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.

Suggested change
c2h::device_vector<T> d_data(TEST_VALUES);
c2h::device_vector<T> d_data(TEST_VALUES, thrust::no_init);

cub::CacheModifiedInputIterator<cache_modifier, T>(const_cast<const T*>(thrust::raw_pointer_cast(d_data.data()))),
h_reference);

if constexpr (cache_modifier != cub::LOAD_CV && cache_modifier != cub::LOAD_VOLATILE)

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.

Q: Why do we have to exclude volatile modifiers? Do they lead to errors?

Comment on lines +217 to +222

/// Structure dereference
_CCCL_HOST_DEVICE_API ValueType* __unwrap() const noexcept
{
return ptr;
}

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.

Q: Do we need this? ptr is a public member :S

@github-actions

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 59m 13s: Pass: 1%/287 | Total: 1d 04h | Max: 59m 08s | Hits: 100%/6015

See results here.

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

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants