QUDA  v0.5.0
A library for QCD on GPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gauge_field.h
Go to the documentation of this file.
1 #ifndef _GAUGE_QUDA_H
2 #define _GAUGE_QUDA_H
3 
4 #include <quda_internal.h>
5 #include <quda.h>
6 #include <lattice_field.h>
7 
8 namespace quda {
9 
11  int nColor;
12  int nFace;
13 
19 
20  double anisotropy;
21  double tadpole;
22 
23  void *gauge; // used when we use a reference to an external field
24 
25  QudaFieldCreate create; // used to determine the type of field created
26 
27  QudaFieldGeometry geometry; // whether the field is a scale, vector or tensor
28  int pinned; //used in cpu field only, where the host memory is pinned
29 
30  // Default constructor
31  GaugeFieldParam(void* const h_gauge=NULL) : LatticeFieldParam(),
32  nColor(3),
33  nFace(0),
39  anisotropy(1.0),
40  tadpole(1.0),
41  gauge(h_gauge),
44  pinned(0)
45  {
46  // variables declared in LatticeFieldParam
49  nDim = 4;
50  pad = 0;
51  for(int dir=0; dir<nDim; ++dir) x[dir] = 0;
52  }
53 
55  const int pad, const QudaFieldGeometry geometry) : LatticeFieldParam(), nColor(3), nFace(0),
56  reconstruct(reconstruct), order(QUDA_INVALID_GAUGE_ORDER), fixed(QUDA_GAUGE_FIXED_NO),
58  tadpole(1.0), gauge(0), create(QUDA_NULL_FIELD_CREATE), geometry(geometry), pinned(0)
59  {
60  // variables declared in LatticeFieldParam
61  this->precision = precision;
62  this->verbosity = QUDA_SILENT;
63  this->nDim = 4;
64  this->pad = pad;
65  for(int dir=0; dir<nDim; ++dir) this->x[dir] = x[dir];
66  }
67 
68  GaugeFieldParam(void *h_gauge, const QudaGaugeParam &param) : LatticeFieldParam(param),
70  fixed(param.gauge_fix), link_type(param.type), t_boundary(param.t_boundary),
71  anisotropy(param.anisotropy), tadpole(param.tadpole_coeff), gauge(h_gauge),
73 
75  else if (link_type == QUDA_ASQTAD_LONG_LINKS) nFace = 3;
76  else errorQuda("Error: invalid link type(%d)\n", link_type);
77  }
78  };
79 
80  std::ostream& operator<<(std::ostream& output, const GaugeFieldParam& param);
81 
82  class GaugeField : public LatticeField {
83 
84  protected:
85  size_t bytes; // bytes allocated per full field
86  int length;
88  int nColor;
89  int nFace;
90  QudaFieldGeometry geometry; // whether the field is a scale, vector or tensor
91 
97 
98  double anisotropy;
99  double tadpole;
100 
101  QudaFieldCreate create; // used to determine the type of field created
102 
103  public:
105  virtual ~GaugeField();
106 
107  int Length() const { return length; }
108  int Ncolor() const { return nColor; }
110  QudaGaugeFieldOrder Order() const { return order; }
111  double Anisotropy() const { return anisotropy; }
112  double Tadpole() const { return tadpole; }
113  QudaTboundary TBoundary() const { return t_boundary; }
114  QudaLinkType LinkType() const { return link_type; }
115  QudaGaugeFixed GaugeFixed() const { return fixed; }
117  QudaFieldGeometry Geometry() const { return geometry; }
118 
119  void checkField(const GaugeField &);
120 
121  const size_t& Bytes() const { return bytes; }
122 
123  };
124 
125  class cudaGaugeField : public GaugeField {
126 
127  friend void bindGaugeTex(const cudaGaugeField &gauge, const int oddBit,
128  void **gauge0, void **gauge1);
129  friend void unbindGaugeTex(const cudaGaugeField &gauge);
130  friend void bindFatGaugeTex(const cudaGaugeField &gauge, const int oddBit,
131  void **gauge0, void **gauge1);
132  friend void unbindFatGaugeTex(const cudaGaugeField &gauge);
133  friend void bindLongGaugeTex(const cudaGaugeField &gauge, const int oddBit,
134  void **gauge0, void **gauge1);
135  friend void unbindLongGaugeTex(const cudaGaugeField &gauge);
136 
137  private:
138  void *gauge;
139  void *even;
140  void *odd;
141 
142  double fat_link_max;
143 
144 #ifdef USE_TEXTURE_OBJECTS
145  cudaTextureObject_t evenTex;
146  cudaTextureObject_t oddTex;
147  void createTexObject(cudaTextureObject_t &tex, void *gauge);
148  void destroyTexObject();
149 #endif
150 
151  public:
153  virtual ~cudaGaugeField();
154 
155  void loadCPUField(const cpuGaugeField &, const QudaFieldLocation &);
156  void saveCPUField(cpuGaugeField &, const QudaFieldLocation &) const;
157 
158  double LinkMax() const { return fat_link_max; }
159 
160  // (ab)use with care
161  void* Gauge_p() { return gauge; }
162  void* Even_p() { return even; }
163  void* Odd_p() { return odd; }
164 
165  const void* Gauge_p() const { return gauge; }
166  const void* Even_p() const { return even; }
167  const void* Odd_p() const { return odd; }
168 
169 #ifdef USE_TEXTURE_OBJECTS
170  const cudaTextureObject_t& EvenTex() const { return evenTex; }
171  const cudaTextureObject_t& OddTex() const { return oddTex; }
172 #endif
173 
174  mutable char *backup_h;
175  mutable bool backed_up;
176  // backs up the cudaGaugeField to CPU memory
177  void backup() const;
178  // restores the cudaGaugeField to CUDA memory
179  void restore();
180 
181  };
182 
183  class cpuGaugeField : public GaugeField {
184 
185  friend void cudaGaugeField::loadCPUField(const cpuGaugeField &cpu, const QudaFieldLocation &);
186  friend void cudaGaugeField::saveCPUField(cpuGaugeField &cpu, const QudaFieldLocation &) const;
187 
188  private:
189  void **gauge; // the actual gauge field
190 
191  mutable void **ghost; // stores the ghost zone of the gauge field
192  int pinned;
193 
194  public:
196  virtual ~cpuGaugeField();
197 
198  void exchangeGhost() const;
199  const void** Ghost() const { return (const void**)ghost; }
200 
201  void* Gauge_p() { return gauge; }
202  void setGauge(void** _gauge); //only allowed when create== QUDA_REFERENCE_FIELD_CREATE
203  };
204 
211  double norm2(const cudaGaugeField &a);
212 
213 } // namespace quda
214 
215 #define gaugeSiteSize 18 // real numbers per gauge field
216 
217 #endif // _GAUGE_QUDA_H