QUDA  v1.1.0
A library for QCD on GPUs
float_vector.h
Go to the documentation of this file.
1 #include <complex_quda.h>
2 
10 #pragma once
11 
12 namespace quda {
13 
14  __host__ __device__ inline double2 operator+(const double2 &x, const double2 &y)
15  {
16  return make_double2(x.x + y.x, x.y + y.y);
17  }
18 
19  __host__ __device__ inline double2 operator-(const double2 &x, const double2 &y)
20  {
21  return make_double2(x.x - y.x, x.y - y.y);
22  }
23 
24  __host__ __device__ inline float2 operator-(const float2 &x, const float2 &y)
25  {
26  return make_float2(x.x - y.x, x.y - y.y);
27  }
28 
29  __host__ __device__ inline float4 operator-(const float4 &x, const float4 &y)
30  {
31  return make_float4(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w);
32  }
33 
34  __host__ __device__ inline float8 operator-(const float8 &x, const float8 &y)
35  {
36  float8 z;
37  z.x = x.x - y.x;
38  z.y = x.y - y.y;
39  return z;
40  }
41 
42  __host__ __device__ inline double3 operator+(const double3 &x, const double3 &y)
43  {
44  return make_double3(x.x + y.x, x.y + y.y, x.z + y.z);
45  }
46 
47  __host__ __device__ inline double4 operator+(const double4 &x, const double4 &y)
48  {
49  return make_double4(x.x + y.x, x.y + y.y, x.z + y.z, x.w + y.w);
50  }
51 
52  __host__ __device__ inline float4 operator*(const float &a, const float4 &x)
53  {
54  float4 y;
55  y.x = a*x.x;
56  y.y = a*x.y;
57  y.z = a*x.z;
58  y.w = a*x.w;
59  return y;
60  }
61 
62  __host__ __device__ inline float2 operator*(const float &a, const float2 &x)
63  {
64  float2 y;
65  y.x = a*x.x;
66  y.y = a*x.y;
67  return y;
68  }
69 
70  __host__ __device__ inline double2 operator*(const double &a, const double2 &x)
71  {
72  double2 y;
73  y.x = a*x.x;
74  y.y = a*x.y;
75  return y;
76  }
77 
78  __host__ __device__ inline double4 operator*(const double &a, const double4 &x)
79  {
80  double4 y;
81  y.x = a*x.x;
82  y.y = a*x.y;
83  y.z = a*x.z;
84  y.w = a*x.w;
85  return y;
86  }
87 
88  __host__ __device__ inline float8 operator*(const float &a, const float8 &x)
89  {
90  float8 y;
91  y.x = a * x.x;
92  y.y = a * x.y;
93  return y;
94  }
95 
96  __host__ __device__ inline float2 operator+(const float2 &x, const float2 &y)
97  {
98  float2 z;
99  z.x = x.x + y.x;
100  z.y = x.y + y.y;
101  return z;
102  }
103 
104  __host__ __device__ inline float4 operator+(const float4 &x, const float4 &y)
105  {
106  float4 z;
107  z.x = x.x + y.x;
108  z.y = x.y + y.y;
109  z.z = x.z + y.z;
110  z.w = x.w + y.w;
111  return z;
112  }
113 
114  __host__ __device__ inline float8 operator+(const float8 &x, const float8 &y)
115  {
116  float8 z;
117  z.x = x.x + y.x;
118  z.y = x.y + y.y;
119  return z;
120  }
121 
122  __host__ __device__ inline float4 operator+=(float4 &x, const float4 &y)
123  {
124  x.x += y.x;
125  x.y += y.y;
126  x.z += y.z;
127  x.w += y.w;
128  return x;
129  }
130 
131  __host__ __device__ inline float2 operator+=(float2 &x, const float2 &y)
132  {
133  x.x += y.x;
134  x.y += y.y;
135  return x;
136  }
137 
138  __host__ __device__ inline float8 operator+=(float8 &x, const float8 &y)
139  {
140  x.x += y.x;
141  x.y += y.y;
142  return x;
143  }
144 
145  __host__ __device__ inline double2 operator+=(double2 &x, const double2 &y)
146  {
147  x.x += y.x;
148  x.y += y.y;
149  return x;
150  }
151 
152  __host__ __device__ inline double3 operator+=(double3 &x, const double3 &y)
153  {
154  x.x += y.x;
155  x.y += y.y;
156  x.z += y.z;
157  return x;
158  }
159 
160  __host__ __device__ inline double4 operator+=(double4 &x, const double4 &y)
161  {
162  x.x += y.x;
163  x.y += y.y;
164  x.z += y.z;
165  x.w += y.w;
166  return x;
167  }
168 
169  __host__ __device__ inline float4 operator-=(float4 &x, const float4 &y)
170  {
171  x.x -= y.x;
172  x.y -= y.y;
173  x.z -= y.z;
174  x.w -= y.w;
175  return x;
176  }
177 
178  __host__ __device__ inline float2 operator-=(float2 &x, const float2 &y)
179  {
180  x.x -= y.x;
181  x.y -= y.y;
182  return x;
183  }
184 
185  __host__ __device__ inline float8 operator-=(float8 &x, const float8 &y)
186  {
187  x.x -= y.x;
188  x.y -= y.y;
189  return x;
190  }
191 
192  __host__ __device__ inline double2 operator-=(double2 &x, const double2 &y)
193  {
194  x.x -= y.x;
195  x.y -= y.y;
196  return x;
197  }
198 
199  __host__ __device__ inline float2 operator*=(float2 &x, const float &a)
200  {
201  x.x *= a;
202  x.y *= a;
203  return x;
204  }
205 
206  __host__ __device__ inline double2 operator*=(double2 &x, const float &a)
207  {
208  x.x *= a;
209  x.y *= a;
210  return x;
211  }
212 
213  __host__ __device__ inline float4 operator*=(float4 &a, const float &b) {
214  a.x *= b;
215  a.y *= b;
216  a.z *= b;
217  a.w *= b;
218  return a;
219  }
220 
221  __host__ __device__ inline float8 operator*=(float8 &a, const float &b)
222  {
223  a.x *= b;
224  a.y *= b;
225  return a;
226  }
227 
228  __host__ __device__ inline double2 operator*=(double2 &a, const double &b) {
229  a.x *= b;
230  a.y *= b;
231  return a;
232  }
233 
234  __host__ __device__ inline double4 operator*=(double4 &a, const double &b) {
235  a.x *= b;
236  a.y *= b;
237  a.z *= b;
238  a.w *= b;
239  return a;
240  }
241 
242  __host__ __device__ inline float2 operator-(const float2 &x) {
243  return make_float2(-x.x, -x.y);
244  }
245 
246  __host__ __device__ inline double2 operator-(const double2 &x) {
247  return make_double2(-x.x, -x.y);
248  }
249 
250  template <typename T> struct RealType {
251  };
252  template <> struct RealType<double> {
253  typedef double type;
254  };
255  template <> struct RealType<double2> {
256  typedef double type;
257  };
258  template <> struct RealType<complex<double>> {
259  typedef double type;
260  };
261  template <> struct RealType<float> {
262  typedef float type;
263  };
264  template <> struct RealType<float2> {
265  typedef float type;
266  };
267  template <> struct RealType<complex<float>> {
268  typedef float type;
269  };
270  template <> struct RealType<float4> {
271  typedef float type;
272  };
273  template <> struct RealType<short> {
274  typedef short type;
275  };
276  template <> struct RealType<short2> {
277  typedef short type;
278  };
279  template <> struct RealType<complex<short>> {
280  typedef short type;
281  };
282  template <> struct RealType<short4> {
283  typedef short type;
284  };
285  template <> struct RealType<int8_t> {
286  typedef int8_t type;
287  };
288  template <> struct RealType<char2> {
289  typedef int8_t type;
290  };
291  template <> struct RealType<complex<int8_t>> {
292  typedef int8_t type;
293  };
294  template <> struct RealType<char4> {
295  typedef int8_t type;
296  };
297 
298 #ifndef __CUDACC_RTC__
299  inline std::ostream &operator<<(std::ostream &output, const double2 &a)
300  {
301  output << "(" << a.x << ", " << a.y << ")";
302  return output;
303  }
304 
305  inline std::ostream &operator<<(std::ostream &output, const double3 &a)
306  {
307  output << "(" << a.x << ", " << a.y << "," << a.z << ")";
308  return output;
309  }
310 
311  inline std::ostream &operator<<(std::ostream &output, const double4 &a)
312  {
313  output << "(" << a.x << ", " << a.y << ", " << a.z << ", " << a.w << ")";
314  return output;
315  }
316 #endif
317 
318  __device__ __host__ inline void zero(double &a) { a = 0.0; }
319  __device__ __host__ inline void zero(double2 &a)
320  {
321  a.x = 0.0;
322  a.y = 0.0;
323  }
324  __device__ __host__ inline void zero(double3 &a)
325  {
326  a.x = 0.0;
327  a.y = 0.0;
328  a.z = 0.0;
329  }
330  __device__ __host__ inline void zero(double4 &a)
331  {
332  a.x = 0.0;
333  a.y = 0.0;
334  a.z = 0.0;
335  a.w = 0.0;
336  }
337 
338  __device__ __host__ inline void zero(float &a) { a = 0.0; }
339  __device__ __host__ inline void zero(float2 &a)
340  {
341  a.x = 0.0;
342  a.y = 0.0;
343  }
344  __device__ __host__ inline void zero(float3 &a)
345  {
346  a.x = 0.0;
347  a.y = 0.0;
348  a.z = 0.0;
349  }
350  __device__ __host__ inline void zero(float4 &a)
351  {
352  a.x = 0.0;
353  a.y = 0.0;
354  a.z = 0.0;
355  a.w = 0.0;
356  }
357 
358  __device__ __host__ inline void zero(short &a) { a = 0; }
359  __device__ __host__ inline void zero(char &a) { a = 0; }
360 
361 #ifdef QUAD_SUM
362  __device__ __host__ inline void zero(doubledouble &x)
363  {
364  x.a.x = 0.0;
365  x.a.y = 0.0;
366  }
367  __device__ __host__ inline void zero(doubledouble2 &x)
368  {
369  zero(x.x);
370  zero(x.y);
371  }
372  __device__ __host__ inline void zero(doubledouble3 &x)
373  {
374  zero(x.x);
375  zero(x.y);
376  zero(x.z);
377  }
378 #endif
379 
383  template <typename scalar, int n> struct vector_type {
385  __device__ __host__ inline scalar &operator[](int i) { return data[i]; }
386  __device__ __host__ inline const scalar &operator[](int i) const { return data[i]; }
387  __device__ __host__ inline static constexpr int size() { return n; }
388  __device__ __host__ inline void operator+=(const vector_type &a)
389  {
390 #pragma unroll
391  for (int i = 0; i < n; i++) data[i] += a[i];
392  }
393  __device__ __host__ vector_type()
394  {
395 #pragma unroll
396  for (int i = 0; i < n; i++) zero(data[i]);
397  }
398  };
399 
400  template <typename T, int n> std::ostream &operator<<(std::ostream &output, const vector_type<T, n> &a)
401  {
402  output << "{ ";
403  for (int i = 0; i < n - 1; i++) output << a[i] << ", ";
404  output << a[n - 1] << " }";
405  return output;
406  }
407 
408  template <typename scalar, int n> __device__ __host__ inline void zero(vector_type<scalar, n> &v)
409  {
410 #pragma unroll
411  for (int i = 0; i < n; i++) zero(v.data[i]);
412  }
413 
414  template <typename scalar, int n>
415  __device__ __host__ inline vector_type<scalar, n> operator+(const vector_type<scalar, n> &a,
416  const vector_type<scalar, n> &b)
417  {
419 #pragma unroll
420  for (int i = 0; i < n; i++) c[i] = a[i] + b[i];
421  return c;
422  }
423 }
__host__ __device__ float4 operator+=(float4 &x, const float4 &y)
Definition: float_vector.h:122
__device__ __host__ ColorSpinor< Float, Nc, Ns > operator*(const S &a, const ColorSpinor< Float, Nc, Ns > &x)
Compute the scalar-vector product y = a * x.
__device__ __host__ void zero(double &a)
Definition: float_vector.h:318
__host__ __device__ float2 operator*=(float2 &x, const float &a)
Definition: float_vector.h:199
__host__ __device__ float4 operator-=(float4 &x, const float4 &y)
Definition: float_vector.h:169
__device__ __host__ ColorSpinor< Float, Nc, Ns > operator+(const ColorSpinor< Float, Nc, Ns > &x, const ColorSpinor< Float, Nc, Ns > &y)
ColorSpinor addition operator.
__device__ __host__ ColorSpinor< Float, Nc, Ns > operator-(const ColorSpinor< Float, Nc, Ns > &x, const ColorSpinor< Float, Nc, Ns > &y)
ColorSpinor subtraction operator.
std::ostream & operator<<(std::ostream &output, const CloverFieldParam &param)
doubledouble x
Definition: dbldbl.h:339
doubledouble y
Definition: dbldbl.h:340
doubledouble x
Definition: dbldbl.h:357
doubledouble y
Definition: dbldbl.h:358
doubledouble z
Definition: dbldbl.h:359
dbldbl a
Definition: dbldbl.h:285
__device__ static constexpr __host__ int size()
Definition: float_vector.h:387
__device__ __host__ scalar & operator[](int i)
Definition: float_vector.h:385
__device__ __host__ vector_type()
Definition: float_vector.h:393
__device__ __host__ const scalar & operator[](int i) const
Definition: float_vector.h:386
__device__ __host__ void operator+=(const vector_type &a)
Definition: float_vector.h:388