]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/exclusive_scan.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / exclusive_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_EXCLUSIVE_SCAN_HPP
12 #define BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_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 exclusive 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 all the previous
26 /// values 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 init value used to initialize the scan sequence
32 /// \param binary_op associative binary operator
33 /// \param queue command queue to perform the operation
34 ///
35 /// \return \c OutputIterator to the end of the result range
36 ///
37 /// The default operation is to add the elements up.
38 ///
39 /// \snippet test/test_scan.cpp exclusive_scan_int
40 ///
41 /// But different associative operation can be specified as \p binary_op
42 /// instead (e.g., multiplication, maximum, minimum). Also value used to
43 /// initialized the scan sequence can be specified.
44 ///
45 /// \snippet test/test_scan.cpp exclusive_scan_int_multiplies
46 ///
47 /// Space complexity on GPUs: \Omega(n)<br>
48 /// Space complexity on GPUs when \p first == \p result: \Omega(2n)<br>
49 /// Space complexity on CPUs: \Omega(1)
50 ///
51 /// \see inclusive_scan()
52 template<class InputIterator, class OutputIterator, class T, class BinaryOperator>
53 inline OutputIterator
54 exclusive_scan(InputIterator first,
55 InputIterator last,
56 OutputIterator result,
57 T init,
58 BinaryOperator binary_op,
59 command_queue &queue = system::default_queue())
60 {
61 return detail::scan(first, last, result, true, init, binary_op, queue);
62 }
63
64 /// \overload
65 template<class InputIterator, class OutputIterator, class T>
66 inline OutputIterator
67 exclusive_scan(InputIterator first,
68 InputIterator last,
69 OutputIterator result,
70 T init,
71 command_queue &queue = system::default_queue())
72 {
73 typedef typename
74 std::iterator_traits<OutputIterator>::value_type output_type;
75
76 return detail::scan(first, last, result, true,
77 init, boost::compute::plus<output_type>(),
78 queue);
79 }
80
81 /// \overload
82 template<class InputIterator, class OutputIterator>
83 inline OutputIterator
84 exclusive_scan(InputIterator first,
85 InputIterator last,
86 OutputIterator result,
87 command_queue &queue = system::default_queue())
88 {
89 typedef typename
90 std::iterator_traits<OutputIterator>::value_type output_type;
91
92 return detail::scan(first, last, result, true,
93 output_type(0), boost::compute::plus<output_type>(),
94 queue);
95 }
96
97 } // end compute namespace
98 } // end boost namespace
99
100 #endif // BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP