25 #ifndef BOLT_PERMUTATION_ITERATOR_H
26 #define BOLT_PERMUTATION_ITERATOR_H
29 #include <type_traits>
32 #include <bolt/cl/iterator/iterator_adaptor.h>
33 #include <bolt/cl/iterator/iterator_facade.h>
96 template<
class ElementIterator
97 ,
class IndexIterator>
100 permutation_iterator<ElementIterator, IndexIterator>
101 , IndexIterator, typename bolt::cl::iterator_traits<ElementIterator>::value_type
102 , use_default, typename bolt::cl::iterator_traits<ElementIterator>::reference
107 , IndexIterator,
typename bolt::cl::iterator_traits<ElementIterator>::value_type
108 , use_default,
typename bolt::cl::iterator_traits<ElementIterator>::reference
114 typedef std::ptrdiff_t difference_type;
115 typedef typename bolt::cl::iterator_traits<ElementIterator>::value_type value_type;
116 typedef typename bolt::cl::iterator_traits<ElementIterator>::value_type * pointer;
117 typedef typename bolt::cl::iterator_traits<IndexIterator>::value_type index_type;
125 template<
class OtherElementIterator,
class OtherIndexIterator>
131 :
super_t(r.base()), m_elt_iter(r.m_elt_iter)
134 index_type* getIndex_pointer ()
136 return &(*(this->base_reference()));
139 value_type* getElement_pointer ()
141 return &(*(this->m_elt_iter));
147 int m_ElementPtr[ 3 ];
151 const Payload gpuPayload( )
const
153 Payload payload = { 0, { 0, 0, 0 }, { 0, 0, 0 } };
157 const difference_type gpuPayloadSize( )
const
159 cl_int l_Error = CL_SUCCESS;
163 cl_uint deviceBits = 32;
165 difference_type payloadSize =
sizeof( int ) + 2*( deviceBits >> 3 );
168 if( deviceBits == 64 )
174 int setKernelBuffers(
int arg_num, ::cl::Kernel &kernel)
const
177 arg_num = m_elt_iter.setKernelBuffers(arg_num, kernel);
179 arg_num = this->base().setKernelBuffers(arg_num, kernel);
185 typename super_t::reference dereference()
const
186 {
return *(m_elt_iter + *this->base()); }
190 ElementIterator m_elt_iter;
194 template <
class ElementIterator,
class IndexIterator>
195 permutation_iterator<ElementIterator, IndexIterator>
196 make_permutation_iterator( ElementIterator e, IndexIterator i )
198 return permutation_iterator<ElementIterator, IndexIterator>( e, i );
203 static std::string devicePermutationIteratorTemplate =
205 bolt::cl::deviceVectorIteratorTemplate +
206 bolt::cl::deviceConstantIterator +
207 bolt::cl::deviceCountingIterator +
208 std::string(
"#if !defined(BOLT_CL_PERMUTATION_ITERATOR) \n#define BOLT_CL_PERMUTATION_ITERATOR \n") +
210 namespace bolt {
namespace cl { \n
211 template<
typename IndexIterator,
typename ElementIterator > \n
212 class permutation_iterator \n
215 typedef int iterator_category; \n
216 typedef typename ElementIterator::value_type value_type; \n
217 typedef typename ElementIterator::value_type base_type; \n
218 typedef typename IndexIterator::value_type index_type; \n
219 typedef int difference_type; \n
220 typedef int size_type; \n
221 typedef value_type* pointer; \n
222 typedef value_type& reference; \n
224 permutation_iterator( value_type init ): m_StartIndex( init ), m_Ptr( 0 ) \n
227 void init( global value_type* element_ptr, global index_type* index_ptr )\n
229 m_ElementPtr = element_ptr; \n
230 m_IndexPtr = index_ptr; \n
233 value_type operator[]( size_type threadID ) const \n
235 return m_ElementPtr[ m_IndexPtr[ m_StartIndex + threadID ] ]; \n
238 value_type operator*( ) const \n
240 return m_ElementPtr[m_IndexPtr[ m_StartIndex + threadID ] ]; \n
243 size_type m_StartIndex; \n
244 global value_type* m_ElementPtr; \n
245 global index_type* m_IndexPtr; \n
249 + std::string(
"#endif \n");