1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP
12 #define BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP
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>
24 template<class InputIterator, class Compare>
25 inline InputIterator find_extrema(InputIterator first,
28 const bool find_minimum,
31 size_t count = iterator_range_size(first, last);
33 // handle trivial cases
34 if(count == 0 || count == 1){
38 const device &device = queue.get_device();
41 if(device.type() & device::cpu) {
42 return find_extrema_on_cpu(first, last, compare, find_minimum, queue);
46 // use serial method for small inputs
49 return serial_find_extrema(first, last, compare, find_minimum, queue);
51 // find_extrema_with_reduce() is used only if requirements are met
52 if(find_extrema_with_reduce_requirements_met(first, last, queue))
54 return find_extrema_with_reduce(first, last, compare, find_minimum, queue);
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);
63 return find_extrema_with_atomics(first, last, compare, find_minimum, queue);
66 } // end detail namespace
67 } // end compute namespace
68 } // end boost namespace
70 #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP