]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/detail/find_extrema.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / detail / find_extrema.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_DETAIL_FIND_EXTREMA_HPP
12 #define BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP
13
14 #include <boost/compute/detail/iterator_range_size.hpp>
15 #include <boost/compute/algorithm/detail/find_extrema_on_cpu.hpp>
16 #include <boost/compute/algorithm/detail/find_extrema_with_reduce.hpp>
17 #include <boost/compute/algorithm/detail/find_extrema_with_atomics.hpp>
18 #include <boost/compute/algorithm/detail/serial_find_extrema.hpp>
19
20 namespace boost {
21 namespace compute {
22 namespace detail {
23
24 template<class InputIterator, class Compare>
25 inline InputIterator find_extrema(InputIterator first,
26 InputIterator last,
27 Compare compare,
28 const bool find_minimum,
29 command_queue &queue)
30 {
31 size_t count = iterator_range_size(first, last);
32
33 // handle trivial cases
34 if(count == 0 || count == 1){
35 return first;
36 }
37
38 const device &device = queue.get_device();
39
40 // CPU
41 if(device.type() & device::cpu) {
42 return find_extrema_on_cpu(first, last, compare, find_minimum, queue);
43 }
44
45 // GPU
46 // use serial method for small inputs
47 if(count < 512)
48 {
49 return serial_find_extrema(first, last, compare, find_minimum, queue);
50 }
51 // find_extrema_with_reduce() is used only if requirements are met
52 if(find_extrema_with_reduce_requirements_met(first, last, queue))
53 {
54 return find_extrema_with_reduce(first, last, compare, find_minimum, queue);
55 }
56
57 // use serial method for OpenCL version 1.0 due to
58 // problems with atomic_cmpxchg()
59 #ifndef BOOST_COMPUTE_CL_VERSION_1_1
60 return serial_find_extrema(first, last, compare, find_minimum, queue);
61 #endif
62
63 return find_extrema_with_atomics(first, last, compare, find_minimum, queue);
64 }
65
66 } // end detail namespace
67 } // end compute namespace
68 } // end boost namespace
69
70 #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP