]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/include/boost/compute/algorithm/detail/serial_accumulate.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / algorithm / detail / serial_accumulate.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_DETAIL_SERIAL_ACCUMULATE_HPP
12 #define BOOST_COMPUTE_ALGORITHM_DETAIL_SERIAL_ACCUMULATE_HPP
13
14 #include <boost/compute/command_queue.hpp>
15 #include <boost/compute/detail/meta_kernel.hpp>
16 #include <boost/compute/detail/iterator_range_size.hpp>
17
18 namespace boost {
19 namespace compute {
20 namespace detail {
21
22 template<class InputIterator, class OutputIterator, class T, class BinaryFunction>
23 inline void serial_accumulate(InputIterator first,
24 InputIterator last,
25 OutputIterator result,
26 T init,
27 BinaryFunction function,
28 command_queue &queue)
29 {
30 const context &context = queue.get_context();
31 size_t count = detail::iterator_range_size(first, last);
32
33 meta_kernel k("serial_accumulate");
34 size_t init_arg = k.add_arg<T>("init");
35 size_t count_arg = k.add_arg<cl_uint>("count");
36
37 k <<
38 k.decl<T>("result") << " = init;\n" <<
39 "for(uint i = 0; i < count; i++)\n" <<
40 " result = " << function(k.var<T>("result"),
41 first[k.var<cl_uint>("i")]) << ";\n" <<
42 result[0] << " = result;\n";
43
44 kernel kernel = k.compile(context);
45
46 kernel.set_arg(init_arg, init);
47 kernel.set_arg(count_arg, static_cast<cl_uint>(count));
48
49 queue.enqueue_task(kernel);
50 }
51
52 } // end detail namespace
53 } // end compute namespace
54 } // end boost namespace
55
56 #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_SERIAL_ACCUMULATE_HPP