QUDA  0.9.0
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  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 
29  // whether we need to compute the fat link maxima
30  // FIXME temporary flag until we have a kernel that can do this, then we just do this in copy()
31  // always set to false, requires external override
33 
36 
39 
41  double i_mu;
42 
44  size_t site_offset;
45 
47  size_t site_size;
48 
49  // Default constructor
50  GaugeFieldParam(void* const h_gauge=NULL) : LatticeFieldParam(),
51  nColor(3),
52  nFace(0),
58  anisotropy(1.0),
59  tadpole(1.0),
60  scale(1.0),
61  gauge(h_gauge),
64  compute_fat_link_max(false),
66  staggeredPhaseApplied(false),
67  i_mu(0.0),
68  site_offset(0),
69  site_size(0)
70  { }
71 
72  GaugeFieldParam(const GaugeField &u);
73 
75  const int pad, const QudaFieldGeometry geometry,
82  staggeredPhaseApplied(false), i_mu(0.0), site_offset(0), site_size(0)
83  { }
84 
87  order(param.gauge_order), fixed(param.gauge_fix),
88  link_type(link_type_ != QUDA_INVALID_LINKS ? link_type_ : param.type), t_boundary(param.t_boundary),
89  anisotropy(param.anisotropy), tadpole(param.tadpole_coeff), scale(param.scale), gauge(h_gauge),
91  compute_fat_link_max(false), staggeredPhaseType(param.staggered_phase_type),
92  staggeredPhaseApplied(param.staggered_phase_applied), i_mu(param.i_mu),
93  site_offset(param.gauge_offset), site_size(param.site_size)
94  {
95  switch(link_type) {
96  case QUDA_SU3_LINKS:
97  case QUDA_GENERAL_LINKS:
98  case QUDA_SMEARED_LINKS:
100  nFace = 1; break;
101  case QUDA_THREE_LINKS:
102  nFace = 3; break;
103  default:
104  errorQuda("Error: invalid link type(%d)\n", link_type);
105  }
106  }
107 
114  this->precision = precision;
117  }
118 
119  };
120 
121  std::ostream& operator<<(std::ostream& output, const GaugeFieldParam& param);
122 
123  class GaugeField : public LatticeField {
124 
125  protected:
126  size_t bytes; // bytes allocated per full field
127  int phase_offset; // offset in bytes to gauge phases - useful to keep track of texture alignment
128  int phase_bytes; // bytes needed to store the phases
129  int length;
131  int nColor;
132  int nFace;
133  QudaFieldGeometry geometry; // whether the field is a scale, vector or tensor
134 
136  int nInternal; // number of degrees of freedom per link matrix
141 
142  double anisotropy;
143  double tadpole;
144  double fat_link_max;
145  double scale;
146 
147  QudaFieldCreate create; // used to determine the type of field created
148 
149  mutable void *ghost[2*QUDA_MAX_DIM]; // stores the ghost zone of the gauge field (non-native fields only)
150 
151  mutable int ghostFace[QUDA_MAX_DIM];// the size of each face
152 
157 
162 
169  void exchange(void **recv, void **send, QudaDirection dir) const;
170 
174  double i_mu;
175 
179  size_t site_offset;
180 
184  size_t site_size;
185 
192  void createGhostZone(const int *R, bool no_comms_fill) const;
193 
194  public:
196  virtual ~GaugeField();
197 
200 
201  int Length() const { return length; }
202  int Ncolor() const { return nColor; }
204  QudaGaugeFieldOrder Order() const { return order; }
205  double Anisotropy() const { return anisotropy; }
206  double Tadpole() const { return tadpole; }
207  double Scale() const { return scale; }
208  QudaTboundary TBoundary() const { return t_boundary; }
209  QudaLinkType LinkType() const { return link_type; }
210  QudaGaugeFixed GaugeFixed() const { return fixed; }
212  QudaFieldGeometry Geometry() const { return geometry; }
215 
219  void applyStaggeredPhase();
220 
224  void removeStaggeredPhase();
225 
229  double iMu() const { return i_mu; }
230 
231  const double& LinkMax() const { return fat_link_max; }
232  int Nface() const { return nFace; }
233 
234  void checkField(const LatticeField &) const;
235 
240  bool isNative() const;
241 
242  size_t Bytes() const { return bytes; }
243  size_t PhaseBytes() const { return phase_bytes; }
244  size_t PhaseOffset() const { return phase_offset; }
245 
246  virtual void* Gauge_p() { errorQuda("Not implemented"); return (void*)0;}
247  virtual void* Even_p() { errorQuda("Not implemented"); return (void*)0;}
248  virtual void* Odd_p() { errorQuda("Not implemented"); return (void*)0;}
249 
250  virtual const void* Gauge_p() const { errorQuda("Not implemented"); return (void*)0;}
251  virtual const void* Even_p() const { errorQuda("Not implemented"); return (void*)0;}
252  virtual const void* Odd_p() const { errorQuda("Not implemented"); return (void*)0;}
253 
254  const void** Ghost() const {
255  if ( isNative() ) errorQuda("No ghost zone pointer for quda-native gauge fields");
256  return (const void**)ghost;
257  }
258 
259  void** Ghost() {
260  if ( isNative() ) errorQuda("No ghost zone pointer for quda-native gauge fields");
261  return ghost;
262  }
263 
268  size_t SiteOffset() const { return site_offset; }
269 
274  size_t SiteSize() const { return site_size; }
275 
279  virtual void zero() = 0;
280 
285  virtual void copy(const GaugeField &src) = 0;
286 
295  uint64_t checksum(bool mini=false) const;
296  };
297 
298  class cudaGaugeField : public GaugeField {
299 
300  private:
301  void *gauge;
302  void *even;
303  void *odd;
304 
305 #ifdef USE_TEXTURE_OBJECTS
306  cudaTextureObject_t tex;
307  cudaTextureObject_t evenTex;
308  cudaTextureObject_t oddTex;
309  cudaTextureObject_t phaseTex;
310  cudaTextureObject_t evenPhaseTex;
311  cudaTextureObject_t oddPhaseTex;
312  void createTexObject(cudaTextureObject_t &tex, void *gauge, bool full, bool isPhase=false);
313  void destroyTexObject();
314 #endif
315 
316  public:
318  virtual ~cudaGaugeField();
319 
325  void exchangeGhost(QudaLinkDirection link_direction = QUDA_LINK_BACKWARDS);
326 
333  void injectGhost(QudaLinkDirection link_direction = QUDA_LINK_BACKWARDS);
334 
341  void createComms(const int *R, bool no_comms_fill);
342 
349  void allocateGhostBuffer(const int *R, bool no_comms_fill) const;
350 
356  void recvStart(int dim, int dir);
357 
365  void sendStart(int dim, int dir, cudaStream_t *stream_p=nullptr);
366 
372  void commsComplete(int dim, int dir);
373 
381  void exchangeExtendedGhost(const int *R, bool no_comms_fill=false);
382 
392  void exchangeExtendedGhost(const int *R, TimeProfile &profile, bool no_comms_fill=false);
393 
398  void copy(const GaugeField &src);
399 
404  void loadCPUField(const cpuGaugeField &cpu);
405 
412  void loadCPUField(const cpuGaugeField &cpu, TimeProfile &profile);
413 
418  void saveCPUField(cpuGaugeField &cpu) const;
419 
426  void saveCPUField(cpuGaugeField &cpu, TimeProfile &profile) const;
427 
428  // (ab)use with care
429  void* Gauge_p() { return gauge; }
430  void* Even_p() { return even; }
431  void* Odd_p() { return odd; }
432 
433  const void* Gauge_p() const { return gauge; }
434  const void* Even_p() const { return even; }
435  const void* Odd_p() const { return odd; }
436 
437 #ifdef USE_TEXTURE_OBJECTS
438  const cudaTextureObject_t& Tex() const { return tex; }
439  const cudaTextureObject_t& EvenTex() const { return evenTex; }
440  const cudaTextureObject_t& OddTex() const { return oddTex; }
441  const cudaTextureObject_t& EvenPhaseTex() const { return evenPhaseTex; }
442  const cudaTextureObject_t& OddPhaseTex() const { return oddPhaseTex; }
443 #endif
444 
445  void setGauge(void* _gauge); //only allowed when create== QUDA_REFERENCE_FIELD_CREATE
446 
450  void zero();
451 
455  void backup() const;
456 
460  void restore();
461 
462  };
463 
464  class cpuGaugeField : public GaugeField {
465 
466  friend void cudaGaugeField::copy(const GaugeField &cpu);
467  friend void cudaGaugeField::loadCPUField(const cpuGaugeField &cpu);
468  friend void cudaGaugeField::saveCPUField(cpuGaugeField &cpu) const;
469 
470  private:
471  void **gauge; // the actual gauge field
472 
473  public:
482  virtual ~cpuGaugeField();
483 
489  void exchangeGhost(QudaLinkDirection link_direction = QUDA_LINK_BACKWARDS);
490 
497  void injectGhost(QudaLinkDirection link_direction = QUDA_LINK_BACKWARDS);
498 
507  void exchangeExtendedGhost(const int *R, bool no_comms_fill=false);
508 
518  void exchangeExtendedGhost(const int *R, TimeProfile &profile, bool no_comms_fill=false);
519 
524  void copy(const GaugeField &src);
525 
526  void* Gauge_p() { return gauge; }
527  const void* Gauge_p() const { return gauge; }
528 
529  void setGauge(void** _gauge); //only allowed when create== QUDA_REFERENCE_FIELD_CREATE
530 
534  void zero();
535 
539  void backup() const;
540 
544  void restore();
545 
546  };
547 
554  double norm1(const GaugeField &u);
555 
562  double norm2(const GaugeField &u);
563 
569  void ax(const double &a, GaugeField &u);
570 
583  void copyGenericGauge(GaugeField &out, const GaugeField &in, QudaFieldLocation location,
584  void *Out=0, void *In=0, void **ghostOut=0, void **ghostIn=0, int type=0);
594  void copyExtendedGauge(GaugeField &out, const GaugeField &in,
595  QudaFieldLocation location, void *Out=0, void *In=0);
596 
609  void extractGaugeGhost(const GaugeField &u, void **ghost, bool extract=true, int offset=0);
610 
619  void extractExtendedGaugeGhost(const GaugeField &u, int dim, const int *R,
620  void **ghost, bool extract);
621 
627  double maxGauge(const GaugeField &u);
628 
633  void applyGaugePhase(GaugeField &u);
634 
644  uint64_t Checksum(const GaugeField &u, bool mini=false);
645 
646 } // namespace quda
647 
648 #endif // _GAUGE_QUDA_H
virtual void * Even_p()
Definition: gauge_field.h:247
QudaTboundary t_boundary
Definition: gauge_field.h:18
void extractGaugeGhost(const GaugeField &u, void **ghost, bool extract=true, int offset=0)
QudaGhostExchange ghostExchange
Definition: lattice_field.h:60
void setGauge(void **_gauge)
double maxGauge(const GaugeField &u)
Definition: max_gauge.cu:31
enum QudaPrecision_s QudaPrecision
void saveCPUField(cpuGaugeField &cpu) const
Upload from this field into a CPU field.
QudaGaugeFieldOrder FieldOrder() const
Definition: gauge_field.h:211
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:38
virtual ~GaugeField()
Definition: gauge_field.cpp:86
const void * Gauge_p() const
Definition: gauge_field.h:527
const void * src
void exchangeExtendedGhost(const int *R, bool no_comms_fill=false)
This does routine will populate the border / halo region of a gauge field that has been created using...
const void * Gauge_p() const
Definition: gauge_field.h:433
#define errorQuda(...)
Definition: util_quda.h:90
void setPrecision(QudaPrecision precision)
Helper function for setting the precision and corresponding field order for QUDA internal fields...
Definition: gauge_field.h:113
enum QudaLinkDirection_s QudaLinkDirection
void injectGhost(QudaLinkDirection link_direction=QUDA_LINK_BACKWARDS)
The opposite of exchangeGhost: take the ghost zone on x, send to node x-1, and inject back into the f...
virtual void * Odd_p()
Definition: gauge_field.h:248
QudaReconstructType reconstruct
Definition: gauge_field.h:135
bool staggeredPhaseApplied
Definition: gauge_field.h:161
uint64_t checksum(bool mini=false) const
QudaLinkType LinkType() const
Definition: gauge_field.h:209
static __inline__ dim3 dim3 void size_t cudaStream_t int dim
uint64_t Checksum(const GaugeField &u, bool mini=false)
Definition: checksum.cu:34
QudaPrecision precision
Definition: lattice_field.h:54
static int R[4]
QudaFieldGeometry Geometry() const
Definition: gauge_field.h:212
void restore()
Restores the cudaGaugeField to CUDA memory.
void applyGaugePhase(GaugeField &u)
Definition: gauge_phase.cu:244
enum QudaTboundary_s QudaTboundary
QudaStaggeredPhase staggeredPhaseType
Definition: gauge_field.h:156
GaugeField(const GaugeFieldParam &param)
Definition: gauge_field.cpp:30
cudaGaugeField(const GaugeFieldParam &)
int Nface() const
Definition: gauge_field.h:232
std::ostream & operator<<(std::ostream &output, const CloverFieldParam &param)
double norm2(const CloverField &a, bool inverse=false)
size_t size_t offset
QudaFieldGeometry geometry
Definition: gauge_field.h:133
QudaGaugeParam param
Definition: pack_test.cpp:17
virtual const void * Odd_p() const
Definition: gauge_field.h:252
int Ncolor() const
Definition: gauge_field.h:202
int x[QUDA_MAX_DIM]
Definition: lattice_field.h:50
double norm1(const CloverField &u, bool inverse=false)
const int * R() const
enum QudaDirection_s QudaDirection
void loadCPUField(const cpuGaugeField &cpu)
Download into this field from a CPU field.
void checkField(const LatticeField &) const
void ax(const double &a, GaugeField &u)
Scale the gauge field by the scalar a.
void commsComplete(int dim, int dir)
Wait for communication to complete.
void allocateGhostBuffer(const int *R, bool no_comms_fill) const
Allocate the ghost buffers.
QudaGaugeFixed fixed
Definition: gauge_field.h:16
enum QudaStaggeredPhase_s QudaStaggeredPhase
size_t Bytes() const
Definition: gauge_field.h:242
bool StaggeredPhaseApplied() const
Definition: gauge_field.h:214
void exchangeExtendedGhost(const int *R, bool no_comms_fill=false)
This does routine will populate the border / halo region of a gauge field that has been created using...
void copy(const GaugeField &src)
double iMu() const
Definition: gauge_field.h:229
void sendStart(int dim, int dir, cudaStream_t *stream_p=nullptr)
Start the sending communicators.
cpuColorSpinorField * in
void extractExtendedGaugeGhost(const GaugeField &u, int dim, const int *R, void **ghost, bool extract)
enum QudaGhostExchange_s QudaGhostExchange
double Anisotropy() const
Definition: gauge_field.h:205
QudaGaugeFieldOrder order
Definition: gauge_field.h:15
enum QudaGaugeFixed_s QudaGaugeFixed
unsigned long long uint64_t
void exchange(void **recv, void **send, QudaDirection dir) const
Exchange the buffers across all dimensions in a given direction.
void exchangeGhost(QudaLinkDirection link_direction=QUDA_LINK_BACKWARDS)
Exchange the ghost and store store in the padded region.
void restore()
Restores the cpuGaugeField.
const void ** Ghost() const
Definition: gauge_field.h:254
enum QudaGaugeFieldOrder_s QudaGaugeFieldOrder
void injectGhost(QudaLinkDirection link_direction=QUDA_LINK_BACKWARDS)
The opposite of exchangeGhost: take the ghost zone on x, send to node x-1, and inject back into the f...
void backup() const
Backs up the cudaGaugeField to CPU memory.
QudaStaggeredPhase staggeredPhaseType
Definition: gauge_field.h:35
enum QudaLinkType_s QudaLinkType
virtual void injectGhost(QudaLinkDirection=QUDA_LINK_BACKWARDS)=0
double Scale() const
Definition: gauge_field.h:207
cpuGaugeField(const GaugeFieldParam &param)
Constructor for cpuGaugeField from a GaugeFieldParam.
void recvStart(int dim, int dir)
Start the receive communicators.
size_t SiteSize() const
Definition: gauge_field.h:274
size_t PhaseOffset() const
Definition: gauge_field.h:244
enum QudaFieldLocation_s QudaFieldLocation
void backup() const
Backs up the cpuGaugeField.
void exchangeGhost(QudaLinkDirection link_direction=QUDA_LINK_BACKWARDS)
Exchange the ghost and store store in the padded region.
size_t PhaseBytes() const
Definition: gauge_field.h:243
void createGhostZone(const int *R, bool no_comms_fill) const
Definition: gauge_field.cpp:90
cpuColorSpinorField * out
QudaLinkType link_type
Definition: gauge_field.h:139
const double & LinkMax() const
Definition: gauge_field.h:231
QudaGaugeFieldOrder gauge_order
enum QudaReconstructType_s QudaReconstructType
Main header file for the QUDA library.
QudaTboundary t_boundary
Definition: gauge_field.h:140
GaugeFieldParam(void *const h_gauge=NULL)
Definition: gauge_field.h:50
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:74
void applyStaggeredPhase()
void setGauge(void *_gauge)
const void * Odd_p() const
Definition: gauge_field.h:435
double Tadpole() const
Definition: gauge_field.h:206
static __inline__ dim3 dim3 void size_t cudaStream_t int enum cudaTextureReadMode readMode static __inline__ const struct texture< T, dim, readMode > & tex
virtual void exchangeGhost(QudaLinkDirection=QUDA_LINK_BACKWARDS)=0
void createComms(const int *R, bool no_comms_fill)
Create the communication handlers and buffers.
QudaFieldCreate create
Definition: gauge_field.h:147
virtual const void * Even_p() const
Definition: gauge_field.h:251
virtual void zero()=0
QudaReconstructType reconstruct
Definition: gauge_field.h:14
virtual const void * Gauge_p() const
Definition: gauge_field.h:250
QudaFieldCreate create
Definition: gauge_field.h:25
QudaReconstructType Reconstruct() const
Definition: gauge_field.h:203
enum QudaFieldCreate_s QudaFieldCreate
enum QudaFieldGeometry_s QudaFieldGeometry
virtual void * Gauge_p()
Definition: gauge_field.h:246
QudaGaugeFieldOrder Order() const
Definition: gauge_field.h:204
#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:27
QudaTboundary TBoundary() const
Definition: gauge_field.h:208
QudaStaggeredPhase StaggeredPhase() const
Definition: gauge_field.h:213
QudaGaugeFieldOrder order
Definition: gauge_field.h:137
QudaGaugeFixed GaugeFixed() const
Definition: gauge_field.h:210
int Length() const
Definition: gauge_field.h:201
void copy(const GaugeField &src)
bool isNative() const
void * ghost[2 *QUDA_MAX_DIM]
Definition: gauge_field.h:149
#define a
QudaGaugeFixed fixed
Definition: gauge_field.h:138
GaugeFieldParam(void *h_gauge, const QudaGaugeParam &param, QudaLinkType link_type_=QUDA_INVALID_LINKS)
Definition: gauge_field.h:85
void ** Ghost()
Definition: gauge_field.h:259
void copyExtendedGauge(GaugeField &out, const GaugeField &in, QudaFieldLocation location, void *Out=0, void *In=0)
const void * Even_p() const
Definition: gauge_field.h:434
virtual void copy(const GaugeField &src)=0
size_t SiteOffset() const
Definition: gauge_field.h:268
int ghostFace[QUDA_MAX_DIM]
Definition: gauge_field.h:151
void removeStaggeredPhase()