|
QUDA v0.3.2
A library for QCD on GPUs
|
00001 #include <blas_reference.h> 00002 00003 // performs the operation x[i] *= a 00004 template <typename Float> 00005 inline void aX(Float a, Float *x, int len) { 00006 for (int i=0; i<len; i++) x[i] *= a; 00007 } 00008 00009 void ax(double a, void *x, int len, QudaPrecision precision) { 00010 if (precision == QUDA_DOUBLE_PRECISION) aX(a, (double*)x, len); 00011 else aX((float)a, (float*)x, len); 00012 } 00013 00014 // performs the operation y[i] -= x[i] (minus x plus y) 00015 template <typename Float> 00016 inline void mXpY(Float *x, Float *y, int len) { 00017 for (int i=0; i<len; i++) y[i] -= x[i]; 00018 } 00019 00020 void mxpy(void* x, void* y, int len, QudaPrecision precision) { 00021 if (precision == QUDA_DOUBLE_PRECISION) mXpY((double*)x, (double*)y, len); 00022 else mXpY((float*)x, (float*)y, len); 00023 } 00024 00025 00026 // returns the square of the L2 norm of the vector 00027 template <typename Float> 00028 inline double norm2(Float *v, int len) { 00029 double sum=0.0; 00030 for (int i=0; i<len; i++) sum += v[i]*v[i]; 00031 return sum; 00032 } 00033 00034 double norm_2(void *v, int len, QudaPrecision precision) { 00035 if (precision == QUDA_DOUBLE_PRECISION) return norm2((double*)v, len); 00036 else return norm2((float*)v, len); 00037 } 00038 00039 00040 /* 00041 00042 00043 // sets all elements of the destination vector to zero 00044 void zero(float* a, int cnt) { 00045 for (int i = 0; i < cnt; i++) 00046 a[i] = 0; 00047 } 00048 00049 // copy one spinor to the other 00050 void copy(float* a, float *b, int len) { 00051 for (int i = 0; i < len; i++) a[i] = b[i]; 00052 } 00053 00054 // performs the operation y[i] = a*x[i] + b*y[i] 00055 void axpby(float a, float *x, float b, float *y, int len) { 00056 for (int i=0; i<len; i++) y[i] = a*x[i] + b*y[i]; 00057 } 00058 00059 // performs the operation y[i] = a*x[i] + y[i] 00060 void axpy(float a, float *x, float *y, int len) { 00061 for (int i=0; i<len; i++) y[i] += a*x[i]; 00062 } 00063 00064 00065 // returns the real part of the dot product of 2 complex valued vectors 00066 float reDotProduct(float *v1, float *v2, int len) { 00067 00068 float dot=0.0; 00069 for (int i=0; i<len; i++) { 00070 dot += v1[i]*v2[i]; 00071 } 00072 00073 return dot; 00074 } 00075 00076 // returns the imaginary part of the dot product of 2 complex valued vectors 00077 float imDotProduct(float *v1, float *v2, int len) { 00078 00079 float dot=0.0; 00080 for (int i=0; i<len; i+=2) { 00081 dot += v1[i]*v2[i+1] - v1[i+1]*v2[i]; 00082 } 00083 00084 return dot; 00085 } 00086 00087 // returns the square of the L2 norm of the vector 00088 double normD(float *v, int len) { 00089 00090 double sum=0.0; 00091 for (int i=0; i<len; i++) { 00092 sum += v[i]*v[i]; 00093 } 00094 00095 return sum; 00096 } 00097 00098 // returns the real part of the dot product of 2 complex valued vectors 00099 double reDotProductD(float *v1, float *v2, int len) { 00100 00101 double dot=0.0; 00102 for (int i=0; i<len; i++) { 00103 dot += v1[i]*v2[i]; 00104 } 00105 00106 return dot; 00107 } 00108 00109 // returns the imaginary part of the dot product of 2 complex valued vectors 00110 double imDotProductD(float *v1, float *v2, int len) { 00111 00112 double dot=0.0; 00113 for (int i=0; i<len; i+=2) { 00114 dot += v1[i]*v2[i+1] - v1[i+1]*v2[i]; 00115 } 00116 00117 return dot; 00118 } 00119 */
1.7.3