Repository navigation
[CUB] Use one item per thread when cub::DeviceTransform fills values over 512 bytes - #11919
SamMausberg wants to merge 1 commit into
Conversation
…over 512 bytes The fill tuning of the vectorized transform kernel stages up to 16 values per thread. Above 512 bytes, these can spill to local memory (17 KiB per thread for 1 KiB values on sm_90+), which the driver reserves for every thread the device can hold, e.g. about 7 GiB for a fill of 4 KiB values on an RTX 5070 Ti. Such values now get one item per thread. Fixes NVIDIA#11758
📝 SummarySummary by CodeRabbit
WalkthroughFor fill operations with output elements larger than 512 bytes, the vectorized policy now uses one item per thread. A new test checks policy selection across five compute capabilities and verifies filled values for two output sizes. ChangesLarge-value fill tuning
Assessment against linked issues
Suggested reviewers: Fixed issue severity: <fixed_issue_severity>Medium</fixed_issue_severity> Priority: ➖ Normal Change: Bug fix Merge Risk: 🔵 Low · up to Large fills currently use one item per thread, but the test does not assert that the vectorized algorithm is selected. Add that assertion so a policy regression cannot restore stack growth without failing the test.
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cub/test/catch2_test_device_transform.cu (1)
588-598: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winsuggestion: Assert the vectorized algorithm as well as the item count.
The test checks
items_per_threadon a separately constructed selector, then checks only the output values fromDeviceTransform::Fill. A different Fill policy can therefore pass the test if it produces the same values. Assertalgorithm == TransformAlgorithm::vectorizedin the selector check to protect the intended large-fill policy.Suggested fix
- REQUIRE(policy_selector_t{}(cuda::compute_capability{cc}).vectorized.items_per_thread == 1); + const auto policy = policy_selector_t{}(cuda::compute_capability{cc}); + REQUIRE(policy.algorithm == TransformAlgorithm::vectorized); + REQUIRE(policy.vectorized.items_per_thread == 1);
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository: NVIDIA/cccl/.coderabbit.yaml
- Review profile: CHILL
- Plan: Enterprise
- Run ID:
b45eb014-c1d1-49a1-8da3-85aace60372d
📒 Files selected for processing (2)
cub/cub/device/dispatch/tuning/tuning_transform.cuhcub/test/catch2_test_device_transform.cu
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
bernhardmgruber
left a comment
There was a problem hiding this comment.
Fix is a bit crude, since I think we should probably scale the items per thread as the value types get bigger, but it's good enough.
|
/ok to test f450e7c |
Description
closes #11758
As suggested in the issue, fills of values larger than 512 bytes now use one item per thread (
TransformVectorizedPolicy{128, 1, 1}) on all architectures. With 16 items per thread, 1 KiB values already needed 17392 bytes of stack per thread on sm_90 and sm_120, which the driver reserves for every thread the device can hold. Up to 512 bytes, the existing tuning needs at most 120 bytes of stack and stays as it is, so all types in the fill benchmark keep their policy. Comparing the policy selector's output before and after for 17 compute capabilities, 0 to 2 inputs and value sizes from 1 byte to 96 KiB shows no other change.For
struct { unsigned char b[N]; }, main → this PR. Stack fromcuobjdump --dump-resource-usage; memory (the repro from the issue) and fill throughput measured on an RTX 5070 Ti with CUDA 13.2:For larger values, one item per thread still needs stack that grows with the value size, 3.7 to 12.8 KiB per thread for 4 KiB values. The prefetch kernel needs no stack for 4 KiB values. It writes 1-byte aligned types byte by byte, though, at 25 GB/s for 1 KiB values.
Transformwith large inputs stages them the same way and could get the same limit in a follow-up.The new test
DeviceTransform::Fill large power-of-two typechecks the policy for sm_75 to sm_120, which fails on main, and fills 2 KiB values, below the 4096-byte kernel parameter limit of CTK 12.0. Allcub.test.device.transform*tests pass on the RTX 5070 Ti with gcc 13.3, and the test file builds without warnings with clang 18, gcc 12 and clang 21 as host compilers. Not tested: MSVC, NVHPC, CTK 12.x.Checklist