QUDA  1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gauge_plaq.cuh
Go to the documentation of this file.
1 #include <quda_matrix.h>
2 #include <gauge_field_order.h>
3 #include <launch_kernel.cuh>
4 #include <index_helper.cuh>
5 #include <cub_helper.cuh>
6 
7 namespace quda {
8 
9  template <typename Gauge>
10  struct GaugePlaqArg : public ReduceArg<double2> {
11  int threads; // number of active threads required
12  int E[4]; // extended grid dimensions
13  int X[4]; // true grid dimensions
14  int border[4];
15  Gauge dataOr;
16 
17  GaugePlaqArg(const Gauge &dataOr, const GaugeField &data)
18  : ReduceArg<double2>(), dataOr(dataOr)
19  {
20  int R = 0;
21  for (int dir=0; dir<4; ++dir){
22  border[dir] = data.R()[dir];
23  E[dir] = data.X()[dir];
24  X[dir] = data.X()[dir] - border[dir]*2;
25  R += border[dir];
26  }
27  threads = X[0]*X[1]*X[2]*X[3]/2;
28  }
29  };
30 
31  template<typename Float, typename Arg>
32  __device__ inline double plaquette(Arg &arg, int x[], int parity, int mu, int nu) {
33  typedef Matrix<complex<Float>,3> Link;
34 
35  int dx[4] = {0, 0, 0, 0};
36  Link U1 = arg.dataOr(mu, linkIndexShift(x,dx,arg.E), parity);
37  dx[mu]++;
38  Link U2 = arg.dataOr(nu, linkIndexShift(x,dx,arg.E), 1-parity);
39  dx[mu]--;
40  dx[nu]++;
41  Link U3 = arg.dataOr(mu, linkIndexShift(x,dx,arg.E), 1-parity);
42  dx[nu]--;
43  Link U4 = arg.dataOr(nu, linkIndexShift(x,dx,arg.E), parity);
44 
45  return getTrace( U1 * U2 * conj(U3) * conj(U4) ).x;
46  }
47 
48  template<int blockSize, typename Float, typename Gauge>
50  int idx = threadIdx.x + blockIdx.x*blockDim.x;
51  int parity = threadIdx.y;
52 
53  double2 plaq = make_double2(0.0,0.0);
54 
55  while (idx < arg.threads) {
56  int x[4];
57  getCoords(x, idx, arg.X, parity);
58  for (int dr=0; dr<4; ++dr) x[dr] += arg.border[dr]; // extended grid coordinates
59 
60  for (int mu = 0; mu < 3; mu++) {
61  for (int nu = (mu+1); nu < 3; nu++) {
62  plaq.x += plaquette<Float>(arg, x, parity, mu, nu);
63  }
64 
65  plaq.y += plaquette<Float>(arg, x, parity, mu, 3);
66  }
67 
68  idx += blockDim.x*gridDim.x;
69  }
70 
71  // perform final inter-block reduction and write out result
72  reduce2d<blockSize,2>(arg, plaq);
73  }
74 
75 } // namespace quda
double mu
Definition: test_util.cpp:1648
static __device__ __host__ int linkIndexShift(const I x[], const J dx[], const K X[4])
static int R[4]
const int * R() const
__global__ void computePlaq(GaugePlaqArg< Gauge > arg)
Definition: gauge_plaq.cuh:49
Main header file for host and device accessors to GaugeFields.
GaugePlaqArg(const Gauge &dataOr, const GaugeField &data)
Definition: gauge_plaq.cuh:17
__device__ __host__ T getTrace(const Matrix< T, 3 > &a)
Definition: quda_matrix.h:415
__host__ __device__ ValueType arg(const complex< ValueType > &z)
Returns the phase angle of z.
__host__ __device__ ValueType conj(ValueType x)
Definition: complex_quda.h:130
QudaParity parity
Definition: covdev_test.cpp:54
double3 plaquette(const GaugeField &U)
Compute the plaquette of the gauge field.
Definition: gauge_plaq.cu:65
__host__ __device__ int getCoords(int coord[], const Arg &arg, int &idx, int parity, int &dim)
Compute the space-time coordinates we are at.
const int * X() const