cub::DeviceFind#

struct DeviceFind#

Public Static Functions

template<typename InputIteratorT, typename OutputIteratorT, typename ScanOpT, typename NumItemsT>
static inline cudaError_t FindIf(
void *d_temp_storage,
size_t &temp_storage_bytes,
InputIteratorT d_in,
OutputIteratorT d_out,
ScanOpT scan_op,
NumItemsT num_items,
cudaStream_t stream = 0
)#

Finds the first element in the input sequence that satisfies the given predicate.

  • The search terminates at the first element where the predicate evaluates to true.

  • The index of the found element is written to d_out.

  • If no element satisfies the predicate, num_items is written to d_out.

  • The range [d_out, d_out + 1) shall not overlap [d_in, d_in + num_items) in any way.

  • When d_temp_storage is nullptr, no work is done and the required allocation size is returned in temp_storage_bytes. See Determining Temporary Storage Requirements for usage guidance.

Snippet#

The code snippet below illustrates the finding of the first element that satisfies the predicate.

Template Parameters:
  • InputIteratorT[inferred] Random-access input iterator type for reading input items (may be a simple pointer type)

  • OutputIteratorT[inferred] Random-access output iterator type for writing the result index (may be a simple pointer type)

  • ScanOpT[inferred] Unary predicate functor type having member bool operator()(const T &a)

  • NumItemsT[inferred] An integral type representing the number of input elements

Parameters:
  • d_temp_storage[in] Device-accessible allocation of temporary storage. When nullptr, the required allocation size is written to temp_storage_bytes and no work is done.

  • temp_storage_bytes[inout] Reference to size in bytes of d_temp_storage allocation

  • d_in[in] Random-access iterator to the input sequence of data items

  • d_out[out] Random-access iterator to the output location for the index of the found element

  • scan_op[in] Unary predicate functor for determining whether an element satisfies the search condition

  • num_items[in] Total number of input items (i.e., the length of d_in)

  • stream[in]

    [optional] CUDA stream to launch kernels within. Default is stream0.

template<typename RangeIteratorT, typename ValuesIteratorT, typename OutputIteratorT, typename CompareOpT>
static inline cudaError_t LowerBound(
void *d_temp_storage,
size_t &temp_storage_bytes,
RangeIteratorT first,
RangeIteratorT last,
ValuesIteratorT values_first,
ValuesIteratorT values_last,
OutputIteratorT output,
CompareOpT comp,
cudaStream_t stream = 0
)#

Overview#

For each value in [values_first, values_last), performs a binary search in the range [first, last), using comp as the comparator to find the iterator to the element of said range which is not ordered before value.

  • The range [first, last) must be sorted consistently with comp.

Template Parameters:
  • RangeIteratorT – is a model of Random Access Iterator, whose value type forms a Relation with the value type of ValuesIteratorT using CompareOpT as the predicate.

  • ValuesIteratorT – is a model of Random Access Iterator, whose value type forms a Relation with the value type of RangeIteratorT using CompareOpT as the predicate.

  • OutputIteratorT – is a model of Random Access Iterator, whose value type is assignable from RangeIteratorT’s difference type.

  • CompareOpT – is a model of Strict Weak Ordering, which forms a Relation with the value types of RangeIteratorT and ValuesIteratorT.

Parameters:
  • d_temp_storage[in] Device-accessible allocation of temporary storage. When nullptr, the required allocation size is written to temp_storage_bytes and no work is done.

  • temp_storage_bytes[inout] Reference to size in bytes of d_temp_storage allocation

  • first[in] Iterator to the beginning of the ordered range to be searched.

  • last[in] Iterator denoting the one-past-the-end element of the ordered range to be searched.

  • values_first[in] Iterator to the beginning of the range of values to be searched for.

  • values_last[in] Iterator denoting the one-past-the-end element of the range of values to be searched for.

  • output[out] Iterator to the beginning of the output range.

  • comp[in] Comparison function object which returns true if its first argument is ordered before the second in the Strict Weak Ordering of the range to be searched.

  • stream[in] [optional] CUDA stream to launch kernels within. Default is stream0.

template<typename RangeIteratorT, typename ValuesIteratorT, typename OutputIteratorT, typename CompareOpT>
static inline cudaError_t UpperBound(
void *d_temp_storage,
size_t &temp_storage_bytes,
RangeIteratorT first,
RangeIteratorT last,
ValuesIteratorT values_first,
ValuesIteratorT values_last,
OutputIteratorT output,
CompareOpT comp,
cudaStream_t stream = 0
)#

Overview#

For each value in [values_first, values_last), performs a binary search in the range [first, last), using comp as the comparator to find the iterator to the element of said range which is ordered after value.

  • The range [first, last) must be sorted consistently with comp.

Template Parameters:
  • RangeIteratorT – is a model of Random Access Iterator, whose value type forms a Relation with the value type of ValuesIteratorT using CompareOpT as the predicate.

  • ValuesIteratorT – is a model of Random Access Iterator, whose value type forms a Relation with the value type of RangeIteratorT using CompareOpT as the predicate.

  • OutputIteratorT – is a model of Random Access Iterator, whose value type is assignable from RangeIteratorT’s difference type.

  • CompareOpT – is a model of Strict Weak Ordering, which forms a Relation with the value types of RangeIteratorT and ValuesIteratorT.

Parameters:
  • d_temp_storage[in] Device-accessible allocation of temporary storage. When nullptr, the required allocation size is written to temp_storage_bytes and no work is done.

  • temp_storage_bytes[inout] Reference to size in bytes of d_temp_storage allocation

  • first[in] Iterator to the beginning of the ordered range to be searched.

  • last[in] Iterator denoting the one-past-the-end element of the ordered range to be searched.

  • values_first[in] Iterator to the beginning of the range of values to be searched for.

  • values_last[in] Iterator denoting the one-past-the-end element of the range of values to be searched for.

  • output[out] Iterator to the beginning of the output range.

  • comp[in] Comparison function object which returns true if its first argument is ordered before the second in the Strict Weak Ordering of the range to be searched.

  • stream[in] [optional] CUDA stream to launch kernels within. Default is stream0.