]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> | |
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 | ||
11 | #ifndef BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP | |
12 | #define BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP | |
13 | ||
14 | #include <vector> | |
15 | #include <iostream> | |
16 | #include <iterator> | |
17 | ||
18 | #include <boost/compute/algorithm/copy.hpp> | |
19 | #include <boost/compute/container/vector.hpp> | |
20 | #include <boost/compute/detail/is_buffer_iterator.hpp> | |
21 | #include <boost/compute/detail/iterator_range_size.hpp> | |
22 | ||
23 | namespace boost { | |
24 | namespace compute { | |
25 | namespace detail { | |
26 | ||
27 | template<class InputIterator> | |
28 | inline void print_range(InputIterator first, | |
29 | InputIterator last, | |
30 | command_queue &queue, | |
31 | typename boost::enable_if< | |
32 | is_buffer_iterator<InputIterator> | |
33 | >::type* = 0) | |
34 | { | |
35 | typedef typename | |
36 | std::iterator_traits<InputIterator>::value_type | |
37 | value_type; | |
38 | ||
39 | const size_t size = iterator_range_size(first, last); | |
40 | ||
41 | // copy values to temporary vector on the host | |
42 | std::vector<value_type> tmp(size); | |
43 | ::boost::compute::copy(first, last, tmp.begin(), queue); | |
44 | ||
45 | // print values | |
46 | std::cout << "[ "; | |
47 | for(size_t i = 0; i < size; i++){ | |
48 | std::cout << tmp[i]; | |
49 | if(i != size - 1){ | |
50 | std::cout << ", "; | |
51 | } | |
52 | } | |
53 | std::cout << " ]" << std::endl; | |
54 | } | |
55 | ||
56 | template<class InputIterator> | |
57 | inline void print_range(InputIterator first, | |
58 | InputIterator last, | |
59 | command_queue &queue, | |
60 | typename boost::enable_if_c< | |
61 | !is_buffer_iterator<InputIterator>::value | |
62 | >::type* = 0) | |
63 | { | |
64 | typedef typename | |
65 | std::iterator_traits<InputIterator>::value_type | |
66 | value_type; | |
67 | ||
68 | const context &context = queue.get_context(); | |
69 | const size_t size = iterator_range_size(first, last); | |
70 | ||
71 | // copy values to temporary vector on the device | |
72 | ::boost::compute::vector<value_type> tmp(size, context); | |
73 | ::boost::compute::copy(first, last, tmp.begin(), queue); | |
74 | ||
75 | print_range(tmp.begin(), tmp.end(), queue); | |
76 | } | |
77 | ||
78 | } // end detail namespace | |
79 | } // end compute namespace | |
80 | } // end boost namespace | |
81 | ||
82 | #endif // BOOST_COMPUTE_DETAIL_PRINT_RANGE_HPP |