24 #ifndef BOLT_TRANSFORM_ITERATOR_H
25 #define BOLT_TRANSFORM_ITERATOR_H
27 #include <type_traits>
29 #include <bolt/cl/iterator/iterator_adaptor.h>
30 #include <bolt/cl/iterator/iterator_facade.h>
142 template <
class UnaryFunction,
class Iterator,
class Reference = use_default,
class Value = use_default>
148 template <
class UnaryFunc,
class Iterator,
class Reference,
class Value>
156 , std::result_of< const UnaryFunc(typename std::iterator_traits<Iterator>::reference) >
166 , std::remove_reference<reference>
181 template <
class UnaryFunc,
class Iterator,
class Reference,
class Value>
193 typedef typename bolt::cl::iterator_category<Iterator>::type memory_system;
196 typedef UnaryFunc unary_func;
197 typedef typename std::iterator_traits<Iterator>::value_type value_type;
198 typedef std::ptrdiff_t difference_type;
199 typedef typename std::iterator_traits<Iterator>::pointer pointer;
212 class OtherUnaryFunction
213 ,
class OtherIterator
214 ,
class OtherReference
219 :
super_t(t.base()), m_f(t.functor())
223 value_type* getPointer()
225 Iterator base_iterator = this->base_reference();
226 return &(*base_iterator);
229 const value_type* getPointer()
const
231 Iterator base_iterator = this->base_reference();
232 return &(*base_iterator);
235 UnaryFunc functor()
const
247 template<
typename Container >
248 Container& getContainer( )
const
250 return this->base().getContainer( );
253 const Payload gpuPayload( )
const
255 Payload payload = { 0, { 0, 0, 0 } };
260 const difference_type gpuPayloadSize( )
const
262 cl_int l_Error = CL_SUCCESS;
266 cl_uint deviceBits = 32;
268 cl_uint szUF =
sizeof(UnaryFunc);
269 szUF = (szUF+3) &(~3);
270 difference_type payloadSize =
sizeof( int ) + ( deviceBits >> 3 ) + szUF;
273 if( deviceBits == 64 )
279 int setKernelBuffers(
int arg_num, ::cl::Kernel &kernel)
const
282 arg_num = this->base().setKernelBuffers(arg_num, kernel);
286 typename super_t::reference dereference()
const
287 {
return m_f(*this->base()); }
292 template <
class UnaryFunc,
class Iterator>
294 make_transform_iterator(Iterator it, UnaryFunc fun)
306 template <
class UnaryFunc,
class Iterator>
307 typename std::enable_if<
308 std::is_class<UnaryFunc>::value
311 make_transform_iterator(Iterator it)
317 static std::string deviceTransformIteratorTemplate =
318 bolt::cl::deviceVectorIteratorTemplate +
319 std::string(
"#if !defined(BOLT_CL_TRANSFORM_ITERATOR) \n#define BOLT_CL_TRANSFORM_ITERATOR \n") +
321 namespace bolt {
namespace cl { \n
322 template<
typename UnaryFunc,
typename Iterator > \n
323 class transform_iterator \n
326 typedef int iterator_category; \n
327 typedef typename UnaryFunc::result_type value_type; \n
328 typedef typename Iterator::value_type base_type; \n
329 typedef int size_type; \n
331 transform_iterator( size_type init ): m_StartIndex( init ), m_Ptr( 0 ) \n
334 void init( global base_type* ptr )\n
339 value_type operator[]( size_type threadID ) const \n
341 base_type tmp = m_Ptr[ m_StartIndex + threadID ]; \n
345 value_type operator*( ) const \n
347 base_type tmp = m_Ptr[ m_StartIndex + threadID ]; \n
348 return m_f( tmp ); \n
351 size_type m_StartIndex; \n
352 global base_type* m_Ptr; \n
357 + std::string(
"#endif \n");
362 #endif // BOLT_TRANSFORM_ITERATOR_H