QUDA  v0.7.0
A library for QCD on GPUs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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];
44  comm_allreduce(&sum);
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 
54 /*
55 
56 
57 // sets all elements of the destination vector to zero
58 void zero(float* a, int cnt) {
59  for (int i = 0; i < cnt; i++)
60  a[i] = 0;
61 }
62 
63 // copy one spinor to the other
64 void copy(float* a, float *b, int len) {
65  for (int i = 0; i < len; i++) a[i] = b[i];
66 }
67 
68 // performs the operation y[i] = a*x[i] + b*y[i]
69 void axpby(float a, float *x, float b, float *y, int len) {
70  for (int i=0; i<len; i++) y[i] = a*x[i] + b*y[i];
71 }
72 
73 // performs the operation y[i] = a*x[i] + y[i]
74 void axpy(float a, float *x, float *y, int len) {
75  for (int i=0; i<len; i++) y[i] += a*x[i];
76 }
77 
78 
79 // returns the real part of the dot product of 2 complex valued vectors
80 float reDotProduct(float *v1, float *v2, int len) {
81 
82  float dot=0.0;
83  for (int i=0; i<len; i++) {
84  dot += v1[i]*v2[i];
85  }
86 
87  return dot;
88 }
89 
90 // returns the imaginary part of the dot product of 2 complex valued vectors
91 float imDotProduct(float *v1, float *v2, int len) {
92 
93  float dot=0.0;
94  for (int i=0; i<len; i+=2) {
95  dot += v1[i]*v2[i+1] - v1[i+1]*v2[i];
96  }
97 
98  return dot;
99 }
100 
101 // returns the square of the L2 norm of the vector
102 double normD(float *v, int len) {
103 
104  double sum=0.0;
105  for (int i=0; i<len; i++) {
106  sum += v[i]*v[i];
107  }
108 
109  return sum;
110 }
111 
112 // returns the real part of the dot product of 2 complex valued vectors
113 double reDotProductD(float *v1, float *v2, int len) {
114 
115  double dot=0.0;
116  for (int i=0; i<len; i++) {
117  dot += v1[i]*v2[i];
118  }
119 
120  return dot;
121 }
122 
123 // returns the imaginary part of the dot product of 2 complex valued vectors
124 double imDotProductD(float *v1, float *v2, int len) {
125 
126  double dot=0.0;
127  for (int i=0; i<len; i+=2) {
128  dot += v1[i]*v2[i+1] - v1[i+1]*v2[i];
129  }
130 
131  return dot;
132 }
133 */
enum QudaPrecision_s QudaPrecision
int y[4]
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)
FloatingPoint< float > Float
Definition: gtest.h:7350
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)
int x[4]
void aX(Float a, Float *x, int len)
void axpy(double a, void *x, void *y, int len, QudaPrecision precision)
void comm_allreduce(double *data)
Definition: comm_mpi.cpp:201