QUDA  v0.7.0
A library for QCD on GPUs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
40 extern bool tune;
41 
43 
44 // where is the packing / unpacking taking place
45 //most orders are CPU only currently
47 
48 void init() {
49 
55 
56  param.X[0] = xdim;
57  param.X[1] = ydim;
58  param.X[2] = zdim;
59  param.X[3] = tdim;
60 #ifdef MULTI_GPU
62 #else
63  param.ga_pad = 0;
64 #endif
65  setDims(param.X);
66 
67  param.anisotropy = 2.3;
70 
71  // construct input fields
72  for (int dir = 0; dir < 4; dir++) {
74  }
76 
77  csParam.nColor = 3;
78  csParam.nSpin = 4;
79  csParam.nDim = 4;
80  for (int d=0; d<4; d++) csParam.x[d] = param.X[d];
82  csParam.pad = 0;
88 
91 
93 
95 
96  setVerbosityQuda(QUDA_VERBOSE, "", stdout);
98 
101  csParam.pad = param.X[0] * param.X[1] * param.X[2];
102 
104 }
105 
106 void end() {
107  // release memory
108  delete cudaSpinor;
109  delete spinor2;
110  delete spinor;
111 
112  for (int dir = 0; dir < 4; dir++) free(qdpCpuGauge_p[dir]);
113  free(cpsCpuGauge_p);
114  endQuda();
115 }
116 
117 void packTest() {
118 
119  float spinorGiB = (float)Vh*spinorSiteSize*param.cuda_prec / (1 << 30);
120  printf("\nSpinor mem: %.3f GiB\n", spinorGiB);
121  printf("Gauge mem: %.3f GiB\n", param.gaugeGiB);
122 
123  printf("Sending fields to GPU...\n"); fflush(stdout);
124 
125 #ifdef BUILD_CPS_INTERFACE
126  {
128 
130  cpuGaugeField cpsCpuGauge(cpsParam);
131  cpsParam.create = QUDA_NULL_FIELD_CREATE;
132  cpsParam.precision = param.cuda_prec;
133  cpsParam.reconstruct = param.reconstruct;
134  cpsParam.pad = param.ga_pad;
135  cpsParam.order = (cpsParam.precision == QUDA_DOUBLE_PRECISION ||
136  cpsParam.reconstruct == QUDA_RECONSTRUCT_NO ) ?
138  cudaGaugeField cudaCpsGauge(cpsParam);
139 
140  stopwatchStart();
141  cudaCpsGauge.loadCPUField(cpsCpuGauge, location);
142  double cpsGtime = stopwatchReadSeconds();
143  printf("CPS Gauge send time = %e seconds\n", cpsGtime);
144 
145  stopwatchStart();
146  cudaCpsGauge.saveCPUField(cpsCpuGauge, location);
147  double cpsGRtime = stopwatchReadSeconds();
148  printf("CPS Gauge restore time = %e seconds\n", cpsGRtime);
149  }
150 #endif
151 
152 #ifdef BUILD_QDP_INTERFACE
153  {
155 
157  cpuGaugeField qdpCpuGauge(qdpParam);
158  qdpParam.create = QUDA_NULL_FIELD_CREATE;
159  qdpParam.precision = param.cuda_prec;
160  qdpParam.reconstruct = param.reconstruct;
161  qdpParam.pad = param.ga_pad;
162  qdpParam.order = (qdpParam.precision == QUDA_DOUBLE_PRECISION ||
163  qdpParam.reconstruct == QUDA_RECONSTRUCT_NO ) ?
165  cudaGaugeField cudaQdpGauge(qdpParam);
166 
167  stopwatchStart();
168  cudaQdpGauge.loadCPUField(qdpCpuGauge, location);
169  double qdpGtime = stopwatchReadSeconds();
170  printf("QDP Gauge send time = %e seconds\n", qdpGtime);
171 
172  stopwatchStart();
173  cudaQdpGauge.saveCPUField(qdpCpuGauge, location);
174  double qdpGRtime = stopwatchReadSeconds();
175  printf("QDP Gauge restore time = %e seconds\n", qdpGRtime);
176  }
177 #endif
178 
179  stopwatchStart();
180 
181  *cudaSpinor = *spinor;
182  double sSendTime = stopwatchReadSeconds();
183  printf("Spinor send time = %e seconds\n", sSendTime); fflush(stdout);
184 
185  stopwatchStart();
186  *spinor2 = *cudaSpinor;
187  double sRecTime = stopwatchReadSeconds();
188  printf("Spinor receive time = %e seconds\n", sRecTime); fflush(stdout);
189 
190  double spinor_norm = norm2(*spinor);
191  double cuda_spinor_norm = norm2(*cudaSpinor);
192  double spinor2_norm = norm2(*spinor2);
193 
194  printf("Norm check: CPU = %e, CUDA = %e, CPU = %e\n",
195  spinor_norm, cuda_spinor_norm, spinor2_norm);
196 
198 
199 }
200 
201 extern void usage(char**);
202 
203 int main(int argc, char **argv) {
204  for (int i=1; i<argc; i++){
205  if(process_command_line_option(argc, argv, &i) == 0){
206  continue;
207  }
208 
209  fprintf(stderr, "ERROR: Invalid option:%s\n", argv[i]);
210  usage(argv);
211  }
212 
213  initComms(argc, argv, gridsize_from_cmdline);
214 
215  init();
216  packTest();
217  end();
218 
219  finalizeComms();
220 }
221 
cpuColorSpinorField * spinor
Definition: pack_test.cpp:22
void setPrecision(QudaPrecision precision)
QudaReconstructType reconstruct_sloppy
Definition: quda.h:46
double anisotropy
Definition: quda.h:31
__constant__ int Vh
void setVerbosityQuda(QudaVerbosity verbosity, const char prefix[], FILE *outfile)
void endQuda(void)
enum QudaPrecision_s QudaPrecision
int V
Definition: test_util.cpp:29
int ga_pad
Definition: quda.h:53
QudaGaugeFixed gauge_fix
Definition: quda.h:51
cpuColorSpinorField * spinor2
Definition: pack_test.cpp:22
void saveCPUField(cpuGaugeField &, const QudaFieldLocation &) const
void setDims(int *)
Definition: test_util.cpp:88
int process_command_line_option(int argc, char **argv, int *idx)
Definition: test_util.cpp:1635
void Source(const QudaSourceType sourceType, const int st=0, const int s=0, const int c=0)
QudaPrecision precision
Definition: lattice_field.h:41
#define gaugeSiteSize
void finalizeComms()
Definition: test_util.cpp:65
QudaGaugeFieldOrder gauge_order
Definition: quda.h:36
void stopwatchStart()
Definition: test_util.cpp:2055
#define spinorSiteSize
QudaSiteSubset siteSubset
Definition: lattice_field.h:42
float kappa
Definition: pack_test.cpp:26
QudaGaugeParam param
Definition: pack_test.cpp:17
int x[QUDA_MAX_DIM]
Definition: lattice_field.h:38
double stopwatchReadSeconds()
Definition: test_util.cpp:2059
void setTuning(QudaTune tune)
Definition: util_quda.cpp:33
void initQuda(int device)
const QudaFieldLocation location
Definition: pack_test.cpp:46
int tdim
Definition: test_util.cpp:1556
cudaColorSpinorField * cudaSpinor
Definition: pack_test.cpp:18
void packTest()
Definition: pack_test.cpp:117
int ODD_BIT
Definition: pack_test.cpp:27
ColorSpinorParam csParam
Definition: pack_test.cpp:24
int DAGGER_BIT
Definition: pack_test.cpp:28
QudaGaugeFieldOrder order
Definition: gauge_field.h:15
bool tune
Definition: test_util.cpp:1562
QudaPrecision prec
Definition: test_util.cpp:1551
QudaPrecision cuda_prec_sloppy
Definition: quda.h:45
void loadCPUField(const cpuGaugeField &, const QudaFieldLocation &)
QudaPrecision prec_cpu
Definition: pack_test.cpp:42
char latfile[]
Definition: test_util.cpp:1561
int ydim
Definition: test_util.cpp:1554
QudaReconstructType link_recon
Definition: test_util.cpp:1549
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:106
static int Compare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, const int resolution=1)
int zdim
Definition: test_util.cpp:1555
void usage(char **)
Definition: test_util.cpp:1584
enum QudaFieldLocation_s QudaFieldLocation
double gaugeGiB
Definition: quda.h:60
enum QudaReconstructType_s QudaReconstructType
void init()
Definition: pack_test.cpp:48
int device
Definition: test_util.cpp:1546
QudaTboundary t_boundary
Definition: quda.h:38
int main(int argc, char **argv)
Definition: pack_test.cpp:203
QudaReconstructType reconstruct
Definition: gauge_field.h:14
QudaFieldCreate create
Definition: gauge_field.h:26
int xdim
Definition: test_util.cpp:1553
int gridsize_from_cmdline[]
Definition: test_util.cpp:1559
double norm2(const ColorSpinorField &)
void initComms(int argc, char **argv, const int *commDims)
Definition: test_util.cpp:48
void * cpsCpuGauge_p
Definition: pack_test.cpp:21
QudaPrecision cpu_prec
Definition: quda.h:40
void * qdpCpuGauge_p[4]
Definition: pack_test.cpp:20