QUDA  v0.5.0
A library for QCD on GPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wilson_dslash_reference.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 
5 #include <util_quda.h>
6 
7 #include <test_util.h>
8 #include <blas_reference.h>
10 
11 #include <gauge_field.h>
12 #include <color_spinor_field.h>
13 #include <face_quda.h>
14 
15 #include <dslash_util.h>
16 #include <string.h>
17 
18 using namespace quda;
19 
20 static const double projector[8][4][4][2] = {
21  {
22  {{1,0}, {0,0}, {0,0}, {0,-1}},
23  {{0,0}, {1,0}, {0,-1}, {0,0}},
24  {{0,0}, {0,1}, {1,0}, {0,0}},
25  {{0,1}, {0,0}, {0,0}, {1,0}}
26  },
27  {
28  {{1,0}, {0,0}, {0,0}, {0,1}},
29  {{0,0}, {1,0}, {0,1}, {0,0}},
30  {{0,0}, {0,-1}, {1,0}, {0,0}},
31  {{0,-1}, {0,0}, {0,0}, {1,0}}
32  },
33  {
34  {{1,0}, {0,0}, {0,0}, {1,0}},
35  {{0,0}, {1,0}, {-1,0}, {0,0}},
36  {{0,0}, {-1,0}, {1,0}, {0,0}},
37  {{1,0}, {0,0}, {0,0}, {1,0}}
38  },
39  {
40  {{1,0}, {0,0}, {0,0}, {-1,0}},
41  {{0,0}, {1,0}, {1,0}, {0,0}},
42  {{0,0}, {1,0}, {1,0}, {0,0}},
43  {{-1,0}, {0,0}, {0,0}, {1,0}}
44  },
45  {
46  {{1,0}, {0,0}, {0,-1}, {0,0}},
47  {{0,0}, {1,0}, {0,0}, {0,1}},
48  {{0,1}, {0,0}, {1,0}, {0,0}},
49  {{0,0}, {0,-1}, {0,0}, {1,0}}
50  },
51  {
52  {{1,0}, {0,0}, {0,1}, {0,0}},
53  {{0,0}, {1,0}, {0,0}, {0,-1}},
54  {{0,-1}, {0,0}, {1,0}, {0,0}},
55  {{0,0}, {0,1}, {0,0}, {1,0}}
56  },
57  {
58  {{1,0}, {0,0}, {-1,0}, {0,0}},
59  {{0,0}, {1,0}, {0,0}, {-1,0}},
60  {{-1,0}, {0,0}, {1,0}, {0,0}},
61  {{0,0}, {-1,0}, {0,0}, {1,0}}
62  },
63  {
64  {{1,0}, {0,0}, {1,0}, {0,0}},
65  {{0,0}, {1,0}, {0,0}, {1,0}},
66  {{1,0}, {0,0}, {1,0}, {0,0}},
67  {{0,0}, {1,0}, {0,0}, {1,0}}
68  }
69 };
70 
71 
72 // todo pass projector
73 template <typename Float>
74 void multiplySpinorByDiracProjector(Float *res, int projIdx, Float *spinorIn) {
75  for (int i=0; i<4*3*2; i++) res[i] = 0.0;
76 
77  for (int s = 0; s < 4; s++) {
78  for (int t = 0; t < 4; t++) {
79  Float projRe = projector[projIdx][s][t][0];
80  Float projIm = projector[projIdx][s][t][1];
81 
82  for (int m = 0; m < 3; m++) {
83  Float spinorRe = spinorIn[t*(3*2) + m*(2) + 0];
84  Float spinorIm = spinorIn[t*(3*2) + m*(2) + 1];
85  res[s*(3*2) + m*(2) + 0] += projRe*spinorRe - projIm*spinorIm;
86  res[s*(3*2) + m*(2) + 1] += projRe*spinorIm + projIm*spinorRe;
87  }
88  }
89  }
90 }
91 
92 
93 //
94 // dslashReference()
95 //
96 // if oddBit is zero: calculate odd parity spinor elements (using even parity spinor)
97 // if oddBit is one: calculate even parity spinor elements
98 //
99 // if daggerBit is zero: perform ordinary dslash operator
100 // if daggerBit is one: perform hermitian conjugate of dslash
101 //
102 
103 #ifndef MULTI_GPU
104 
105 template <typename sFloat, typename gFloat>
106 void dslashReference(sFloat *res, gFloat **gaugeFull, sFloat *spinorField, int oddBit, int daggerBit) {
107  for (int i=0; i<Vh*mySpinorSiteSize; i++) res[i] = 0.0;
108 
109  gFloat *gaugeEven[4], *gaugeOdd[4];
110  for (int dir = 0; dir < 4; dir++) {
111  gaugeEven[dir] = gaugeFull[dir];
112  gaugeOdd[dir] = gaugeFull[dir]+Vh*gaugeSiteSize;
113  }
114 
115  for (int i = 0; i < Vh; i++) {
116  for (int dir = 0; dir < 8; dir++) {
117  gFloat *gauge = gaugeLink(i, dir, oddBit, gaugeEven, gaugeOdd, 1);
118  sFloat *spinor = spinorNeighbor(i, dir, oddBit, spinorField, 1);
119 
120  sFloat projectedSpinor[4*3*2], gaugedSpinor[4*3*2];
121  int projIdx = 2*(dir/2)+(dir+daggerBit)%2;
122  multiplySpinorByDiracProjector(projectedSpinor, projIdx, spinor);
123 
124  for (int s = 0; s < 4; s++) {
125  if (dir % 2 == 0) su3Mul(&gaugedSpinor[s*(3*2)], gauge, &projectedSpinor[s*(3*2)]);
126  else su3Tmul(&gaugedSpinor[s*(3*2)], gauge, &projectedSpinor[s*(3*2)]);
127  }
128 
129  sum(&res[i*(4*3*2)], &res[i*(4*3*2)], gaugedSpinor, 4*3*2);
130  }
131  }
132 }
133 
134 #else
135 
136 template <typename sFloat, typename gFloat>
137 void dslashReference(sFloat *res, gFloat **gaugeFull, gFloat **ghostGauge, sFloat *spinorField,
138  sFloat **fwdSpinor, sFloat **backSpinor, int oddBit, int daggerBit) {
139  for (int i=0; i<Vh*mySpinorSiteSize; i++) res[i] = 0.0;
140 
141  gFloat *gaugeEven[4], *gaugeOdd[4];
142  gFloat *ghostGaugeEven[4], *ghostGaugeOdd[4];
143  for (int dir = 0; dir < 4; dir++) {
144  gaugeEven[dir] = gaugeFull[dir];
145  gaugeOdd[dir] = gaugeFull[dir]+Vh*gaugeSiteSize;
146 
147  ghostGaugeEven[dir] = ghostGauge[dir];
148  ghostGaugeOdd[dir] = ghostGauge[dir] + (faceVolume[dir]/2)*gaugeSiteSize;
149  }
150 
151  for (int i = 0; i < Vh; i++) {
152 
153  for (int dir = 0; dir < 8; dir++) {
154  gFloat *gauge = gaugeLink_mg4dir(i, dir, oddBit, gaugeEven, gaugeOdd, ghostGaugeEven, ghostGaugeOdd, 1, 1);
155  sFloat *spinor = spinorNeighbor_mg4dir(i, dir, oddBit, spinorField, fwdSpinor, backSpinor, 1, 1);
156 
157  sFloat projectedSpinor[mySpinorSiteSize], gaugedSpinor[mySpinorSiteSize];
158  int projIdx = 2*(dir/2)+(dir+daggerBit)%2;
159  multiplySpinorByDiracProjector(projectedSpinor, projIdx, spinor);
160 
161  for (int s = 0; s < 4; s++) {
162  if (dir % 2 == 0) su3Mul(&gaugedSpinor[s*(3*2)], gauge, &projectedSpinor[s*(3*2)]);
163  else su3Tmul(&gaugedSpinor[s*(3*2)], gauge, &projectedSpinor[s*(3*2)]);
164  }
165 
166  sum(&res[i*(4*3*2)], &res[i*(4*3*2)], gaugedSpinor, 4*3*2);
167  }
168 
169  }
170 }
171 
172 #endif
173 
174 // this actually applies the preconditioned dslash, e.g., D_ee^{-1} D_eo or D_oo^{-1} D_oe
175 void wil_dslash(void *out, void **gauge, void *in, int oddBit, int daggerBit,
177 
178 #ifndef MULTI_GPU
179  if (precision == QUDA_DOUBLE_PRECISION)
180  dslashReference((double*)out, (double**)gauge, (double*)in, oddBit, daggerBit);
181  else
182  dslashReference((float*)out, (float**)gauge, (float*)in, oddBit, daggerBit);
183 #else
184 
185  GaugeFieldParam gauge_field_param(gauge, gauge_param);
186  cpuGaugeField cpu(gauge_field_param);
187  cpu.exchangeGhost();
188  void **ghostGauge = (void**)cpu.Ghost();
189 
190  // Get spinor ghost fields
191  // First wrap the input spinor into a ColorSpinorField
193  csParam.v = in;
194  csParam.nColor = 3;
195  csParam.nSpin = 4;
196  csParam.nDim = 4;
197  for (int d=0; d<4; d++) csParam.x[d] = Z[d];
198  csParam.precision = precision;
199  csParam.pad = 0;
201  csParam.x[0] /= 2;
206 
207  cpuColorSpinorField inField(csParam);
208 
209  { // Now do the exchange
210  QudaParity otherParity = QUDA_INVALID_PARITY;
211  if (oddBit == QUDA_EVEN_PARITY) otherParity = QUDA_ODD_PARITY;
212  else if (oddBit == QUDA_ODD_PARITY) otherParity = QUDA_EVEN_PARITY;
213  else errorQuda("ERROR: full parity not supported in function %s", __FUNCTION__);
214 
215  int nFace = 1;
216  FaceBuffer faceBuf(Z, 4, mySpinorSiteSize, nFace, precision);
217  faceBuf.exchangeCpuSpinor(inField, otherParity, daggerBit);
218  }
219  void** fwd_nbr_spinor = inField.fwdGhostFaceBuffer;
220  void** back_nbr_spinor = inField.backGhostFaceBuffer;
221 
222  if (precision == QUDA_DOUBLE_PRECISION) {
223  dslashReference((double*)out, (double**)gauge, (double**)ghostGauge, (double*)in,
224  (double**)fwd_nbr_spinor, (double**)back_nbr_spinor, oddBit, daggerBit);
225  } else{
226  dslashReference((float*)out, (float**)gauge, (float**)ghostGauge, (float*)in,
227  (float**)fwd_nbr_spinor, (float**)back_nbr_spinor, oddBit, daggerBit);
228  }
229 
230 #endif
231 
232 }
233 
234 // applies b*(1 + i*a*gamma_5)
235 template <typename sFloat>
236 void twistGamma5(sFloat *out, sFloat *in, const int dagger, const sFloat kappa, const sFloat mu,
237  const QudaTwistFlavorType flavor, const int V, QudaTwistGamma5Type twist) {
238 
239  sFloat a=0.0,b=0.0;
240  if (twist == QUDA_TWIST_GAMMA5_DIRECT) { // applying the twist
241  a = 2.0 * kappa * mu * flavor; // mu already includes the flavor
242  b = 1.0;
243  } else if (twist == QUDA_TWIST_GAMMA5_INVERSE) { // applying the inverse twist
244  a = -2.0 * kappa * mu * flavor;
245  b = 1.0 / (1.0 + a*a);
246  } else {
247  printf("Twist type %d not defined\n", twist);
248  exit(0);
249  }
250 
251  if (dagger) a *= -1.0;
252 
253  for(int i = 0; i < V; i++) {
254  sFloat tmp[24];
255  for(int s = 0; s < 4; s++)
256  for(int c = 0; c < 3; c++) {
257  sFloat a5 = ((s / 2) ? -1.0 : +1.0) * a;
258  tmp[s * 6 + c * 2 + 0] = b* (in[i * 24 + s * 6 + c * 2 + 0] - a5*in[i * 24 + s * 6 + c * 2 + 1]);
259  tmp[s * 6 + c * 2 + 1] = b* (in[i * 24 + s * 6 + c * 2 + 1] + a5*in[i * 24 + s * 6 + c * 2 + 0]);
260  }
261 
262  for (int j=0; j<24; j++) out[i*24+j] = tmp[j];
263  }
264 
265 }
266 
267 void twist_gamma5(void *out, void *in, int daggerBit, double kappa, double mu, QudaTwistFlavorType flavor,
268  int V, QudaTwistGamma5Type twist, QudaPrecision precision) {
269 
270  if (precision == QUDA_DOUBLE_PRECISION) {
271  twistGamma5((double*)out, (double*)in, daggerBit, kappa, mu, flavor, V, twist);
272  } else {
273  twistGamma5((float*)out, (float*)in, daggerBit, (float)kappa, (float)mu, flavor, V, twist);
274  }
275 }
276 
277 
278 void tm_dslash(void *res, void **gaugeFull, void *spinorField, double kappa, double mu,
279  QudaTwistFlavorType flavor, int oddBit, int daggerBit, QudaPrecision precision,
281 {
282 
283  if (daggerBit) twist_gamma5(spinorField, spinorField, daggerBit, kappa, mu,
284  flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
285 
286  wil_dslash(res, gaugeFull, spinorField, oddBit, daggerBit, precision, gauge_param);
287 
288  if (!daggerBit) {
289  twist_gamma5(res, res, daggerBit, kappa, mu, flavor,
290  Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
291  } else {
292  twist_gamma5(spinorField, spinorField, daggerBit, kappa, mu, flavor,
293  Vh, QUDA_TWIST_GAMMA5_DIRECT, precision);
294  }
295 
296 }
297 
298 void wil_mat(void *out, void **gauge, void *in, double kappa, int dagger_bit, QudaPrecision precision,
300 
301  void *inEven = in;
302  void *inOdd = (char*)in + Vh*spinorSiteSize*precision;
303  void *outEven = out;
304  void *outOdd = (char*)out + Vh*spinorSiteSize*precision;
305 
306  wil_dslash(outOdd, gauge, inEven, 1, dagger_bit, precision, gauge_param);
307  wil_dslash(outEven, gauge, inOdd, 0, dagger_bit, precision, gauge_param);
308 
309  // lastly apply the kappa term
310  if (precision == QUDA_DOUBLE_PRECISION) xpay((double*)in, -kappa, (double*)out, V*spinorSiteSize);
311  else xpay((float*)in, -(float)kappa, (float*)out, V*spinorSiteSize);
312 }
313 
314 void tm_mat(void *out, void **gauge, void *in, double kappa, double mu,
315  QudaTwistFlavorType flavor, int dagger_bit, QudaPrecision precision,
317 
318  void *inEven = in;
319  void *inOdd = (char*)in + Vh*spinorSiteSize*precision;
320  void *outEven = out;
321  void *outOdd = (char*)out + Vh*spinorSiteSize*precision;
322  void *tmp = malloc(V*spinorSiteSize*precision);
323 
324  wil_dslash(outOdd, gauge, inEven, 1, dagger_bit, precision, gauge_param);
325  wil_dslash(outEven, gauge, inOdd, 0, dagger_bit, precision, gauge_param);
326 
327  // apply the twist term to the full lattice
328  twist_gamma5(tmp, in, dagger_bit, kappa, mu, flavor, V, QUDA_TWIST_GAMMA5_DIRECT, precision);
329 
330  // combine
331  if (precision == QUDA_DOUBLE_PRECISION) xpay((double*)tmp, -kappa, (double*)out, V*spinorSiteSize);
332  else xpay((float*)tmp, -(float)kappa, (float*)out, V*spinorSiteSize);
333 
334  free(tmp);
335 }
336 
337 // Apply the even-odd preconditioned Dirac operator
338 void wil_matpc(void *outEven, void **gauge, void *inEven, double kappa,
339  QudaMatPCType matpc_type, int daggerBit, QudaPrecision precision,
341 
342  void *tmp = malloc(Vh*spinorSiteSize*precision);
343 
344  // FIXME: remove once reference clover is finished
345  // full dslash operator
346  if (matpc_type == QUDA_MATPC_EVEN_EVEN || matpc_type == QUDA_MATPC_EVEN_EVEN_ASYMMETRIC) {
347  wil_dslash(tmp, gauge, inEven, 1, daggerBit, precision, gauge_param);
348  wil_dslash(outEven, gauge, tmp, 0, daggerBit, precision, gauge_param);
349  } else {
350  wil_dslash(tmp, gauge, inEven, 0, daggerBit, precision, gauge_param);
351  wil_dslash(outEven, gauge, tmp, 1, daggerBit, precision, gauge_param);
352  }
353 
354  // lastly apply the kappa term
355  double kappa2 = -kappa*kappa;
356  if (precision == QUDA_DOUBLE_PRECISION) xpay((double*)inEven, kappa2, (double*)outEven, Vh*spinorSiteSize);
357  else xpay((float*)inEven, (float)kappa2, (float*)outEven, Vh*spinorSiteSize);
358 
359  free(tmp);
360 }
361 
362 // Apply the even-odd preconditioned Dirac operator
363 void tm_matpc(void *outEven, void **gauge, void *inEven, double kappa, double mu, QudaTwistFlavorType flavor,
364  QudaMatPCType matpc_type, int daggerBit, QudaPrecision precision, QudaGaugeParam &gauge_param) {
365 
366  void *tmp = malloc(Vh*spinorSiteSize*precision);
367 
368  if (matpc_type == QUDA_MATPC_EVEN_EVEN_ASYMMETRIC) {
369  wil_dslash(tmp, gauge, inEven, 1, daggerBit, precision, gauge_param);
370  twist_gamma5(tmp, tmp, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
371  wil_dslash(outEven, gauge, tmp, 0, daggerBit, precision, gauge_param);
372  twist_gamma5(tmp, inEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_DIRECT, precision);
373  } else if (matpc_type == QUDA_MATPC_ODD_ODD_ASYMMETRIC) {
374  wil_dslash(tmp, gauge, inEven, 0, daggerBit, precision, gauge_param);
375  twist_gamma5(tmp, tmp, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
376  wil_dslash(outEven, gauge, tmp, 1, daggerBit, precision, gauge_param);
377  twist_gamma5(tmp, inEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_DIRECT, precision);
378  } else if (!daggerBit) {
379  if (matpc_type == QUDA_MATPC_EVEN_EVEN) {
380  wil_dslash(tmp, gauge, inEven, 1, daggerBit, precision, gauge_param);
381  twist_gamma5(tmp, tmp, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
382  wil_dslash(outEven, gauge, tmp, 0, daggerBit, precision, gauge_param);
383  twist_gamma5(outEven, outEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
384  } else if (matpc_type == QUDA_MATPC_ODD_ODD) {
385  wil_dslash(tmp, gauge, inEven, 0, daggerBit, precision, gauge_param);
386  twist_gamma5(tmp, tmp, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
387  wil_dslash(outEven, gauge, tmp, 1, daggerBit, precision, gauge_param);
388  twist_gamma5(outEven, outEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
389  }
390  } else {
391  if (matpc_type == QUDA_MATPC_EVEN_EVEN) {
392  twist_gamma5(inEven, inEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
393  wil_dslash(tmp, gauge, inEven, 1, daggerBit, precision, gauge_param);
394  twist_gamma5(tmp, tmp, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
395  wil_dslash(outEven, gauge, tmp, 0, daggerBit, precision, gauge_param);
396  twist_gamma5(inEven, inEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_DIRECT, precision);
397  } else if (matpc_type == QUDA_MATPC_ODD_ODD) {
398  twist_gamma5(inEven, inEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
399  wil_dslash(tmp, gauge, inEven, 0, daggerBit, precision, gauge_param);
400  twist_gamma5(tmp, tmp, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
401  wil_dslash(outEven, gauge, tmp, 1, daggerBit, precision, gauge_param);
402  twist_gamma5(inEven, inEven, daggerBit, kappa, mu, flavor, Vh, QUDA_TWIST_GAMMA5_DIRECT, precision); // undo
403  }
404  }
405  // lastly apply the kappa term
406  double kappa2 = -kappa*kappa;
407  if (matpc_type == QUDA_MATPC_EVEN_EVEN || matpc_type == QUDA_MATPC_ODD_ODD) {
408  if (precision == QUDA_DOUBLE_PRECISION) xpay((double*)inEven, kappa2, (double*)outEven, Vh*spinorSiteSize);
409  else xpay((float*)inEven, (float)kappa2, (float*)outEven, Vh*spinorSiteSize);
410  } else {
411  if (precision == QUDA_DOUBLE_PRECISION) xpay((double*)tmp, kappa2, (double*)outEven, Vh*spinorSiteSize);
412  else xpay((float*)tmp, (float)kappa2, (float*)outEven, Vh*spinorSiteSize);
413  }
414 
415  free(tmp);
416 }
417 
418 
419 //----- for non-degenerate dslash only----
420 template <typename sFloat>
421 void ndegTwistGamma5(sFloat *out1, sFloat *out2, sFloat *in1, sFloat *in2, const int dagger, const sFloat kappa, const sFloat mu,
422  const sFloat epsilon, const int V, QudaTwistGamma5Type twist) {
423 
424  sFloat a=0.0, b=0.0, d=0.0;
425  if (twist == QUDA_TWIST_GAMMA5_DIRECT) { // applying the twist
426  a = 2.0 * kappa * mu;
427  b = -2.0 * kappa * epsilon;
428  d = 1.0;
429  } else if (twist == QUDA_TWIST_GAMMA5_INVERSE) { // applying the inverse twist
430  a = -2.0 * kappa * mu;
431  b = 2.0 * kappa * epsilon;
432  d = 1.0 / (1.0 + a*a - b*b);
433  } else {
434  printf("Twist type %d not defined\n", twist);
435  exit(0);
436  }
437 
438  if (dagger) a *= -1.0;
439 
440  for(int i = 0; i < V; i++) {
441  sFloat tmp1[24];
442  sFloat tmp2[24];
443  for(int s = 0; s < 4; s++)
444  for(int c = 0; c < 3; c++) {
445  sFloat a5 = ((s / 2) ? -1.0 : +1.0) * a;
446  tmp1[s * 6 + c * 2 + 0] = d* (in1[i * 24 + s * 6 + c * 2 + 0] - a5*in1[i * 24 + s * 6 + c * 2 + 1] + b*in2[i * 24 + s * 6 + c * 2 + 0]);
447  tmp1[s * 6 + c * 2 + 1] = d* (in1[i * 24 + s * 6 + c * 2 + 1] + a5*in1[i * 24 + s * 6 + c * 2 + 0] + b*in2[i * 24 + s * 6 + c * 2 + 1]);
448  tmp2[s * 6 + c * 2 + 0] = d* (in2[i * 24 + s * 6 + c * 2 + 0] + a5*in2[i * 24 + s * 6 + c * 2 + 1] + b*in1[i * 24 + s * 6 + c * 2 + 0]);
449  tmp2[s * 6 + c * 2 + 1] = d* (in2[i * 24 + s * 6 + c * 2 + 1] - a5*in2[i * 24 + s * 6 + c * 2 + 0] + b*in1[i * 24 + s * 6 + c * 2 + 1]);
450  }
451  for (int j=0; j<24; j++) out1[i*24+j] = tmp1[j], out2[i*24+j] = tmp2[j];
452  }
453 
454 }
455 
456 void ndeg_twist_gamma5(void *outf1, void *outf2, void *inf1, void *inf2, const int dagger, const double kappa, const double mu,
457  const double epsilon, const int Vf, QudaTwistGamma5Type twist, QudaPrecision precision)
458 {
459  if (precision == QUDA_DOUBLE_PRECISION)
460  {
461  ndegTwistGamma5((double*)outf1, (double*)outf2, (double*)inf1, (double*)inf2, dagger, kappa, mu, epsilon, Vf, twist);
462  }
463  else //single precision dslash
464  {
465  ndegTwistGamma5((float*)outf1, (float*)outf2, (float*)inf1, (float*)inf2, dagger, (float)kappa, (float)mu, (float)epsilon, Vf, twist);
466  }
467 }
468 
469 void tm_ndeg_dslash(void *res1, void *res2, void **gauge, void *spinorField1, void *spinorField2, double kappa, double mu,
470  double epsilon, int oddBit, int daggerBit, QudaMatPCType matpc_type, QudaPrecision precision, QudaGaugeParam &gauge_param)
471 {
472  if (daggerBit && (matpc_type == QUDA_MATPC_EVEN_EVEN || matpc_type == QUDA_MATPC_ODD_ODD))
473  ndeg_twist_gamma5(spinorField1, spinorField2, spinorField1, spinorField2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
474 
475  wil_dslash(res1, gauge, spinorField1, oddBit, daggerBit, precision, gauge_param);
476  wil_dslash(res2, gauge, spinorField2, oddBit, daggerBit, precision, gauge_param);
477 
478  if (!daggerBit || (matpc_type == QUDA_MATPC_EVEN_EVEN_ASYMMETRIC || matpc_type == QUDA_MATPC_ODD_ODD_ASYMMETRIC)) {
479  ndeg_twist_gamma5(res1, res2, res1, res2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
480  }
481 }
482 
483 
484 void tm_ndeg_matpc(void *outEven1, void *outEven2, void **gauge, void *inEven1, void *inEven2, double kappa, double mu, double epsilon,
485  QudaMatPCType matpc_type, int daggerBit, QudaPrecision precision, QudaGaugeParam &gauge_param) {
486 
487  void *tmp1 = malloc(Vh*spinorSiteSize*precision);
488  void *tmp2 = malloc(Vh*spinorSiteSize*precision);
489 
490  if (!daggerBit) {
491  if (matpc_type == QUDA_MATPC_EVEN_EVEN) {
492  wil_dslash(tmp1, gauge, inEven1, 1, daggerBit, precision, gauge_param);
493  wil_dslash(tmp2, gauge, inEven2, 1, daggerBit, precision, gauge_param);
494  ndeg_twist_gamma5(tmp1, tmp2, tmp1, tmp2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
495  wil_dslash(outEven1, gauge, tmp1, 0, daggerBit, precision, gauge_param);
496  wil_dslash(outEven2, gauge, tmp2, 0, daggerBit, precision, gauge_param);
497  ndeg_twist_gamma5(outEven1, outEven2, outEven1, outEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
498  } else if (matpc_type == QUDA_MATPC_ODD_ODD) {
499  wil_dslash(tmp1, gauge, inEven1, 0, daggerBit, precision, gauge_param);
500  wil_dslash(tmp2, gauge, inEven2, 0, daggerBit, precision, gauge_param);
501  ndeg_twist_gamma5(tmp1, tmp2, tmp1, tmp2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
502  wil_dslash(outEven1, gauge, tmp1, 1, daggerBit, precision, gauge_param);
503  wil_dslash(outEven2, gauge, tmp2, 1, daggerBit, precision, gauge_param);
504  ndeg_twist_gamma5(outEven1, outEven2, outEven1, outEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
505  }
506  } else {
507  if (matpc_type == QUDA_MATPC_EVEN_EVEN) {
508  ndeg_twist_gamma5(tmp1, tmp2, inEven1, inEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
509  wil_dslash(outEven1, gauge, tmp1, 1, daggerBit, precision, gauge_param);
510  wil_dslash(outEven2, gauge, tmp2, 1, daggerBit, precision, gauge_param);
511  ndeg_twist_gamma5(tmp1, tmp2, outEven1, outEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
512  wil_dslash(outEven1, gauge, tmp1, 0, daggerBit, precision, gauge_param);
513  wil_dslash(outEven2, gauge, tmp2, 0, daggerBit, precision, gauge_param);
514  } else if (matpc_type == QUDA_MATPC_ODD_ODD) {
515  ndeg_twist_gamma5(tmp1, tmp2, inEven1, inEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
516  wil_dslash(outEven1, gauge, tmp1, 0, daggerBit, precision, gauge_param);
517  wil_dslash(outEven2, gauge, tmp2, 0, daggerBit, precision, gauge_param);
518  ndeg_twist_gamma5(tmp1, tmp2, outEven1, outEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
519  wil_dslash(outEven1, gauge, tmp1, 1, daggerBit, precision, gauge_param);
520  wil_dslash(outEven2, gauge, tmp2, 1, daggerBit, precision, gauge_param);
521  }
522  }
523 
524  if (matpc_type == QUDA_MATPC_EVEN_EVEN_ASYMMETRIC) {
525  wil_dslash(tmp1, gauge, inEven1, 1, daggerBit, precision, gauge_param);
526  wil_dslash(tmp2, gauge, inEven2, 1, daggerBit, precision, gauge_param);
527  ndeg_twist_gamma5(tmp1, tmp2, tmp1, tmp2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
528  wil_dslash(outEven1, gauge, tmp1, 0, daggerBit, precision, gauge_param);
529  wil_dslash(outEven2, gauge, tmp2, 0, daggerBit, precision, gauge_param);
530  } else if (matpc_type == QUDA_MATPC_ODD_ODD_ASYMMETRIC) {
531  wil_dslash(tmp1, gauge, inEven1, 0, daggerBit, precision, gauge_param);
532  wil_dslash(tmp2, gauge, inEven2, 0, daggerBit, precision, gauge_param);
533  ndeg_twist_gamma5(tmp1, tmp2, tmp1, tmp2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_INVERSE, precision);
534  wil_dslash(outEven1, gauge, tmp1, 1, daggerBit, precision, gauge_param);
535  wil_dslash(outEven2, gauge, tmp2, 1, daggerBit, precision, gauge_param);
536  }
537 
538  // lastly apply the kappa term
539  double kappa2 = -kappa*kappa;
540  if (matpc_type == QUDA_MATPC_EVEN_EVEN_ASYMMETRIC || matpc_type == QUDA_MATPC_ODD_ODD_ASYMMETRIC) {
541  ndeg_twist_gamma5(inEven1, inEven2, inEven1, inEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_DIRECT, precision);
542  }
543 
544  if (precision == QUDA_DOUBLE_PRECISION){
545  xpay((double*)inEven1, kappa2, (double*)outEven1, Vh*spinorSiteSize);
546  xpay((double*)inEven2, kappa2, (double*)outEven2, Vh*spinorSiteSize);
547  }
548  else{
549  xpay((float*)inEven1, (float)kappa2, (float*)outEven1, Vh*spinorSiteSize);
550  xpay((float*)inEven2, (float)kappa2, (float*)outEven2, Vh*spinorSiteSize);
551  }
552 
553  free(tmp1);
554  free(tmp2);
555 }
556 
557 
558 void tm_ndeg_mat(void *evenOut, void* oddOut, void **gauge, void *evenIn, void *oddIn, double kappa, double mu, double epsilon, int daggerBit, QudaPrecision precision, QudaGaugeParam &gauge_param)
559 {
560  //V-4d volume and Vh=V/2
561  void *inEven1 = evenIn;
562  void *inEven2 = (char*)evenIn + precision*Vh*spinorSiteSize;
563 
564  void *inOdd1 = oddIn;
565  void *inOdd2 = (char*)oddIn + precision*Vh*spinorSiteSize;
566 
567  void *outEven1 = evenOut;
568  void *outEven2 = (char*)evenOut + precision*Vh*spinorSiteSize;
569 
570  void *outOdd1 = oddOut;
571  void *outOdd2 = (char*)oddOut + precision*Vh*spinorSiteSize;
572 
573  void *tmpEven1 = malloc(Vh*spinorSiteSize*precision);
574  void *tmpEven2 = malloc(Vh*spinorSiteSize*precision);
575 
576  void *tmpOdd1 = malloc(Vh*spinorSiteSize*precision);
577  void *tmpOdd2 = malloc(Vh*spinorSiteSize*precision);
578 
579  // full dslash operator:
580  wil_dslash(outOdd1, gauge, inEven1, 1, daggerBit, precision, gauge_param);
581  wil_dslash(outOdd2, gauge, inEven2, 1, daggerBit, precision, gauge_param);
582 
583  wil_dslash(outEven1, gauge, inOdd1, 0, daggerBit, precision, gauge_param);
584  wil_dslash(outEven2, gauge, inOdd2, 0, daggerBit, precision, gauge_param);
585 
586  // apply the twist term
587  ndeg_twist_gamma5(tmpEven1, tmpEven2, inEven1, inEven2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_DIRECT, precision);
588  ndeg_twist_gamma5(tmpOdd1, tmpOdd2, inOdd1, inOdd2, daggerBit, kappa, mu, epsilon, Vh, QUDA_TWIST_GAMMA5_DIRECT, precision);
589  // combine
590  if (precision == QUDA_DOUBLE_PRECISION){
591  xpay((double*)tmpOdd1, -kappa, (double*)outOdd1, Vh*spinorSiteSize);
592  xpay((double*)tmpOdd2, -kappa, (double*)outOdd2, Vh*spinorSiteSize);
593 
594  xpay((double*)tmpEven1, -kappa, (double*)outEven1, Vh*spinorSiteSize);
595  xpay((double*)tmpEven2, -kappa, (double*)outEven2, Vh*spinorSiteSize);
596  }
597  else{
598  xpay((float*)tmpOdd1, (float)(-kappa), (float*)outOdd1, Vh*spinorSiteSize);
599  xpay((float*)tmpOdd2, (float)(-kappa), (float*)outOdd2, Vh*spinorSiteSize);
600 
601  xpay((float*)tmpEven1, (float)(-kappa), (float*)outEven1, Vh*spinorSiteSize);
602  xpay((float*)tmpEven2, (float)(-kappa), (float*)outEven2, Vh*spinorSiteSize);
603  }
604 
605  free(tmpOdd1);
606  free(tmpOdd2);
607  //
608  free(tmpEven1);
609  free(tmpEven2);
610 }
611 
612 //End of nondeg TM