QUDA  v0.7.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  double scale;
23 
24  void *gauge; // used when we use a reference to an external field
25 
26  QudaFieldCreate create; // used to determine the type of field created
27 
28  QudaFieldGeometry geometry; // whether the field is a scale, vector or tensor
29  int pinned; //used in cpu field only, where the host memory is pinned
30 
31  // whether we need to compute the fat link maxima
32  // FIXME temporary flag until we have a kernel that can do this, then we just do this in copy()
33  // always set to false, requires external override
35 
38 
41 
44 
47 
48  // Default constructor
49  GaugeFieldParam(void* const h_gauge=NULL) : LatticeFieldParam(),
50  nColor(3),
51  nFace(0),
57  anisotropy(1.0),
58  tadpole(1.0),
59  scale(1.0),
60  gauge(h_gauge),
63  pinned(0),
64  compute_fat_link_max(false),
66 
69  {
70  // variables declared in LatticeFieldParam
72  nDim = 4;
73  pad = 0;
74  for(int dir=0; dir<nDim; ++dir) {
75  x[dir] = 0;
76  r[dir] = 0;
77  }
78  }
79 
81  const int pad, const QudaFieldGeometry geometry,
83  : LatticeFieldParam(), nColor(3), nFace(0), reconstruct(reconstruct),
86  tadpole(1.0), scale(1.0), gauge(0), create(QUDA_NULL_FIELD_CREATE), geometry(geometry),
89  {
90  // variables declared in LatticeFieldParam
91  this->precision = precision;
92  this->nDim = 4;
93  this->pad = pad;
94  for(int dir=0; dir<nDim; ++dir) {
95  this->x[dir] = x[dir];
96  this->r[dir] = 0;
97  }
98  }
99 
100  GaugeFieldParam(void *h_gauge, const QudaGaugeParam &param) : LatticeFieldParam(param),
102  fixed(param.gauge_fix), link_type(param.type), t_boundary(param.t_boundary),
103  anisotropy(param.anisotropy), tadpole(param.tadpole_coeff), scale(param.scale), gauge(h_gauge),
106  staggeredPhaseType(param.staggered_phase_type),
107  staggeredPhaseApplied(param.staggered_phase_applied)
108  {
110  else if (link_type == QUDA_ASQTAD_LONG_LINKS) nFace = 3;
111  else errorQuda("Error: invalid link type(%d)\n", link_type);
112  for (int d=0; d<nDim; d++) r[d] = 0;
113  }
114  };
115 
116  std::ostream& operator<<(std::ostream& output, const GaugeFieldParam& param);
117 
118  class GaugeField : public LatticeField {
119 
120  protected:
121  size_t bytes; // bytes allocated per full field
122  int phase_offset; // offset in bytes to gauge phases - useful to keep track of texture alignment
123  int phase_bytes; // bytes needed to store the phases
124  int length;
126  int nColor;
127  int nFace;
128  QudaFieldGeometry geometry; // whether the field is a scale, vector or tensor
129 
135 
136  double anisotropy;
137  double tadpole;
138  double fat_link_max;
139  double scale;
140 
141 
142  QudaFieldCreate create; // used to determine the type of field created
143 
146 
147  QudaGhostExchange ghostExchange; // the type of ghost exchange to perform
148  mutable void *ghost[QUDA_MAX_DIM]; // stores the ghost zone of the gauge field (non-native fields only)
149 
152 
155 
160  bool isNative() const;
161 
162  public:
164  virtual ~GaugeField();
165 
166  int Length() const { return length; }
167  int Ncolor() const { return nColor; }
169  QudaGaugeFieldOrder Order() const { return order; }
170  double Anisotropy() const { return anisotropy; }
171  double Tadpole() const { return tadpole; }
172  double Scale() const { return scale; }
173  QudaTboundary TBoundary() const { return t_boundary; }
174  QudaLinkType LinkType() const { return link_type; }
175  QudaGaugeFixed GaugeFixed() const { return fixed; }
177  QudaFieldGeometry Geometry() const { return geometry; }
178  const int* R() const { return r; }
181 
185  void applyStaggeredPhase();
186 
190  void removeStaggeredPhase();
191 
192  const double& LinkMax() const { return fat_link_max; }
193  int Nface() const { return nFace; }
194 
195  void checkField(const GaugeField &);
196 
197  size_t Bytes() const { return bytes; }
198  size_t PhaseBytes() const { return phase_bytes; }
199  size_t PhaseOffset() const { return phase_offset; }
200 
201  virtual void* Gauge_p() { errorQuda("Not implemented"); return (void*)0;}
202  virtual void* Even_p() { errorQuda("Not implemented"); return (void*)0;}
203  virtual void* Odd_p() { errorQuda("Not implemented"); return (void*)0;}
204 
205  virtual const void* Gauge_p() const { errorQuda("Not implemented"); return (void*)0;}
206  virtual const void* Even_p() const { errorQuda("Not implemented"); return (void*)0;}
207  virtual const void* Odd_p() const { errorQuda("Not implemented"); return (void*)0;}
208 
209  const void** Ghost() const {
210  if ( isNative() ) errorQuda("No ghost zone pointer for quda-native gauge fields");
211  return (const void**)ghost;
212  }
213 
214  };
215 
216  class cudaGaugeField : public GaugeField {
217 
218  private:
219  void *gauge;
220  void *even;
221  void *odd;
222 
223 #ifdef USE_TEXTURE_OBJECTS
224  cudaTextureObject_t evenTex;
225  cudaTextureObject_t oddTex;
226  cudaTextureObject_t evenPhaseTex;
227  cudaTextureObject_t oddPhaseTex;
228  void createTexObject(cudaTextureObject_t &tex, void *gauge, int isPhase=0);
229  void destroyTexObject();
230 #endif
231 
232  public:
234  virtual ~cudaGaugeField();
235 
236  void exchangeGhost(); // exchange the ghost and store store in the padded region
237 
246  void exchangeExtendedGhost(const int *R, bool no_comms_fill=false);
247 
248  void copy(const GaugeField &); // generic gauge field copy
249  void loadCPUField(const cpuGaugeField &, const QudaFieldLocation &);
250  void saveCPUField(cpuGaugeField &, const QudaFieldLocation &) const;
251 
252  // (ab)use with care
253  void* Gauge_p() { return gauge; }
254  void* Even_p() { return even; }
255  void* Odd_p() { return odd; }
256 
257  const void* Gauge_p() const { return gauge; }
258  const void* Even_p() const { return even; }
259  const void* Odd_p() const { return odd; }
260 
261 #ifdef USE_TEXTURE_OBJECTS
262  const cudaTextureObject_t& EvenTex() const { return evenTex; }
263  const cudaTextureObject_t& OddTex() const { return oddTex; }
264  const cudaTextureObject_t& EvenPhaseTex() const { return evenPhaseTex; }
265  const cudaTextureObject_t& OddPhaseTex() const { return oddPhaseTex; }
266 #endif
267 
268  mutable char *backup_h;
269  mutable bool backed_up;
270  // backs up the cudaGaugeField to CPU memory
271  void backup() const;
272  // restores the cudaGaugeField to CUDA memory
273  void restore();
274 
275  void setGauge(void* _gauge); //only allowed when create== QUDA_REFERENCE_FIELD_CREATE
276  };
277 
278  class cpuGaugeField : public GaugeField {
279 
280  friend void cudaGaugeField::copy(const GaugeField &cpu);
281  friend void cudaGaugeField::loadCPUField(const cpuGaugeField &cpu, const QudaFieldLocation &);
282  friend void cudaGaugeField::saveCPUField(cpuGaugeField &cpu, const QudaFieldLocation &) const;
283 
284  private:
285  void **gauge; // the actual gauge field
286  int pinned;
287 
288  public:
290  virtual ~cpuGaugeField();
291 
292  void exchangeGhost();
293 
302  void exchangeExtendedGhost(const int *R, bool no_comms_fill=false);
303 
304  void* Gauge_p() { return gauge; }
305  const void* Gauge_p() const { return gauge; }
306  void setGauge(void** _gauge); //only allowed when create== QUDA_REFERENCE_FIELD_CREATE
307  };
308 
315  double norm2(const cudaGaugeField &u);
316 
329  void copyGenericGauge(GaugeField &out, const GaugeField &in, QudaFieldLocation location,
330  void *Out=0, void *In=0, void **ghostOut=0, void **ghostIn=0, int type=0);
340  void copyExtendedGauge(GaugeField &out, const GaugeField &in,
341  QudaFieldLocation location, void *Out=0, void *In=0);
342 
349  void extractGaugeGhost(const GaugeField &u, void **ghost);
350 
359  void extractExtendedGaugeGhost(const GaugeField &u, int dim, const int *R,
360  void **ghost, bool extract);
361 
368  double maxGauge(const GaugeField &u);
369 
375  void applyGaugePhase(GaugeField &u);
376 
377 } // namespace quda
378 
379 
380 //FIXME remove this legacy macro
381 #define gaugeSiteSize 18 // real numbers per gauge field
382 
383 #endif // _GAUGE_QUDA_H
size_t PhaseOffset() const
Definition: gauge_field.h:199
virtual void * Even_p()
Definition: gauge_field.h:202
QudaTboundary t_boundary
Definition: gauge_field.h:18
double Tadpole() const
Definition: gauge_field.h:171
QudaGaugeFieldOrder FieldOrder() const
Definition: gauge_field.h:176
void setGauge(void **_gauge)
QudaGhostExchange GhostExchange() const
Definition: gauge_field.h:179
double maxGauge(const GaugeField &u)
Definition: max_gauge.cu:29
const void ** Ghost() const
Definition: gauge_field.h:209
enum QudaPrecision_s QudaPrecision
void copyGenericGauge(GaugeField &out, const GaugeField &in, QudaFieldLocation location, void *Out=0, void *In=0, void **ghostOut=0, void **ghostIn=0, int type=0)
Definition: copy_gauge.cu:30
virtual ~GaugeField()
Definition: gauge_field.cpp:62
void exchangeExtendedGhost(const int *R, bool no_comms_fill=false)
int Ncolor() const
Definition: gauge_field.h:167
void saveCPUField(cpuGaugeField &, const QudaFieldLocation &) const
#define errorQuda(...)
Definition: util_quda.h:73
void * ghost[QUDA_MAX_DIM]
Definition: gauge_field.h:148
void extractGaugeGhost(const GaugeField &u, void **ghost)
QudaGaugeFieldOrder Order() const
Definition: gauge_field.h:169
virtual void * Odd_p()
Definition: gauge_field.h:203
QudaReconstructType reconstruct
Definition: gauge_field.h:130
bool staggeredPhaseApplied
Definition: gauge_field.h:154
const void * Even_p() const
Definition: gauge_field.h:258
const void * Odd_p() const
Definition: gauge_field.h:259
QudaPrecision precision
Definition: lattice_field.h:41
int Nface() const
Definition: gauge_field.h:193
void applyGaugePhase(GaugeField &u)
Definition: gauge_phase.cu:261
enum QudaTboundary_s QudaTboundary
QudaStaggeredPhase staggeredPhaseType
Definition: gauge_field.h:151
GaugeField(const GaugeFieldParam &param)
Definition: gauge_field.cpp:6
cudaGaugeField(const GaugeFieldParam &)
std::ostream & operator<<(std::ostream &output, const CloverFieldParam &param)
QudaFieldGeometry geometry
Definition: gauge_field.h:128
QudaGaugeParam param
Definition: pack_test.cpp:17
int x[QUDA_MAX_DIM]
Definition: lattice_field.h:38
size_t Bytes() const
Definition: gauge_field.h:197
int r[QUDA_MAX_DIM]
Definition: gauge_field.h:145
QudaStaggeredPhase StaggeredPhase() const
Definition: gauge_field.h:180
const void * Gauge_p() const
Definition: gauge_field.h:305
GaugeFieldParam(void *h_gauge, const QudaGaugeParam &param)
Definition: gauge_field.h:100
virtual const void * Even_p() const
Definition: gauge_field.h:206
virtual const void * Odd_p() const
Definition: gauge_field.h:207
const QudaFieldLocation location
Definition: pack_test.cpp:46
QudaGaugeFixed fixed
Definition: gauge_field.h:16
enum QudaStaggeredPhase_s QudaStaggeredPhase
double Scale() const
Definition: gauge_field.h:172
virtual const void * Gauge_p() const
Definition: gauge_field.h:205
void exchangeExtendedGhost(const int *R, bool no_comms_fill=false)
cpuColorSpinorField * in
void extractExtendedGaugeGhost(const GaugeField &u, int dim, const int *R, void **ghost, bool extract)
enum QudaGhostExchange_s QudaGhostExchange
QudaGaugeFieldOrder order
Definition: gauge_field.h:15
QudaReconstructType Reconstruct() const
Definition: gauge_field.h:168
enum QudaGaugeFixed_s QudaGaugeFixed
QudaGaugeFixed GaugeFixed() const
Definition: gauge_field.h:175
void loadCPUField(const cpuGaugeField &, const QudaFieldLocation &)
enum QudaGaugeFieldOrder_s QudaGaugeFieldOrder
const double & LinkMax() const
Definition: gauge_field.h:192
QudaStaggeredPhase staggeredPhaseType
Definition: gauge_field.h:43
enum QudaLinkType_s QudaLinkType
int Length() const
Definition: gauge_field.h:166
const void * Gauge_p() const
Definition: gauge_field.h:257
QudaGhostExchange ghostExchange
Definition: gauge_field.h:40
const int * R() const
Definition: gauge_field.h:178
void checkField(const GaugeField &)
enum QudaFieldLocation_s QudaFieldLocation
QudaGhostExchange ghostExchange
Definition: gauge_field.h:147
cpuColorSpinorField * out
QudaLinkType link_type
Definition: gauge_field.h:133
QudaGaugeFieldOrder gauge_order
enum QudaReconstructType_s QudaReconstructType
Main header file for the QUDA library.
QudaTboundary t_boundary
Definition: gauge_field.h:134
GaugeFieldParam(void *const h_gauge=NULL)
Definition: gauge_field.h:49
QudaLinkType LinkType() const
Definition: gauge_field.h:174
QudaLinkType link_type
Definition: gauge_field.h:17
GaugeFieldParam(const int *x, const QudaPrecision precision, const QudaReconstructType reconstruct, const int pad, const QudaFieldGeometry geometry, const QudaGhostExchange ghostExchange=QUDA_GHOST_EXCHANGE_PAD)
Definition: gauge_field.h:80
void applyStaggeredPhase()
Definition: gauge_field.cpp:66
bool isNative() const
Definition: gauge_field.cpp:92
void setGauge(void *_gauge)
QudaFieldCreate create
Definition: gauge_field.h:142
QudaReconstructType reconstruct
Definition: gauge_field.h:14
QudaFieldCreate create
Definition: gauge_field.h:26
void copy(const GaugeField &)
enum QudaFieldCreate_s QudaFieldCreate
enum QudaFieldGeometry_s QudaFieldGeometry
virtual void * Gauge_p()
Definition: gauge_field.h:201
#define QUDA_MAX_DIM
Maximum number of dimensions supported by QUDA. In practice, no routines make use of more than 5...
QudaFieldGeometry geometry
Definition: gauge_field.h:28
QudaFieldGeometry Geometry() const
Definition: gauge_field.h:177
QudaGaugeFieldOrder order
Definition: gauge_field.h:131
double norm2(const ColorSpinorField &)
QudaTboundary TBoundary() const
Definition: gauge_field.h:173
cpuGaugeField(const GaugeFieldParam &)
size_t PhaseBytes() const
Definition: gauge_field.h:198
QudaGaugeFixed fixed
Definition: gauge_field.h:132
void copyExtendedGauge(GaugeField &out, const GaugeField &in, QudaFieldLocation location, void *Out=0, void *In=0)
double Anisotropy() const
Definition: gauge_field.h:170
int r[QUDA_MAX_DIM]
Definition: gauge_field.h:37
void removeStaggeredPhase()
Definition: gauge_field.cpp:79