]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/inclusive_scan.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / inclusive_scan.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_INCLUSIVE_SCAN_HPP
12 #define BOOST_COMPUTE_ALGORITHM_INCLUSIVE_SCAN_HPP
13
14 #include <boost/compute/functional.hpp>
15 #include <boost/compute/system.hpp>
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/algorithm/detail/scan.hpp>
18
19 namespace boost {
20 namespace compute {
21
22 /// Performs an inclusive scan of the elements in the range [\p first, \p last)
23 /// and stores the results in the range beginning at \p result.
24 ///
25 /// Each element in the output is assigned to the sum of the current value in
26 /// the input with the sum of every previous value in the input.
27 ///
28 /// \param first first element in the range to scan
29 /// \param last last element in the range to scan
30 /// \param result first element in the result range
31 /// \param binary_op associative binary operator
32 /// \param queue command queue to perform the operation
33 ///
34 /// \return \c OutputIterator to the end of the result range
35 ///
36 /// The default operation is to add the elements up.
37 ///
38 /// \snippet test/test_scan.cpp inclusive_scan_int
39 ///
40 /// But different associative operation can be specified as \p binary_op
41 /// instead (e.g., multiplication, maximum, minimum).
42 ///
43 /// \snippet test/test_scan.cpp inclusive_scan_int_multiplies
44 ///
45 /// Space complexity on GPUs: \Omega(n)<br>
46 /// Space complexity on GPUs when \p first == \p result: \Omega(2n)<br>
47 /// Space complexity on CPUs: \Omega(1)
48 ///
49 /// \see exclusive_scan()
50 template<class InputIterator, class OutputIterator, class BinaryOperator>
51 inline OutputIterator
52 inclusive_scan(InputIterator first,
53 InputIterator last,
54 OutputIterator result,
55 BinaryOperator binary_op,
56 command_queue &queue = system::default_queue())
57 {
58 typedef typename
59 std::iterator_traits<OutputIterator>::value_type output_type;
60
61 return detail::scan(first, last, result, false,
62 output_type(0), binary_op,
63 queue);
64 }
65
66 /// \overload
67 template<class InputIterator, class OutputIterator>
68 inline OutputIterator
69 inclusive_scan(InputIterator first,
70 InputIterator last,
71 OutputIterator result,
72 command_queue &queue = system::default_queue())
73 {
74 typedef typename
75 std::iterator_traits<OutputIterator>::value_type output_type;
76
77 return detail::scan(first, last, result, false,
78 output_type(0), boost::compute::plus<output_type>(),
79 queue);
80 }
81
82 } // end compute namespace
83 } // end boost namespace
84
85 #endif // BOOST_COMPUTE_ALGORITHM_INCLUSIVE_SCAN_HPP