Repository navigation
Implement prefetching - #9723
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
See: #3126 (comment) that justifies this PR |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds ChangesPrefetch helper primitives
Assessment against linked issues
Out-of-scope changes
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 54e03265-c405-4ed7-9a6a-2dda8d2ab5e1
📒 Files selected for processing (6)
cub/benchmarks/bench/reduce/by_key.cucub/cub/agent/agent_reduce_by_key.cuhcub/cub/detail/prefetch.cuhcub/cub/device/dispatch/dispatch_reduce_by_key.cuhcub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuhcub/test/catch2_test_device_reduce_by_key_env.cu
This comment has been minimized.
This comment has been minimized.
010f57a to
6c6b182
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b9f60ed6-bca2-4a64-8026-af6c18a4821f
📒 Files selected for processing (1)
cub/cub/detail/prefetch.cuh
233e4e5 to
e299245
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
cub/cub/detail/prefetch.cuh (1)
133-135: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winimportant: keep
l1mapped to L2 until native L1 support is gated.The PR contract says
l1falls back to L2 on current unsupported architectures, but this branch always emitsprefetch.global.L1. Until there is an architecture-gated native path, emit L2 here.if constexpr (PrefetchLevel == LoadPrefetch::l1) { - asm volatile("prefetch.global.L1 [%0];" : : "l"(::cuda::ptx::__as_ptr_gmem(src_ptr + offset)) : "memory"); + asm volatile("prefetch.global.L2 [%0];" : : "l"(::cuda::ptx::__as_ptr_gmem(src_ptr + offset)) : "memory"); }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 4a3923e5-b623-4845-80b7-4ab8e42f07db
📒 Files selected for processing (2)
cub/cub/detail/prefetch.cuhcub/test/catch2_test_block_prefetch.cu
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fbusato
left a comment
There was a problem hiding this comment.
PrefetchStride template or runtime discussion is not a blocker.
The main point is that template arguments are for compile-time values/types, everything else should be at run-time if it doesn't affect performance. My guess is that early CUB versions use template args for constant propagation, affecting the design.
…tor params - Use Apache-2.0 WITH LLVM-exception on both new files (BSD-3-Clause is the legacy license; all recently added CUB files use Apache-2.0) - Drop BlockPrefetch's T template parameter and the static_assert that policed it; the element size is derived from the iterator's value type instead - Rename iterator template parameters to It: can_prefetch_from accepts any iterator category and tests for contiguous, so RandomAccessIterator was misleading
- Cover the iterators users actually pass: thrust::device_vector and thrust::universal_vector (rejected by can_prefetch_from, safe no-op) and cuda::buffer's heterogeneous_iterator (contiguous, accepted), per review - Use thrust::no_init for all vectors whose contents get overwritten - Use signed byte/offset math; a non-positive count now trivially no-ops
- Use cuda::ptr_rebind<char> instead of reinterpret_cast for the byte pointer - Call the __cvta_generic_to_global intrinsic directly instead of the cuda::ptx::__as_ptr_gmem library internal; drop the now-unneeded include - auto/const spelling cleanups in the bulk path
ac37d23 to
cc7b767
Compare
🥳 CI Workflow Results🟩 Finished in 3h 47m: Pass: 100%/287 | Total: 2d 15h | Max: 48m 04s | Hits: 97%/209186See results here. |
* Add cub::detail::BlockPrefetch tile-prefetch facility * Rename Prefetch template param to PrefetchLevel so it doesn't shadow function * add unit test * Address review: fix license, drop redundant T parameter, rename iterator params - Use Apache-2.0 WITH LLVM-exception on both new files (BSD-3-Clause is the legacy license; all recently added CUB files use Apache-2.0) - Drop BlockPrefetch's T template parameter and the static_assert that policed it; the element size is derived from the iterator's value type instead - Rename iterator template parameters to It: can_prefetch_from accepts any iterator category and tests for contiguous, so RandomAccessIterator was misleading * Rename Prefetch args to tile_base/items_to_prefetch and document tile-total semantics * Drop dead Doxygen guard and add block statement to NV_IF_TARGET * Fix unit test reviews (coverage, nits): - Cover the iterators users actually pass: thrust::device_vector and thrust::universal_vector (rejected by can_prefetch_from, safe no-op) and cuda::buffer's heterogeneous_iterator (contiguous, accepted), per review - Use thrust::no_init for all vectors whose contents get overwritten - Use signed byte/offset math; a non-positive count now trivially no-ops * Supress 'variable declared but not referenced' MSVC error * msvc warning in test file
fixes #9588 with a new design.
Adds
cub::detail::BlockPrefetch, a standalone block-scope facility for cooperatively emitting global-memory tile-prefetch hints.Design-only PR: it lands the facility and nothing else, no algorithm is wired to it yet (net diff is a single new header).
What this adds
cub::detail::LoadPrefetch- enum of prefetch targets:none,l2(prefetch.global.L2), l1 (prefetch.global.L1, falls back to L2 where real L1 prefetch is unavailable), andbulk_l2(TMAcp.async.bulk.prefetchinto L2; requires SM90+, no-op on older arch).cub::detail::BlockPrefetch<T, ThreadsPerBlock, Prefetch, PrefetchStride>- a collective with a single staticPrefetch(it, items_to_prefetch). The block's threads cooperatively stride the tile, one hint per cache line (or one TMA bulk prefetch forbulk_l2). A no-op for none and for iterators that can't yield a raw address (e.g.CacheModifiedInputIterator), so call sites need no enablement check.Everything is under detail, no public-API or stability commitment.