Skip to content

Refactor CUB device-scope APIs to take an environment instead of cudaStream_t #9875

Description

@bernhardmgruber

We decided a while back on Slack that in order to solve the problem of querying the temporary storage size of CUB APIs that take an environment and have no equivalent non-env overload, we should just replace all cudaStream_t parameters in public device-scope APIs by a const Env& parameter and add the additional environment handling (excluding temporary storage allocation). This would result in every CUB API to have two flavors:

struct DeviceAlg {
  // two-phase overload, user must handle temp storage allocation
  template <..., typename Env>
  static cudaError_t Algorithm(void* ts_ptr, size_t& ts_size, ..., const Env& env);

  // single-phase overload, handles temp storage allocation itself
  template <..., typename Env>
  static cudaError_t Algorithm(..., const Env& env);
}

This change is transparent to users, since a passed cudaStream_t (or a type convertible to that) will be handled appropriately by the stream query of the environment.

This work has already begun, but was mostly driven by needs in PSTL to query the temporary storage to combine that storage with further allocations (like an output parameter). See also #9328 and the following PRs:

However, we should complete this work. Here are the currently missing overloads that still have a cudaStream_t parameter:

Struct Public methods taking cudaStream_t
DeviceFind LowerBoundSortedValues, UpperBoundSortedValues
DeviceFor Bulk, ForEach, ForEachN, ForEachCopy, ForEachCopyN, ForEachInExtents, ForEachInLayout
DeviceHistogram MultiHistogramRange (deprecated raw-array overload only)
DeviceMemcpy Batched
DeviceMerge MergeKeys, MergePairs
DeviceMergeSort SortKeys, SortKeysCopy, SortPairs, SortPairsCopy, StableSortKeys, StableSortKeysCopy, StableSortPairs, SortKeysNoNVTX, SortKeysCopyNoNVTX, SortPairsNoNVTX
DeviceRadixSort SortKeys, SortKeysDescending, SortPairs, SortPairsDescending
DeviceReduce Reduce, Sum, Min, Max, ArgMin, ArgMax, ReduceByKey, TransformReduce
DeviceRunLengthEncode Encode, NonTrivialRuns
DeviceScan ExclusiveScan, ExclusiveScanByKey, ExclusiveSum, ExclusiveSumByKey, InclusiveScan, InclusiveScanByKey, InclusiveScanInit, InclusiveSum, InclusiveSumByKey
DeviceSegmentedRadixSort SortKeys, SortKeysDescending, SortPairs, SortPairsDescending
DeviceSegmentedReduce Reduce, Sum, Min, Max, ArgMin, ArgMax
DeviceSegmentedScan ExclusiveSegmentedScan, ExclusiveSegmentedSum, InclusiveSegmentedScan, InclusiveSegmentedScanInit, InclusiveSegmentedSum
DeviceSegmentedSort SortKeys, SortKeysDescending, SortPairs, SortPairsDescending, StableSortKeys, StableSortKeysDescending, StableSortPairs, StableSortPairsDescending

Metadata

Metadata

Assignees

Labels

help wantedRequest for input or help from the community

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions