QUDA  0.9.0
hisq_paths_force_test.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 #include <cstring>
4 
5 #include <quda.h>
6 #include "test_util.h"
7 #include "gauge_field.h"
8 #include "misc.h"
9 #include "hisq_force_reference.h"
10 #include "ks_improved_force.h"
11 #include "hw_quda.h"
12 #include <dslash_quda.h>
13 #include <sys/time.h>
14 
15 #define TDIFF(a,b) (b.tv_sec - a.tv_sec + 0.000001*(b.tv_usec - a.tv_usec))
16 
17 using namespace quda;
18 
19 extern void usage(char** argv);
20 extern int device;
23 
26 
30 
33 static void* hw; // the array of half_wilson_vector
34 
36 
41 
42 extern bool verify_results;
43 int ODD_BIT = 1;
44 extern int xdim, ydim, zdim, tdim;
45 extern int gridsize_from_cmdline[];
46 
47 extern QudaPrecision prec;
53 
62 
65 
66 static void setPrecision(QudaPrecision precision)
67 {
68  link_prec = precision;
69  hw_prec = precision;
70  cpu_hw_prec = precision;
71  mom_prec = precision;
72  return;
73 }
74 
76 {
77  //total IO counting for the middle/side/all link kernels
78  //Explanation about these numbers can be founed in the corresnponding kernel functions in
79  //the hisq kernel core file
80  int linksize = prec*recon;
81  int cmsize = prec*18;
82 
83  int matrix_mul_flops = 198;
84  int matrix_add_flops = 18;
85 
86  int num_calls_middle_link[6] = {24, 24, 96, 96, 24, 24};
87  int middle_link_data_io[6][2] = {
88  {3,6},
89  {3,4},
90  {3,7},
91  {3,5},
92  {3,5},
93  {3,2}
94  };
95  int middle_link_data_flops[6][2] = {
96  {3,1},
97  {2,0},
98  {4,1},
99  {3,0},
100  {4,1},
101  {2,0}
102  };
103 
104  int num_calls_side_link[2]= {192, 48};
105  int side_link_data_io[2][2] = {
106  {1, 6},
107  {0, 3}
108  };
109  int side_link_data_flops[2][2] = {
110  {2, 2},
111  {0, 1}
112  };
113 
114  int num_calls_all_link[2] ={192, 192};
115  int all_link_data_io[2][2] = {
116  {3, 8},
117  {3, 6}
118  };
119  int all_link_data_flops[2][2] = {
120  {6, 3},
121  {4, 2}
122  };
123 
124  double total_io = 0;
125  for(int i = 0;i < 6; i++){
126  total_io += num_calls_middle_link[i]
127  *(middle_link_data_io[i][0]*linksize + middle_link_data_io[i][1]*cmsize);
128  }
129 
130  for(int i = 0;i < 2; i++){
131  total_io += num_calls_side_link[i]
132  *(side_link_data_io[i][0]*linksize + side_link_data_io[i][1]*cmsize);
133  }
134  for(int i = 0;i < 2; i++){
135  total_io += num_calls_all_link[i]
136  *(all_link_data_io[i][0]*linksize + all_link_data_io[i][1]*cmsize);
137  }
138  total_io *= V;
139 
140 
141  double total_flops = 0;
142  for(int i = 0;i < 6; i++){
143  total_flops += num_calls_middle_link[i]
144  *(middle_link_data_flops[i][0]*matrix_mul_flops + middle_link_data_flops[i][1]*matrix_add_flops);
145  }
146 
147  for(int i = 0;i < 2; i++){
148  total_flops += num_calls_side_link[i]
149  *(side_link_data_flops[i][0]*matrix_mul_flops + side_link_data_flops[i][1]*matrix_add_flops);
150  }
151  for(int i = 0;i < 2; i++){
152  total_flops += num_calls_all_link[i]
153  *(all_link_data_flops[i][0]*matrix_mul_flops + all_link_data_flops[i][1]*matrix_add_flops);
154  }
155  total_flops *= V;
156 
157  *io=total_io;
158  *flops = total_flops;
159 
160  printfQuda("flop/byte =%.1f\n", total_flops/total_io);
161  return ;
162 }
163 
164 #ifdef MULTI_GPU
165 static int R[4] = {2, 2, 2, 2};
166 #else
167 static int R[4] = {0, 0, 0, 0};
168 #endif
169 
170 // allocate memory
171 // set the layout, etc.
172 static void hisq_force_init()
173 {
174  initQuda(device);
175 
176  qudaGaugeParam.X[0] = xdim;
177  qudaGaugeParam.X[1] = ydim;
178  qudaGaugeParam.X[2] = zdim;
179  qudaGaugeParam.X[3] = tdim;
180 
182 
187 
189 
193 
196 
202  for (int d=0; d<4; d++) { gParam_ex.r[d] = R[d]; gParam_ex.x[d] = gParam.x[d] + 2*gParam_ex.r[d]; } // set halo region for CPU
204 
207  } else {
208  errorQuda("Unsupported gauge order %d", gauge_order);
209  }
210 
212 
216  gParam_ex.pad = 0;
218  for (int d=0; d<4; d++) { gParam_ex.r[d] = (comm_dim_partitioned(d)) ? 2 : 0; gParam_ex.x[d] = gParam.x[d] + 2*gParam_ex.r[d]; } // set halo region
221  //record gauge pad size
222 
223  gParam_ex.pad = 0;
227  for (int d=0; d<4; d++) { gParam_ex.r[d] = R[d]; gParam_ex.x[d] = gParam.x[d] + 2*gParam_ex.r[d]; } // set halo region for CPU
229 
230 
233  for (int d=0; d<4; d++) { gParam_ex.r[d] = (comm_dim_partitioned(d)) ? 2 : 0; gParam_ex.x[d] = gParam.x[d] + 2*gParam_ex.r[d]; } // set halo region
235 
236  // create the momentum matrix
237  gParam.pad = 0;
243  cpuMom = new cpuGaugeField(gParam);
244  refMom = new cpuGaugeField(gParam);
245 
246  //createMomCPU(cpuMom->Gauge_p(), mom_prec);
247 
249  if (hw == NULL){
250  fprintf(stderr, "ERROR: malloc failed for hw\n");
251  exit(1);
252  }
253 
255 
259  gParam.pad = 0;
264 
268  for (int d=0; d<4; d++) { gParam_ex.r[d] = R[d]; gParam_ex.x[d] = gParam.x[d] + 2*gParam_ex.r[d]; } // set halo region for CPU
271 
273 
275 
277  for (int d=0; d<4; d++) { gParam_ex.r[d] = (comm_dim_partitioned(d)) ? 2 : 0; gParam_ex.x[d] = gParam.x[d] + 2*gParam_ex.r[d]; } // set halo region
279 
280 }
281 
282 static void hisq_force_end()
283 {
284  delete cudaMom;
285  delete cudaGauge;
286  delete cudaForce_ex;
287  delete cudaGauge_ex;
288  //delete cudaOprod_ex; // already deleted
289  delete cudaLongLinkOprod_ex;
290 
291  delete cpuGauge;
292  delete cpuMom;
293  delete refMom;
294  delete cpuOprod;
295  delete cpuLongLinkOprod;
296 
297  delete cpuGauge_ex;
298  delete cpuForce_ex;
299  delete cpuOprod_ex;
300  delete cpuLongLinkOprod_ex;
301 
302  free(hw);
303 
304  endQuda();
305 }
306 
307 static int hisq_force_test(void)
308 {
310 
311  hisq_force_init();
312 
313  //float weight = 1.0;
314  float act_path_coeff[6];
315 
316  act_path_coeff[0] = 0.625000;
317  act_path_coeff[1] = -0.058479;
318  act_path_coeff[2] = -0.087719;
319  act_path_coeff[3] = 0.030778;
320  act_path_coeff[4] = -0.007200;
321  act_path_coeff[5] = -0.123113;
322 
323  //double d_weight = 1.0;
324  double d_act_path_coeff[6];
325  for(int i=0; i<6; ++i){
326  d_act_path_coeff[i] = act_path_coeff[i];
327  }
328 
332 
336 
338 
339  struct timeval ht0, ht1;
340  gettimeofday(&ht0, NULL);
341  if (verify_results){
345  }
346  gettimeofday(&ht1, NULL);
347 
348  struct timeval t0, t1, t2, t3;
349 
350  gettimeofday(&t0, NULL);
351 
353  cudaDeviceSynchronize();
354  gettimeofday(&t1, NULL);
355 
356  delete cudaOprod_ex; //doing this to lower the peak memory usage
358  for (int d=0; d<4; d++) { gParam_ex.r[d] = (comm_dim_partitioned(d)) ? 2 : 0; gParam_ex.x[d] = gParam.x[d] + 2*gParam_ex.r[d]; } // set halo region
363  cudaDeviceSynchronize();
364 
365  gettimeofday(&t2, NULL);
366 
370  gParam.pad = 0; //X1*X2*X3/2;
372  cudaMom = new cudaGaugeField(gParam); // Are the elements initialised to zero? - No!
373 
374  //record the mom pad
376 
378 
379  cudaDeviceSynchronize();
380  gettimeofday(&t3, NULL);
381 
382  checkCudaError();
383 
385 
386  int accuracy_level = 3;
387  if(verify_results){
388  int res;
390 
392  printfQuda("Test %s\n",(1 == res) ? "PASSED" : "FAILED");
393  }
394  double total_io;
395  double total_flops;
396  total_staple_io_flops(link_prec, link_recon, &total_io, &total_flops);
397 
398  float perf_flops = total_flops / (TDIFF(t0, t1)) *1e-9;
399  float perf = total_io / (TDIFF(t0, t1)) *1e-9;
400  printfQuda("Staples time: %.2f ms, perf = %.2f GFLOPS, achieved bandwidth= %.2f GB/s\n", TDIFF(t0,t1)*1000, perf_flops, perf);
401  printfQuda("Staples time : %g ms\t LongLink time : %g ms\t Completion time : %g ms\n", TDIFF(t0,t1)*1000, TDIFF(t1,t2)*1000, TDIFF(t2,t3)*1000);
402  printfQuda("Host time (half-wilson fermion force) : %g ms\n", TDIFF(ht0, ht1)*1000);
403 
404  hisq_force_end();
405 
406  return accuracy_level;
407 }
408 
409 
410 static void display_test_info()
411 {
412  printfQuda("running the following fermion force computation test:\n");
413 
414  printfQuda("link_precision link_reconstruct space_dim(x/y/z) T_dimension Gauge_order\n");
415  printfQuda("%s %s %d/%d/%d %d %s\n",
418  xdim, ydim, zdim, tdim,
420  return ;
421 
422 }
423 
424 int main(int argc, char **argv)
425 {
426  int i;
427  for (i =1;i < argc; i++){
428 
429  if(process_command_line_option(argc, argv, &i) == 0){
430  continue;
431  }
432 
433  if( strcmp(argv[i], "--gauge-order") == 0){
434  if(i+1 >= argc){
435  usage(argv);
436  }
437 
438  if(strcmp(argv[i+1], "milc") == 0){
440  }else if(strcmp(argv[i+1], "qdp") == 0){
442  }else{
443  fprintf(stderr, "Error: unsupported gauge-field order\n");
444  exit(1);
445  }
446  i++;
447  continue;
448  }
449 
450  fprintf(stderr, "ERROR: Invalid option:%s\n", argv[i]);
451  usage(argv);
452  }
453 
455  errorQuda("Multi-gpu for milc order is not supported\n");
456  }
457 
458  initComms(argc, argv, gridsize_from_cmdline);
459 
461 
463 
464  int accuracy_level = hisq_force_test();
465 
466  finalizeComms();
467 
468  if(accuracy_level >=3 ){
469  return EXIT_SUCCESS;
470  }else{
471  return -1;
472  }
473 
474 }
475 
476 
QudaPrecision hw_prec
int main(int argc, char **argv)
double anisotropy
Definition: quda.h:31
cpuGaugeField * cpuOprod
QudaGhostExchange ghostExchange
Definition: lattice_field.h:60
void endQuda(void)
void free(void *)
cpuGaugeField * cpuForce_ex
enum QudaPrecision_s QudaPrecision
void saveCPUField(cpuGaugeField &cpu) const
Upload from this field into a CPU field.
cudaGaugeField * cudaOprod_ex
void exchangeExtendedGhost(const int *R, bool no_comms_fill=false)
This does routine will populate the border / halo region of a gauge field that has been created using...
cudaGaugeField * cudaForce_ex
int xdim
Definition: test_util.cpp:1620
#define errorQuda(...)
Definition: util_quda.h:90
void hisqStaplesForceCPU(const double *path_coeff, const QudaGaugeParam &param, quda::cpuGaugeField &oprod, quda::cpuGaugeField &link, quda::cpuGaugeField *newOprod)
void createHwCPU(void *hw, QudaPrecision precision)
Definition: test_util.cpp:1492
cudaGaugeField * cudaMom
static int R[4]
int process_command_line_option(int argc, char **argv, int *idx)
Definition: test_util.cpp:1795
int gridsize_from_cmdline[]
Definition: test_util.cpp:50
static void setPrecision(QudaPrecision precision)
QudaPrecision precision
Definition: lattice_field.h:54
void finalizeComms()
Definition: test_util.cpp:107
cpuGaugeField * cpuMom
const char * get_gauge_order_str(QudaGaugeFieldOrder order)
Definition: misc.cpp:743
int ydim
Definition: test_util.cpp:1621
int compare_floats(void *a, void *b, int len, double epsilon, QudaPrecision precision)
Definition: test_util.cpp:437
const char * get_prec_str(QudaPrecision prec)
Definition: misc.cpp:704
int tdim
Definition: test_util.cpp:1623
void createSiteLinkCPU(void **link, QudaPrecision precision, int phase)
Definition: test_util.cpp:1229
QudaPrecision cpu_hw_prec
void exit(int) __attribute__((noreturn))
void setDims(int *)
Definition: test_util.cpp:130
static void hisq_force_init()
else return(__swbuf(_c, _p))
static void display_test_info()
void hisqCompleteForceCPU(const QudaGaugeParam &param, quda::cpuGaugeField &oprod, quda::cpuGaugeField &link, quda::cpuGaugeField *mom)
int strcmp(const char *__s1, const char *__s2)
int x[QUDA_MAX_DIM]
Definition: lattice_field.h:50
const int * R() const
void loadCPUField(const cpuGaugeField &cpu)
Download into this field from a CPU field.
cpuGaugeField * refMom
void initQuda(int device)
void hisqLongLinkForce(GaugeField &newOprod, const GaugeField &oprod, const GaugeField &link, double coeff, long long *flops=nullptr)
Compute the long-link contribution to the fermion force.
void * malloc(size_t __size) __attribute__((__warn_unused_result__)) __attribute__((alloc_size(1)))
int site_ga_pad
Definition: quda.h:55
#define TDIFF(a, b)
void hisqStaplesForce(GaugeField &newOprod, const GaugeField &oprod, const GaugeField &link, const double path_coeff[6], long long *flops=nullptr)
Compute the fat-link contribution to the fermion force.
QudaPrecision link_prec
static void * hw
cudaGaugeField * cudaLongLinkOprod
void exchangeExtendedGhost(const int *R, bool no_comms_fill=false)
This does routine will populate the border / halo region of a gauge field that has been created using...
QudaReconstructType link_recon
Definition: test_util.cpp:1612
const char * get_recon_str(QudaReconstructType recon)
Definition: misc.cpp:770
bool verify_results
Definition: test_util.cpp:1641
int V
Definition: test_util.cpp:28
cpuGaugeField * cpuOprod_ex
static QudaGaugeParam qudaGaugeParam
QudaGaugeFieldOrder order
Definition: gauge_field.h:15
enum QudaGaugeFieldOrder_s QudaGaugeFieldOrder
int Volume() const
static void computeLinkOrderedOuterProduct(half_wilson_vector *src, su3_matrix *dest, int gauge_order)
void hisqLongLinkForceCPU(double coeff, const QudaGaugeParam &param, quda::cpuGaugeField &oprod, quda::cpuGaugeField &link, quda::cpuGaugeField *newOprod)
QudaReconstructType reconstruct
Definition: quda.h:43
QudaPrecision cuda_prec
Definition: quda.h:42
int X[4]
Definition: quda.h:29
int fprintf(FILE *, const char *,...) __attribute__((__format__(__printf__
int strong_check_mom(void *momA, void *momB, int len, QudaPrecision prec)
Definition: test_util.cpp:1565
int zdim
Definition: test_util.cpp:1622
void * memcpy(void *__dst, const void *__src, size_t __n)
#define hwSiteSize
Definition: test_util.h:10
static QudaGaugeParam qudaGaugeParam_ex
GaugeFieldParam gParam_ex
cpuGaugeField * cpuLongLinkOprod_ex
cudaGaugeField * cudaGauge_ex
void hisqCompleteForce(GaugeField &momentum, const GaugeField &oprod, const GaugeField &link, long long *flops=nullptr)
Multiply the computed the force matrix by the gauge field and perform traceless anti-hermitian projec...
QudaPrecision prec
Definition: test_util.cpp:1615
GaugeFieldParam gParam
cpuGaugeField * cpuLongLinkOprod
enum QudaReconstructType_s QudaReconstructType
Main header file for the QUDA library.
QudaLinkType link_type
Definition: gauge_field.h:17
int mom_ga_pad
Definition: quda.h:59
static int hisq_force_test(void)
#define printfQuda(...)
Definition: util_quda.h:84
static void hisq_force_end()
QudaPrecision mom_prec
unsigned long long flops
Definition: blas_quda.cu:42
cpuGaugeField * cpuGauge_ex
cudaGaugeField * cudaGauge
QudaGaugeFieldOrder gauge_order
QudaReconstructType reconstruct
Definition: gauge_field.h:14
QudaFieldCreate create
Definition: gauge_field.h:25
cpuGaugeField * cpuGauge
#define checkCudaError()
Definition: util_quda.h:129
cudaGaugeField * cudaForce
cudaGaugeField * cudaOprod
static __inline__ size_t size_t d
int r[QUDA_MAX_DIM]
Definition: lattice_field.h:63
cudaGaugeField * cudaLongLinkOprod_ex
void initComms(int argc, char **argv, const int *commDims)
Definition: test_util.cpp:72
void copyExtendedGauge(GaugeField &out, const GaugeField &in, QudaFieldLocation location, void *Out=0, void *In=0)
void setVerbosity(const QudaVerbosity verbosity)
Definition: util_quda.cpp:24
cpuGaugeField * cpuForce
QudaPrecision cpu_prec
Definition: quda.h:40
int comm_dim_partitioned(int dim)
void usage(char **argv)
Definition: test_util.cpp:1693
#define momSiteSize
Definition: test_util.h:9
void total_staple_io_flops(QudaPrecision prec, QudaReconstructType recon, double *io, double *flops)