]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/include/boost/compute/algorithm/gather.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / algorithm / gather.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_GATHER_HPP
12 #define BOOST_COMPUTE_ALGORITHM_GATHER_HPP
13
14 #include <boost/compute/command_queue.hpp>
15 #include <boost/compute/detail/iterator_range_size.hpp>
16 #include <boost/compute/detail/meta_kernel.hpp>
17 #include <boost/compute/exception.hpp>
18 #include <boost/compute/iterator/buffer_iterator.hpp>
19 #include <boost/compute/system.hpp>
20 #include <boost/compute/type_traits/type_name.hpp>
21
22 namespace boost {
23 namespace compute {
24 namespace detail {
25
26 template<class InputIterator, class MapIterator, class OutputIterator>
27 class gather_kernel : public meta_kernel
28 {
29 public:
30 gather_kernel() : meta_kernel("gather")
31 {}
32
33 void set_range(MapIterator first,
34 MapIterator last,
35 InputIterator input,
36 OutputIterator result)
37 {
38 m_count = iterator_range_size(first, last);
39
40 *this <<
41 "const uint i = get_global_id(0);\n" <<
42 result[expr<uint_>("i")] << "=" <<
43 input[first[expr<uint_>("i")]] << ";\n";
44 }
45
46 event exec(command_queue &queue)
47 {
48 if(m_count == 0) {
49 return event();
50 }
51
52 return exec_1d(queue, 0, m_count);
53 }
54
55 private:
56 size_t m_count;
57 };
58
59 } // end detail namespace
60
61 /// Copies the elements using the indices from the range [\p first, \p last)
62 /// to the range beginning at \p result using the input values from the range
63 /// beginning at \p input.
64 ///
65 /// \see scatter()
66 template<class InputIterator, class MapIterator, class OutputIterator>
67 inline void gather(MapIterator first,
68 MapIterator last,
69 InputIterator input,
70 OutputIterator result,
71 command_queue &queue = system::default_queue())
72 {
73 detail::gather_kernel<InputIterator, MapIterator, OutputIterator> kernel;
74
75 kernel.set_range(first, last, input, result);
76 kernel.exec(queue);
77 }
78
79 } // end compute namespace
80 } // end boost namespace
81
82 #endif // BOOST_COMPUTE_ALGORITHM_GATHER_HPP