You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEA]: Find use cases for SOL Fancy Iterators #11915
I went through the rapids repositories with my agent with the following report:
Summary
Unwrapping and bulk copy are the right fix for fancy iterators that wrap contiguous memory. The synthesizing-iterator work is the right fix for iterators that produce values from their own state. Most of the cuDF performance history is the second shape, and treating those iterators as contiguous is what made those kernels slower.
Two shapes
A fancy iterator is either a wrapper over contiguous memory, or it synthesizes its value.
Memory wrappers are transform_iterator<F, T*>, zip_iterator<T*, U*>, zip_transform_iterator, transform_output_iterator<T*, G>, and transform_input_output_iterator over a pointer. Dereference loads or stores real bytes, then applies a function. cub::DeviceTransform takes cp.async.bulk on sm_90 and newer only when every input is contiguous and trivially relocatable, the output is dense, and addresses do not need to stay stable. These wrappers fail is_contiguous_iterator, so scan, reduce, and transform fall off the bulk-copy and vectorized paths even though the pointers underneath would qualify. That is the gap in this issue: on B200, cuDF’s JSON reset-segment scan is up to about 58% slower through cuda::transform_iterator(char*) and make_transform_output_iterator(uint8_t*) than through the raw pointers.
Synthesizing iterators produce a value from iterator state. On the synthesizing_block_load branch, __is_synthesizing_iterator_v is true for counting_iterator, constant_iterator, and shuffle_iterator, and for strided_iterator, transform_iterator, zip_iterator, and zip_transform_iterator only when every base is synthesizing. Thrust’s copies of those types specialize the same variable. A synthesizing input does not have a pointer to bulk-copy. load_algorithm_for_input therefore rewrites BLOCK_LOAD_TRANSPOSE, BLOCK_LOAD_WARP_TRANSPOSE, and BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED to BLOCK_LOAD_DIRECT, and nudges items_per_thread to a nearby power of two so the blocked index is a shift. The shared-memory transpose only coalesces loads that never happen.
The trait does not look inside the functor. transform_iterator<F, counting_iterator> is synthesizing even when F captures a pointer and loads through it. That is the dominant cuDF pattern, and it is the right classification for the load policy: the value the iterator yields is computed, so a transpose of that value is overhead. The hidden loads stay inside F, in whatever order F addresses them. Bulk-copying the iterator would invent a memcpy of values that were never in memory.
transform_output_iterator and transform_input_output_iterator are not in the trait. They are store-side adaptors. A zip is synthesizing only when every component is. A zip of a pointer and a counting iterator still has one real stream to move and one stream to synthesize.
How common each spelling is
Counts are files on the default branch of public GitHub, with NVIDIA/cccl excluded and the old thrust and cub repos excluded where the name would otherwise hit the library itself. A file with several call sites counts once. Forks, vendored CUB, and changelogs inflate the rarer patterns by roughly 5–10×. A “next to cub::Device” hit means both strings occur in the same file, not necessarily in the same call.
Spelling
Files
Next to cub::Device
make_transform_iterator
53,120
744
make_zip_iterator
28,480
386
counting_iterator and make_transform_iterator together
11,360
TransformInputIterator (legacy CUB name)
4,208
1,872
thrust::zip_iterator
3,376
make_transform_output_iterator
1,572
113
transform_input_output_iterator
832
32
make_transform_input_output_iterator
624
make_counting_transform_iterator
432
cuda::transform_iterator
295
65
cuda::make_transform_iterator
241
thrust::transform_output_iterator
248
zip_transform_iterator
136
cuda::zip_iterator
86
6
cuda::make_zip_iterator
75
make_zip_transform_iterator
5
make_transform_iterator stays about 48,000 even outside paths named thrust, cub, or third_party. That is the ordinary Thrust idiom, including host code. It is not a count of missed CUB fast paths.
The legacy CUB name is the one that actually shows up beside device algorithms: 1,872 files mention TransformInputIterator and cub::Device, against 65 for cuda::transform_iterator. transform_input_output_iterator is real but small, and only 32 of those files also mention cub::Device. zip_transform_iterator is almost unused outside CCCL (five call sites of the factory).
Narrower CUB pairings, still including forks:
transform_iterator with DeviceScan: 611. With DeviceReduce: 577. With DeviceTransform: 91.
zip_iterator with DeviceTransform: 111. With DeviceScan: 130.
transform_output_iterator with DeviceScan: 98.
Both a transform iterator and a transform-output iterator with DeviceScan: 70 files in 50 repos. After dropping forks, changelogs, and vendored tests, that is cuDF logical_stack.cuh, DGL neighbor sampling, and the AprilTag CUDA port. XGBoost’s row partitioner is the same call shape and does not contain the literal string transform_iterator.
make_transform_iterator also sits next to inclusive_scan in 1,864 files and exclusive_scan in 2,124. Those are Thrust scans, which still land in CUB.
Where the call sites actually live
cuDF is the cuda:: user. It has 124 files mentioning cuda::transform_iterator, 73 of them outside tests and benchmarks. Other non-test counts: 94 make_counting_transform_iterator, 39 make_zip_iterator, 6 make_transform_output_iterator, and no remaining thrust::make_transform_iterator. Only 15 of the cuda::transform_iterator files also mention cub::Device. The rest go through Thrust. The 94 counting-transform files are synthesizing iterators whose functors index captured pointers. The pointer-wrapper scan in logical_stack.cuh is the memory-wrapper case in the issue reproducer. The other two call sites cited on the issue are the same split: strings_column_factories.cu is a counting transform into thrust::exclusive_scan, and scan_inclusive.cu is a null-replacement / counting transform into thrust::inclusive_scan.
cuOpt has 30 files with make_zip_iterator and 5 with make_transform_output_iterator. The PDLP iteration (cccl#6143) already passes raw pointers into cub::DeviceTransform and uses a zip of three pointers only as the output, so the missed fast path is the vectorized store.
cuGraph has 9 files mentioning cuda::transform_iterator (one is a trait) and 86 non-test files with make_zip_iterator.
cuVS kmeans builds thrust::transform_iterator<Op, InputT*> and thrust::transform_iterator<Op, KeyValuePair*> and passes them to cub::DeviceReduce.
cuML has 3 make_transform_iterator files. RAFT has none.
Outside NVIDIA, the same call site is copied widely and owned by a few upstreams:
XGBoost’s GPU histogram has helpers whose purpose is to build these iterators, and row_partitioner.cuh feeds a counting transform plus a transform_output_iterator to DeviceScan::InclusiveScan.
DGL and GraphBolt sampling pass make_transform_iterator to DeviceScan::ExclusiveSum and use zip plus transform-output as the sink of copy_if.
PyTorch centralizes it in aten/src/ATen/cuda/cub.cuh as transform_iterator<Functor, const T*>.
FlashInfer’s top-k is mostly counting and strided iterators, plus a transform-output on the index store.
StringZilla replaced cub::TransformInputIterator with its own iterator.
AprilTag CUDA is the other small DeviceScan user in the 70-file set.
cuDF cases, sorted onto those two shapes
The cases collected in Bradley’s gist separate three mechanisms. They line up with the trait.
Memory wrappers, where unpack plus bulk copy or a vectorized load helps
cccl#8258.cuda::zip_iterator of two contiguous pointers into DeviceTransform (swap_ranges). Thrust already unpacks this zip. CUB does not, and the zipped form was much slower for large types. After an unpack, each stream meets the contiguous, trivially relocatable check.
This issue, and cuDF logical_stack.cuh. Bulk-copy the char*, apply the 0/1 functor on the staged values, scan, then do a vectorized store through the unwrapped uint8_t*. The output functor is a narrowing conversion.
cuVS kmeans reduce. Same as a vectorized load of T* with the functor applied after the load.
cuDF #21973. Materializing a typed iterator into a buffer before a reduce cost 2–4×. Unpacking a pointer-backed iterator keeps the fused reduce and still vectorizes. A type-erased iterator has no base to unpack; that 10–430% gap stays.
cuDF #17623 and #12900, the flat-type half. Replacing a materialized buffer with a transform was 10–50% faster, and materializing before unique_copy was 20–50% slower for non-nested types. The win is staying fused. Bulk copy adds more only when the base is a contiguous trivially copyable pointer and the functor stays cheap.
Bulk copy still requires 16-byte multiples, pointer alignment, and a tile that fits in shared memory. On Hopper, 1- and 2-byte multi-input transforms already prefer the vectorized kernel. A zip that contains a permutation or a counting iterator can bulk-copy only its pointer components.
Synthesizing iterators, where bulk copy is the wrong tool
cccl#9070 / cuDF #22632.thrust::tabulate of a wide row hash. The input is a counting iterator. The functor captures a column-major pointer and does a strided load per column. proclaim_copyable_arguments forced the vectorized DeviceTransform kernel, 8–16 items per thread, which is the 1.6–4× regression (4–6× in a third-party report). cuDF moved this to cub::DeviceFor::Bulk. The synthesizing policy’s direct load is the matching treatment. There is no input pointer to stage.
cuDF #24448. The same vectorized kernel, opted into by hand, made is_null and mask_to_bools about 2× faster and one_hot_encode about 1.35× faster, and made string like / char_types up to 11× slower. Those inputs are counting or bitmask iterators. A policy that treats every fancy iterator as contiguous reproduces this split.
cuDF #10511 left semi-join.copy_if over a counting iterator whose predicate probes a hash table. Occupancy went from 37% to 72% after the probe was pulled into a bool buffer, and join benchmarks moved 15–30%. The bytes that matter are random loads inside the predicate.
cuDF #23532 sort-merge join. Taking the row comparator out of DeviceSelect dropped the kernel from 120–255 registers to 48, and 358 of 378 benchmarks improved. Repacking that comparator onto a bulk-copied tile puts the registers back.
cuDF #23285 groupby offsets. A comparator over a counting iterator became a flag buffer plus copy_if, 14–22% faster on B200. The iterator was never a memcpy source.
cuDF #15018. The input iterator was also the stencil and was evaluated twice. The benchmark input was a counting iterator. Unwrapping does not remove the second pass.
cccl#8640. A transform_iterator used as a scatter map reported input_iterator_tag, the permutation_iterator inherited it, and thrust::scatter left the CUB path (2.5–3.3×, and new pool OOM). That was a category bug and is fixed. The visited stream is still a permutation. Bulk-copying it in iterator order would be wrong. cccl#7097 is the same kind of indirect stream, and the measurement is disputed.
cuDF #11864. A permutation_iterator inside inclusive_scan_by_key beat a separate gather by about 17%. That is one kernel instead of two. The visit order is not contiguous.
What to build
The unpack (unpack to pointers plus a function, repack on chip, a trait used where is_contiguous_iterator is used today) should be the memory-wrapper path only.
Automatic, with no user annotation:transform_iterator, zip_iterator, zip_transform_iterator, transform_output_iterator, and transform_input_output_iterator whose memory-backed bases are contiguous and trivially copyable, and for which __is_synthesizing_iterator_v is false. Apply bulk copy or a vectorized load to those bases, run the functor on the staged values, and synthesize any counting or constant components in registers. Output iterators unwrap to vectorized stores. transform_input_output_iterator needs both directions: load and apply the input function, store and apply the output function. This covers the issue reproducer, cccl#8258, cuVS kmeans, cuOpt’s zip stores, PyTorch’s const T* transform, and the legacy TransformInputIterator<F, T*> spelling. The 1,872-file TransformInputIterator set is the historical population of that last form.
Leave synthesizing iterators on the direct load from synthesizing_block_load. Do not stage them with cp.async.bulk. That includes the 11,360 files that combine counting_iterator with make_transform_iterator, cuDF’s 94 counting-transform files, and the tabulate, semi-join, sort-merge, and groupby cases. Their functors may still load memory. That load is not the iterator’s base, so neither a transpose nor a bulk copy of the iterator can make it coalesced. Heavy functors also need a separate choice of items per thread. The vectorized kernel’s 8–16 items per thread is the regression in cccl#9070 and cuDF #24448, independent of whether the iterator unwraps.
Ask the user to opt in only for a contiguous base the trait cannot see: a custom iterator, or a type-erased iterator such as the slow path in cuDF #21973. Do not ask them to opt a counting transform into bulk copy. Permutation and scatter maps stay gathers.
Hi! Here is a use case using fancy iterators in DeviceTransform that fails to reach SOL on B200. The benchmark below performs a delta transformation on a batch of arrays. What seems to be preventing good performance is that each thread needs to search for the corresponding array in the batch before performing the transformation on the element. Even if we simplify it by having every array be exactly the same size, removing the need for the search, the transform only reaches 25% of BW on B200.
Having a DeviceSegmentedTransform would probably solve this and make usage much simpler, do you have intention of adding such a function to the API?
Here is the benchmark:
// NVBench benchmark: batched "previous minus current" delta with cub::DeviceTransform.
//
// The batch is BatchSize arrays of about RefChunkBytes each (the reference size plus or
// minus max_size_delta elements), one device vector per array, filled with random
// values by CCCL's nvbench_helper. For every array a:
// out[a][0] = in[a][0]
// out[a][i] = in[a][i - 1] - in[a][i] for i > 0
//
// The whole batch is processed by a single DeviceTransform call over the flattened
// index range [0, total_elems). Array c spans [offsets[c], offsets[c + 1]) of that
// range, where offsets is the exclusive prefix sum of the array sizes; a flat index is
// mapped back to (array, element) with a binary search over offsets. Because no array
// is larger than the maximum array size, the search first covers a small window of
// arrays starting at idx / max_chunk_elems, and only searches the arrays after the
// window if idx lies past it.
// - input: a counting iterator yields the flat index; the op locates its array and
// reads the input arrays through a device array of per-array pointers.
// - output: a tabulate output iterator scatters each result to the matching element
// of the output arrays through a device array of per-array pointers.
//
// An untimed first run is copied to the host and checked against a host reference
// before the timed runs.
//
// Requires NVBench (link nvbench::main) and CCCL's nvbench_helper
// (nvbench_helper/nvbench_helper/nvbench_helper.cu, which links cuRAND).
// Run: ./cub_batched_delta [NVBench options, e.g. -a BatchSize=1024 -a RefChunkBytes=65536]
#include <cub/device/device_transform.cuh>
#include <cuda/iterator>
#include <cuda/std/algorithm>
#include <cuda/stream_ref>
#include <nvbench/nvbench.cuh>
#include <nvbench_helper.cuh>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/memory.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <vector>
struct ChunkElem {
size_t chunk; // array index within the batch
size_t i; // element index within the array
};
// Maps a flat index over the whole batch to (array, element).
struct BatchLayout {
static constexpr size_t search_window = 32; // number of arrays searched first
const size_t* offsets; // num_chunks + 1 entries, exclusive prefix sum of the array sizes
size_t num_chunks;
size_t max_chunk_elems; // no array has more elements than this
__device__ ChunkElem locate(size_t idx) const
{
// offsets[c] <= c * max_chunk_elems, so the array containing idx is at least `first`.
// Search the window [first, window_end) if idx lies inside it, otherwise the arrays
// after it.
const size_t first = idx / max_chunk_elems;
const size_t window_end = cuda::std::min(first + search_window, num_chunks);
const bool in_window = idx < offsets[window_end];
const size_t* begin = offsets + (in_window ? first : window_end);
const size_t* end = offsets + (in_window ? window_end : num_chunks) + 1;
const size_t chunk = cuda::std::upper_bound(begin, end, idx) - offsets - 1;
return {chunk, idx - offsets[chunk]};
}
};
// Transform op: flat index -> delta of the corresponding element of its input array.
template <typename T>
struct PrevMinusCur {
const T* const* in; // one pointer per array
BatchLayout layout;
__device__ T operator()(size_t idx) const
{
const ChunkElem e = layout.locate(idx);
const T* chunk = in[e.chunk];
// The first element of each array is stored as is.
return (e.i == 0) ? chunk[0] : chunk[e.i - 1] - chunk[e.i];
}
};
// Output function: stores the result for a flat index into its output array.
template <typename T>
struct StoreToChunk {
T* const* out; // one pointer per array
BatchLayout layout;
// tabulate_output_iterator requires a signed index type.
__device__ void operator()(ptrdiff_t idx, T value) const
{
const ChunkElem e = layout.locate(static_cast<size_t>(idx));
out[e.chunk][e.i] = value;
}
};
// Copies every input and output array to the host and checks the outputs against a
// host reference. Works per array, independently of the device-side index mapping.
template <typename T>
bool check_results(const std::vector<thrust::device_vector<T>>& d_in,
const std::vector<thrust::device_vector<T>>& d_out)
{
size_t mismatches = 0;
for (size_t c = 0; c < d_in.size(); ++c) {
const thrust::host_vector<T> in = d_in[c];
const thrust::host_vector<T> out = d_out[c];
for (size_t i = 0; i < in.size(); ++i) {
const T expected = (i == 0) ? in[0] : static_cast<T>(in[i - 1] - in[i]);
if (out[i] != expected && mismatches++ < 10) {
std::fprintf(stderr, "mismatch at array %zu elem %zu: got %llu, expected %llu\n", c, i,
static_cast<unsigned long long>(out[i]), static_cast<unsigned long long>(expected));
}
}
}
if (mismatches != 0) {
std::fprintf(stderr, "%zu mismatches\n", mismatches);
}
return mismatches == 0;
}
void benchmark_delta(nvbench::state& state)
{
using T = uint32_t;
constexpr size_t max_size_delta = 10; // each array has the reference size +/- up to this many elements
const auto batch_size = static_cast<size_t>(state.get_int64("BatchSize"));
const size_t ref_chunk_elems = static_cast<size_t>(state.get_int64("RefChunkBytes")) / sizeof(T);
// Random array sizes and their exclusive prefix sum.
const thrust::device_vector<size_t> d_sizes =
generate(batch_size, bit_entropy::_1_000, ref_chunk_elems - max_size_delta, ref_chunk_elems + max_size_delta);
const thrust::host_vector<size_t> h_sizes = d_sizes;
std::vector<size_t> h_offsets(batch_size + 1, 0);
for (size_t c = 0; c < batch_size; ++c) {
h_offsets[c + 1] = h_offsets[c] + h_sizes[c];
}
const size_t total_elems = h_offsets.back();
const size_t max_chunk_elems = *std::max_element(h_sizes.begin(), h_sizes.end());
const thrust::device_vector<size_t> d_offsets(h_offsets);
const BatchLayout layout{thrust::raw_pointer_cast(d_offsets.data()), batch_size, max_chunk_elems};
// One device vector per chunk, each holding its slice of one random buffer.
const thrust::device_vector<T> d_data = generate(total_elems);
std::vector<thrust::device_vector<T>> d_in(batch_size);
std::vector<thrust::device_vector<T>> d_out(batch_size);
std::vector<const T*> h_in_ptrs(batch_size);
std::vector<T*> h_out_ptrs(batch_size);
for (size_t c = 0; c < batch_size; ++c) {
d_in[c].assign(d_data.begin() + h_offsets[c], d_data.begin() + h_offsets[c + 1]);
d_out[c].resize(h_sizes[c]);
h_in_ptrs[c] = thrust::raw_pointer_cast(d_in[c].data());
h_out_ptrs[c] = thrust::raw_pointer_cast(d_out[c].data());
}
const thrust::device_vector<const T*> d_in_ptrs(h_in_ptrs);
const thrust::device_vector<T*> d_out_ptrs(h_out_ptrs);
const auto run_delta = [&](cuda::stream_ref stream) {
NVBENCH_CUDA_CALL(cub::DeviceTransform::Transform(
cuda::counting_iterator<size_t>{0},
cuda::make_tabulate_output_iterator(StoreToChunk<T>{thrust::raw_pointer_cast(d_out_ptrs.data()), layout}),
total_elems,
PrevMinusCur<T>{thrust::raw_pointer_cast(d_in_ptrs.data()), layout},
stream));
};
const cuda::stream_ref stream{state.get_cuda_stream().get_stream()};
run_delta(stream);
stream.sync();
if (!check_results(d_in, d_out)) {
state.skip("Results do not match the host reference");
return;
}
// Counts each input and output element once; the neighbour, pointer and offset
// reads are not included.
state.add_element_count(total_elems);
state.add_global_memory_reads<T>(total_elems, "Input");
state.add_global_memory_writes<T>(total_elems, "Output");
state.exec([&](nvbench::launch& launch) { run_delta(cuda::stream_ref{launch.get_stream().get_stream()}); });
}
NVBENCH_BENCH(benchmark_delta)
.add_int64_axis("BatchSize", {256, 1024, 4096, 8192})
.add_int64_axis("RefChunkBytes", {16 * 1024, 64 * 1024, 256 * 1024});
Activity
miscco commentedon Oct 9, 2026
I went through the rapids repositories with my agent with the following report:
Summary
Unwrapping and bulk copy are the right fix for fancy iterators that wrap contiguous memory. The synthesizing-iterator work is the right fix for iterators that produce values from their own state. Most of the cuDF performance history is the second shape, and treating those iterators as contiguous is what made those kernels slower.
Two shapes
A fancy iterator is either a wrapper over contiguous memory, or it synthesizes its value.
Memory wrappers are
transform_iterator<F, T*>,zip_iterator<T*, U*>,zip_transform_iterator,transform_output_iterator<T*, G>, andtransform_input_output_iteratorover a pointer. Dereference loads or stores real bytes, then applies a function.cub::DeviceTransformtakescp.async.bulkon sm_90 and newer only when every input is contiguous and trivially relocatable, the output is dense, and addresses do not need to stay stable. These wrappers failis_contiguous_iterator, so scan, reduce, and transform fall off the bulk-copy and vectorized paths even though the pointers underneath would qualify. That is the gap in this issue: on B200, cuDF’s JSON reset-segment scan is up to about 58% slower throughcuda::transform_iterator(char*)andmake_transform_output_iterator(uint8_t*)than through the raw pointers.Synthesizing iterators produce a value from iterator state. On the
synthesizing_block_loadbranch,__is_synthesizing_iterator_vis true forcounting_iterator,constant_iterator, andshuffle_iterator, and forstrided_iterator,transform_iterator,zip_iterator, andzip_transform_iteratoronly when every base is synthesizing. Thrust’s copies of those types specialize the same variable. A synthesizing input does not have a pointer to bulk-copy.load_algorithm_for_inputtherefore rewritesBLOCK_LOAD_TRANSPOSE,BLOCK_LOAD_WARP_TRANSPOSE, andBLOCK_LOAD_WARP_TRANSPOSE_TIMESLICEDtoBLOCK_LOAD_DIRECT, and nudgesitems_per_threadto a nearby power of two so the blocked index is a shift. The shared-memory transpose only coalesces loads that never happen.The trait does not look inside the functor.
transform_iterator<F, counting_iterator>is synthesizing even whenFcaptures a pointer and loads through it. That is the dominant cuDF pattern, and it is the right classification for the load policy: the value the iterator yields is computed, so a transpose of that value is overhead. The hidden loads stay insideF, in whatever orderFaddresses them. Bulk-copying the iterator would invent a memcpy of values that were never in memory.transform_output_iteratorandtransform_input_output_iteratorare not in the trait. They are store-side adaptors. A zip is synthesizing only when every component is. A zip of a pointer and a counting iterator still has one real stream to move and one stream to synthesize.How common each spelling is
Counts are files on the default branch of public GitHub, with
NVIDIA/ccclexcluded and the oldthrustandcubrepos excluded where the name would otherwise hit the library itself. A file with several call sites counts once. Forks, vendored CUB, and changelogs inflate the rarer patterns by roughly 5–10×. A “next tocub::Device” hit means both strings occur in the same file, not necessarily in the same call.cub::Devicemake_transform_iteratormake_zip_iteratorcounting_iteratorandmake_transform_iteratortogetherTransformInputIterator(legacy CUB name)thrust::zip_iteratormake_transform_output_iteratortransform_input_output_iteratormake_transform_input_output_iteratormake_counting_transform_iteratorcuda::transform_iteratorcuda::make_transform_iteratorthrust::transform_output_iteratorzip_transform_iteratorcuda::zip_iteratorcuda::make_zip_iteratormake_zip_transform_iteratormake_transform_iteratorstays about 48,000 even outside paths namedthrust,cub, orthird_party. That is the ordinary Thrust idiom, including host code. It is not a count of missed CUB fast paths.The legacy CUB name is the one that actually shows up beside device algorithms: 1,872 files mention
TransformInputIteratorandcub::Device, against 65 forcuda::transform_iterator.transform_input_output_iteratoris real but small, and only 32 of those files also mentioncub::Device.zip_transform_iteratoris almost unused outside CCCL (five call sites of the factory).Narrower CUB pairings, still including forks:
transform_iteratorwithDeviceScan: 611. WithDeviceReduce: 577. WithDeviceTransform: 91.zip_iteratorwithDeviceTransform: 111. WithDeviceScan: 130.transform_output_iteratorwithDeviceScan: 98.DeviceScan: 70 files in 50 repos. After dropping forks, changelogs, and vendored tests, that is cuDFlogical_stack.cuh, DGL neighbor sampling, and the AprilTag CUDA port. XGBoost’s row partitioner is the same call shape and does not contain the literal stringtransform_iterator.make_transform_iteratoralso sits next toinclusive_scanin 1,864 files andexclusive_scanin 2,124. Those are Thrust scans, which still land in CUB.Where the call sites actually live
cuDF is the
cuda::user. It has 124 files mentioningcuda::transform_iterator, 73 of them outside tests and benchmarks. Other non-test counts: 94make_counting_transform_iterator, 39make_zip_iterator, 6make_transform_output_iterator, and no remainingthrust::make_transform_iterator. Only 15 of thecuda::transform_iteratorfiles also mentioncub::Device. The rest go through Thrust. The 94 counting-transform files are synthesizing iterators whose functors index captured pointers. The pointer-wrapper scan inlogical_stack.cuhis the memory-wrapper case in the issue reproducer. The other two call sites cited on the issue are the same split:strings_column_factories.cuis a counting transform intothrust::exclusive_scan, andscan_inclusive.cuis a null-replacement / counting transform intothrust::inclusive_scan.cuOpt has 30 files with
make_zip_iteratorand 5 withmake_transform_output_iterator. The PDLP iteration (cccl#6143) already passes raw pointers intocub::DeviceTransformand uses a zip of three pointers only as the output, so the missed fast path is the vectorized store.cuGraph has 9 files mentioning
cuda::transform_iterator(one is a trait) and 86 non-test files withmake_zip_iterator.cuVS kmeans builds
thrust::transform_iterator<Op, InputT*>andthrust::transform_iterator<Op, KeyValuePair*>and passes them tocub::DeviceReduce.cuML has 3
make_transform_iteratorfiles. RAFT has none.Outside NVIDIA, the same call site is copied widely and owned by a few upstreams:
row_partitioner.cuhfeeds a counting transform plus atransform_output_iteratortoDeviceScan::InclusiveScan.make_transform_iteratortoDeviceScan::ExclusiveSumand use zip plus transform-output as the sink ofcopy_if.aten/src/ATen/cuda/cub.cuhastransform_iterator<Functor, const T*>.cub::TransformInputIteratorwith its own iterator.DeviceScanuser in the 70-file set.cuDF cases, sorted onto those two shapes
The cases collected in Bradley’s gist separate three mechanisms. They line up with the trait.
Memory wrappers, where unpack plus bulk copy or a vectorized load helps
cuda::zip_iteratorof two contiguous pointers intoDeviceTransform(swap_ranges). Thrust already unpacks this zip. CUB does not, and the zipped form was much slower for large types. After an unpack, each stream meets the contiguous, trivially relocatable check.logical_stack.cuh. Bulk-copy thechar*, apply the 0/1 functor on the staged values, scan, then do a vectorized store through the unwrappeduint8_t*. The output functor is a narrowing conversion.T*with the functor applied after the load.unique_copywas 20–50% slower for non-nested types. The win is staying fused. Bulk copy adds more only when the base is a contiguous trivially copyable pointer and the functor stays cheap.Bulk copy still requires 16-byte multiples, pointer alignment, and a tile that fits in shared memory. On Hopper, 1- and 2-byte multi-input transforms already prefer the vectorized kernel. A zip that contains a permutation or a counting iterator can bulk-copy only its pointer components.
Synthesizing iterators, where bulk copy is the wrong tool
thrust::tabulateof a wide row hash. The input is a counting iterator. The functor captures a column-major pointer and does a strided load per column.proclaim_copyable_argumentsforced the vectorizedDeviceTransformkernel, 8–16 items per thread, which is the 1.6–4× regression (4–6× in a third-party report). cuDF moved this tocub::DeviceFor::Bulk. The synthesizing policy’s direct load is the matching treatment. There is no input pointer to stage.is_nullandmask_to_boolsabout 2× faster andone_hot_encodeabout 1.35× faster, and made stringlike/char_typesup to 11× slower. Those inputs are counting or bitmask iterators. A policy that treats every fancy iterator as contiguous reproduces this split.copy_ifover a counting iterator whose predicate probes a hash table. Occupancy went from 37% to 72% after the probe was pulled into aboolbuffer, and join benchmarks moved 15–30%. The bytes that matter are random loads inside the predicate.DeviceSelectdropped the kernel from 120–255 registers to 48, and 358 of 378 benchmarks improved. Repacking that comparator onto a bulk-copied tile puts the registers back.copy_if, 14–22% faster on B200. The iterator was never a memcpy source.transform_iteratorused as a scatter map reportedinput_iterator_tag, thepermutation_iteratorinherited it, andthrust::scatterleft the CUB path (2.5–3.3×, and new pool OOM). That was a category bug and is fixed. The visited stream is still a permutation. Bulk-copying it in iterator order would be wrong. cccl#7097 is the same kind of indirect stream, and the measurement is disputed.permutation_iteratorinsideinclusive_scan_by_keybeat a separate gather by about 17%. That is one kernel instead of two. The visit order is not contiguous.What to build
The unpack (
unpackto pointers plus a function,repackon chip, a trait used whereis_contiguous_iteratoris used today) should be the memory-wrapper path only.Automatic, with no user annotation:
transform_iterator,zip_iterator,zip_transform_iterator,transform_output_iterator, andtransform_input_output_iteratorwhose memory-backed bases are contiguous and trivially copyable, and for which__is_synthesizing_iterator_vis false. Apply bulk copy or a vectorized load to those bases, run the functor on the staged values, and synthesize any counting or constant components in registers. Output iterators unwrap to vectorized stores.transform_input_output_iteratorneeds both directions: load and apply the input function, store and apply the output function. This covers the issue reproducer, cccl#8258, cuVS kmeans, cuOpt’s zip stores, PyTorch’sconst T*transform, and the legacyTransformInputIterator<F, T*>spelling. The 1,872-fileTransformInputIteratorset is the historical population of that last form.Leave synthesizing iterators on the direct load from
synthesizing_block_load. Do not stage them withcp.async.bulk. That includes the 11,360 files that combinecounting_iteratorwithmake_transform_iterator, cuDF’s 94 counting-transform files, and the tabulate, semi-join, sort-merge, and groupby cases. Their functors may still load memory. That load is not the iterator’s base, so neither a transpose nor a bulk copy of the iterator can make it coalesced. Heavy functors also need a separate choice of items per thread. The vectorized kernel’s 8–16 items per thread is the regression in cccl#9070 and cuDF #24448, independent of whether the iterator unwraps.Ask the user to opt in only for a contiguous base the trait cannot see: a custom iterator, or a type-erased iterator such as the slow path in cuDF #21973. Do not ask them to opt a counting transform into bulk copy. Permutation and scatter maps stay gathers.
mfranzrebsal commentedon Oct 15, 2026
Hi! Here is a use case using fancy iterators in
DeviceTransformthat fails to reach SOL on B200. The benchmark below performs a delta transformation on a batch of arrays. What seems to be preventing good performance is that each thread needs to search for the corresponding array in the batch before performing the transformation on the element. Even if we simplify it by having every array be exactly the same size, removing the need for the search, the transform only reaches 25% of BW on B200.Having a
DeviceSegmentedTransformwould probably solve this and make usage much simpler, do you have intention of adding such a function to the API?Here is the benchmark:
And results on B200: