Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:54

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP
0013 
0014 #include <boost/compute/detail/iterator_range_size.hpp>
0015 #include <boost/compute/algorithm/detail/find_extrema_on_cpu.hpp>
0016 #include <boost/compute/algorithm/detail/find_extrema_with_reduce.hpp>
0017 #include <boost/compute/algorithm/detail/find_extrema_with_atomics.hpp>
0018 #include <boost/compute/algorithm/detail/serial_find_extrema.hpp>
0019 
0020 namespace boost {
0021 namespace compute {
0022 namespace detail {
0023 
0024 template<class InputIterator, class Compare>
0025 inline InputIterator find_extrema(InputIterator first,
0026                                   InputIterator last,
0027                                   Compare compare,
0028                                   const bool find_minimum,
0029                                   command_queue &queue)
0030 {
0031     size_t count = iterator_range_size(first, last);
0032 
0033     // handle trivial cases
0034     if(count == 0 || count == 1){
0035         return first;
0036     }
0037 
0038     const device &device = queue.get_device();
0039 
0040     // CPU
0041     if(device.type() & device::cpu) {
0042         return find_extrema_on_cpu(first, last, compare, find_minimum, queue);
0043     }
0044 
0045     // GPU
0046     // use serial method for small inputs
0047     if(count < 512)
0048     {
0049         return serial_find_extrema(first, last, compare, find_minimum, queue);
0050     }
0051     // find_extrema_with_reduce() is used only if requirements are met
0052     if(find_extrema_with_reduce_requirements_met(first, last, queue))
0053     {
0054         return find_extrema_with_reduce(first, last, compare, find_minimum, queue);
0055     }
0056 
0057     // use serial method for OpenCL version 1.0 due to
0058     // problems with atomic_cmpxchg()
0059     #ifndef BOOST_COMPUTE_CL_VERSION_1_1
0060         return serial_find_extrema(first, last, compare, find_minimum, queue);
0061     #endif
0062 
0063     return find_extrema_with_atomics(first, last, compare, find_minimum, queue);
0064 }
0065 
0066 } // end detail namespace
0067 } // end compute namespace
0068 } // end boost namespace
0069 
0070 #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_FIND_EXTREMA_HPP