File indexing completed on 2025-01-18 09:29:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_COMPACT_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_DETAIL_COMPACT_HPP
0013
0014 #include <iterator>
0015
0016 #include <boost/compute/container/vector.hpp>
0017 #include <boost/compute/detail/iterator_range_size.hpp>
0018 #include <boost/compute/detail/meta_kernel.hpp>
0019 #include <boost/compute/system.hpp>
0020
0021 namespace boost {
0022 namespace compute {
0023 namespace detail {
0024
0025
0026
0027
0028
0029
0030
0031 class compact_kernel : public meta_kernel
0032 {
0033 public:
0034 unsigned int tile_size;
0035
0036 compact_kernel() : meta_kernel("compact")
0037 {
0038 tile_size = 4;
0039 }
0040
0041 template<class InputIterator1, class InputIterator2, class OutputIterator>
0042 void set_range(InputIterator1 start,
0043 InputIterator2 counts_begin,
0044 InputIterator2 counts_end,
0045 OutputIterator result)
0046 {
0047 m_count = iterator_range_size(counts_begin, counts_end) - 1;
0048
0049 *this <<
0050 "uint i = get_global_id(0);\n" <<
0051 "uint count = i*" << tile_size << ";\n" <<
0052 "for(uint j = " << counts_begin[expr<uint_>("i")] << "; j<" <<
0053 counts_begin[expr<uint_>("i+1")] << "; j++, count++)\n" <<
0054 "{\n" <<
0055 result[expr<uint_>("j")] << " = " << start[expr<uint_>("count")]
0056 << ";\n" <<
0057 "}\n";
0058 }
0059
0060 event exec(command_queue &queue)
0061 {
0062 if(m_count == 0) {
0063 return event();
0064 }
0065
0066 return exec_1d(queue, 0, m_count);
0067 }
0068
0069 private:
0070 size_t m_count;
0071 };
0072
0073 }
0074 }
0075 }
0076
0077 #endif