Bolt  1.3
C++ template library with support for OpenCL
addressof.h
1 /***************************************************************************
2 * © 2012,2014 Advanced Micro Devices, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 
16 ***************************************************************************/
17 #ifndef BOLT_AMP_ADDRESSOF_H
18 #define BOLT_AMP_ADDRESSOF_H
19 #include <bolt/amp/device_vector.h>
24 
25 namespace bolt{
26 namespace amp{
27 
28  template < typename Iterator >
29  Iterator
30  create_mapped_iterator(bolt::amp::permutation_iterator_tag, Iterator first1, int sz, bool var, ::bolt::amp::control &ctl)
31  {
32  return first1;
33  }
34 
35  template <typename Iterator>
36  Iterator
37  create_mapped_iterator(bolt::amp::transform_iterator_tag, Iterator first1, int sz, bool var, ::bolt::amp::control &ctl)
38  {
39  return first1;
40  }
41 
42  template <typename Iterator>
44  create_mapped_iterator(bolt::amp::device_vector_tag, Iterator itr, int sz, bool var, ::bolt::amp::control &ctl)
45  {
46  return itr;
47  }
48 
49  template <typename Iterator>
51  create_mapped_iterator(std::random_access_iterator_tag, Iterator first1, int sz, bool var, ::bolt::amp::control &ctl)
52  {
53  typedef typename std::iterator_traits<Iterator>::value_type iType;
54  typedef typename std::iterator_traits<Iterator>::pointer pointer1;
55 
56  pointer1 first_pointer1 = std::addressof(*first1);
57 
58  device_vector< iType, concurrency::array_view > dvInput1( first_pointer1, sz, var, ctl );
59  return dvInput1.begin();
60 
61  }
62 
63 
64  template <typename T>
66  create_mapped_iterator(std::random_access_iterator_tag, T* first1, int sz, bool var, ::bolt::amp::control &ctl)
67  {
68  device_vector< T, concurrency::array_view > dvInput1( first1, sz, var, ctl );
69  return dvInput1.begin();
70  }
71 
72  template <typename Iterator>
73  const constant_iterator<typename Iterator::value_type>
74  create_mapped_iterator(bolt::amp::constant_iterator_tag, Iterator itr, int sz, bool var, ::bolt::amp::control &ctl)
75  {
76  return itr;
77  }
78 
79  template <typename Iterator>
80  const counting_iterator<typename Iterator::value_type>
81  create_mapped_iterator(bolt::amp::counting_iterator_tag, Iterator itr, int sz, bool var, ::bolt::amp::control &ctl)
82  {
83  return itr;
84  }
85 
86 
87 
88  template <typename Iterator>
89  Iterator
90  create_mapped_iterator(bolt::amp::transform_iterator_tag, bolt::amp::control &ctl, Iterator &itr)
91  {
92  return itr;
93  }
94 
95  template <typename Iterator>
96  Iterator
97  create_mapped_iterator(bolt::amp::permutation_iterator_tag, bolt::amp::control &ctl, Iterator &itr)
98  {
99  return itr;
100  }
101 
102 
103  template <typename T>
104  T *
105  create_mapped_iterator(std::random_access_iterator_tag, bolt::amp::control &ctl, T* first1)
106  {
107  return first1;
108  }
109 
110 
111  template <typename Iterator>
112  typename std::vector<typename Iterator::value_type>::iterator
113  create_mapped_iterator(std::random_access_iterator_tag, bolt::amp::control &ctl, Iterator &itr)
114  {
115  return itr;
116  }
117 
118 
119  template <typename Iterator>
120  typename std::iterator_traits<Iterator>::value_type *
121  create_mapped_iterator(bolt::amp::device_vector_tag, bolt::amp::control &ctl, Iterator &itr)
122  {
123  typedef typename std::iterator_traits<Iterator>::value_type iType1;
124  bolt::amp::device_vector< iType1 >::pointer first1Ptr = itr.getContainer( ).data( );
125 
126  return first1Ptr + itr.m_Index;
127  }
128 
129  template <typename Iterator>
130  const constant_iterator<typename Iterator::value_type> &
131  create_mapped_iterator(bolt::amp::constant_iterator_tag, bolt::amp::control &ctl, Iterator &itr)
132  {
133  return itr;
134  }
135 
136  template <typename Iterator>
137  const counting_iterator<typename Iterator::value_type> &
138  create_mapped_iterator(bolt::amp::counting_iterator_tag, bolt::amp::control &ctl, Iterator &itr)
139  {
140  return itr;
141  }
142 
143  }
144 }
145 
146 
147 #endif