1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2014 Roshan <thisisroshansmail@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_COMPACT_HPP
12 #define BOOST_COMPUTE_ALGORITHM_DETAIL_COMPACT_HPP
16 #include <boost/compute/container/vector.hpp>
17 #include <boost/compute/detail/iterator_range_size.hpp>
18 #include <boost/compute/detail/meta_kernel.hpp>
19 #include <boost/compute/system.hpp>
26 /// \brief Compact kernel class
28 /// Subclass of meta_kernel to compact the result of set kernels to
31 class compact_kernel : public meta_kernel
34 unsigned int tile_size;
36 compact_kernel() : meta_kernel("compact")
41 template<class InputIterator1, class InputIterator2, class OutputIterator>
42 void set_range(InputIterator1 start,
43 InputIterator2 counts_begin,
44 InputIterator2 counts_end,
45 OutputIterator result)
47 m_count = iterator_range_size(counts_begin, counts_end) - 1;
50 "uint i = get_global_id(0);\n" <<
51 "uint count = i*" << tile_size << ";\n" <<
52 "for(uint j = " << counts_begin[expr<uint_>("i")] << "; j<" <<
53 counts_begin[expr<uint_>("i+1")] << "; j++, count++)\n" <<
55 result[expr<uint_>("j")] << " = " << start[expr<uint_>("count")]
60 event exec(command_queue &queue)
66 return exec_1d(queue, 0, m_count);
73 } //end detail namespace
74 } //end compute namespace
75 } //end boost namespace
77 #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_COMPACT_HPP