/usr/include/boost/compute/algorithm
Edit: /usr/include/boost/compute/algorithm/reverse_copy.hpp (2678B)
//---------------------------------------------------------------------------//
// 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_REVERSE_COPY_HPP
#define BOOST_COMPUTE_ALGORITHM_REVERSE_COPY_HPP
#include
#include
#include
#include
#include
#include
#include
namespace boost {
namespace compute {
namespace detail {
template
struct reverse_copy_kernel : public meta_kernel
{
reverse_copy_kernel(Iterator first, Iterator last, OutputIterator result)
: meta_kernel("reverse_copy")
{
// store size of the range
m_size = detail::iterator_range_size(first, last);
add_set_arg("size", static_cast(m_size));
*this <<
decl("i") << " = get_global_id(0);\n" <<
decl("j") << " = size - get_global_id(0) - 1;\n" <<
result[var("j")] << "=" << first[var("i")] << ";\n";
}
void exec(command_queue &queue)
{
exec_1d(queue, 0, m_size);
}
size_t m_size;
};
} // end detail namespace
/// Copies the elements in the range [\p first, \p last) in reversed
/// order to the range beginning at \p result.
///
/// Space complexity: \Omega(1)
///
/// \see reverse()
template
inline OutputIterator
reverse_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue = system::default_queue())
{
BOOST_STATIC_ASSERT(is_device_iterator::value);
BOOST_STATIC_ASSERT(is_device_iterator::value);
typedef typename std::iterator_traits::difference_type difference_type;
difference_type count = std::distance(first, last);
detail::reverse_copy_kernel
kernel(first, last, result);
// run kernel
kernel.exec(queue);
// return iterator to the end of result
return result + count;
}
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_ALGORITHM_REVERSE_COPY_HPP