Repository navigation
Implement the new tuning API for DispatchSegmentedSort - #7874
Conversation
DispatchSegmentedSort
|
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. |
This comment has been minimized.
This comment has been minimized.
c84b86a to
6747636
Compare
This comment has been minimized.
This comment has been minimized.
b0a429c to
7703799
Compare
This comment has been minimized.
This comment has been minimized.
89007f7 to
e0c82ba
Compare
| *static_cast<indirect_arg_t**>(&val_arg_in), *static_cast<indirect_arg_t**>(&val_arg_out)); | ||
|
|
||
| auto exec_status = cub::DispatchSegmentedSort< | ||
| // TODO(bgruber): remove all template arguments except the first two (the others can be deduced) |
| auto medium_segment_policy = RuntimeSubWarpMergeSortAgentPolicy::from_json(runtime_policy, "MediumSegmentPolicy"); | ||
|
|
||
| int partitioning_threshold = runtime_policy["PartitioningThreshold"].get<int>(); | ||
| // TODO(bgruber): convert to the new tuning API |
29c8a14 to
0e08988
Compare
| template <typename PartitionPolicyHub, | ||
| typename LargeKernelT, | ||
| typename SmallKernelT, | ||
| typename KeyT, | ||
| typename ValueT, | ||
| typename BeginOffsetIteratorT, | ||
| typename EndOffsetIteratorT, | ||
| typename KernelSource, | ||
| typename PartitionKernelSource, | ||
| typename KernelLauncherFactory, | ||
| typename GetFinalOutputOp> | ||
| CUB_RUNTIME_FUNCTION _CCCL_VISIBILITY_HIDDEN _CCCL_FORCEINLINE cudaError_t sort_with_partitioning( | ||
| LargeKernelT large_kernel, | ||
| SmallKernelT small_kernel, | ||
| global_segment_offset_t num_segments, | ||
| ::cuda::std::int64_t num_items, | ||
| BeginOffsetIteratorT d_begin_offsets, | ||
| EndOffsetIteratorT d_end_offsets, | ||
| cudaStream_t stream, | ||
| size_t three_way_partition_temp_storage_bytes, | ||
| DoubleBuffer<KeyT>& d_keys, | ||
| DoubleBuffer<ValueT>& d_values, | ||
| device_double_buffer<KeyT>& d_keys_double_buffer, | ||
| device_double_buffer<ValueT>& d_values_double_buffer, | ||
| typename KernelSource::LargeSegmentsSelectorT& large_segments_selector, | ||
| typename KernelSource::SmallSegmentsSelectorT& small_segments_selector, | ||
| temporary_storage::alias<uint8_t>& device_partition_temp_storage, | ||
| temporary_storage::alias<local_segment_index_t>& large_and_medium_segments_indices, | ||
| temporary_storage::alias<local_segment_index_t>& small_segments_indices, | ||
| temporary_storage::alias<local_segment_index_t>& group_sizes, | ||
| KernelSource& kernel_source, | ||
| PartitionKernelSource& partition_kernel_source, | ||
| KernelLauncherFactory& launcher_factory, | ||
| typename PartitionPolicyHub::MaxPolicy partition_max_policy, | ||
| const segmented_sort_policy& active_policy, | ||
| GetFinalOutputOp&& get_final_output) |
There was a problem hiding this comment.
This was of course generated by Cursor, because no sane person would type this out. I also tried using a lambda inside the dispatch function below, but then it gets really long and is also unreadable. I will gladly take any suggestions on how to make this more readable. I even considered moving back to a struct with member functions, so we can share all the template parameters between the functions.
There was a problem hiding this comment.
Why do we pass the individual aliases of the temporary storage individually?
There was a problem hiding this comment.
Also why is there
DoubleBuffer<KeyT>& d_keys,
DoubleBuffer<ValueT>& d_values,
device_double_buffer<KeyT>& d_keys_double_buffer,
device_double_buffer<ValueT>& d_values_double_buffer,
There was a problem hiding this comment.
Why do we pass the individual aliases of the temporary storage individually?
Because they have references internally to the main temporary_storage_variable outside the function.
Also why is there ...
The first two are the user inputs, the last two are either pointing into those or into some auxiliary buffers depending on some settings.
This comment has been minimized.
This comment has been minimized.
|
I tried to simplify the code for about half an hour now, but couldn't beat the current line count or reduce the complexity :S |
0e08988 to
beeb42b
Compare
This comment has been minimized.
This comment has been minimized.
| // FIXME(bgruber): input_values_it.value_type.size is 4 when it represents cub::NullType, which is very odd | ||
| keys_only ? 0 : static_cast<int>(input_values_it.value_type.size), | ||
| keys_only ? 0 : static_cast<int>(input_values_it.value_type.size), // TODO(bgruber): instead of 0 we should probably | ||
| // use int{sizeof(cub::NullType)} |
There was a problem hiding this comment.
Nitpick:
| // FIXME(bgruber): input_values_it.value_type.size is 4 when it represents cub::NullType, which is very odd | |
| keys_only ? 0 : static_cast<int>(input_values_it.value_type.size), | |
| keys_only ? 0 : static_cast<int>(input_values_it.value_type.size), // TODO(bgruber): instead of 0 we should probably | |
| // use int{sizeof(cub::NullType)} | |
| // FIXME(bgruber): input_values_it.value_type.size is 4 when it represents cub::NullType, which is very odd | |
| // TODO(bgruber): instead of 0 we should probably use int{sizeof(cub::NullType)} | |
| keys_only ? 0 : static_cast<int>(input_values_it.value_type.size), |
Co-authored-by: Michael Schellenberger Costa <[email protected]>
Co-authored-by: Michael Schellenberger Costa <[email protected]>
|
|
||
| namespace detail::segmented_sort | ||
| { | ||
| struct segmented_radix_sort_policy |
There was a problem hiding this comment.
Nit: for reduce, we named the equivalent policy agent_reduce_policy. I think it would be more consistent to name this agent_segmented_radix_sort_policy.
There was a problem hiding this comment.
It's actually the other way around. The name agent_ should completely disappear. This will also happen before the tuning API goes public.
| #endif // !_CCCL_COMPILER(NVRTC) | ||
| }; | ||
|
|
||
| struct sub_warp_merge_sort_policy |
There was a problem hiding this comment.
Nit: same as above, name this agent_sub_warp_merge_sort_policy
This comment has been minimized.
This comment has been minimized.
🥳 CI Workflow Results🟩 Finished in 2h 09m: Pass: 100%/255 | Total: 1d 21h | Max: 44m 15s | Hits: 98%/156304See results here. |

cub.bench.segmented_sort.keys.baseon SM75;80;86.The large and small kernels are no longer emitted since their code paths are not taken. If you look into the git history, I forced emitting them to verify their SASS did not change, but the PR ultimately removes the kernels from the SASS entirely.(reverted)Note: the implementation of
DispatchSegmentedSortalso usesDeviceThreeWayPartition, which will be rewritten separately in #7900Fixes: #7643
Fixes: #7477