QUDA  v0.5.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 
41 
42 // where is the packing / unpacking taking place
43 //most orders are CPU only currently
45 
46 void init() {
47 
53 
54  param.X[0] = xdim;
55  param.X[1] = ydim;
56  param.X[2] = zdim;
57  param.X[3] = tdim;
58 #ifdef MULTI_GPU
60 #else
61  param.ga_pad = 0;
62 #endif
63  setDims(param.X);
64 
65  param.anisotropy = 2.3;
68 
69  // construct input fields
70  for (int dir = 0; dir < 4; dir++) {
72  }
74 
75  csParam.nColor = 3;
76  csParam.nSpin = 4;
77  csParam.nDim = 4;
78  for (int d=0; d<4; d++) csParam.x[d] = param.X[d];
80  csParam.pad = 0;
86 
89 
91 
93 
97  csParam.pad = param.X[0] * param.X[1] * param.X[2];
98 
100 }
101 
102 void end() {
103  // release memory
104  delete cudaSpinor;
105  delete spinor2;
106  delete spinor;
107 
108  for (int dir = 0; dir < 4; dir++) free(qdpCpuGauge_p[dir]);
109  free(cpsCpuGauge_p);
110  endQuda();
111 }
112 
113 void packTest() {
114 
115  float spinorGiB = (float)Vh*spinorSiteSize*param.cuda_prec / (1 << 30);
116  printf("\nSpinor mem: %.3f GiB\n", spinorGiB);
117  printf("Gauge mem: %.3f GiB\n", param.gaugeGiB);
118 
119  printf("Sending fields to GPU...\n"); fflush(stdout);
120 
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, location);
137  double cpsGtime = stopwatchReadSeconds();
138  printf("CPS Gauge send time = %e seconds\n", cpsGtime);
139 
140  stopwatchStart();
141  cudaCpsGauge.saveCPUField(cpsCpuGauge, location);
142  double cpsGRtime = stopwatchReadSeconds();
143  printf("CPS Gauge restore time = %e seconds\n", cpsGRtime);
144  }
145 
146  {
148 
150  cpuGaugeField qdpCpuGauge(qdpParam);
151  qdpParam.create = QUDA_NULL_FIELD_CREATE;
152  qdpParam.precision = param.cuda_prec;
153  qdpParam.reconstruct = param.reconstruct;
154  qdpParam.pad = param.ga_pad;
155  qdpParam.order = (qdpParam.precision == QUDA_DOUBLE_PRECISION ||
156  qdpParam.reconstruct == QUDA_RECONSTRUCT_NO ) ?
158  cudaGaugeField cudaQdpGauge(qdpParam);
159 
160  stopwatchStart();
161  cudaQdpGauge.loadCPUField(qdpCpuGauge, location);
162  double qdpGtime = stopwatchReadSeconds();
163  printf("QDP Gauge send time = %e seconds\n", qdpGtime);
164 
165  stopwatchStart();
166  cudaQdpGauge.saveCPUField(qdpCpuGauge, location);
167  double qdpGRtime = stopwatchReadSeconds();
168  printf("QDP Gauge restore time = %e seconds\n", qdpGRtime);
169  }
170 
171  stopwatchStart();
172 
173  *cudaSpinor = *spinor;
174  double sSendTime = stopwatchReadSeconds();
175  printf("Spinor send time = %e seconds\n", sSendTime); fflush(stdout);
176 
177  stopwatchStart();
178  *spinor2 = *cudaSpinor;
179  double sRecTime = stopwatchReadSeconds();
180  printf("Spinor receive time = %e seconds\n", sRecTime); fflush(stdout);
181 
182  double spinor_norm = norm2(*spinor);
183  double cuda_spinor_norm = norm2(*cudaSpinor);
184  double spinor2_norm = norm2(*spinor2);
185 
186  printf("Norm check: CPU = %e, CUDA = %e, CPU = %e\n",
187  spinor_norm, cuda_spinor_norm, spinor2_norm);
188 
190 
191 }
192 
193 extern void usage(char**);
194 
195 int main(int argc, char **argv) {
196  for (int i=1; i<argc; i++){
197  if(process_command_line_option(argc, argv, &i) == 0){
198  continue;
199  }
200 
201  fprintf(stderr, "ERROR: Invalid option:%s\n", argv[i]);
202  usage(argv);
203  }
204 
205  initComms(argc, argv, gridsize_from_cmdline);
206 
207  init();
208  packTest();
209  end();
210 
211  finalizeComms();
212 }
213