31 #include <cugar/basic/numbers.h> 38 template <
typename VectorType>
41 if (vec.size() < size)
50 template <
typename PredicateIterator>
54 const PredicateIterator pred,
57 const uint32 i = threadIdx.x + blockIdx.x * blockDim.x;
59 const bool p_i = (i < n ? pred[i] :
false);
60 const bool p = __syncthreads_or( p_i );
70 template <
typename PredicateIterator>
74 const PredicateIterator pred,
77 const uint32 i = threadIdx.x + blockIdx.x * blockDim.x;
79 const bool p_i = (i < n ? pred[i] :
true);
80 const bool p = __syncthreads_and( p_i );
90 template <
typename PredicateIterator>
93 const PredicateIterator pred)
95 const uint32 block_dim = 256;
96 const uint32 n_blocks =
divide_ri( n, block_dim );
98 thrust::device_vector<uint32> r( 1u, 0u );
106 template <
typename PredicateIterator>
109 const PredicateIterator pred)
111 const uint32 block_dim = 256;
112 const uint32 n_blocks =
divide_ri( n, block_dim );
114 thrust::device_vector<uint32> r( 1u, 1u );
122 template <
typename Iterator1,
typename Iterator2>
126 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
127 is_sorted_iterator(
const Iterator1 _it1,
const Iterator2 _it2) : it1( _it1 ), it2( _it2 ) {}
130 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
131 bool operator[] (
const uint32 i)
const {
return it1[i] <= it2[i]; }
139 template <
typename Iterator1,
typename Iterator2,
typename Headflags>
143 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
144 is_segment_sorted_iterator(
const Iterator1 _it1,
const Iterator2 _it2,
const Headflags _hd) : it1( _it1 ), it2( _it2 ), hd(_hd) {}
147 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
148 bool operator[] (
const uint32 i)
const {
return hd[i] || (it1[i] <= it2[i]); }
157 template <
typename Iterator>
160 const Iterator values)
168 template <
typename Iterator,
typename Headflags>
171 const Iterator values,
172 const Headflags flags)
184 template <
typename InputIterator,
typename BinaryOp>
185 typename std::iterator_traits<InputIterator>::value_type
reduce(
189 thrust::device_vector<uint8>& d_temp_storage)
191 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
193 thrust::device_vector<value_type> d_out(1);
195 size_t temp_bytes = 0;
197 cub::DeviceReduce::Reduce(
198 (
void*)NULL, temp_bytes,
205 temp_bytes = cugar::max( uint64(temp_bytes), uint64(16) );
208 cub::DeviceReduce::Reduce(
227 template <
typename InputIterator,
typename OutputIterator,
typename BinaryOp>
231 OutputIterator d_out,
233 thrust::device_vector<uint8>& d_temp_storage)
235 size_t temp_bytes = 0;
237 cub::DeviceScan::InclusiveScan(
238 (
void*)NULL, temp_bytes,
244 temp_bytes = cugar::max( uint64(temp_bytes), uint64(16) );
247 cub::DeviceScan::InclusiveScan(
264 template <
typename InputIterator,
typename OutputIterator,
typename BinaryOp,
typename Identity>
268 OutputIterator d_out,
271 thrust::device_vector<uint8>& d_temp_storage)
273 size_t temp_bytes = 0;
275 cub::DeviceScan::ExclusiveScan(
276 (
void*)NULL, temp_bytes,
283 temp_bytes = cugar::max( uint64(temp_bytes), uint64(16) );
286 cub::DeviceScan::ExclusiveScan(
305 template <
typename InputIterator,
typename FlagsIterator,
typename OutputIterator>
309 FlagsIterator d_flags,
310 OutputIterator d_out,
311 thrust::device_vector<uint8>& d_temp_storage)
313 size_t temp_bytes = 0;
314 thrust::device_vector<int> d_num_selected(1);
316 cub::DeviceSelect::Flagged(
317 (
void*)NULL, temp_bytes,
324 temp_bytes = cugar::max( uint64(temp_bytes), uint64(16) );
327 cub::DeviceSelect::Flagged(
335 return uint32( d_num_selected[0] );
348 template <
typename InputIterator,
typename OutputIterator,
typename Predicate>
352 OutputIterator d_out,
353 const Predicate pred,
354 thrust::device_vector<uint8>& d_temp_storage)
356 size_t temp_bytes = 0;
357 thrust::device_vector<int> d_num_selected(1);
359 cub::DeviceSelect::If(
360 (
void*)NULL, temp_bytes,
367 temp_bytes = cugar::max( uint64(temp_bytes), uint64(16) );
370 cub::DeviceSelect::If(
378 return uint32( d_num_selected[0] );
391 template <
typename InputIterator,
typename OutputIterator,
typename CountIterator>
395 OutputIterator d_out,
396 CountIterator d_counts,
397 thrust::device_vector<uint8>& d_temp_storage)
399 size_t temp_bytes = 0;
400 thrust::device_vector<int> d_num_selected(1);
402 cub::DeviceRunLengthEncode::Encode(
403 (
void*)NULL, temp_bytes,
410 temp_bytes = cugar::max( uint64(temp_bytes), uint64(16) );
413 cub::DeviceRunLengthEncode::Encode(
421 return uint32( d_num_selected[0] );
437 template <
typename KeyIterator,
typename ValueIterator,
typename OutputKeyIterator,
typename OutputValueIterator,
typename ReductionOp>
440 KeyIterator d_keys_in,
441 ValueIterator d_values_in,
442 OutputKeyIterator d_keys_out,
443 OutputValueIterator d_values_out,
444 ReductionOp reduction_op,
445 thrust::device_vector<uint8>& d_temp_storage)
447 size_t temp_bytes = 0;
448 thrust::device_vector<int> d_num_selected(1);
450 cub::DeviceReduce::ReduceByKey(
451 (
void*)NULL, temp_bytes,
460 temp_bytes = cugar::max( uint64(temp_bytes), uint64(16) );
463 cub::DeviceReduce::ReduceByKey(
473 return uint32( d_num_selected[0] );
Definition: primitives_inl.h:123
bool any(const uint32 n, const PredicateIterator pred)
Definition: primitives_inl.h:91
vector_view< T *, uint64 > plain_view(thrust::device_vector< T > &vec)
Definition: thrust_view.h:49
void alloc_temp_storage(VectorType &vec, const uint64 size)
Definition: primitives_inl.h:39
T * raw_pointer(thrust::device_vector< T, Alloc > &vec)
Definition: thrust_view.h:69
Definition: primitives_inl.h:140
bool is_sorted(const uint32 n, const Iterator values)
Definition: primitives_inl.h:234
uint32 runlength_encode(const uint32 n, InputIterator in, OutputIterator out, CountIterator counts, cugar::vector< system_tag, uint8 > &temp_storage)
Definition: primitives_inl.h:859
CUGAR_HOST_DEVICE L divide_ri(const L x, const R y)
Definition: numbers.h:180
bool all(const uint32 n, const PredicateIterator pred)
Definition: primitives_inl.h:101
bool is_segment_sorted(const uint32 n, const Iterator values, const Headflags flags)
Definition: primitives_inl.h:245
void exclusive_scan(const uint32 n, InputIterator in, OutputIterator out, BinaryOp op, Identity identity, cugar::vector< system_tag, uint8 > &temp_storage)
Definition: primitives_inl.h:569
uint32 reduce_by_key(const uint32 n, KeyIterator keys_in, ValueIterator values_in, OutputKeyIterator keys_out, OutputValueIterator values_out, ReductionOp reduction_op, cugar::vector< system_tag, uint8 > &temp_storage)
Definition: primitives_inl.h:882
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
uint32 copy_if(const uint32 n, InputIterator in, OutputIterator out, const Predicate pred, cugar::vector< system_tag, uint8 > &temp_storage)
Definition: primitives_inl.h:838
std::iterator_traits< InputIterator >::value_type reduce(const uint32 n, InputIterator in, BinaryOp op, cugar::vector< system_tag, uint8 > &temp_storage)
Definition: primitives_inl.h:520
void inclusive_scan(const uint32 n, InputIterator in, OutputIterator out, BinaryOp op, cugar::vector< system_tag, uint8 > &temp_storage)
Definition: primitives_inl.h:543
uint32 copy_flagged(const uint32 n, InputIterator in, FlagsIterator flags, OutputIterator out, cugar::vector< system_tag, uint8 > &temp_storage)
Definition: primitives_inl.h:817