Back to home page

EIC code displayed by LXR

 
 

    


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

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_INCLUSIVE_SCAN_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_INCLUSIVE_SCAN_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/compute/functional.hpp>
0017 #include <boost/compute/system.hpp>
0018 #include <boost/compute/command_queue.hpp>
0019 #include <boost/compute/algorithm/detail/scan.hpp>
0020 #include <boost/compute/type_traits/is_device_iterator.hpp>
0021 
0022 namespace boost {
0023 namespace compute {
0024 
0025 /// Performs an inclusive scan of the elements in the range [\p first, \p last)
0026 /// and stores the results in the range beginning at \p result.
0027 ///
0028 /// Each element in the output is assigned to the sum of the current value in
0029 /// the input with the sum of every previous value in the input.
0030 ///
0031 /// \param first first element in the range to scan
0032 /// \param last last element in the range to scan
0033 /// \param result first element in the result range
0034 /// \param binary_op associative binary operator
0035 /// \param queue command queue to perform the operation
0036 ///
0037 /// \return \c OutputIterator to the end of the result range
0038 ///
0039 /// The default operation is to add the elements up.
0040 ///
0041 /// \snippet test/test_scan.cpp inclusive_scan_int
0042 ///
0043 /// But different associative operation can be specified as \p binary_op
0044 /// instead (e.g., multiplication, maximum, minimum).
0045 ///
0046 /// \snippet test/test_scan.cpp inclusive_scan_int_multiplies
0047 ///
0048 /// Space complexity on GPUs: \Omega(n)<br>
0049 /// Space complexity on GPUs when \p first == \p result: \Omega(2n)<br>
0050 /// Space complexity on CPUs: \Omega(1)
0051 ///
0052 /// \see exclusive_scan()
0053 template<class InputIterator, class OutputIterator, class BinaryOperator>
0054 inline OutputIterator
0055 inclusive_scan(InputIterator first,
0056                InputIterator last,
0057                OutputIterator result,
0058                BinaryOperator binary_op,
0059                command_queue &queue = system::default_queue())
0060 {
0061     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0062     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0063     typedef typename
0064         std::iterator_traits<OutputIterator>::value_type output_type;
0065 
0066     return detail::scan(first, last, result, false,
0067                         output_type(0), binary_op,
0068                         queue);
0069 }
0070 
0071 /// \overload
0072 template<class InputIterator, class OutputIterator>
0073 inline OutputIterator
0074 inclusive_scan(InputIterator first,
0075                InputIterator last,
0076                OutputIterator result,
0077                command_queue &queue = system::default_queue())
0078 {
0079     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0080     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0081     typedef typename
0082         std::iterator_traits<OutputIterator>::value_type output_type;
0083 
0084     return detail::scan(first, last, result, false,
0085                         output_type(0), boost::compute::plus<output_type>(),
0086                         queue);
0087 }
0088 
0089 } // end compute namespace
0090 } // end boost namespace
0091 
0092 #endif // BOOST_COMPUTE_ALGORITHM_INCLUSIVE_SCAN_HPP