Repository navigation
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. |
7dde881 to
dccf644
Compare
|
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 BlockLoad direct-load prefetch support, extends block-load tests, and threads a separate load-prefetch setting through reduce-by-key tuning, dispatch, and benchmarking. ChangesBlockLoad prefetch support
Reduce-by-key prefetch wiring
Assessment against linked issues
Out-of-scope changes
Suggested reviewers
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
cub/test/catch2_test_block_load.cu (1)
216-232: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winsuggestion: Add a brief comment explaining the
#if IPT == 1guard. The test hardcodesitems_per_thread = 4, so the guard exists only to register the case once across the IPT-parametrized builds, not because of a platform constraint. Without a note the intent is opaque.As per path instructions: "If a test is unsupported, expected to fail, disabled, or skipped on a platform, motivate it with a comment".
Source: Path instructions
cub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh (1)
1644-1652: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winsuggestion:
policy_selector_from_hubrebuildsReduceByKeyPolicywithout forwardingReduceByKeyPolicyT::LOAD_PREFETCH, soload_prefetchsilently falls back tonone. Harmless today since every hub tuning defaults tonone, but the moment a compile-time tuning sets a prefetch level this path will drop it. Forward it for symmetry with the runtime selectors.ReduceByKeyPolicyT::SCAN_ALGORITHM, lookback_delay_policy_from_type<typename ReduceByKeyPolicyT::detail::delay_constructor_t>, + ReduceByKeyPolicyT::LOAD_PREFETCH, };cub/cub/agent/agent_reduce_by_key.cuh (1)
745-751: 🎯 Functional Correctness | 🔵 Trivialsuggestion:
LOAD_PREFETCHis independent ofLOAD_ALGORITHMhere, so this can emit prefetch hints even on non-BLOCK_LOAD_DIRECTpaths. If that exception is intentional, document it; otherwise add an explicit guard before issuing the hints.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 52afeb81-727b-458c-9d07-510a403a77db
📒 Files selected for processing (6)
cub/benchmarks/bench/reduce/by_key.cucub/cub/agent/agent_reduce_by_key.cuhcub/cub/block/block_load.cuhcub/cub/device/dispatch/dispatch_reduce_by_key.cuhcub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuhcub/test/catch2_test_block_load.cu
| #include <cub/util_ptx.cuh> | ||
| #include <cub/util_type.cuh> | ||
|
|
||
| #include <cuda/__annotated_ptr/apply_access_property.h> |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Locate the header that defines cuda::access_property
fd -t f . --full-path -p '*__annotated_ptr*' | sort
rg -nP 'struct\s+access_property|class\s+access_property|namespace\s+__ap' -g '*annotated_ptr*' -C2
Repository: NVIDIA/cccl
Length of output: 254
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the target file and locate the declaration/definition of cuda::access_property.
git ls-files 'cub/cub/block/block_load.cuh' 'cuda/**' | sed -n '1,120p'
echo '--- block_load.cuh ---'
cat -n cub/cub/block/block_load.cuh | sed -n '1,120p'
echo '--- search access_property ---'
rg -n --hidden --glob '!**/build/**' --glob '!**/.git/**' 'access_property' cuda cub libcudacxx thrust c 2>/dev/null | sed -n '1,200p'
Repository: NVIDIA/cccl
Length of output: 34556
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find headers related to apply_access_property and access_property.
fd -a -t f 'apply_access_property.h' .
fd -a -t f 'access_property' .
Repository: NVIDIA/cccl
Length of output: 1404
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- file size ---'
wc -l cub/cub/block/block_load.cuh
echo '--- block_load.cuh (relevant lines) ---'
sed -n '1,120p' cub/cub/block/block_load.cuh | cat -n
echo '--- all occurrences of access_property ---'
rg -n --hidden --glob '!**/build/**' --glob '!**/.git/**' 'access_property' . | sed -n '1,240p'
echo '--- candidate headers containing access_property definition ---'
rg -n --hidden --glob '!**/build/**' --glob '!**/.git/**' 'struct\s+access_property|enum\s+class\s+access_property|namespace\s+access_property' cuda libcudacxx cub thrust c | sed -n '1,240p'
Repository: NVIDIA/cccl
Length of output: 40925
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Narrow search to CUDA headers that could define cuda::access_property.
fd -a -t f 'apply_access_property.h' cuda
fd -a -t f 'access_property.h' cuda
fd -a -t f '__access_property' cuda
Repository: NVIDIA/cccl
Length of output: 241
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- block_load.cuh ---'
sed -n '1,120p' cub/cub/block/block_load.cuh | cat -n
echo '--- access_property references ---'
rg -n --hidden --glob '!**/build/**' --glob '!**/.git/**' 'access_property' cuda cub libcudacxx thrust c | sed -n '1,240p'
echo '--- candidate defining headers ---'
fd -a -t f 'access_property.h' cuda libcudacxx cub thrust c
fd -a -t f 'apply_access_property.h' cuda libcudacxx cub thrust c
Repository: NVIDIA/cccl
Length of output: 40264
important: include <cuda/__annotated_ptr/access_property.h> explicitly here; ::cuda::access_property::normal is used directly, so this header should not rely on the transitive include from <cuda/__annotated_ptr/apply_access_property.h>.
Source: Coding guidelines
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
cub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh (1)
41-44: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick wincritical: inserting
load_prefetchbeforescan_algorithmbreaks the many positionalReduceByKeyPolicy{...}initializers that were not updated below. For example, Line 1040 now feedsBLOCK_SCAN_WARP_SCANSintoload_prefetch, so the SM80/SM90/SM100 selector tables stop compiling. Keep the new field at the end of the aggregate or update every positional initializer to passBlockLoadPrefetch::noneexplicitly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: fd11b43c-09ed-4480-84c7-eff772d0c110
📒 Files selected for processing (5)
cub/cub/block/block_load.cuhcub/cub/device/device_run_length_encode.cuhcub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuhcub/test/catch2_test_block_load.cucub/test/catch2_test_device_reduce_env.cu
🚧 Files skipped from review as they are similar to previous changes (2)
- cub/test/catch2_test_block_load.cu
- cub/cub/block/block_load.cuh
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
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/tuning/tuning_reduce_by_key.cuh (1)
43-52: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winimportant: Adding
load_prefetchhere makes the existing 6-field aggregate initializers silently keep compiling, butpolicy_selector_from_hubstill constructsReduceByKeyPolicywithoutReduceByKeyPolicyT::LOAD_PREFETCHon Lines 1645-1652. Any hub-based selector with a non-default prefetch will therefore be downgraded back todetail::BlockLoadPrefetch::none, so the dispatch layer never sees the tuned value. Please threadLOAD_PREFETCHthrough that conversion too. As per path instructions, "Focus on algorithm correctness, temporary-storage protocol, dispatch/policy selection, stream behavior, CUDA error handling, synchronization, memory access safety, performance regressions, and test coverage."Source: Path instructions
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 716bb11e-fd08-4c27-855e-e2626b5cdab4
📒 Files selected for processing (1)
cub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh
5ad52a2 to
500c518
Compare
This comment has been minimized.
This comment has been minimized.
| // Fire prefetch before look-back stall so data arrives in L2 in time | ||
| if constexpr (AgentReduceByKeyPolicyT::LOAD_PREFETCH != detail::BlockLoadPrefetch::none) | ||
| { | ||
| const int items_to_prefetch = static_cast<int>(::cuda::std::min(num_remaining, static_cast<OffsetT>(TILE_ITEMS))); |
There was a problem hiding this comment.
Suggestion: prefetching is not a memory access wrt. to access checking, so we can prefetch any amount of data, even out of bounds (we just later must not actually touch out of bounds data, as usual). Since the min has a small cost and creates a branch and two code paths, maybe we are more efficient with just always prefetching the entire tile (thus loading more data then necessary in the last tile):
| const int items_to_prefetch = static_cast<int>(::cuda::std::min(num_remaining, static_cast<OffsetT>(TILE_ITEMS))); | |
| const int items_to_prefetch = TILE_ITEMS; |
Can you try to measure the impact?
There was a problem hiding this comment.
that will take some time as TMA work preempts. I 'll leave your comment open as a reminder before we wrap
| if constexpr (can_prefetch_block_load<RandomAccessIterator>) | ||
| { | ||
| using input_t = cub::detail::it_value_t<RandomAccessIterator>; | ||
| const ::cuda::std::size_t total_bytes = static_cast<::cuda::std::size_t>(items_to_prefetch) * sizeof(input_t); |
There was a problem hiding this comment.
Suggestion: we probably never prefetch more than 4GiB of data, so the total_bytes and offset below could just be a 32-bit unsigned int.
@bernhardmgruber we discussed this offline, we should not unwrap cache modified iterators. User might've expressed intent to skip caching to preserve other data in cache. If we unwrap iterator on a minor update, we'll evict some cache all of a suden and likely cause unpleasent performance investigation. The two options are: consider prefetch as a hint and skip it for iterators, or static assert and fail to compile. |
|
beautiful results - encodings incoming. worth noting that many tunings have |
3dc95c1 to
6826bd2
Compare
This comment has been minimized.
This comment has been minimized.
1223650 to
6dfff87
Compare
This comment has been minimized.
This comment has been minimized.
- use raw ptx intrinsic
6dfff87 to
f853fbe
Compare
f853fbe to
d99482b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| static constexpr BlockLoadAlgorithm load_algorithm = BLOCK_LOAD_DIRECT; | ||
| using delay_constructor = exponential_backon_jitter_window_constructor_t<2044, 240>; | ||
| static constexpr CacheLoadModifier load_modifier = LOAD_CA; | ||
| static constexpr BlockLoadPrefetch load_prefetch = BlockLoadPrefetch::none; |
There was a problem hiding this comment.
Suggestion: Please avoid making changes to the obsolete tunings and policy hubs.
BLOCK_LOAD_DIRECT_PREFETCHPrefetch as an option to all cub::BlockLoad algorithms
😬 CI Workflow Results🟥 Finished in 2h 46m: Pass: 97%/287 | Total: 12d 08h | Max: 2h 45m | Hits: 19%/1060811See results here. |
bernhardmgruber
left a comment
There was a problem hiding this comment.
In principle, LGTM. Just a lot of nits, so I'll wait another round before approving.
| //! Enumerates the cache levels that :cpp:class:`cub::BlockLoad` can prefetch into when using | ||
| //! :cpp:enumerator:`cub::BLOCK_LOAD_DIRECT`. |
There was a problem hiding this comment.
Maybe:
| //! Enumerates the cache levels that :cpp:class:`cub::BlockLoad` can prefetch into when using | |
| //! :cpp:enumerator:`cub::BLOCK_LOAD_DIRECT`. | |
| //! Enumerates the cache levels that :cpp:class:`cub::BlockLoad` can prefetch into. |
| //! Pass as the ``Prefetch`` template argument of :cpp:class:`cub::BlockLoad`. The default is | ||
| //! ``detail::BlockLoadPrefetch::none`` (no prefetch). | ||
| //! | ||
| //! .. note:: | ||
| //! Prefetch hints are silently suppressed for :cpp:class:`cub::CacheModifiedInputIterator`. | ||
| //! Those iterators apply a load modifier (e.g. ``LOAD_NC``) that routes loads through a | ||
| //! specific cache path. Emitting a prefetch hint for the same addresses would touch caches | ||
| //! the user explicitly chose to bypass, defeating the purpose of the modifier. | ||
| //! Prefetch hints are also suppressed for any iterator type that is not a contiguous | ||
| //! memory iterator (i.e., one for which ``std::to_address`` is not applicable). |
There was a problem hiding this comment.
Strong suggestion: This documents behavior of BlockLoad, not the enum. So this comment should be moved to BlockLoad.
| //! @endrst | ||
| enum class BlockLoadPrefetch : int | ||
| { | ||
| //! No prefetch hint emitted. Default behavior, identical to not specifying a prefetch level. |
There was a problem hiding this comment.
| //! No prefetch hint emitted. Default behavior, identical to not specifying a prefetch level. | |
| //! No prefetch hint emitted. |
| { | ||
| //! No prefetch hint emitted. Default behavior, identical to not specifying a prefetch level. | ||
| none, | ||
| //! Emit an L2 prefetch hint (``prefetch.global.L2``) before loading each cache line. |
There was a problem hiding this comment.
| //! Emit an L2 prefetch hint (``prefetch.global.L2``) before loading each cache line. | |
| //! Emit an L2 prefetch hint (``prefetch.global.L2``) to all affected cache lines. |
| //! No prefetch hint emitted. Default behavior, identical to not specifying a prefetch level. | ||
| none, | ||
| //! Emit an L2 prefetch hint (``prefetch.global.L2``) before loading each cache line. | ||
| //! All threads collectively cover the tile, each issuing one instruction per cache line. |
There was a problem hiding this comment.
Suggestion: Again, I would document this at the level of BlockLoad
Applies to the other enumerators as well.
| { | ||
| using input_t = cub::detail::it_value_t<RandomAccessIterator>; | ||
| const unsigned int total_bytes = static_cast<unsigned int>(items_to_prefetch) * sizeof(input_t); | ||
| const auto* const base = reinterpret_cast<const char*>(::cuda::std::to_address(block_src_it)); |
There was a problem hiding this comment.
Suggestion: base is a bit generic as a name, I'd use something like:
| const auto* const base = reinterpret_cast<const char*>(::cuda::std::to_address(block_src_it)); | |
| const auto* const src_ptr = reinterpret_cast<const char*>(::cuda::std::to_address(block_src_it)); |
To say it's the source memory and it really is a pointer.
| if (::cuda::device::__block_elect_one()) | ||
| { | ||
| // srcMem must be 16-byte aligned per PTX ISA; align base down and extend size to compensate | ||
| const auto* const aligned_base = ::cuda::align_down(base, 16); | ||
| const unsigned int prefix = static_cast<unsigned int>(base - aligned_base); | ||
| const unsigned int aligned_size = ::cuda::round_up(total_bytes + prefix, 16u); | ||
| if (aligned_size > 0) | ||
| { | ||
| #if _CCCL_CUDA_COMPILER(NVHPC) || __CUDA_ARCH__ >= 900 | ||
| asm volatile("cp.async.bulk.prefetch.L2.global [%0], %1;" | ||
| : | ||
| : "l"(::cuda::ptx::__as_ptr_gmem(aligned_base)), "r"(aligned_size) | ||
| : "memory"); | ||
| #endif | ||
| } | ||
| } |
There was a problem hiding this comment.
Strong suggestion: I think I would guard the entire block by NV_IF_TARGET(NV_PROVIDES_SM90. There is no point in running the elect_one or the address computation if we are not going to run the asm statement later. We could even consider, to static_assert when we are not compiling for SM90+.
| //! - BlockLoad can be optionally specialized by different data movement strategies: | ||
| //! | ||
| //! #. :cpp:enumerator:`cub::BLOCK_LOAD_DIRECT`: | ||
| //! A :ref:`blocked arrangement <flexible-data-arrangement>` of data is read directly from memory. | ||
| //! Combine with ``Prefetch = cub::detail::BlockLoadPrefetch::l2`` to emit L2 prefetch hints before each load. |
There was a problem hiding this comment.
Suggestion: I would add another paragraph after the numerators that lists the prefetch enumerators. We can then document that they only work for BLOCK_LOAD_DIRECT today. But the design is open to use prefetching for the other modifiers as well.
| if constexpr (Prefetch != detail::BlockLoadPrefetch::none) | ||
| { | ||
| detail::prefetch_block_load_tile<ThreadsPerBlock, 128, Prefetch>( | ||
| linear_tid, block_src_it, ThreadsPerBlock * ItemsPerThread); | ||
| } |
There was a problem hiding this comment.
Suggestion: if we put the handling of detail::BlockLoadPrefetch::none into prefetch_block_load_tile, we don't need to repeat the if constexpr all over the place here and below ;)
| template <int ItemsPerThread, | ||
| int ThreadsInBlock, | ||
| cub::BlockLoadAlgorithm LoadAlgorithm, | ||
| typename InputIteratorT, | ||
| typename OutputIteratorT> | ||
| typename OutputIteratorT, | ||
| cub::detail::BlockLoadPrefetch Prefetch = cub::detail::BlockLoadPrefetch::none> |
There was a problem hiding this comment.
Suggestion: In general, try to place non-deducible template parameters first, because you have to list them at the call site. But then you don't have to list the ones that can be deduced by the compiler. So here, I would put the Prefetch parameter after LoadAlgorithm, so InputIteratorT and OutputIteratorT can be deduced.
* Use 32-bit multiplication for the tile byte count (truncated anyway) * Guard the entire bulk_l2 branch with NV_IF_TARGET(NV_PROVIDES_SM_90) instead of only the asm statement * Handle LoadPrefetch::none inside prefetch_tile so call sites need no enablement check * Move the Prefetch template parameter before the defaulted PrefetchStride so common call sites don't restate the stride
|
I am closing this in favor of #9723 |
fixes #9588 and #9589 with one shot
Introduce prefetching as an enum option to all
BlockLoadalgorithms and add testsThe value options for prefetching are
{l2, l1, bulk_l2, none}. None is no-op and onlyl2andbulk_l2(TMA) are currently supported. If user tries L1 it will just dispatch to L2 silently.Native ptx assembly is being used, until instructions is exposed as a library option later on.
!is_primitive<input_t>Current PR is expected to emit no SASS diffs with main