QUDA  v1.1.0
A library for QCD on GPUs
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 <host_utils.h>
10 #include <command_line_params.h>
11 #include <dslash_reference.h>
12 
13 #include <color_spinor_field.h>
14 #include <blas_quda.h>
15 
16 using namespace quda;
17 
20 
21 void *qdpCpuGauge_p[4];
24 
26 
27 int ODD_BIT = 0;
28 int DAGGER_BIT = 0;
29 
31 
32 void init() {
33 
39 
40  param.X[0] = xdim;
41  param.X[1] = ydim;
42  param.X[2] = zdim;
43  param.X[3] = tdim;
44 #ifdef MULTI_GPU
46 #else
47  param.ga_pad = 0;
48 #endif
49  setDims(param.X);
50 
51  param.anisotropy = 2.3;
54 
55  // construct input fields
56  for (int dir = 0; dir < 4; dir++) { qdpCpuGauge_p[dir] = malloc(V * gauge_site_size * param.cpu_prec); }
57  cpsCpuGauge_p = malloc(4 * V * gauge_site_size * param.cpu_prec);
58 
59  csParam.nColor = 3;
60  csParam.nSpin = 4;
61  csParam.nDim = 4;
62  for (int d=0; d<4; d++) csParam.x[d] = param.X[d];
64  csParam.pad = 0;
70 
73 
75 
77 
78  setVerbosityQuda(QUDA_VERBOSE, "", stdout);
79 
83  csParam.pad = param.X[0] * param.X[1] * param.X[2];
84 
86 }
87 
88 void end() {
89  // release memory
90  delete cudaSpinor;
91  delete spinor2;
92  delete spinor;
93 
94  for (int dir = 0; dir < 4; dir++) free(qdpCpuGauge_p[dir]);
95  free(cpsCpuGauge_p);
96  endQuda();
97 }
98 
99 void packTest() {
100 
101  printfQuda("Sending fields to GPU...\n");
102 
103 #ifdef BUILD_CPS_INTERFACE
104  {
106 
108  cpuGaugeField cpsCpuGauge(cpsParam);
109  cpsParam.create = QUDA_NULL_FIELD_CREATE;
110  cpsParam.reconstruct = param.reconstruct;
111  cpsParam.setPrecision(param.cuda_prec, true);
112  cpsParam.pad = param.ga_pad;
113  cudaGaugeField cudaCpsGauge(cpsParam);
114 
115  stopwatchStart();
116  cudaCpsGauge.loadCPUField(cpsCpuGauge);
117  double cpsGtime = stopwatchReadSeconds();
118  printfQuda("CPS Gauge send time = %e seconds\n", cpsGtime);
119 
120  stopwatchStart();
121  cudaCpsGauge.saveCPUField(cpsCpuGauge);
122  double cpsGRtime = stopwatchReadSeconds();
123  printfQuda("CPS Gauge restore time = %e seconds\n", cpsGRtime);
124  }
125 #endif
126 
127 #ifdef BUILD_QDP_INTERFACE
128  {
130 
132  cpuGaugeField qdpCpuGauge(qdpParam);
133  qdpParam.create = QUDA_NULL_FIELD_CREATE;
134  qdpParam.reconstruct = param.reconstruct;
135  qdpParam.setPrecision(param.cuda_prec, true);
136  qdpParam.pad = param.ga_pad;
137  cudaGaugeField cudaQdpGauge(qdpParam);
138 
139  stopwatchStart();
140  cudaQdpGauge.loadCPUField(qdpCpuGauge);
141  double qdpGtime = stopwatchReadSeconds();
142  printfQuda("QDP Gauge send time = %e seconds\n", qdpGtime);
143 
144  stopwatchStart();
145  cudaQdpGauge.saveCPUField(qdpCpuGauge);
146  double qdpGRtime = stopwatchReadSeconds();
147  printfQuda("QDP Gauge restore time = %e seconds\n", qdpGRtime);
148  }
149 #endif
150 
151  stopwatchStart();
152 
153  *cudaSpinor = *spinor;
154  double sSendTime = stopwatchReadSeconds();
155  printfQuda("Spinor send time = %e seconds\n", sSendTime);
156 
157  stopwatchStart();
158  *spinor2 = *cudaSpinor;
159  double sRecTime = stopwatchReadSeconds();
160  printfQuda("Spinor receive time = %e seconds\n", sRecTime);
161 
162  double spinor_norm = blas::norm2(*spinor);
163  double cuda_spinor_norm = blas::norm2(*cudaSpinor);
164  double spinor2_norm = blas::norm2(*spinor2);
165 
166  printfQuda("Norm check: CPU = %e, CUDA = %e, CPU = %e\n", spinor_norm, cuda_spinor_norm, spinor2_norm);
167 
169 }
170 
171 int main(int argc, char **argv) {
172  // command line options
173  auto app = make_app();
174  try {
175  app->parse(argc, argv);
176  } catch (const CLI::ParseError &e) {
177  return app->exit(e);
178  }
179 
180  initComms(argc, argv, gridsize_from_cmdline);
181 
182  init();
183  packTest();
184  end();
185 
186  finalizeComms();
187 }
188 
void setPrecision(QudaPrecision precision, QudaPrecision ghost_precision=QUDA_INVALID_PRECISION, bool force_native=false)
void Source(const QudaSourceType sourceType, const int st=0, const int s=0, const int c=0)
static int Compare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, const int resolution=1)
Perform a component by component comparison of two color-spinor fields. In doing we normalize with re...
void loadCPUField(const cpuGaugeField &cpu)
Download into this field from a CPU field.
void saveCPUField(cpuGaugeField &cpu) const
Upload from this field into a CPU field.
std::shared_ptr< QUDAApp > make_app(std::string app_description, std::string app_name)
QudaReconstructType link_recon
int device_ordinal
int & ydim
int & zdim
QudaPrecision prec
int & tdim
int & xdim
std::array< int, 4 > gridsize_from_cmdline
int V
Definition: host_utils.cpp:37
void setDims(int *)
Definition: host_utils.cpp:315
enum QudaPrecision_s QudaPrecision
@ QUDA_RANDOM_SOURCE
Definition: enum_quda.h:376
@ QUDA_VERBOSE
Definition: enum_quda.h:267
@ QUDA_PARITY_SITE_SUBSET
Definition: enum_quda.h:332
@ QUDA_DEGRAND_ROSSI_GAMMA_BASIS
Definition: enum_quda.h:368
@ QUDA_ANTI_PERIODIC_T
Definition: enum_quda.h:56
@ QUDA_GAUGE_FIXED_NO
Definition: enum_quda.h:80
@ QUDA_EVEN_ODD_SITE_ORDER
Definition: enum_quda.h:340
@ QUDA_DOUBLE_PRECISION
Definition: enum_quda.h:65
@ QUDA_QDP_GAUGE_ORDER
Definition: enum_quda.h:44
@ QUDA_CPS_WILSON_GAUGE_ORDER
Definition: enum_quda.h:46
@ QUDA_FLOAT2_FIELD_ORDER
Definition: enum_quda.h:348
@ QUDA_SPACE_SPIN_COLOR_FIELD_ORDER
Definition: enum_quda.h:351
@ QUDA_NULL_FIELD_CREATE
Definition: enum_quda.h:360
#define gauge_site_size
Definition: face_gauge.cpp:34
void initComms(int argc, char **argv, std::array< int, 4 > &commDims)
Definition: host_utils.cpp:255
void finalizeComms()
Definition: host_utils.cpp:292
double stopwatchReadSeconds()
void stopwatchStart()
double norm2(const ColorSpinorField &a)
void init()
Definition: pack_test.cpp:32
int main(int argc, char **argv)
Definition: pack_test.cpp:171
void * qdpCpuGauge_p[4]
Definition: pack_test.cpp:21
ColorSpinorParam csParam
Definition: pack_test.cpp:25
cudaColorSpinorField * cudaSpinor
Definition: pack_test.cpp:19
QudaPrecision prec_cpu
Definition: pack_test.cpp:30
int ODD_BIT
Definition: pack_test.cpp:27
int DAGGER_BIT
Definition: pack_test.cpp:28
void * cpsCpuGauge_p
Definition: pack_test.cpp:22
cpuColorSpinorField * spinor
Definition: pack_test.cpp:23
void end()
Definition: pack_test.cpp:88
QudaGaugeParam param
Definition: pack_test.cpp:18
cpuColorSpinorField * spinor2
Definition: pack_test.cpp:23
void packTest()
Definition: pack_test.cpp:99
void setVerbosityQuda(QudaVerbosity verbosity, const char prefix[], FILE *outfile)
void initQuda(int device)
void endQuda(void)
double anisotropy
Definition: quda.h:37
QudaReconstructType reconstruct
Definition: quda.h:49
int ga_pad
Definition: quda.h:65
QudaPrecision cuda_prec_sloppy
Definition: quda.h:51
QudaReconstructType reconstruct_sloppy
Definition: quda.h:52
QudaGaugeFixed gauge_fix
Definition: quda.h:63
QudaGaugeFieldOrder gauge_order
Definition: quda.h:42
QudaPrecision cuda_prec
Definition: quda.h:48
int X[4]
Definition: quda.h:35
QudaPrecision cpu_prec
Definition: quda.h:46
QudaTboundary t_boundary
Definition: quda.h:44
QudaReconstructType reconstruct
Definition: gauge_field.h:50
void setPrecision(QudaPrecision precision, bool force_native=false)
Helper function for setting the precision and corresponding field order for QUDA internal fields.
Definition: gauge_field.h:173
QudaFieldCreate create
Definition: gauge_field.h:60
int x[QUDA_MAX_DIM]
Definition: lattice_field.h:68
QudaSiteSubset siteSubset
Definition: lattice_field.h:72
#define printfQuda(...)
Definition: util_quda.h:114