QUDA v0.4.0
A library for QCD on GPUs
quda/include/gauge_field.h
Go to the documentation of this file.
00001 #ifndef _GAUGE_QUDA_H
00002 #define _GAUGE_QUDA_H
00003 
00004 #include <quda_internal.h>
00005 #include <quda.h>
00006 #include <lattice_field.h>
00007 
00008 struct GaugeFieldParam : public LatticeFieldParam {
00009   int nColor;
00010   int nFace;
00011 
00012   QudaReconstructType reconstruct;
00013   QudaGaugeFieldOrder order;
00014   QudaGaugeFixed fixed;
00015   QudaLinkType link_type;
00016   QudaTboundary t_boundary;
00017 
00018   double anisotropy;
00019   double tadpole;
00020 
00021   void *gauge; // used when we use a reference to an external field
00022 
00023   QudaFieldCreate create; // used to determine the type of field created
00024 
00025   int is_staple; //set to 1 for staple, used in fatlink computation
00026   int pinned; //used in cpu field only, where the host memory is pinned
00027 
00028   // Default constructor
00029   GaugeFieldParam(void* const h_gauge=NULL) : LatticeFieldParam(),
00030         nColor(3),
00031         nFace(0),
00032         reconstruct(QUDA_RECONSTRUCT_NO),
00033         order(QUDA_INVALID_GAUGE_ORDER),
00034         fixed(QUDA_GAUGE_FIXED_NO),
00035         link_type(QUDA_WILSON_LINKS),
00036         t_boundary(QUDA_INVALID_T_BOUNDARY),
00037         anisotropy(1.0),
00038         tadpole(1.0),
00039         gauge(h_gauge),
00040         create(QUDA_REFERENCE_FIELD_CREATE), 
00041         is_staple(0), 
00042         pinned(0)
00043         {
00044           // variables declared in LatticeFieldParam
00045           precision = QUDA_INVALID_PRECISION;
00046           verbosity = QUDA_SILENT;
00047           nDim = 4;
00048           pad  = 0;
00049           for(int dir=0; dir<nDim; ++dir) x[dir] = 0;
00050         }
00051         
00052   
00053   
00054  GaugeFieldParam(void *h_gauge, const QudaGaugeParam &param) : LatticeFieldParam(param),
00055     nColor(3), nFace(0), reconstruct(QUDA_RECONSTRUCT_NO),
00056     order(param.gauge_order), fixed(param.gauge_fix), link_type(param.type), 
00057     t_boundary(param.t_boundary), anisotropy(param.anisotropy), tadpole(param.tadpole_coeff),
00058     gauge(h_gauge), create(QUDA_REFERENCE_FIELD_CREATE), is_staple(0), pinned(0) {
00059 
00060     if (link_type == QUDA_WILSON_LINKS || link_type == QUDA_ASQTAD_FAT_LINKS) nFace = 1;
00061     else if (link_type == QUDA_ASQTAD_LONG_LINKS) nFace = 3;
00062     else errorQuda("Error: invalid link type(%d)\n", link_type);
00063   }
00064 };
00065 
00066 std::ostream& operator<<(std::ostream& output, const GaugeFieldParam& param);
00067 
00068 class GaugeField : public LatticeField {
00069 
00070  protected:
00071   size_t bytes; // bytes allocated per clover full field 
00072   int length;
00073   int real_length;
00074   int nColor;
00075   int nFace;
00076 
00077   QudaReconstructType reconstruct;
00078   QudaGaugeFieldOrder order;
00079   QudaGaugeFixed fixed;
00080   QudaLinkType link_type;
00081   QudaTboundary t_boundary;
00082 
00083   double anisotropy;
00084   double tadpole;
00085 
00086   QudaFieldCreate create; // used to determine the type of field created
00087   int is_staple; //set to 1 for staple, used in fatlink computation
00088   
00089  public:
00090   GaugeField(const GaugeFieldParam &param, const QudaFieldLocation &location);
00091   virtual ~GaugeField();
00092 
00093   int Ncolor() const { return nColor; }
00094   QudaReconstructType Reconstruct() const { return reconstruct; }
00095   QudaGaugeFieldOrder Order() const { return order; }
00096   double Anisotropy() const { return anisotropy; }
00097   double Tadpole() const { return tadpole; }
00098   QudaTboundary TBoundary() const { return t_boundary; }
00099   QudaLinkType LinkType() const { return link_type; }
00100   QudaGaugeFixed GaugeFixed() const { return fixed; }
00101 
00102   void checkField(const GaugeField &);
00103 
00104   const size_t& Bytes() const { return bytes; }
00105 
00106 };
00107 
00108 class cudaGaugeField : public GaugeField {
00109 
00110   friend void bindGaugeTex(const cudaGaugeField &gauge, const int oddBit, 
00111                            void **gauge0, void **gauge1);
00112   friend void unbindGaugeTex(const cudaGaugeField &gauge);
00113   friend void bindFatGaugeTex(const cudaGaugeField &gauge, const int oddBit, 
00114                               void **gauge0, void **gauge1);
00115   friend void unbindFatGaugeTex(const cudaGaugeField &gauge);
00116   friend void bindLongGaugeTex(const cudaGaugeField &gauge, const int oddBit, 
00117                                void **gauge0, void **gauge1);
00118   friend void unbindLongGaugeTex(const cudaGaugeField &gauge);
00119 
00120  private:
00121   void *gauge;
00122   void *even;
00123   void *odd;
00124 
00125   double fat_link_max;
00126   
00127  public:
00128   cudaGaugeField(const GaugeFieldParam &);
00129   virtual ~cudaGaugeField();
00130 
00131   void loadCPUField(const cpuGaugeField &, const QudaFieldLocation &);
00132   void saveCPUField(cpuGaugeField &, const QudaFieldLocation &) const;
00133 
00134   double LinkMax() const { return fat_link_max; }
00135 
00136   // (ab)use with care
00137   void* Gauge_p() { return gauge; }
00138   void* Even_p() { return even; }
00139   void* Odd_p() { return odd; }
00140 
00141   const void* Gauge_p() const { return gauge; }
00142   const void* Even_p() const { return even; }
00143   const void* Odd_p() const { return odd; }     
00144 
00145 };
00146 
00147 class cpuGaugeField : public GaugeField {
00148 
00149   friend void cudaGaugeField::loadCPUField(const cpuGaugeField &cpu, const QudaFieldLocation &);
00150   friend void cudaGaugeField::saveCPUField(cpuGaugeField &cpu, const QudaFieldLocation &) const;
00151 
00152  private:
00153   void **gauge; // the actual gauge field
00154 
00155   mutable void **ghost; // stores the ghost zone of the gauge field
00156   int pinned;
00157   
00158  public:
00159   cpuGaugeField(const GaugeFieldParam &);
00160   virtual ~cpuGaugeField();
00161 
00162   void exchangeGhost() const;
00163   const void** Ghost() const { return (const void**)ghost; }
00164 
00165   void* Gauge_p() { return gauge; }
00166   void setGauge(void** _gauge); //only allowed when create== QUDA_REFERENCE_FIELD_CREATE
00167 };
00168 
00169 #define gaugeSiteSize 18 // real numbers per gauge field
00170   
00171 #endif // _GAUGE_QUDA_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines