QUDA  0.9.0
lattice_field.h
Go to the documentation of this file.
1 #ifndef _LATTICE_FIELD_H
2 #define _LATTICE_FIELD_H
3 
4 #include <quda.h>
5 #include <iostream>
6 #include <comm_quda.h>
7 #include <map>
8 
17 namespace quda {
18 
19  // LatticeField is an abstract base clase for all Field objects.
20 
21  // Forward declaration of all children
22  class LatticeField;
23 
24  class ColorSpinorField;
25  class cudaColorSpinorField;
26  class cpuColorSpinorField;
27 
28  class EigValueSet;
29  class cudaEigValueSet;
30  class cpuEigValueSet;
31 
32  class EigVecSet;
33  class cpuEigVecSet;
34  class cudaEigVecSet;
35 
36  class GaugeField;
37  class cpuGaugeField;
38  class cudaGaugeField;
39 
40  class CloverField;
41  class cudaCloverField;
42  class cpuCloverField;
43 
45 
47  int nDim;
48 
51 
52  int pad;
53 
56 
58 
61 
64 
71  {
72  for (int i=0; i<nDim; i++) {
73  x[i] = 0;
74  r[i] = 0;
75  }
76  }
77 
90  {
91  if (nDim > QUDA_MAX_DIM) errorQuda("Number of dimensions too great");
92  for (int i=0; i<nDim; i++) {
93  this->x[i] = x[i];
94  this->r[i] = 0;
95  }
96  }
97 
107  {
108  for (int i=0; i<nDim; i++) {
109  this->x[i] = param.X[i];
110  this->r[i] = 0;
111  }
112  }
113 
117  LatticeFieldParam(const LatticeField &field);
118  };
119 
120  std::ostream& operator<<(std::ostream& output, const LatticeFieldParam& param);
121 
122  class LatticeField : public Object {
123 
124  protected:
126  int volume;
127 
129  int volumeCB;
130 
131  int stride;
132  int pad;
133 
134  size_t total_bytes;
135 
137  int nDim;
138 
141 
144 
147 
150 
153 
156 
157  // The below are additions for inter-GPU communication (merging FaceBuffer functionality)
158 
161 
162  /*
163  The need for persistent message handlers (for GPUDirect support)
164  means that we allocate different message handlers for each number of
165  faces we can send.
166  */
167 
171  static void *ghost_send_buffer_d[2];
172 
176  static void *ghost_recv_buffer_d[2];
177 
181  static void *ghost_pinned_buffer_h[2];
182 
186  static void *ghost_pinned_buffer_hd[2];
187 
192 
196  static size_t ghostFaceBytes;
197 
201  static bool initGhostFaceBuffer;
202 
206  mutable size_t ghost_bytes;
207 
212 
216  mutable int ghostOffset[QUDA_MAX_DIM][2];
217 
221  mutable int ghostNormOffset[QUDA_MAX_DIM][2];
222 
224  void *my_face_h[2];
226  void *my_face_hd[2];
227 
230 
233 
236 
238  void *from_face_h[2];
240  void *from_face_hd[2];
241 
244 
247 
250 
253 
256 
259 
262 
265 
268 
271 
274 
277 
280 
283 
286 
289 
292 
295 
298 
300  static cudaEvent_t ipcCopyEvent[2][2][QUDA_MAX_DIM];
301 
303  static cudaEvent_t ipcRemoteCopyEvent[2][2][QUDA_MAX_DIM];
304 
306  bool initComms;
307 
309  static bool initIPCComms;
310 
313 
315  virtual void setTuningString();
316 
319 
320  mutable char *backup_h;
321  mutable char *backup_norm_h;
322  mutable bool backed_up;
323 
324  public:
325 
331 
337  LatticeField(const LatticeField &field);
338 
342  virtual ~LatticeField();
343 
348  void allocateGhostBuffer(size_t ghost_bytes) const;
349 
353  static void freeGhostBuffer(void);
354 
360  void createComms(bool no_comms_fill=false);
361 
365  void destroyComms();
366 
370  void createIPCComms();
371 
375  static void destroyIPCComms();
376 
380  inline bool ipcCopyComplete(int dir, int dim);
381 
385  inline bool ipcRemoteCopyComplete(int dir, int dim);
386 
390  const cudaEvent_t& getIPCCopyEvent(int dir, int dim) const;
391 
395  const cudaEvent_t& getIPCRemoteCopyEvent(int dir, int dim) const;
396 
400  static int bufferIndex;
401 
405  static bool ghost_field_reset;
406 
410  int Ndim() const { return nDim; }
411 
415  const int* X() const { return x; }
416 
420  int Volume() const { return volume; }
421 
425  int VolumeCB() const { return volumeCB; }
426 
431  const int* SurfaceCB() const { return surfaceCB; }
432 
437  int SurfaceCB(const int i) const { return surfaceCB[i]; }
438 
442  int Stride() const { return stride; }
443 
447  int Pad() const { return pad; }
448 
452  const int* R() const { return r; }
453 
458 
462  QudaPrecision Precision() const { return precision; }
463 
467  virtual QudaSiteSubset SiteSubset() const { return siteSubset; }
468 
472  virtual QudaMemoryType MemType() const { return mem_type; }
473 
478  int Nvec() const;
479 
483  QudaFieldLocation Location() const;
484 
488  size_t GBytes() const { return total_bytes / (1<<30); }
489 
494  void checkField(const LatticeField &a) const;
495 
500  virtual void read(char *filename);
501 
506  virtual void write(char *filename);
507 
508  virtual void gather(int nFace, int dagger, int dir, cudaStream_t *stream_p=NULL)
509  { errorQuda("Not implemented"); }
510 
511  virtual void commsStart(int nFace, int dir, int dagger=0, cudaStream_t *stream_p=NULL, bool gdr_send=false, bool gdr_recv=true)
512  { errorQuda("Not implemented"); }
513 
514  virtual int commsQuery(int nFace, int dir, int dagger=0, cudaStream_t *stream_p=NULL, bool gdr_send=false, bool gdr_recv=true)
515  { errorQuda("Not implemented"); return 0; }
516 
517  virtual void commsWait(int nFace, int dir, int dagger=0, cudaStream_t *stream_p=NULL, bool gdr_send=false, bool gdr_recv=true)
518  { errorQuda("Not implemented"); }
519 
520  virtual void scatter(int nFace, int dagger, int dir)
521  { errorQuda("Not implemented"); }
522 
524  inline const char *VolString() const { return vol_string; }
525 
527  virtual void backup() const { errorQuda("Not implemented"); }
528 
530  virtual void restore() { errorQuda("Not implemented"); }
531  };
532 
539  inline QudaFieldLocation Location_(const char *func, const char *file, int line,
540  const LatticeField &a, const LatticeField &b) {
542  if (a.Location() == b.Location()) location = a.Location();
543  else errorQuda("Locations %d %d do not match (%s:%d in %s())\n",
544  a.Location(), b.Location(), file, line, func);
545  return location;
546  }
547 
555  template <typename... Args>
556  inline QudaFieldLocation Location_(const char *func, const char *file, int line,
557  const LatticeField &a, const LatticeField &b, const Args &... args) {
558  return static_cast<QudaFieldLocation>(Location_(func,file,line,a,b) & Location_(func,file,line,a,args...));
559  }
560 
561 #define checkLocation(...)Location_(__func__, __FILE__, __LINE__, __VA_ARGS__)
562 
569  inline QudaPrecision Precision_(const char *func, const char *file, int line,
570  const LatticeField &a, const LatticeField &b) {
572  if (a.Precision() == b.Precision()) precision = a.Precision();
573  else errorQuda("Precisions %d %d do not match (%s:%d in %s())\n",
574  a.Precision(), b.Precision(), file, line, func);
575  return precision;
576  }
577 
585  template <typename... Args>
586  inline QudaPrecision Precision_(const char *func, const char *file, int line,
587  const LatticeField &a, const LatticeField &b,
588  const Args &... args) {
589  return static_cast<QudaPrecision>(Precision_(func,file,line,a,b) & Precision_(func,file,line,a,args...));
590  }
591 
592 #define checkPrecision(...) Precision_(__func__, __FILE__, __LINE__, __VA_ARGS__)
593 
601 
609 
610 } // namespace quda
611 
612 #endif // _LATTICE_FIELD_H
static int buffer_recv_p2p_back[2][QUDA_MAX_DIM]
QudaPrecision Precision_(const char *func, const char *file, int line, const LatticeField &a, const LatticeField &b)
Helper function for determining if the precision of the fields is the same.
bool ipcRemoteCopyComplete(int dir, int dim)
QudaFieldLocation reorder_location()
Return whether data is reordered on the CPU or GPU. This can set at QUDA initialization using the env...
QudaGhostExchange ghostExchange
Definition: lattice_field.h:60
virtual void read(char *filename)
void allocateGhostBuffer(size_t ghost_bytes) const
Allocate the static ghost buffers.
int ghostNormOffset[QUDA_MAX_DIM][2]
enum QudaPrecision_s QudaPrecision
void * my_face_dim_dir_d[2][QUDA_MAX_DIM][2]
void createComms(bool no_comms_fill=false)
const void * func
virtual void commsWait(int nFace, int dir, int dagger=0, cudaStream_t *stream_p=NULL, bool gdr_send=false, bool gdr_recv=true)
static void * ghost_pinned_buffer_hd[2]
int Stride() const
#define errorQuda(...)
Definition: util_quda.h:90
QudaSiteSubset siteSubset
virtual int commsQuery(int nFace, int dir, int dagger=0, cudaStream_t *stream_p=NULL, bool gdr_send=false, bool gdr_recv=true)
static __inline__ dim3 dim3 void size_t cudaStream_t int dim
int SurfaceCB(const int i) const
const char * VolString() const
int x[QUDA_MAX_DIM]
virtual void restore()
Restores the cpuGaugeField.
QudaPrecision precision
Definition: lattice_field.h:54
static MsgHandle * mh_send_p2p_back[2][QUDA_MAX_DIM]
const int * SurfaceCB() const
void * from_face_dim_dir_hd[2][QUDA_MAX_DIM][2]
LatticeFieldParam(const QudaGaugeParam &param)
Constructor for creating a LatticeFieldParam from a QudaGaugeParam. Used for wrapping around a CPU re...
virtual void setTuningString()
MsgHandle * mh_send_rdma_fwd[2][QUDA_MAX_DIM]
bool ipcCopyComplete(int dir, int dim)
static bool initGhostFaceBuffer
QudaSiteSubset siteSubset
Definition: lattice_field.h:55
std::ostream & operator<<(std::ostream &output, const CloverFieldParam &param)
QudaPrecision cpu_prec
Definition: covdev_test.cpp:33
static int buffer_recv_p2p_fwd[2][QUDA_MAX_DIM]
QudaGaugeParam param
Definition: pack_test.cpp:17
#define b
virtual QudaMemoryType MemType() const
void * my_face_dim_dir_hd[2][QUDA_MAX_DIM][2]
static void * ghost_pinned_buffer_h[2]
int x[QUDA_MAX_DIM]
Definition: lattice_field.h:50
const int * R() const
MsgHandle * mh_send_rdma_back[2][QUDA_MAX_DIM]
static MsgHandle * mh_recv_p2p_fwd[2][QUDA_MAX_DIM]
const cudaEvent_t & getIPCCopyEvent(int dir, int dim) const
static bool ghost_field_reset
static int bufferIndex
void * from_face_hd[2]
void checkField(const LatticeField &a) const
MsgHandle * mh_recv_back[2][QUDA_MAX_DIM]
enum QudaGhostExchange_s QudaGhostExchange
MsgHandle * mh_recv_rdma_fwd[2][QUDA_MAX_DIM]
QudaGhostExchange ghostExchange
static void * ghost_remote_send_buffer_d[2][QUDA_MAX_DIM][2]
int Volume() const
const cudaEvent_t & getIPCRemoteCopyEvent(int dir, int dim) const
virtual void backup() const
Backs up the LatticeField.
char vol_string[TuneKey::volume_n]
virtual void write(char *filename)
void * from_face_dim_dir_d[2][QUDA_MAX_DIM][2]
int X[4]
Definition: quda.h:29
size_t ghost_face_bytes[QUDA_MAX_DIM]
static void destroyIPCComms()
MsgHandle * mh_send_fwd[2][QUDA_MAX_DIM]
dim3 dim3 void ** args
static int buffer_send_p2p_fwd[2][QUDA_MAX_DIM]
enum QudaSiteSubset_s QudaSiteSubset
QudaFieldLocation Location() const
static QudaFieldLocation reorder_location_
static int buffer_send_p2p_back[2][QUDA_MAX_DIM]
static size_t ghostFaceBytes
static void * ghost_send_buffer_d[2]
int surface[QUDA_MAX_DIM]
enum QudaFieldLocation_s QudaFieldLocation
int ghostOffset[QUDA_MAX_DIM][2]
void * from_face_dim_dir_h[2][QUDA_MAX_DIM][2]
virtual void scatter(int nFace, int dagger, int dir)
Main header file for the QUDA library.
int r[QUDA_MAX_DIM]
static MsgHandle * mh_send_p2p_fwd[2][QUDA_MAX_DIM]
static void * ghost_recv_buffer_d[2]
virtual QudaSiteSubset SiteSubset() const
MsgHandle * mh_recv_rdma_back[2][QUDA_MAX_DIM]
QudaMemoryType mem_type
Definition: lattice_field.h:57
static cudaEvent_t ipcCopyEvent[2][2][QUDA_MAX_DIM]
int VolumeCB() const
LatticeFieldParam()
Default constructor for LatticeFieldParam.
Definition: lattice_field.h:68
int surfaceCB[QUDA_MAX_DIM]
static cudaEvent_t ipcRemoteCopyEvent[2][2][QUDA_MAX_DIM]
#define QUDA_MAX_DIM
Maximum number of dimensions supported by QUDA. In practice, no routines make use of more than 5...
MsgHandle * mh_recv_fwd[2][QUDA_MAX_DIM]
static MsgHandle * mh_recv_p2p_back[2][QUDA_MAX_DIM]
QudaGhostExchange GhostExchange() const
virtual void commsStart(int nFace, int dir, int dagger=0, cudaStream_t *stream_p=NULL, bool gdr_send=false, bool gdr_recv=true)
static const int volume_n
Definition: tune_key.h:10
LatticeFieldParam(int nDim, const int *x, int pad, QudaPrecision precision, QudaGhostExchange ghostExchange=QUDA_GHOST_EXCHANGE_PAD)
Constructor for creating a LatticeFieldParam from a set of parameters.
Definition: lattice_field.h:86
QudaPrecision Precision() const
void * my_face_dim_dir_h[2][QUDA_MAX_DIM][2]
int r[QUDA_MAX_DIM]
Definition: lattice_field.h:63
void reorder_location_set(QudaFieldLocation reorder_location_)
Set whether data is reorderd on the CPU or GPU. This can set at QUDA initialization using the environ...
static void freeGhostBuffer(void)
Free statically allocated ghost buffers.
QudaMemoryType mem_type
QudaPrecision precision
LatticeField(const LatticeFieldParam &param)
QudaFieldLocation Location_(const char *func, const char *file, int line, const LatticeField &a, const LatticeField &b)
Helper function for determining if the location of the fields is the same.
virtual void gather(int nFace, int dagger, int dir, cudaStream_t *stream_p=NULL)
MsgHandle * mh_send_back[2][QUDA_MAX_DIM]
#define a
enum QudaMemoryType_s QudaMemoryType
static bool initIPCComms
size_t GBytes() const
const int * X() const