File indexing completed on 2025-01-18 09:29:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_SERIAL_ACCUMULATE_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_DETAIL_SERIAL_ACCUMULATE_HPP
0013
0014 #include <boost/compute/command_queue.hpp>
0015 #include <boost/compute/detail/meta_kernel.hpp>
0016 #include <boost/compute/detail/iterator_range_size.hpp>
0017
0018 namespace boost {
0019 namespace compute {
0020 namespace detail {
0021
0022 template<class InputIterator, class OutputIterator, class T, class BinaryFunction>
0023 inline void serial_accumulate(InputIterator first,
0024 InputIterator last,
0025 OutputIterator result,
0026 T init,
0027 BinaryFunction function,
0028 command_queue &queue)
0029 {
0030 const context &context = queue.get_context();
0031 size_t count = detail::iterator_range_size(first, last);
0032
0033 meta_kernel k("serial_accumulate");
0034 size_t init_arg = k.add_arg<T>("init");
0035 size_t count_arg = k.add_arg<cl_uint>("count");
0036
0037 k <<
0038 k.decl<T>("result") << " = init;\n" <<
0039 "for(uint i = 0; i < count; i++)\n" <<
0040 " result = " << function(k.var<T>("result"),
0041 first[k.var<cl_uint>("i")]) << ";\n" <<
0042 result[0] << " = result;\n";
0043
0044 kernel kernel = k.compile(context);
0045
0046 kernel.set_arg(init_arg, init);
0047 kernel.set_arg(count_arg, static_cast<cl_uint>(count));
0048
0049 queue.enqueue_task(kernel);
0050 }
0051
0052 }
0053 }
0054 }
0055
0056 #endif