//---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_ALGORITHM_GATHER_HPP #define BOOST_COMPUTE_ALGORITHM_GATHER_HPP #include #include #include #include #include #include #include namespace boost { namespace compute { namespace detail { template class gather_kernel : public meta_kernel { public: gather_kernel() : meta_kernel("gather") {} void set_range(MapIterator first, MapIterator last, InputIterator input, OutputIterator result) { m_count = iterator_range_size(first, last); *this << "const uint i = get_global_id(0);\n" << result[expr("i")] << "=" << input[first[expr("i")]] << ";\n"; } event exec(command_queue &queue) { if(m_count == 0) { return event(); } return exec_1d(queue, 0, m_count); } private: size_t m_count; }; } // end detail namespace /// Copies the elements using the indices from the range [\p first, \p last) /// to the range beginning at \p result using the input values from the range /// beginning at \p input. /// /// \see scatter() template inline void gather(MapIterator first, MapIterator last, InputIterator input, OutputIterator result, command_queue &queue = system::default_queue()) { detail::gather_kernel kernel; kernel.set_range(first, last, input, result); kernel.exec(queue); } } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_ALGORITHM_GATHER_HPP