QUDA  v1.1.0
A library for QCD on GPUs
max_gauge.cu
Go to the documentation of this file.
1 #include <gauge_field_order.h>
2 #include <instantiate.h>
3 
4 namespace quda {
5 
6  using namespace gauge;
7 
8  enum norm_type_ {
9  NORM1,
10  NORM2,
11  ABS_MAX,
12  ABS_MIN
13  };
14 
15  template <typename reg_type, typename real, int Nc, QudaGaugeFieldOrder order>
16  double norm(const GaugeField &u, int d, norm_type_ type) {
17  double norm_ = 0.0;
18  switch(type) {
19  case NORM1: norm_ = FieldOrder<reg_type,Nc,1,order,true,real>(const_cast<GaugeField &>(u)).norm1(d); break;
20  case NORM2: norm_ = FieldOrder<reg_type,Nc,1,order,true,real>(const_cast<GaugeField &>(u)).norm2(d); break;
21  case ABS_MAX: norm_ = FieldOrder<reg_type,Nc,1,order,true,real>(const_cast<GaugeField &>(u)).abs_max(d); break;
22  case ABS_MIN: norm_ = FieldOrder<reg_type,Nc,1,order,true,real>(const_cast<GaugeField &>(u)).abs_min(d); break;
23  }
24  return norm_;
25  }
26 
27  template <typename reg_type, typename real, int Nc>
28  double norm(const GaugeField &u, int d, norm_type_ type) {
29  double norm_ = 0.0;
30  switch (u.FieldOrder()) {
31  case QUDA_FLOAT2_GAUGE_ORDER: norm_ = norm<reg_type, real,Nc,QUDA_FLOAT2_GAUGE_ORDER>(u, d, type); break;
32  case QUDA_QDP_GAUGE_ORDER: norm_ = norm<reg_type, real,Nc, QUDA_QDP_GAUGE_ORDER>(u, d, type); break;
33  case QUDA_MILC_GAUGE_ORDER: norm_ = norm<reg_type, real,Nc, QUDA_MILC_GAUGE_ORDER>(u, d, type); break;
34  default: errorQuda("Gauge field %d order not supported", u.Order());
35  }
36  return norm_;
37  }
38 
39  template <typename T, bool fixed> struct type_mapper {
40  using reg_t = typename mapper<T>::type;
41  using store_t = T;
42  };
43 
44  // fixed-point single-precision field
45  template <> struct type_mapper<float, true> {
46  using reg_t = float;
47  using store_t = int;
48  };
49 
50  template <typename T, bool fixed>
51  double norm(const GaugeField &u, int d, norm_type_ type) {
52  using reg_t = typename type_mapper<T, fixed>::reg_t;
53  using store_t = typename type_mapper<T, fixed>::store_t;
54 
55  double norm_ = 0.0;
56  switch(u.Ncolor()) {
57  case 3: norm_ = norm<reg_t, store_t, 3>(u, d, type); break;
58 #ifdef GPU_MULTIGRID
59  case 48: norm_ = norm<reg_t, store_t, 48>(u, d, type); break;
60 #ifdef NSPIN4
61  case 12: norm_ = norm<reg_t, store_t, 12>(u, d, type); break;
62  case 64: norm_ = norm<reg_t, store_t, 64>(u, d, type); break;
63 #endif // NSPIN4
64 #ifdef NSPIN1
65  case 128: norm_ = norm<reg_t, store_t, 128>(u, d, type); break;
66  case 192: norm_ = norm<reg_t, store_t, 192>(u, d, type); break;
67 #endif // NSPIN1
68 #endif // GPU_MULTIGRID
69  default: errorQuda("Unsupported color %d", u.Ncolor());
70  }
71  return norm_;
72  }
73 
74  template <typename T> struct Norm {
75  Norm(const GaugeField &u, double &nrm, int d, bool fixed, norm_type_ type)
76  {
77  if (fixed && u.Precision() > QUDA_SINGLE_PRECISION)
78  errorQuda("Fixed point override only enabled for 8-bit, 16-bit and 32-bit fields");
79 
80  if (fixed) nrm = norm<T, true>(u, d, type);
81  else nrm = norm<T, false>(u, d, type);
82  }
83  };
84 
85  double GaugeField::norm1(int d, bool fixed) const {
86  if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
87  double nrm;
88  instantiatePrecision<Norm>(*this, nrm, d, fixed, NORM1);
89  return nrm;
90  }
91 
92  double GaugeField::norm2(int d, bool fixed) const {
93  if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
94  double nrm;
95  instantiatePrecision<Norm>(*this, nrm, d, fixed, NORM2);
96  return nrm;
97  }
98 
99  double GaugeField::abs_max(int d, bool fixed) const {
100  if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
101  double nrm;
102  instantiatePrecision<Norm>(*this, nrm, d, fixed, ABS_MAX);
103  return nrm;
104  }
105 
106  double GaugeField::abs_min(int d, bool fixed) const {
107  if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
108  double nrm;
109  instantiatePrecision<Norm>(*this, nrm, d, fixed, ABS_MIN);
110  return nrm;
111  }
112 
113 } // namespace quda