Unique#
unique#
- 
template<class Config = default_config, class InputIterator, class OutputIterator, class UniqueCountOutputIterator, class EqualityOp = ::rocprim::equal_to<typename std::iterator_traits<InputIterator>::value_type>>
 inline hipError_t rocprim::unique(void *temporary_storage, size_t &storage_size, InputIterator input, OutputIterator output, UniqueCountOutputIterator unique_count_output, const size_t size, EqualityOp equality_op = EqualityOp(), const hipStream_t stream = 0, const bool debug_synchronous = false)#
- Device-level parallel unique primitive. - From given - inputrange unique primitive eliminates all but the first element from every consecutive group of equivalent elements and copies them into- output.- Overview
- Returns the required size of - temporary_storagein- storage_sizeif- temporary_storageis a null pointer.
- Range specified by - inputmust have at least- sizeelements.
- Range specified by - outputmust have at least so many elements, that all selected values can be copied into it.
- Range specified by - unique_count_outputmust have at least 1 element.
- By default - InputIterator::value_type’s equality operator is used to check if elements are equivalent.
 
- Example
- In this example a device-level unique operation is performed on an array of integer values. - #include <rocprim/rocprim.hpp> // Prepare input and output (declare pointers, allocate device memory etc.) size_t input_size; // e.g., 8 int * input; // e.g., [1, 4, 2, 4, 4, 7, 7, 7] int * output; // empty array of 8 elements size_t * output_count; // empty array of 1 element size_t temporary_storage_size_bytes; void * temporary_storage_ptr = nullptr; // Get required size of the temporary storage rocprim::unique( temporary_storage_ptr, temporary_storage_size_bytes, input, output, output_count, input_size ); // allocate temporary storage hipMalloc(&temporary_storage_ptr, temporary_storage_size_bytes); // perform unique operation rocprim::unique( temporary_storage_ptr, temporary_storage_size_bytes, input, output, output_count, input_size ); // output: [1, 4, 2, 4, 7] // output_count: 5 
 - Template Parameters:
- Config – - [optional] Configuration of the primitive, must be - default_configor- select_config.
- InputIterator – - random-access iterator type of the input range. It can be a simple pointer type. 
- OutputIterator – - random-access iterator type of the output range. It can be a simple pointer type. 
- UniqueCountOutputIterator – - random-access iterator type of the unique_count_output value used to return number of unique values. It can be a simple pointer type. 
- EqualityOp – - type of an binary operator used to compare values for equality. 
 
- Parameters:
- temporary_storage – [in] - pointer to a device-accessible temporary storage. When a null pointer is passed, the required allocation size (in bytes) is written to - storage_sizeand function returns without performing the unique operation.
- storage_size – [inout] - reference to a size (in bytes) of - temporary_storage.
- input – [in] - iterator to the first element in the range to select values from. 
- output – [out] - iterator to the first element in the output range. 
- unique_count_output – [out] - iterator to the total number of selected values (length of - output).
- size – [in] - number of element in the input range. 
- equality_op – [in] - [optional] binary function object used to compare input values for equality. The signature of the function should be equivalent to the following: - bool equal_to(const T &a, const T &b);. The signature does not need to have- const &, but function object must not modify the object passed to it.
- stream – [in] - [optional] HIP stream object. The default is - 0(default stream).
- debug_synchronous – [in] - [optional] If true, synchronization after every kernel launch is forced in order to check for errors. The default value is - false.
 
 
unique_by_key#
- 
template<typename Config = default_config, typename KeyIterator, typename ValueIterator, typename OutputKeyIterator, typename OutputValueIterator, typename UniqueCountOutputIterator, typename EqualityOp = ::rocprim::equal_to<typename std::iterator_traits<KeyIterator>::value_type>>
 inline hipError_t rocprim::unique_by_key(void *temporary_storage, size_t &storage_size, const KeyIterator keys_input, const ValueIterator values_input, const OutputKeyIterator keys_output, const OutputValueIterator values_output, const UniqueCountOutputIterator unique_count_output, const size_t size, const EqualityOp equality_op = EqualityOp(), const hipStream_t stream = 0, const bool debug_synchronous = false)#
- Device-level parallel unique by key primitive. - From given - inputrange unique primitive eliminates all but the first element from every consecutive group of equivalent elements and copies them and their corresponding keys into- output.- Overview
- Returns the required size of - temporary_storagein- storage_sizeif- temporary_storageis a null pointer.
- Ranges specified by - keys_inputand value_input must have at least- sizeelements each.
- Ranges specified by - keys_outputand values_output each must have at least so many elements, that all selected values can be copied into them.
- Range specified by - unique_count_outputmust have at least 1 element.
- By default - InputIterator::value_type’s equality operator is used to check if elements are equivalent.
 
 - Template Parameters:
- Config – - [optional] Configuration of the primitive, must be - default_configor- select_config.
- KeyIterator – - random-access iterator type of the input key range. It can be a simple pointer type. 
- ValueIterator – - random-access iterator type of the input value range. It can be a simple pointer type. 
- OutputKeyIterator – - random-access iterator type of the output key range. It can be a simple pointer type. 
- OutputValueIterator – - random-access iterator type of the output value range. It can be a simple pointer type. 
- UniqueCountOutputIterator – - random-access iterator type of the unique_count_output value used to return number of unique keys and values. It can be a simple pointer type. 
- EqualityOp – - type of an binary operator used to compare keys for equality. 
 
- Parameters:
- temporary_storage – [in] - pointer to a device-accessible temporary storage. When a null pointer is passed, the required allocation size (in bytes) is written to - storage_sizeand function returns without performing the unique operation.
- storage_size – [inout] - reference to a size (in bytes) of - temporary_storage.
- keys_input – [in] - iterator to the first element in the range to select keys from. 
- values_input – [in] - iterator to the first element in the range of values corresponding to keys 
- keys_output – [out] - iterator to the first element in the output key range. 
- values_output – [out] - iterator to the first element in the output value range. 
- unique_count_output – [out] - iterator to the total number of selected values (length of - output).
- size – [in] - number of element in the input range. 
- equality_op – [in] - [optional] binary function object used to compare input values for equality. The signature of the function should be equivalent to the following: - bool equal_to(const T &a, const T &b);. The signature does not need to have- const &, but function object must not modify the object passed to it.
- stream – [in] - [optional] HIP stream object. The default is - 0(default stream).
- debug_synchronous – [in] - [optional] If true, synchronization after every kernel launch is forced in order to check for errors. The default value is - false.