[libcu++][CUB][Thrust] Only include `<iosfwd>` to declare stream operators #12809
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12809"
general
weight: 0.35
bernhardmgruber
Description
Many CCCL headers include
<ostream>,<istream>or<sstream>only to declare stream operators. With libstdc++,<ostream>alone adds about 16k lines to an empty TU, while<iosfwd>adds about 600.This PR makes those headers include
<iosfwd>instead, through the new<cuda/std/__host_stdlib/iosfwd>wrapper:error_code,pointerandreference, are templates over the stream type already, so only the include changes.normal_distributionandpoisson_distributionnamed the format flags throughstd::ios_base, which needs its definition. They now name them through the stream type, like the other distributions.KeyValuePairand the iterators become templates over the stream type, so that declaring them only needs<iosfwd>. Wide character streams can now print them too. The policy example in the CUB developer guide shows the new form.cub/detail/logging.cuhonly includes<sstream>withCUB_DEBUG_LOGor when logging is compiled in.cub/device/dispatch/dispatch_merge.cuhdrops an unused<sstream>, andthrust/system/tbb/memory.han unused<ostream>.Code that streams CCCL types and relied on CCCL for
<ostream>,<istream>or<sstream>now needs to include them directly.c2h'shalf_tandbfloat16_tdid, so they now include<ostream>.Because the CUB stream operators are now templates, a user-provided function template such as
template <class K, class V> std::ostream& operator<<(std::ostream&, const cub::KeyValuePair<K, V>&)is ambiguous with CUB's. The CUB test utilities had such an operator. It was never selected, so this PR removes it.Not in this PR:
<complex>, which libstdc++ implements on top of<sstream>. It will get its own PR.std::cerr.log_dispatch()incub/detail/logging.cuh, which needs a completestd::stringstreamwhenever logging is compiled in.Measurements
Non-blank lines of the preprocessed output of a TU that only includes the header, without line markers (nvcc 13.4 host pass, GCC 15.2,
mainat 92873cab3f):| Header | C++17
main| C++17 PR | C++20main| C++20 PR ||---|---|---|---|---|
|
cuda/std/random| 71,653 | 67,459 | 76,181 | 71,897 ||
thrust/random.h| 63,920 | 59,725 | 68,951 | 64,666 ||
thrust/random/linear_congruential_engine.h| 38,466 | 21,912 | 44,122 | 25,520 ||
thrust/system/error_code.h| 38,292 | 31,978 | 43,949 | 37,565 ||
thrust/iterator/counting_iterator.h| 57,004 | 54,094 | 63,842 | 60,836 ||
cub/block/block_load.cuh| 54,116 | 51,210 | 59,030 | 56,028 ||
cub/block/block_scan.cuh| 70,508 | 67,604 | 75,371 | 72,371 ||
cub/block/block_reduce.cuh| 85,234 | 82,330 | 98,088 | 97,734 ||
cub/device/device_reduce.cuh| 139,820 | 139,862 | 147,674 | 147,716 ||
cub/cub.cuh| 289,202 | 289,378 | 297,208 | 297,384 ||
cub/device/device_reduce.cuhwithCCCL_DISABLE_LOGGING| 139,810 | 135,026 | 147,664 | 145,213 ||
thrust/device_vector.hwithCCCL_DISABLE_LOGGING| 182,578 | 177,832 | 190,474 | 188,061 |An empty TU has 20,663 lines in C++17 and 24,258 in C++20.
<ostream>is made of, for example 43% forthrust/random/linear_congruential_engine.h.cuda/std/__memory/construct_at.h, such ascub/block/block_reduce.cuh, save only 300 to 360 lines in C++20, because libstdc++'s<memory>includes<bits/ostream.h>there.<cub/cub.cuh>still get<sstream>throughcub/detail/logging.cuh. They grow by up to 176 lines, because each templated operator declaration takes three lines instead of one. WithCCCL_DISABLE_LOGGINGthey save about 4.8k lines in C++17 and 2.4k in C++20.Testing
Locally with CUDA 13.4 and GCC 15:
*_envdevice tests that print their tuning policies, and the CUB block and warp load, store, reduce, scan and radix rank, thread load and iterator tests. The printing, enum formatting and logging tests also in C++17.random,device_reference,dereference,raw_reference_castandreference_swaptests in C++17 and C++20With CUDA 13.4 and GCC 12, every changed header compiles in a TU that includes nothing else, also when the host
<iterator>is replaced by libstdc++'s<bits/stl_iterator_base_types.h>, and the operators work on narrow and wide streams once the TU includes<sstream>.Checklist