Repository navigation
Vectorize output store in ublkcp DeviceTransform kernel - #9481
Conversation
12991ad to
c6559fb
Compare
|
/ok to test c6559fb |
|
/ok to test 365bf3a |
365bf3a to
c2a253d
Compare
|
/ok to test c2a253d |
|
@nanan-nvidia can you please post the output of |
This comment was marked as outdated.
This comment was marked as outdated.
| // When the caller guarantees aligned_size_t<N> num_items, i.e. the output pointer is N-byte aligned and the element | ||
| // count is a multiple of N, if 1. there are no predicates, 2. memory layout is contiguous, 3. semantically we can |
There was a problem hiding this comment.
Critical:
the element count is a multiple of N
This is only true for elements with power of two size. Think of aligned_size_t<16>{n} and int3*, which is valid for every n that is a multiple of 4.
There was a problem hiding this comment.
In vectorize_store we require both input element size and output element size to be pow2, so this should not be a bug.
From the definition,
explicit constexpr aligned_size_t(size_t __s) : value(__s) {
_CCCL_ASSERT(value % align == 0,
"aligned_size_t must be constructed with a size that is a multiple of the alignment");
}
It seems aligned_size_t<16>(n) just mean n % 16 == 0? Does it actually mean (sizeof(T) * n) % 16 == 0 semantically?
There was a problem hiding this comment.
aligned_size_t refers to a size in bytes, not in elements, at least according to what we currently document.
|
@nanan-nvidia the results look promising. I think the implementation needs a bit more work though. Please check out the notes I have from a discussion with DevTech working on PyTorch: https://github.com/NVIDIA-dev/cccl_private/issues/598. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/ok to test 6b64983 |
ublkcp kernel for deviceTransform when user promises cuda::aligned_size_t<16>…type-erased iterator)
…default-constructible outputs)
…ar3 is_aligned assert)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bernhardmgruber
left a comment
There was a problem hiding this comment.
This is looking quite good already. Here is some more feedback. I will try to have a more detailed look when I am back next week, because I need an IDE for that.
|
The benchmarks look pretty good in general. Some are showing strong regressions tough for small problem sizes, like |
I think this is the classical trade off: since we use a bit more registers when we vectorize, we have a bit worse occupancy, and the problem size is too small for vectorization to show its benefits. A quick run from my local RTX6000 card shows:
also when problem size is small, the noise tends to be a lot more pronounced too. |
That makes sense and your quick introspection seems to confirm that. I am fine with accepting the regressions for the otherwise massive benefit. |
|
/ok to test 813550f |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…n_vectorize in-kernel
…ctors need not set it)
bernhardmgruber
left a comment
There was a problem hiding this comment.
I believe the logic is fine. I'd like to give it another view next week, but the PR otherwise LGTM.
Can you please apply the few suggestions below. I think the overlapping of the can_vectorize with the bulk copy can save a few cycles. Please update one or two benchmarks again, so we have the latest perf.
Really great work!
Co-authored-by: Bernhard Manfred Gruber <[email protected]>
bernhardmgruber
left a comment
There was a problem hiding this comment.
I reviewed the vectorized store logic and I think it LGTM. Here are some renaming suggestions that would improve readability IMO:
|
@nanan-nvidia I added a bunch of commits with small fixes. The last commit overlaps the |
bernhardmgruber
left a comment
There was a problem hiding this comment.
@nanan-nvidia please consider the above naming suggestions to use in_vec instead of chunk and update the benchmarks. If perf looks good, we can merge.
|
/ok to test 0172a01 |
🥳 CI Workflow Results🟩 Finished in 3h 32m: Pass: 100%/287 | Total: 12d 13h | Max: 3h 31m | Hits: 9%/1671302See results here. |
* cub: vectorize ublkcp output stores for aligned_size_t transforms * cub: test DeviceTransform aligned_size_t vectorized store (same-width/narrowing/widening) * c/parallel: thread OutputAlign through transform_kernel name * cub: runtime-dispatch ublkcp vectorized output store via can_vectorize * cub: add tunable store_vec to ublkcp vectorized transform store * cub: test ublkcp vectorized transform store on generic counts (narrowing/widening) * cub: store_vec=1 disables ublkcp vectorized store; cap to 16B * cub: guard host vectorize check on contiguous output (fix c.parallel type-erased iterator) * cub: avoid default-constructing the ublkcp store buffer (support non-default-constructible outputs) * cub: gate host vectorize check on power-of-two element sizes (fix uchar3 is_aligned assert) * cub: update copyright year on vectorized transform test * cub: gate ublkcp store_vec on power-of-two width; add non-pow2 store_vec regression test * cub: clang-format vectorized transform store changes * cub: rename store_vec to store_vec_size; static_assert power-of-two store width * cub: address ublkcp vectorized store review (renames, head_padding assert, docs) * cub: resolve ublkcp store width in the policy selector and compute can_vectorize in-kernel * cub: treat store_vec_size 0 as auto in the ublkcp kernel (custom selectors need not set it) * Apply suggestions from code review Co-authored-by: Bernhard Manfred Gruber <[email protected]> * Guard test not using launch wrappers * Comment * Extend docs for unroll_factor * Overlap store vector check with bulk copy * cub: rename ublkcp gather locals to in_vec per review --------- Co-authored-by: Bernhard Manfred Gruber <[email protected]>
As per #9210, we noticed that the
ublkcpkernel forDeviceTransformhas unvectorized stores, leaving some performance on the table. This PR vectorizes the output store (STG.128) whenever it's safe. There is no change to existing call sites.The store width is controlled by a tunable policy knob
store_vec(output elements per store):0= auto (a 16-byte STG.128, the default),1= disable vectorization (the branch is compiled out, useful for register-heavy functors), andN= useNelements, silently capped to 16 bytes.Fixes: #8227
Benchmarks (B200)
Ref = stock CUB, Cmp = this PR. FAST = this PR faster.
For heavy and complex_cmp, we use the opt-out path (
store_vec=1), since in those cases we should disable the vectorized store. We also show the regressions at the end if vectorization is enabled for those cases.babelstream: before vs this PR (auto)
On heavy, complex, fibnacci, there are no impact from this pr since they disable vectorization (i.e.
store_vec_width=1)For example: