Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:53

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2014 Roshan <thisisroshansmail@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
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 /// \brief Compact kernel class
0027 ///
0028 /// Subclass of meta_kernel to compact the result of set kernels to
0029 /// get actual sets
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 } //end detail namespace
0074 } //end compute namespace
0075 } //end boost namespace
0076 
0077 #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_COMPACT_HPP