File indexing completed on 2025-01-18 09:29:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
0013
0014 #include <boost/static_assert.hpp>
0015
0016 #include <boost/compute/device.hpp>
0017 #include <boost/compute/system.hpp>
0018 #include <boost/compute/command_queue.hpp>
0019 #include <boost/compute/algorithm/detail/count_if_with_ballot.hpp>
0020 #include <boost/compute/algorithm/detail/count_if_with_reduce.hpp>
0021 #include <boost/compute/algorithm/detail/count_if_with_threads.hpp>
0022 #include <boost/compute/algorithm/detail/serial_count_if.hpp>
0023 #include <boost/compute/detail/iterator_range_size.hpp>
0024 #include <boost/compute/type_traits/is_device_iterator.hpp>
0025
0026 namespace boost {
0027 namespace compute {
0028
0029
0030
0031
0032
0033
0034 template<class InputIterator, class Predicate>
0035 inline size_t count_if(InputIterator first,
0036 InputIterator last,
0037 Predicate predicate,
0038 command_queue &queue = system::default_queue())
0039 {
0040 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0041 const device &device = queue.get_device();
0042
0043 size_t input_size = detail::iterator_range_size(first, last);
0044 if(input_size == 0){
0045 return 0;
0046 }
0047
0048 if(device.type() & device::cpu){
0049 if(input_size < 1024){
0050 return detail::serial_count_if(first, last, predicate, queue);
0051 }
0052 else {
0053 return detail::count_if_with_threads(first, last, predicate, queue);
0054 }
0055 }
0056 else {
0057 if(input_size < 32){
0058 return detail::serial_count_if(first, last, predicate, queue);
0059 }
0060 else {
0061 return detail::count_if_with_reduce(first, last, predicate, queue);
0062 }
0063 }
0064 }
0065
0066 }
0067 }
0068
0069 #endif