]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/count_if.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / count_if.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
12 #define BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
13
14 #include <boost/compute/device.hpp>
15 #include <boost/compute/system.hpp>
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/algorithm/detail/count_if_with_ballot.hpp>
18 #include <boost/compute/algorithm/detail/count_if_with_reduce.hpp>
19 #include <boost/compute/algorithm/detail/count_if_with_threads.hpp>
20 #include <boost/compute/algorithm/detail/serial_count_if.hpp>
21 #include <boost/compute/detail/iterator_range_size.hpp>
22
23 namespace boost {
24 namespace compute {
25
26 /// Returns the number of elements in the range [\p first, \p last)
27 /// for which \p predicate returns \c true.
28 ///
29 /// Space complexity on CPUs: \Omega(1)<br>
30 /// Space complexity on GPUs: \Omega(n)
31 template<class InputIterator, class Predicate>
32 inline size_t count_if(InputIterator first,
33 InputIterator last,
34 Predicate predicate,
35 command_queue &queue = system::default_queue())
36 {
37 const device &device = queue.get_device();
38
39 size_t input_size = detail::iterator_range_size(first, last);
40 if(input_size == 0){
41 return 0;
42 }
43
44 if(device.type() & device::cpu){
45 if(input_size < 1024){
46 return detail::serial_count_if(first, last, predicate, queue);
47 }
48 else {
49 return detail::count_if_with_threads(first, last, predicate, queue);
50 }
51 }
52 else {
53 if(input_size < 32){
54 return detail::serial_count_if(first, last, predicate, queue);
55 }
56 else {
57 return detail::count_if_with_reduce(first, last, predicate, queue);
58 }
59 }
60 }
61
62 } // end compute namespace
63 } // end boost namespace
64
65 #endif // BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP