QUDA  0.9.0
pack_test.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <iostream>
4 
5 #include <quda_internal.h>
6 #include <gauge_field.h>
7 #include <util_quda.h>
8 
9 #include <test_util.h>
10 #include <dslash_util.h>
11 
12 #include <color_spinor_field.h>
13 #include <blas_quda.h>
14 
15 using namespace quda;
16 
19 
20 void *qdpCpuGauge_p[4];
23 
25 
26 float kappa = 1.0;
27 int ODD_BIT = 0;
28 int DAGGER_BIT = 0;
29 
30 extern int device;
31 extern int xdim;
32 extern int ydim;
33 extern int zdim;
34 extern int tdim;
36 extern QudaPrecision prec;
37 extern char latfile[];
38 extern int gridsize_from_cmdline[];
39 
41 
42 void init() {
43 
49 
50  param.X[0] = xdim;
51  param.X[1] = ydim;
52  param.X[2] = zdim;
53  param.X[3] = tdim;
54 #ifdef MULTI_GPU
56 #else
57  param.ga_pad = 0;
58 #endif
59  setDims(param.X);
60 
61  param.anisotropy = 2.3;
64 
65  // construct input fields
66  for (int dir = 0; dir < 4; dir++) {
68  }
70 
71  csParam.nColor = 3;
72  csParam.nSpin = 4;
73  csParam.nDim = 4;
74  for (int d=0; d<4; d++) csParam.x[d] = param.X[d];
76  csParam.pad = 0;
82 
85 
87 
89 
90  setVerbosityQuda(QUDA_VERBOSE, "", stdout);
91 
96  csParam.pad = param.X[0] * param.X[1] * param.X[2];
97 
99 }
100 
101 void end() {
102  // release memory
103  delete cudaSpinor;
104  delete spinor2;
105  delete spinor;
106 
107  for (int dir = 0; dir < 4; dir++) free(qdpCpuGauge_p[dir]);
109  endQuda();
110 }
111 
112 void packTest() {
113 
114  float spinorGiB = (float)Vh*spinorSiteSize*param.cuda_prec / (1 << 30);
115  printf("\nSpinor mem: %.3f GiB\n", spinorGiB);
116  printf("Gauge mem: %.3f GiB\n", param.gaugeGiB);
117 
118  printf("Sending fields to GPU...\n"); fflush(stdout);
119 
120 #ifdef BUILD_CPS_INTERFACE
121  {
123 
125  cpuGaugeField cpsCpuGauge(cpsParam);
126  cpsParam.create = QUDA_NULL_FIELD_CREATE;
127  cpsParam.precision = param.cuda_prec;
128  cpsParam.reconstruct = param.reconstruct;
129  cpsParam.pad = param.ga_pad;
130  cpsParam.order = (cpsParam.precision == QUDA_DOUBLE_PRECISION ||
131  cpsParam.reconstruct == QUDA_RECONSTRUCT_NO ) ?
133  cudaGaugeField cudaCpsGauge(cpsParam);
134 
135  stopwatchStart();
136  cudaCpsGauge.loadCPUField(cpsCpuGauge);
137  double cpsGtime = stopwatchReadSeconds();
138  printf("CPS Gauge send time = %e seconds\n", cpsGtime);
139 
140  stopwatchStart();
141  cudaCpsGauge.saveCPUField(cpsCpuGauge);
142  double cpsGRtime = stopwatchReadSeconds();
143  printf("CPS Gauge restore time = %e seconds\n", cpsGRtime);
144  }
145 #endif
146 
147 #ifdef BUILD_QDP_INTERFACE
148  {
150 
152  cpuGaugeField qdpCpuGauge(qdpParam);
153  qdpParam.create = QUDA_NULL_FIELD_CREATE;
154  qdpParam.precision = param.cuda_prec;
155  qdpParam.reconstruct = param.reconstruct;
156  qdpParam.pad = param.ga_pad;
157  qdpParam.order = (qdpParam.precision == QUDA_DOUBLE_PRECISION ||
158  qdpParam.reconstruct == QUDA_RECONSTRUCT_NO ) ?
160  cudaGaugeField cudaQdpGauge(qdpParam);
161 
162  stopwatchStart();
163  cudaQdpGauge.loadCPUField(qdpCpuGauge);
164  double qdpGtime = stopwatchReadSeconds();
165  printf("QDP Gauge send time = %e seconds\n", qdpGtime);
166 
167  stopwatchStart();
168  cudaQdpGauge.saveCPUField(qdpCpuGauge);
169  double qdpGRtime = stopwatchReadSeconds();
170  printf("QDP Gauge restore time = %e seconds\n", qdpGRtime);
171  }
172 #endif
173 
174  stopwatchStart();
175 
176  *cudaSpinor = *spinor;
177  double sSendTime = stopwatchReadSeconds();
178  printf("Spinor send time = %e seconds\n", sSendTime); fflush(stdout);
179 
180  stopwatchStart();
181  *spinor2 = *cudaSpinor;
182  double sRecTime = stopwatchReadSeconds();
183  printf("Spinor receive time = %e seconds\n", sRecTime); fflush(stdout);
184 
185  double spinor_norm = blas::norm2(*spinor);
186  double cuda_spinor_norm = blas::norm2(*cudaSpinor);
187  double spinor2_norm = blas::norm2(*spinor2);
188 
189  printf("Norm check: CPU = %e, CUDA = %e, CPU = %e\n",
190  spinor_norm, cuda_spinor_norm, spinor2_norm);
191 
193 
194 }
195 
196 extern void usage(char**);
197 
198 int main(int argc, char **argv) {
199  for (int i=1; i<argc; i++){
200  if(process_command_line_option(argc, argv, &i) == 0){
201  continue;
202  }
203 
204  fprintf(stderr, "ERROR: Invalid option:%s\n", argv[i]);
205  usage(argv);
206  }
207 
208  initComms(argc, argv, gridsize_from_cmdline);
209 
210  init();
211  packTest();
212  end();
213 
214  finalizeComms();
215 }
216 
cpuColorSpinorField * spinor
Definition: pack_test.cpp:22
void setPrecision(QudaPrecision precision)
QudaReconstructType reconstruct_sloppy
Definition: quda.h:46
double anisotropy
Definition: quda.h:31
void setVerbosityQuda(QudaVerbosity verbosity, const char prefix[], FILE *outfile)
void endQuda(void)
void free(void *)
enum QudaPrecision_s QudaPrecision
int ga_pad
Definition: quda.h:53
void saveCPUField(cpuGaugeField &cpu) const
Upload from this field into a CPU field.
QudaGaugeFixed gauge_fix
Definition: quda.h:51
int fflush(FILE *)
cpuColorSpinorField * spinor2
Definition: pack_test.cpp:22
double norm2(const ColorSpinorField &a)
Definition: reduce_quda.cu:241
int process_command_line_option(int argc, char **argv, int *idx)
Definition: test_util.cpp:1795
void Source(const QudaSourceType sourceType, const int st=0, const int s=0, const int c=0)
QudaPrecision precision
Definition: lattice_field.h:54
void finalizeComms()
Definition: test_util.cpp:107
QudaGaugeFieldOrder gauge_order
Definition: quda.h:36
void stopwatchStart()
Definition: test_util.cpp:2869
#define spinorSiteSize
QudaSiteSubset siteSubset
Definition: lattice_field.h:55
void setDims(int *)
Definition: test_util.cpp:130
float kappa
Definition: pack_test.cpp:26
QudaGaugeParam param
Definition: pack_test.cpp:17
int x[QUDA_MAX_DIM]
Definition: lattice_field.h:50
double stopwatchReadSeconds()
Definition: test_util.cpp:2873
void loadCPUField(const cpuGaugeField &cpu)
Download into this field from a CPU field.
void initQuda(int device)
void * malloc(size_t __size) __attribute__((__warn_unused_result__)) __attribute__((alloc_size(1)))
int printf(const char *,...) __attribute__((__format__(__printf__
int tdim
Definition: test_util.cpp:1623
cudaColorSpinorField * cudaSpinor
Definition: pack_test.cpp:18
void packTest()
Definition: pack_test.cpp:112
int ODD_BIT
Definition: pack_test.cpp:27
ColorSpinorParam csParam
Definition: pack_test.cpp:24
int V
Definition: test_util.cpp:28
int DAGGER_BIT
Definition: pack_test.cpp:28
#define gaugeSiteSize
Definition: test_util.h:6
QudaGaugeFieldOrder order
Definition: gauge_field.h:15
QudaPrecision prec
Definition: test_util.cpp:1615
QudaPrecision cuda_prec_sloppy
Definition: quda.h:45
QudaPrecision prec_cpu
Definition: pack_test.cpp:40
char latfile[]
Definition: test_util.cpp:1627
int ydim
Definition: test_util.cpp:1621
QudaReconstructType link_recon
Definition: test_util.cpp:1612
QudaReconstructType reconstruct
Definition: quda.h:43
QudaPrecision cuda_prec
Definition: quda.h:42
int X[4]
Definition: quda.h:29
void end()
Definition: pack_test.cpp:101
int fprintf(FILE *, const char *,...) __attribute__((__format__(__printf__
static int Compare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, const int resolution=1)
int zdim
Definition: test_util.cpp:1622
void usage(char **)
Definition: test_util.cpp:1693
double gaugeGiB
Definition: quda.h:60
enum QudaReconstructType_s QudaReconstructType
void init()
Definition: pack_test.cpp:42
QudaTboundary t_boundary
Definition: quda.h:38
int Vh
Definition: test_util.cpp:29
int main(int argc, char **argv)
Definition: pack_test.cpp:198
QudaReconstructType reconstruct
Definition: gauge_field.h:14
QudaFieldCreate create
Definition: gauge_field.h:25
int xdim
Definition: test_util.cpp:1620
int gridsize_from_cmdline[]
Definition: test_util.cpp:50
static __inline__ size_t size_t d
void initComms(int argc, char **argv, const int *commDims)
Definition: test_util.cpp:72
void * cpsCpuGauge_p
Definition: pack_test.cpp:21
QudaPrecision cpu_prec
Definition: quda.h:40
void * qdpCpuGauge_p[4]
Definition: pack_test.cpp:20