Skip to content

Commit c83944b

Browse files
committed
qphix_interface work:
1) pass parameters to qphix from input file, new "BeginExternalInverter QPHIX" structure implemented for this purpose (warning: no correctness checks here) 2) move _initQphix call into invert_eo_qphix 3) add sample file to call qphix Wilson inverter 4) use angled brackets to include qphix headers caveats: single precision results in a segfault, only the Wilson operator is currently supported
1 parent c17b5d9 commit c83944b

File tree

5 files changed

+185
-27
lines changed

5 files changed

+185
-27
lines changed

invert_eo.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ int invert_eo(spinor * const Even_new, spinor * const Odd_new,
102102
return invert_eo_qphix(Even_new, Odd_new, Even, Odd,
103103
precision, max_iter,
104104
solver_flag, rel_prec,
105-
solver_params, compression);
105+
solver_params,
106+
compression);
106107
}
107108
#endif
108109

qphix_interface.cpp

+46-21
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ extern "C" {
7070
#include <cfloat>
7171
#include <cstdlib>
7272
#include <cstring>
73-
#include "qphix/blas_new_c.h"
74-
#include "qphix/invcg.h"
75-
#include "qphix/invbicgstab.h"
76-
#include "qphix/print_utils.h"
77-
#include "qphix/qphix_config.h"
78-
#include "qphix/wilson.h"
73+
#include <qphix/blas_new_c.h>
74+
#include <qphix/invcg.h>
75+
#include <qphix/invbicgstab.h>
76+
#include <qphix/print_utils.h>
77+
#include <qphix/qphix_config.h>
78+
#include <qphix/wilson.h>
7979
using namespace std;
8080
using namespace QPhiX;
8181

@@ -118,6 +118,15 @@ using namespace QPhiX;
118118
#include <qmp.h>
119119
#endif
120120

121+
int qphix_input_By;
122+
int qphix_input_Bz;
123+
int qphix_input_NCores;
124+
int qphix_input_Sy;
125+
int qphix_input_Sz;
126+
int qphix_input_PadXY;
127+
int qphix_input_PadXYZ;
128+
int qphix_input_MinCt;
129+
121130
int By;
122131
int Bz;
123132
int NCores;
@@ -128,7 +137,7 @@ int PadXYZ;
128137
int MinCt;
129138
int N_simt;
130139
bool compress12;
131-
QphixPrec precision;
140+
QphixPrec qphix_precision;
132141

133142
int subLattSize[4];
134143
int lattSize[4];
@@ -174,9 +183,10 @@ void _initQphix(int argc, char **argv, int By_, int Bz_, int NCores_, int Sy_, i
174183
MinCt = MinCt_;
175184
N_simt = Sy_ * Sz_;
176185
compress12 = c12;
177-
precision = precision_;
186+
qphix_precision = precision_;
178187

179-
omp_set_num_threads(NCores * Sy * Sz);
188+
// this is called within tmLQCD already, it should not be called here
189+
//omp_set_num_threads(NCores * Sy * Sz);
180190

181191
#ifdef QPHIX_QMP_COMMS
182192
// Declare the logical topology
@@ -564,11 +574,7 @@ int invert_eo_qphix_helper(spinor * const tmlqcd_even_out,
564574
* *
565575
************************/
566576

567-
// FIXME: This should be called properly somewhere else
568-
_initQphix(0, nullptr, /* By = */ 2, /* Bz = */ 2, /* Ncores = */ 1,
569-
/* Sy = */ 1, /* Sz = */ 1,
570-
/* PadXY = */ 1, /* PadXYZ = */ 1, /* MinCt = */ 1,
571-
/* compress12 = */ 1, QPHIX_DOUBLE_PREC);
577+
// _initQphix should have been called at this point
572578

573579
masterPrintf("# VECLEN = %d, SOALEN = %d\n", V, S);
574580
masterPrintf("# Declared QMP Topology: %d %d %d %d\n",
@@ -860,7 +866,7 @@ int invert_eo_qphix_helper(spinor * const tmlqcd_even_out,
860866

861867
// Template wrapper for the Dslash operator call-able from C code
862868
void D_psi_qphix(spinor* tmlqcd_out, const spinor* tmlqcd_in) {
863-
if (precision == QPHIX_DOUBLE_PREC) {
869+
if (qphix_precision == QPHIX_DOUBLE_PREC) {
864870
if (QPHIX_SOALEN > VECLEN_DP) {
865871
masterPrintf("SOALEN=%d is greater than the double prec VECLEN=%d\n", QPHIX_SOALEN,
866872
VECLEN_DP);
@@ -872,7 +878,7 @@ void D_psi_qphix(spinor* tmlqcd_out, const spinor* tmlqcd_in) {
872878
} else {
873879
D_psi<double, VECLEN_DP, QPHIX_SOALEN, false>(tmlqcd_out, tmlqcd_in);
874880
}
875-
} else if (precision == QPHIX_FLOAT_PREC) {
881+
} else if (qphix_precision == QPHIX_FLOAT_PREC) {
876882
if (QPHIX_SOALEN > VECLEN_SP) {
877883
masterPrintf("SOALEN=%d is greater than the single prec VECLEN=%d\n", QPHIX_SOALEN,
878884
VECLEN_SP);
@@ -886,7 +892,7 @@ void D_psi_qphix(spinor* tmlqcd_out, const spinor* tmlqcd_in) {
886892
}
887893
}
888894
#if defined(QPHIX_MIC_SOURCE)
889-
else if (precision == QPHIX_HALF_PREC) {
895+
else if (qphix_precision == QPHIX_HALF_PREC) {
890896
if (QPHIX_SOALEN > VECLEN_HP) {
891897
masterPrintf("SOALEN=%d is greater than the single prec VECLEN=%d\n", QPHIX_SOALEN,
892898
VECLEN_SP);
@@ -924,6 +930,11 @@ int invert_eo_qphix(spinor * const Even_new,
924930
}
925931
masterPrintf("# INITIALIZING QPHIX SOLVER\n");
926932
masterPrintf("# USING DOUBLE PRECISION\n");
933+
_initQphix(0, nullptr, qphix_input_By, qphix_input_Bz, qphix_input_NCores,
934+
qphix_input_Sy, qphix_input_Sz,
935+
qphix_input_PadXY, qphix_input_PadXYZ, qphix_input_MinCt,
936+
compression, QPHIX_DOUBLE_PREC);
937+
927938
if (compress12) {
928939
return invert_eo_qphix_helper<double, VECLEN_DP, QPHIX_SOALEN, true>
929940
(Even_new,
@@ -949,16 +960,25 @@ int invert_eo_qphix(spinor * const Even_new,
949960
solver_params,
950961
compression);
951962
}
963+
#ifdef QPHIX_MIC_SOURCE
952964
} else if (precision < rsdTarget<float>::value) {
965+
#else
966+
} else {
967+
#endif
953968
if (QPHIX_SOALEN > VECLEN_SP) {
954969
masterPrintf("SOALEN=%d is greater than the single prec VECLEN=%d\n", QPHIX_SOALEN,
955970
VECLEN_SP);
956971
abort();
957972
}
958973
masterPrintf("# INITIALIZING QPHIX SOLVER\n");
959974
masterPrintf("# USING SINGLE PRECISION\n");
975+
_initQphix(0, nullptr, qphix_input_By, qphix_input_Bz, qphix_input_NCores,
976+
qphix_input_Sy, qphix_input_Sz,
977+
qphix_input_PadXY, qphix_input_PadXYZ, qphix_input_MinCt,
978+
compression, QPHIX_FLOAT_PREC);
979+
960980
if (compress12) {
961-
return invert_eo_qphix_helper<float, VECLEN_DP, QPHIX_SOALEN, true>
981+
return invert_eo_qphix_helper<float, VECLEN_SP, QPHIX_SOALEN, true>
962982
(Even_new,
963983
Odd_new,
964984
Even,
@@ -970,7 +990,7 @@ int invert_eo_qphix(spinor * const Even_new,
970990
solver_params,
971991
compression);
972992
} else {
973-
return invert_eo_qphix_helper<float, VECLEN_DP, QPHIX_SOALEN, false>
993+
return invert_eo_qphix_helper<float, VECLEN_SP, QPHIX_SOALEN, false>
974994
(Even_new,
975995
Odd_new,
976996
Even,
@@ -992,8 +1012,13 @@ int invert_eo_qphix(spinor * const Even_new,
9921012
}
9931013
masterPrintf("# INITIALIZING QPHIX SOLVER\n");
9941014
masterPrintf("# USING HALF PRECISION\n");
1015+
_initQphix(0, nullptr, qphix_input_By, qphix_input_Bz, qphix_input_NCores,
1016+
qphix_input_Sy, qphix_input_Sz,
1017+
qphix_input_PadXY, qphix_input_PadXYZ, qphix_input_MinCt,
1018+
compression, QPHIX_HALF_PREC);
1019+
9951020
if (compress12) {
996-
return invert_eo_qphix_helper<half, VECLEN_DP, QPHIX_SOALEN, true>
1021+
return invert_eo_qphix_helper<half, VECLEN_SP, QPHIX_SOALEN, true>
9971022
(Even_new,
9981023
Odd_new,
9991024
Even,
@@ -1005,7 +1030,7 @@ int invert_eo_qphix(spinor * const Even_new,
10051030
solver_params,
10061031
compression);
10071032
} else {
1008-
return invert_eo_qphix_helper<half, VECLEN_DP, QPHIX_SOALEN, false>
1033+
return invert_eo_qphix_helper<half, VECLEN_SP, QPHIX_SOALEN, false>
10091034
(Even_new,
10101035
Odd_new,
10111036
Even,

read_input.l

+72-4
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,19 @@ static inline void rmQuotes(char *str){
190190
double mu_Msap;
191191
192192
int use_preconditioning;
193+
194+
#ifdef TM_USE_QPHIX
195+
extern int qphix_input_By;
196+
extern int qphix_input_Bz;
197+
extern int qphix_input_NCores;
198+
extern int qphix_input_Sy;
199+
extern int qphix_input_Sz;
200+
extern int qphix_input_PadXY;
201+
extern int qphix_input_PadXYZ;
202+
extern int qphix_input_MinCt;
203+
#endif
204+
193205
194-
int use_qudainverter;
195206
%}
196207
197208
%option never-interactive
@@ -344,6 +355,8 @@ static inline void rmQuotes(char *str){
344355
%x LOWMEM
345356
%x SUBPROCESS
346357
358+
%x INITEXTERNALINVERTER
359+
347360
%%
348361
^SourceFilename{EQL} BEGIN(SOURCEFILE);
349362
^PropagatorFilename{EQL} BEGIN(PROPFILE);
@@ -412,8 +425,6 @@ static inline void rmQuotes(char *str){
412425
^NoSamples{EQL} BEGIN(NOSAMPLES);
413426
^SplittedPropagator{EQL} BEGIN(PROPSPLIT);
414427
^UsePreconditioning{EQL} BEGIN(PRECONDITIONING);
415-
^UseQudaInverter{EQL} BEGIN(QUDAINVERTER);
416-
^UseQphixInverter{EQL} BEGIN(QPHIXINVERTER);
417428
^UseCompression{EQL} BEGIN(COMPRESSION);
418429
419430
^BeginMeasurement{SPC}+ BEGIN(INITMEASUREMENT);
@@ -425,6 +436,8 @@ static inline void rmQuotes(char *str){
425436
^BeginInt BEGIN(INITINTEGRATOR);
426437
^BeginOperator{SPC}+ BEGIN(INITOPERATOR);
427438
439+
^BeginExternalInverter{SPC}+ BEGIN(INITEXTERNALINVERTER);
440+
428441
^PropagatorComparison{EQL} BEGIN(PCOMP);
429442
^NbCoresPerNode{EQL} BEGIN(NBCORES);
430443
@@ -1081,6 +1094,61 @@ static inline void rmQuotes(char *str){
10811094
}
10821095
}
10831096

1097+
<INITEXTERNALINVERTER>{TYPE} {
1098+
if(strcmp(yytext, "QPHIX")==0) {
1099+
if(myverbose) printf("Setting QPHIX external inverter parameters line %d\n", line_of_file);
1100+
BEGIN(QPHIXINVERTER);
1101+
} else {
1102+
printf("Error on line %d, inverter '%s' is unknown. Exiting!\n", line_of_file, yytext);
1103+
exit(1);
1104+
}
1105+
}
1106+
<QPHIXINVERTER>{
1107+
{SPC}*NCores{EQL}{DIGIT}+ {
1108+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1109+
qphix_input_NCores = a;
1110+
if(myverbose) printf(" Ncores = %d, line %d\n", a, line_of_file );
1111+
}
1112+
{SPC}*By{EQL}{DIGIT}+ {
1113+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1114+
qphix_input_By = a;
1115+
if(myverbose) printf(" By = %d, line %d\n", a, line_of_file );
1116+
}
1117+
{SPC}*Bz{EQL}{DIGIT}+ {
1118+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1119+
qphix_input_Bz = a;
1120+
if(myverbose) printf(" Bz = %d, line %d\n", a, line_of_file );
1121+
}
1122+
{SPC}*Sy{EQL}{DIGIT}+ {
1123+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1124+
qphix_input_Sy = a;
1125+
if(myverbose) printf(" Sy = %d, line %d\n", a, line_of_file );
1126+
}
1127+
{SPC}*Sz{EQL}{DIGIT}+ {
1128+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1129+
qphix_input_Sz = a;
1130+
if(myverbose) printf(" Sz = %d, line %d\n", a, line_of_file );
1131+
}
1132+
{SPC}*PadXY{EQL}{DIGIT}+ {
1133+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1134+
qphix_input_PadXY = a;
1135+
if(myverbose) printf(" PadXY = %d, line %d\n", a, line_of_file );
1136+
}
1137+
{SPC}*PadXYZ{EQL}{DIGIT}+ {
1138+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1139+
qphix_input_PadXYZ = a;
1140+
if(myverbose) printf(" PadXYZ = %d, line %d\n", a, line_of_file );
1141+
}
1142+
{SPC}*MinCt{EQL}{DIGIT}+ {
1143+
sscanf(yytext, " %[a-zA-Z] = %d", name, &a);
1144+
qphix_input_MinCt = a;
1145+
if(myverbose) printf(" MinCt = %d, line %d\n", a, line_of_file );
1146+
}
1147+
^EndExternalInverter{SPC}* {
1148+
if(myverbose) printf("QPHIX external inverter parameters parsed on line %d\n\n", line_of_file);
1149+
BEGIN(0);
1150+
}
1151+
}
10841152

10851153
<CSWSOLVER>{
10861154
increigcg {
@@ -2360,7 +2428,7 @@ static inline void rmQuotes(char *str){
23602428
BEGIN(comment_caller);
23612429
}
23622430

2363-
<INITMONOMIAL,DETMONOMIAL,CLDETMONOMIAL,CLDETRATMONOMIAL,CLDETRATRWMONOMIAL,NDPOLYMONOMIAL,NDRATMONOMIAL,NDRATCORMONOMIAL,NDCLRATMONOMIAL,NDCLRATCORMONOMIAL,CLPOLYMONOMIAL,GAUGEMONOMIAL,INTEGRATOR,INITINTEGRATOR,INITMEASUREMENT,PIONNORMMEAS,ONLINEMEAS,ORIENTEDPLAQUETTESMEAS,GRADIENTFLOWMEAS,INITOPERATOR,TMOP,DBTMOP,OVERLAPOP,WILSONOP,CLOVEROP,DBCLOVEROP,POLYMONOMIAL,PLOOP,INITGPU,GPU,RATMONOMIAL,RATCORMONOMIAL,CLRATMONOMIAL,CLRATCORMONOMIAL,INITDEFLATION,DEFLATION>{SPC}*\n {
2431+
<INITMONOMIAL,DETMONOMIAL,CLDETMONOMIAL,CLDETRATMONOMIAL,CLDETRATRWMONOMIAL,NDPOLYMONOMIAL,NDRATMONOMIAL,NDRATCORMONOMIAL,NDCLRATMONOMIAL,NDCLRATCORMONOMIAL,CLPOLYMONOMIAL,GAUGEMONOMIAL,INTEGRATOR,INITINTEGRATOR,INITMEASUREMENT,PIONNORMMEAS,ONLINEMEAS,ORIENTEDPLAQUETTESMEAS,GRADIENTFLOWMEAS,INITOPERATOR,TMOP,DBTMOP,OVERLAPOP,WILSONOP,CLOVEROP,DBCLOVEROP,POLYMONOMIAL,PLOOP,INITGPU,GPU,RATMONOMIAL,RATCORMONOMIAL,CLRATMONOMIAL,CLRATCORMONOMIAL,INITDEFLATION,DEFLATION,INITEXTERNALINVERTER,QPHIXINVERTER>{SPC}*\n {
23642432
line_of_file++;
23652433
}
23662434
<*>{SPC}*\n {
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
L=24
2+
T=48
3+
4+
# number of MPI tasks in T direction is computed automatically
5+
6+
# number of MPI tasks in Z direction
7+
nrzprocs=2
8+
9+
# currently only two-dimensional parallelisation works properly
10+
# also, qphix is slower when parallelized in x or y (especially x is poblematic)
11+
nrxprocs=1
12+
nryprocs=1
13+
14+
# OpenMP threads per MPI task
15+
# down below, Ncores * Sy * Sz = ompnumthreads
16+
ompnumthreads = 12
17+
18+
DebugLevel = 3
19+
InitialStoreCounter = 1000
20+
Measurements = 1
21+
2kappamu = 0.0008238
22+
kappa = 0.1373
23+
csw = 1.57551
24+
BCAngleT = 0
25+
GaugeConfigInputFile = conf
26+
disableiochecks=yes
27+
UseEvenOdd = yes
28+
29+
SourceType = point
30+
indices = 0
31+
ReadSource = no
32+
33+
userelativeprecision = no
34+
35+
BeginExternalInverter QPHIX
36+
# physical cores per MPI task
37+
NCores = 12
38+
39+
# block sizes (see qphix papers for details)
40+
By = 4
41+
Bz = 4
42+
MinCt = 2
43+
44+
# thread geometry
45+
# ompnumthreads = Ncores * Sy * Sz
46+
# hyperthreads should be specified here
47+
Sy = 1
48+
Sz = 1
49+
50+
# paddings in XY and XYZ blocks
51+
PadXY = 0
52+
PadXYZ = 0
53+
EndExternalInverter
54+
55+
BeginOperator WILSON
56+
kappa = 0.132
57+
Solver = cg
58+
# solverprecision must be <= 1e-13 such that the CG in double precision is launched
59+
# the other floating point precisions (single, half) seem to segfault currently
60+
SolverPrecision = 1e-17
61+
MaxSolverIterations = 20000
62+
useqphixinverter = yes
63+
EndOperator
64+

test_Dslash.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <config.h>
1717
#endif
1818
#ifdef TM_USE_QPHIX
19-
#include "qphix/qphix_config.h"
19+
#include <qphix/qphix_config.h>
2020
#endif
2121
#include <float.h>
2222
#include <math.h>

0 commit comments

Comments
 (0)