QUDA  1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dslash_wilson_clover.cu
Go to the documentation of this file.
1 #include <gauge_field.h>
2 #include <color_spinor_field.h>
3 #include <clover_field.h>
4 #include <dslash.h>
5 #include <worker.h>
6 
7 #include <dslash_policy.cuh>
9 
14 namespace quda
15 {
16 
21  template <typename Float, int nDim, int nColor, int nParity, bool dagger, bool xpay, KernelType kernel_type, typename Arg>
23  static constexpr const char *kernel = "quda::wilsonCloverGPU"; // kernel name for jit compilation
24  template <typename Dslash>
25  inline static void launch(Dslash &dslash, TuneParam &tp, Arg &arg, const cudaStream_t &stream)
26  {
27  static_assert(xpay == true, "wilsonClover operator only defined for xpay");
28  dslash.launch(wilsonCloverGPU<Float, nDim, nColor, nParity, dagger, xpay, kernel_type, Arg>, tp, arg, stream);
29  }
30  };
31 
32  template <typename Float, int nDim, int nColor, typename Arg> class WilsonClover : public Dslash<Float>
33  {
34 
35 protected:
36  Arg &arg;
38 
39 public:
41  Dslash<Float>(arg, out, in, "kernels/dslash_wilson_clover.cuh"),
42  arg(arg),
43  in(in)
44  {
45  }
46 
47  virtual ~WilsonClover() {}
48 
49  void apply(const cudaStream_t &stream)
50  {
51  TuneParam tp = tuneLaunch(*this, getTuning(), getVerbosity());
53  if (arg.xpay)
54  Dslash<Float>::template instantiate<WilsonCloverLaunch, nDim, nColor, true>(tp, arg, stream);
55  else
56  errorQuda("Wilson-clover operator only defined for xpay=true");
57  }
58 
59  long long flops() const
60  {
61  int clover_flops = 504;
62  long long flops = Dslash<Float>::flops();
63  switch (arg.kernel_type) {
64  case EXTERIOR_KERNEL_X:
65  case EXTERIOR_KERNEL_Y:
66  case EXTERIOR_KERNEL_Z:
67  case EXTERIOR_KERNEL_T:
68  case EXTERIOR_KERNEL_ALL: break; // all clover flops are in the interior kernel
69  case INTERIOR_KERNEL:
70  case KERNEL_POLICY: flops += clover_flops * in.Volume(); break;
71  }
72  return flops;
73  }
74 
75  long long bytes() const
76  {
77  bool isFixed = (in.Precision() == sizeof(short) || in.Precision() == sizeof(char)) ? true : false;
78  int clover_bytes = 72 * in.Precision() + (isFixed ? 2 * sizeof(float) : 0);
79 
80  long long bytes = Dslash<Float>::bytes();
81  switch (arg.kernel_type) {
82  case EXTERIOR_KERNEL_X:
83  case EXTERIOR_KERNEL_Y:
84  case EXTERIOR_KERNEL_Z:
85  case EXTERIOR_KERNEL_T:
86  case EXTERIOR_KERNEL_ALL: break;
87  case INTERIOR_KERNEL:
88  case KERNEL_POLICY: bytes += clover_bytes * in.Volume(); break;
89  }
90 
91  return bytes;
92  }
93 
94  TuneKey tuneKey() const
95  {
96  return TuneKey(in.VolString(), typeid(*this).name(), Dslash<Float>::aux[arg.kernel_type]);
97  }
98  };
99 
100  template <typename Float, int nColor, QudaReconstructType recon> struct WilsonCloverApply {
101 
103  double a, const ColorSpinorField &x, int parity, bool dagger, const int *comm_override, TimeProfile &profile)
104  {
105  constexpr int nDim = 4;
106  WilsonCloverArg<Float, nColor, recon> arg(out, in, U, A, a, 0.0, x, parity, dagger, comm_override);
108 
110  const_cast<cudaColorSpinorField *>(static_cast<const cudaColorSpinorField *>(&in)), in.VolumeCB(),
111  in.GhostFaceCB(), profile);
112  policy.apply(0);
113 
114  checkCudaError();
115  }
116  };
117 
118  // Apply the Wilson-clover operator
119  // out(x) = M*in = (A(x) + a * \sum_mu U_{-\mu}(x)in(x+mu) + U^\dagger_mu(x-mu)in(x-mu))
120  // Uses the kappa normalization for the Wilson operator.
122  double a, const ColorSpinorField &x, int parity, bool dagger, const int *comm_override, TimeProfile &profile)
123  {
124 #ifdef GPU_CLOVER_DIRAC
125  if (in.V() == out.V()) errorQuda("Aliasing pointers");
126  if (in.FieldOrder() != out.FieldOrder())
127  errorQuda("Field order mismatch in = %d, out = %d", in.FieldOrder(), out.FieldOrder());
128 
129  // check all precisions match
130  checkPrecision(out, in, U, A);
131 
132  // check all locations match
133  checkLocation(out, in, U, A);
134 
135  instantiate<WilsonCloverApply>(out, in, U, A, a, x, parity, dagger, comm_override, profile);
136 #else
137  errorQuda("Clover dslash has not been built");
138 #endif
139  }
140 
141 } // namespace quda
void launch(T *f, const TuneParam &tp, Arg &arg, const cudaStream_t &stream)
Definition: dslash.h:101
void setParam(Arg &arg)
Definition: dslash.h:66
void apply(const cudaStream_t &stream)
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:21
#define checkPrecision(...)
#define errorQuda(...)
Definition: util_quda.h:121
void apply(const cudaStream_t &stream)
cudaStream_t * stream
const char * VolString() const
This is a helper class that is used to instantiate the correct templated kernel for the dslash...
static void launch(Dslash &dslash, TuneParam &tp, Arg &arg, const cudaStream_t &stream)
void xpay(ColorSpinorField &x, double a, ColorSpinorField &y)
Definition: blas_quda.h:37
const ColorSpinorField & in
WilsonClover(Arg &arg, const ColorSpinorField &out, const ColorSpinorField &in)
virtual long long bytes() const
Definition: dslash.h:364
long long bytes() const
static constexpr const char * kernel
__device__ __host__ void wilson(Arg &arg, int idx, int s, int parity)
cpuColorSpinorField * in
const int * GhostFaceCB() const
TuneParam & tuneLaunch(Tunable &tunable, QudaTune enabled, QudaVerbosity verbosity)
Definition: tune.cpp:643
#define checkLocation(...)
long long flops() const
cpuColorSpinorField * out
void ApplyWilsonClover(ColorSpinorField &out, const ColorSpinorField &in, const GaugeField &U, const CloverField &A, double kappa, const ColorSpinorField &x, int parity, bool dagger, const int *comm_override, TimeProfile &profile)
Driver for applying the Wilson-clover stencil.
WilsonCloverApply(ColorSpinorField &out, const ColorSpinorField &in, const GaugeField &U, const CloverField &A, double a, const ColorSpinorField &x, int parity, bool dagger, const int *comm_override, TimeProfile &profile)
unsigned long long flops
Definition: blas_quda.cu:22
__host__ __device__ ValueType arg(const complex< ValueType > &z)
Returns the phase angle of z.
#define checkCudaError()
Definition: util_quda.h:161
virtual long long flops() const
Definition: dslash.h:316
QudaTune getTuning()
Query whether autotuning is enabled or not. Default is enabled but can be overridden by setting QUDA_...
Definition: util_quda.cpp:52
QudaPrecision Precision() const
QudaDagType dagger
Definition: test_util.cpp:1620
QudaParity parity
Definition: covdev_test.cpp:54
QudaFieldOrder FieldOrder() const
unsigned long long bytes
Definition: blas_quda.cu:23