QUDA  0.9.0
blas_reference.cpp
Go to the documentation of this file.
1 #include <blas_reference.h>
2 #include <stdio.h>
3 #include <comm_quda.h>
4 
5 template <typename Float>
6 inline void aXpY(Float a, Float *x, Float *y, int len)
7 {
8  for(int i=0; i < len; i++){ y[i] += a*x[i]; }
9 }
10 
11 void axpy(double a, void *x, void *y, int len, QudaPrecision precision) {
12  if( precision == QUDA_DOUBLE_PRECISION ) aXpY(a, (double *)x, (double *)y, len);
13  else aXpY((float)a, (float *)x, (float *)y, len);
14 }
15 
16 // performs the operation x[i] *= a
17 template <typename Float>
18 inline void aX(Float a, Float *x, int len) {
19  for (int i=0; i<len; i++) x[i] *= a;
20 }
21 
22 void ax(double a, void *x, int len, QudaPrecision precision) {
23  if (precision == QUDA_DOUBLE_PRECISION) aX(a, (double*)x, len);
24  else aX((float)a, (float*)x, len);
25 }
26 
27 // performs the operation y[i] -= x[i] (minus x plus y)
28 template <typename Float>
29 inline void mXpY(Float *x, Float *y, int len) {
30  for (int i=0; i<len; i++) y[i] -= x[i];
31 }
32 
33 void mxpy(void* x, void* y, int len, QudaPrecision precision) {
34  if (precision == QUDA_DOUBLE_PRECISION) mXpY((double*)x, (double*)y, len);
35  else mXpY((float*)x, (float*)y, len);
36 }
37 
38 
39 // returns the square of the L2 norm of the vector
40 template <typename Float>
41 inline double norm2(Float *v, int len) {
42  double sum=0.0;
43  for (int i=0; i<len; i++) sum += v[i]*v[i];
45  return sum;
46 }
47 
48 double norm_2(void *v, int len, QudaPrecision precision) {
49  if (precision == QUDA_DOUBLE_PRECISION) return norm2((double*)v, len);
50  else return norm2((float*)v, len);
51 }
52 
53 // performs the operation y[i] = x[i] + a*y[i]
54 template <typename Float>
55 static inline void xpay(Float *x, Float a, Float *y, int len) {
56  for (int i=0; i<len; i++) y[i] = x[i] + a*y[i];
57 }
58 
59 void xpay(void *x, double a, void *y, int length, QudaPrecision precision) {
60  if (precision == QUDA_DOUBLE_PRECISION) xpay((double*)x, a, (double*)y, length);
61  else xpay((float*)x, (float)a, (float*)y, length);
62 }
63 
64 
65 
66 /*
67 
68 
69 // sets all elements of the destination vector to zero
70 void zero(float* a, int cnt) {
71  for (int i = 0; i < cnt; i++)
72  a[i] = 0;
73 }
74 
75 // copy one spinor to the other
76 void copy(float* a, float *b, int len) {
77  for (int i = 0; i < len; i++) a[i] = b[i];
78 }
79 
80 // performs the operation y[i] = a*x[i] + b*y[i]
81 void axpby(float a, float *x, float b, float *y, int len) {
82  for (int i=0; i<len; i++) y[i] = a*x[i] + b*y[i];
83 }
84 
85 // performs the operation y[i] = a*x[i] + y[i]
86 void axpy(float a, float *x, float *y, int len) {
87  for (int i=0; i<len; i++) y[i] += a*x[i];
88 }
89 
90 
91 // returns the real part of the dot product of 2 complex valued vectors
92 float reDotProduct(float *v1, float *v2, int len) {
93 
94  float dot=0.0;
95  for (int i=0; i<len; i++) {
96  dot += v1[i]*v2[i];
97  }
98 
99  return dot;
100 }
101 
102 // returns the imaginary part of the dot product of 2 complex valued vectors
103 float imDotProduct(float *v1, float *v2, int len) {
104 
105  float dot=0.0;
106  for (int i=0; i<len; i+=2) {
107  dot += v1[i]*v2[i+1] - v1[i+1]*v2[i];
108  }
109 
110  return dot;
111 }
112 
113 // returns the square of the L2 norm of the vector
114 double normD(float *v, int len) {
115 
116  double sum=0.0;
117  for (int i=0; i<len; i++) {
118  sum += v[i]*v[i];
119  }
120 
121  return sum;
122 }
123 
124 // returns the real part of the dot product of 2 complex valued vectors
125 double reDotProductD(float *v1, float *v2, int len) {
126 
127  double dot=0.0;
128  for (int i=0; i<len; i++) {
129  dot += v1[i]*v2[i];
130  }
131 
132  return dot;
133 }
134 
135 // returns the imaginary part of the dot product of 2 complex valued vectors
136 double imDotProductD(float *v1, float *v2, int len) {
137 
138  double dot=0.0;
139  for (int i=0; i<len; i+=2) {
140  dot += v1[i]*v2[i+1] - v1[i+1]*v2[i];
141  }
142 
143  return dot;
144 }
145 */
enum QudaPrecision_s QudaPrecision
void ax(double a, void *x, int len, QudaPrecision precision)
void aXpY(Float a, Float *x, Float *y, int len)
void mXpY(Float *x, Float *y, int len)
__host__ __device__ void sum(double &a, double &b)
static void xpay(Float *x, Float a, Float *y, int len)
double norm2(Float *v, int len)
void mxpy(void *x, void *y, int len, QudaPrecision precision)
double norm_2(void *v, int len, QudaPrecision precision)
void aX(Float a, Float *x, int len)
void axpy(double a, void *x, void *y, int len, QudaPrecision precision)
void size_t length
void comm_allreduce(double *data)
Definition: comm_mpi.cpp:281
#define a