Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:04:26

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@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_DETAIL_PRINT_RANGE_HPP
0012 #define BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP
0013 
0014 #include <vector>
0015 #include <iostream>
0016 #include <iterator>
0017 
0018 #include <boost/compute/algorithm/copy.hpp>
0019 #include <boost/compute/container/vector.hpp>
0020 #include <boost/compute/detail/is_buffer_iterator.hpp>
0021 #include <boost/compute/detail/iterator_range_size.hpp>
0022 
0023 namespace boost {
0024 namespace compute {
0025 namespace detail {
0026 
0027 template<class InputIterator>
0028 inline void print_range(InputIterator first,
0029                         InputIterator last,
0030                         command_queue &queue,
0031                         typename boost::enable_if<
0032                             is_buffer_iterator<InputIterator>
0033                         >::type* = 0)
0034 {
0035     typedef typename
0036         std::iterator_traits<InputIterator>::value_type
0037         value_type;
0038 
0039     const size_t size = iterator_range_size(first, last);
0040 
0041     // copy values to temporary vector on the host
0042     std::vector<value_type> tmp(size);
0043     ::boost::compute::copy(first, last, tmp.begin(), queue);
0044 
0045     // print values
0046     std::cout << "[ ";
0047     for(size_t i = 0; i < size; i++){
0048         std::cout << tmp[i];
0049         if(i != size - 1){
0050             std::cout << ", ";
0051         }
0052     }
0053     std::cout << " ]" << std::endl;
0054 }
0055 
0056 template<class InputIterator>
0057 inline void print_range(InputIterator first,
0058                         InputIterator last,
0059                         command_queue &queue,
0060                         typename boost::enable_if_c<
0061                             !is_buffer_iterator<InputIterator>::value
0062                         >::type* = 0)
0063 {
0064     typedef typename
0065         std::iterator_traits<InputIterator>::value_type
0066         value_type;
0067 
0068     const context &context = queue.get_context();
0069     const size_t size = iterator_range_size(first, last);
0070 
0071     // copy values to temporary vector on the device
0072     ::boost::compute::vector<value_type> tmp(size, context);
0073     ::boost::compute::copy(first, last, tmp.begin(), queue);
0074 
0075     print_range(tmp.begin(), tmp.end(), queue);
0076 }
0077 
0078 } // end detail namespace
0079 } // end compute namespace
0080 } // end boost namespace
0081 
0082 #endif // BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP