1 #include <gauge_field_order.h>
2 #include <instantiate.h>
15 template <typename reg_type, typename real, int Nc, QudaGaugeFieldOrder order>
16 double norm(const GaugeField &u, int d, norm_type_ 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;
27 template <typename reg_type, typename real, int Nc>
28 double norm(const GaugeField &u, int d, norm_type_ type) {
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());
39 template <typename T, bool fixed> struct type_mapper {
40 using reg_t = typename mapper<T>::type;
44 // fixed-point single-precision field
45 template <> struct type_mapper<float, true> {
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;
57 case 3: norm_ = norm<reg_t, store_t, 3>(u, d, type); break;
59 case 48: norm_ = norm<reg_t, store_t, 48>(u, d, type); break;
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;
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;
68 #endif // GPU_MULTIGRID
69 default: errorQuda("Unsupported color %d", u.Ncolor());
74 template <typename T> struct Norm {
75 Norm(const GaugeField &u, double &nrm, int d, bool fixed, norm_type_ type)
77 if (fixed && u.Precision() > QUDA_SINGLE_PRECISION)
78 errorQuda("Fixed point override only enabled for 8-bit, 16-bit and 32-bit fields");
80 if (fixed) nrm = norm<T, true>(u, d, type);
81 else nrm = norm<T, false>(u, d, type);
85 double GaugeField::norm1(int d, bool fixed) const {
86 if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
88 instantiatePrecision<Norm>(*this, nrm, d, fixed, NORM1);
92 double GaugeField::norm2(int d, bool fixed) const {
93 if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
95 instantiatePrecision<Norm>(*this, nrm, d, fixed, NORM2);
99 double GaugeField::abs_max(int d, bool fixed) const {
100 if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
102 instantiatePrecision<Norm>(*this, nrm, d, fixed, ABS_MAX);
106 double GaugeField::abs_min(int d, bool fixed) const {
107 if (reconstruct != QUDA_RECONSTRUCT_NO) errorQuda("Unsupported reconstruct=%d", reconstruct);
109 instantiatePrecision<Norm>(*this, nrm, d, fixed, ABS_MIN);