37 #ifndef VIGRA_OPENCL_HXX
38 #define VIGRA_OPENCL_HXX
40 #include "numerictraits.hxx"
43 #include <OpenCL/opencl.h>
45 #include <CL/opencl.h>
56 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION
58 #define VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(basetype, n) \
60 struct NumericTraits< basetype##n > \
62 typedef basetype##n Type; \
63 typedef Type Promote; \
64 typedef Type UnsignedPromote; \
65 typedef Type RealPromote; \
66 typedef std::complex<Type> ComplexPromote; \
67 typedef basetype ValueType; \
69 typedef VigraFalseType isIntegral; \
70 typedef VigraFalseType isScalar; \
71 typedef typename NumericTraits<ValueType>::isSigned isSigned; \
72 typedef VigraFalseType isOrdered; \
73 typedef typename NumericTraits<ValueType>::isComplex isComplex; \
75 static Type zero() { Type x; bzero(&x, sizeof(x)); return x; } \
76 static Type one() { Type x = {{1}}; return x; } \
77 static Type nonZero() { return one(); } \
79 static Promote toPromote(Type const & v) { return v; } \
80 static Type fromPromote(Promote const & v) { return v; } \
81 static Type fromRealPromote(RealPromote v) { return v; } \
84 #define VIGRA_OPENCL_VECTYPEN_REAL_TRAITS(basetype, n) \
86 struct NumericTraits< basetype##n > \
88 typedef basetype##n Type; \
89 typedef Type Promote; \
90 typedef Type UnsignedPromote; \
91 typedef Type RealPromote; \
92 typedef std::complex<Type> ComplexPromote; \
93 typedef basetype ValueType; \
95 typedef VigraFalseType isIntegral; \
96 typedef VigraFalseType isScalar; \
97 typedef typename NumericTraits<ValueType>::isSigned isSigned; \
98 typedef VigraFalseType isOrdered; \
99 typedef typename NumericTraits<ValueType>::isComplex isComplex; \
101 static Type zero() { Type x; bzero(&x, sizeof(x)); return x; } \
102 static Type one() { Type x = {{1}}; return x; } \
103 static Type nonZero() { return one(); } \
104 static Type epsilon() { Type x; x.x = NumericTraits<ValueType>::epsilon(); return x; } \
105 static Type smallestPositive() { Type x; x.x = NumericTraits<ValueType>::smallestPositive(); return x; } \
107 static Promote toPromote(Type const & v) { return v; } \
108 static Type fromPromote(Promote const & v) { return v; } \
109 static Type fromRealPromote(RealPromote v) { return v; } \
114 #define VIGRA_OPENCL_VECN_TRAITS(n) \
115 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_char, n); \
116 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_uchar, n); \
117 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_short, n); \
118 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_ushort, n); \
119 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_int, n); \
120 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_uint, n); \
121 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_long, n); \
122 VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS(cl_ulong, n); \
123 VIGRA_OPENCL_VECTYPEN_REAL_TRAITS(cl_float, n); \
124 VIGRA_OPENCL_VECTYPEN_REAL_TRAITS(cl_double, n);
126 VIGRA_OPENCL_VECN_TRAITS(2);
127 VIGRA_OPENCL_VECN_TRAITS(3);
129 VIGRA_OPENCL_VECN_TRAITS(8);
130 VIGRA_OPENCL_VECN_TRAITS(16);
132 #undef VIGRA_OPENCL_VECTYPEN_INTEGER_TRAITS
133 #undef VIGRA_OPENCL_VECTYPEN_REAL_TRAITS
134 #undef VIGRA_OPENCL_VECN_TRAITS
142 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION
158 struct NormTraits<fftw_complex>
160 typedef fftw_complex Type;
161 typedef fftw_real SquaredNormType;
162 typedef fftw_real NormType;
166 struct NormTraits<FFTWComplex<Real> >
168 typedef FFTWComplex<Real> Type;
169 typedef typename Type::SquaredNormType SquaredNormType;
170 typedef typename Type::NormType NormType;
182 struct CanSkipInitialization<std::complex<T> >
184 typedef typename CanSkipInitialization<T>::type type;
185 static const bool value = type::asBool;
195 namespace multi_math {
292 #define VIGRA_OPENCL_TYPE_ACCESSOR(basetype, n, NTH) \
293 class basetype##n##Accessor_##NTH \
297 typedef NumericTraits< basetype##n >::ValueType value_type; \
300 template <class ITERATOR> \
301 value_type operator()(ITERATOR const & i) const { \
306 template <class ITERATOR, class DIFFERENCE> \
307 value_type operator()(ITERATOR const & i, DIFFERENCE d) const { \
312 template <class ITERATOR> \
313 void set(value_type const & v, ITERATOR const & i) const { \
318 template <class ITERATOR, class DIFFERENCE> \
319 void set(value_type const & v, ITERATOR const & i, DIFFERENCE d) const { \
324 template <class R, class ITERATOR> \
325 void set(FFTWComplex<R> const & v, ITERATOR const & i) const { \
330 template <class R, class ITERATOR, class DIFFERENCE> \
331 void set(FFTWComplex<R> const & v, ITERATOR const & i, DIFFERENCE d) const { \
335 class basetype##n##WriteAccessor_##NTH \
336 : public basetype##n##Accessor_##NTH \
340 typedef NumericTraits< basetype##n >::ValueType value_type; \
343 template <class ITERATOR> \
344 void set(value_type const & v, ITERATOR const & i) const { \
349 template <class ITERATOR, class DIFFERENCE> \
350 void set(value_type const & v, ITERATOR const & i, DIFFERENCE d) const { \
355 #define VIGRA_OPENCL_TYPE2_ACCESSORS(basetype) \
356 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 2, s0); \
357 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 2, s1); \
358 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 2, x); \
359 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 2, y);
361 #define VIGRA_OPENCL_TYPE3_ACCESSORS(basetype) \
362 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 3, s0); \
363 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 3, s1); \
364 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 3, s2); \
365 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 3, x); \
366 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 3, y); \
367 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 3, z);
369 #define VIGRA_OPENCL_TYPE4_ACCESSORS(basetype) \
370 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, s0); \
371 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, s1); \
372 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, s2); \
373 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, s3); \
374 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, x); \
375 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, y); \
376 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, z); \
377 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 4, w);
379 #define VIGRA_OPENCL_TYPE8_ACCESSORS(basetype) \
380 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s0); \
381 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s1); \
382 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s2); \
383 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s3); \
384 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s4); \
385 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s5); \
386 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s6); \
387 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s7); \
388 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 8, s8);
390 #define VIGRA_OPENCL_TYPE16_ACCESSORS(basetype) \
391 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s0); \
392 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s1); \
393 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s2); \
394 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s3); \
395 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s4); \
396 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s5); \
397 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s6); \
398 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s7); \
399 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, s8); \
400 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sa); \
401 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sb); \
402 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sc); \
403 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sd); \
404 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, se); \
405 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sf); \
406 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sA); \
407 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sB); \
408 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sC); \
409 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sD); \
410 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sE); \
411 VIGRA_OPENCL_TYPE_ACCESSOR(basetype, 16, sF);
415 #define VIGRA_OPENCL_ACCESSORS(basetype) \
416 VIGRA_OPENCL_TYPE2_ACCESSORS(basetype); \
417 VIGRA_OPENCL_TYPE3_ACCESSORS(basetype); \
418 VIGRA_OPENCL_TYPE4_ACCESSORS(basetype); \
419 VIGRA_OPENCL_TYPE8_ACCESSORS(basetype); \
420 VIGRA_OPENCL_TYPE16_ACCESSORS(basetype);
422 VIGRA_OPENCL_ACCESSORS(cl_char);
423 VIGRA_OPENCL_ACCESSORS(cl_uchar);
424 VIGRA_OPENCL_ACCESSORS(cl_short);
425 VIGRA_OPENCL_ACCESSORS(cl_ushort);
426 VIGRA_OPENCL_ACCESSORS(cl_int);
427 VIGRA_OPENCL_ACCESSORS(cl_uint);
428 VIGRA_OPENCL_ACCESSORS(cl_long);
429 VIGRA_OPENCL_ACCESSORS(cl_ulong);
430 VIGRA_OPENCL_ACCESSORS(cl_float);
431 VIGRA_OPENCL_ACCESSORS(cl_double);
433 #undef VIGRA_OPENCL_TYPE_ACCESSOR
434 #undef VIGRA_OPENCL_TYPE2_ACCESSORS
435 #undef VIGRA_OPENCL_TYPE3_ACCESSORS
436 #undef VIGRA_OPENCL_TYPE4_ACCESSORS
437 #undef VIGRA_OPENCL_TYPE8_ACCESSORS
438 #undef VIGRA_OPENCL_TYPE16_ACCESSORS
439 #undef VIGRA_OPENCL_ACCESSORS
443 #endif // VIGRA_OPENCL_HXX