copy_n.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <[email protected]>
  3. //
  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
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_ALGORITHM_COPY_N_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_COPY_N_HPP
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/command_queue.hpp>
  14. #include <boost/compute/algorithm/copy.hpp>
  15. namespace boost {
  16. namespace compute {
  17. /// Copies \p count elements from \p first to \p result.
  18. ///
  19. /// For example, to copy four values from the host to the device:
  20. /// \code
  21. /// // values on the host and vector on the device
  22. /// float values[4] = { 1.f, 2.f, 3.f, 4.f };
  23. /// boost::compute::vector<float> vec(4, context);
  24. ///
  25. /// // copy from the host to the device
  26. /// boost::compute::copy_n(values, 4, vec.begin(), queue);
  27. /// \endcode
  28. ///
  29. /// Space complexity: \Omega(1)
  30. ///
  31. /// \see copy()
  32. template<class InputIterator, class Size, class OutputIterator>
  33. inline OutputIterator copy_n(InputIterator first,
  34. Size count,
  35. OutputIterator result,
  36. command_queue &queue = system::default_queue(),
  37. const wait_list &events = wait_list())
  38. {
  39. typedef typename std::iterator_traits<InputIterator>::difference_type difference_type;
  40. return ::boost::compute::copy(first,
  41. first + static_cast<difference_type>(count),
  42. result,
  43. queue,
  44. events);
  45. }
  46. } // end compute namespace
  47. } // end boost namespace
  48. #endif // BOOST_COMPUTE_ALGORITHM_COPY_N_HPP