QUDA v0.3.2
A library for QCD on GPUs

quda/tests/pack_test.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <iostream>
00004 
00005 #include <quda_internal.h>
00006 #include <gauge_quda.h>
00007 #include <util_quda.h>
00008 
00009 #include <test_util.h>
00010 #include <wilson_dslash_reference.h>
00011 
00012 #include <color_spinor_field.h>
00013 #include <blas_quda.h>
00014 
00015 QudaGaugeParam param;
00016 FullGauge cudaGauge;
00017 cudaColorSpinorField *cudaSpinor;
00018 
00019 void *qdpGauge[4];
00020 void *cpsGauge;
00021 cpuColorSpinorField *spinor, *spinor2;
00022 
00023 ColorSpinorParam csParam;
00024 
00025 float kappa = 1.0;
00026 int ODD_BIT = 0;
00027 int DAGGER_BIT = 0;
00028     
00029 void init() {
00030 
00031   param.cpu_prec = QUDA_SINGLE_PRECISION;
00032   param.cuda_prec = QUDA_HALF_PRECISION;
00033   param.reconstruct = QUDA_RECONSTRUCT_8;
00034   param.cuda_prec_sloppy = param.cuda_prec;
00035   param.reconstruct_sloppy = param.reconstruct;
00036   
00037   param.X[0] = 4;
00038   param.X[1] = 4;
00039   param.X[2] = 4;
00040   param.X[3] = 4;
00041   param.ga_pad = 0;
00042   setDims(param.X);
00043 
00044   param.anisotropy = 2.3;
00045   param.t_boundary = QUDA_ANTI_PERIODIC_T;
00046   param.gauge_fix = QUDA_GAUGE_FIXED_NO;
00047 
00048   // construct input fields
00049   for (int dir = 0; dir < 4; dir++) {
00050     qdpGauge[dir] = malloc(V*gaugeSiteSize*param.cpu_prec);
00051   }
00052   cpsGauge = malloc(4*V*gaugeSiteSize*param.cpu_prec);
00053 
00054   csParam.fieldLocation = QUDA_CPU_FIELD_LOCATION;
00055   csParam.nColor = 3;
00056   csParam.nSpin = 4;
00057   csParam.nDim = 4;
00058   for (int d=0; d<4; d++) csParam.x[d] = param.X[d];
00059   csParam.precision = QUDA_SINGLE_PRECISION;
00060   csParam.pad = 0;
00061   csParam.siteSubset = QUDA_PARITY_SITE_SUBSET;
00062   csParam.siteOrder = QUDA_EVEN_ODD_SITE_ORDER;
00063   csParam.fieldOrder = QUDA_SPACE_SPIN_COLOR_FIELD_ORDER;
00064   csParam.gammaBasis = QUDA_DEGRAND_ROSSI_GAMMA_BASIS;
00065   csParam.create = QUDA_NULL_FIELD_CREATE;
00066 
00067   spinor = new cpuColorSpinorField(csParam);
00068   spinor2 = new cpuColorSpinorField(csParam);
00069 
00070   spinor->Source(QUDA_RANDOM_SOURCE);
00071 
00072   initQuda(0);
00073 
00074   csParam.fieldLocation = QUDA_CUDA_FIELD_LOCATION;
00075   csParam.fieldOrder = QUDA_FLOAT4_FIELD_ORDER;
00076   csParam.gammaBasis = QUDA_UKQCD_GAMMA_BASIS;
00077   csParam.pad = 0;
00078   csParam.precision = QUDA_HALF_PRECISION;
00079 
00080   cudaSpinor = new cudaColorSpinorField(csParam);
00081 }
00082 
00083 void end() {
00084   // release memory
00085   delete cudaSpinor;
00086   delete spinor2;
00087   delete spinor;
00088 
00089   for (int dir = 0; dir < 4; dir++) free(qdpGauge[dir]);
00090   free(cpsGauge);
00091   endQuda();
00092 }
00093 
00094 void packTest() {
00095 
00096   float spinorGiB = (float)Vh*spinorSiteSize*param.cuda_prec / (1 << 30);
00097   printf("\nSpinor mem: %.3f GiB\n", spinorGiB);
00098   printf("Gauge mem: %.3f GiB\n", param.gaugeGiB);
00099 
00100   printf("Sending fields to GPU...\n"); fflush(stdout);
00101   
00102   stopwatchStart();
00103   param.gauge_order = QUDA_CPS_WILSON_GAUGE_ORDER;
00104   createGaugeField(&cudaGauge, cpsGauge, param.cuda_prec, param.cpu_prec, param.gauge_order, param.reconstruct, 
00105                    param.gauge_fix, param.t_boundary, param.X, 1.0, 1.0, param.ga_pad);
00106   double cpsGtime = stopwatchReadSeconds();
00107   printf("CPS Gauge send time = %e seconds\n", cpsGtime);
00108 
00109   stopwatchStart();
00110   restoreGaugeField(cpsGauge, &cudaGauge, param.cpu_prec, param.gauge_order);
00111   double cpsGRtime = stopwatchReadSeconds();
00112   printf("CPS Gauge restore time = %e seconds\n", cpsGRtime);
00113 
00114   stopwatchStart();
00115   param.gauge_order = QUDA_QDP_GAUGE_ORDER;
00116   createGaugeField(&cudaGauge, qdpGauge, param.cuda_prec, param.cpu_prec, param.gauge_order, param.reconstruct, 
00117                    param.gauge_fix, param.t_boundary, param.X, 1.0, 1.0, param.ga_pad);
00118   double qdpGtime = stopwatchReadSeconds();
00119   printf("QDP Gauge send time = %e seconds\n", qdpGtime);
00120 
00121   stopwatchStart();
00122   restoreGaugeField(qdpGauge, &cudaGauge, param.cpu_prec, param.gauge_order);
00123   double qdpGRtime = stopwatchReadSeconds();
00124   printf("QDP Gauge restore time = %e seconds\n", qdpGRtime);
00125 
00126   stopwatchStart();
00127   *cudaSpinor = *spinor;
00128   double sSendTime = stopwatchReadSeconds();
00129   printf("Spinor send time = %e seconds\n", sSendTime);
00130 
00131   stopwatchStart();
00132   *spinor2 = *cudaSpinor;
00133   double sRecTime = stopwatchReadSeconds();
00134   printf("Spinor receive time = %e seconds\n", sRecTime);
00135   
00136   std::cout << "Norm check: CPU = " << norm2(*spinor) << 
00137     ", CUDA = " << norm2(*cudaSpinor) << 
00138     ", CPU =  " << norm2(*spinor2) << std::endl;
00139 
00140   cpuColorSpinorField::Compare(*spinor, *spinor2, 1);
00141 
00142 }
00143 
00144 int main(int argc, char **argv) {
00145   init();
00146   packTest();
00147   end();
00148 }
00149 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines