-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathdirac_quda.h
More file actions
2657 lines (2231 loc) · 118 KB
/
dirac_quda.h
File metadata and controls
2657 lines (2231 loc) · 118 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include <typeinfo>
#include <quda_internal.h>
#include <timer.h>
#include <color_spinor_field.h>
#include <gauge_field.h>
#include <clover_field.h>
#include <blas_quda.h>
#include <field_cache.h>
#include <memory>
namespace quda {
// Forward declare: MG Transfer Class
class Transfer;
// Forward declare: Dirac Op Base Class
class Dirac;
// Params for Dirac operator
class DiracParam {
public:
QudaDiracType type;
double kappa;
double mass;
double m5; // used by domain wall only
int Ls; // used by domain wall and twisted mass
Complex b_5[QUDA_MAX_DWF_LS]; // used by mobius domain wall only
Complex c_5[QUDA_MAX_DWF_LS]; // used by mobius domain wall only
// The EOFA parameters. See the description in InvertParam
double eofa_shift;
int eofa_pm;
double mq1;
double mq2;
double mq3;
QudaMatPCType matpcType;
QudaDagType dagger;
GaugeField *gauge;
GaugeField *fatGauge; // used by staggered only
GaugeField *longGauge; // used by staggered only
int laplace3D;
int covdev_mu;
bool covdev_shift;
CloverField *clover;
GaugeField *xInvKD; // used for the Kahler-Dirac operator only
double mu; // used by twisted mass only
double mu_factor; // used by multigrid only
double epsilon; //2nd tm parameter (used by twisted mass only)
double tm_rho; // "rho"-type Hasenbusch mass used for twisted clover (like regular rho but
// applied like a twisted mass and ignored in the inverse)
array<int, QUDA_MAX_DIM> commDim; // whether to do comms or not
QudaPrecision halo_precision; // only does something for DiracCoarse at present
// for multigrid only
Transfer *transfer;
Dirac *dirac;
bool need_bidirectional; // whether or not we need to force a bi-directional build
bool setup_use_mma; // whether to use tensor cores where applicable for setup
bool dslash_use_mma; // whether to use tensor cores where applicable for dslash
bool allow_truncation; /** whether or not we let MG coarsening drop improvements, for ex drop long links for small aggregate dimensions */
bool use_mobius_fused_kernel; // Whether or not use fused kernels for Mobius
double distance_pc_alpha0; // used by distance preconditioning
int distance_pc_t0; // used by distance preconditioning
// Default constructor
DiracParam() :
type(QUDA_INVALID_DIRAC),
kappa(0.0),
m5(0.0),
matpcType(QUDA_MATPC_INVALID),
dagger(QUDA_DAG_INVALID),
gauge(0),
clover(0),
mu(0.0),
mu_factor(0.0),
epsilon(0.0),
tm_rho(0.0),
halo_precision(QUDA_INVALID_PRECISION),
need_bidirectional(false),
#ifdef QUDA_MMA_AVAILABLE
setup_use_mma(true),
#else
setup_use_mma(false),
#endif
dslash_use_mma(false),
allow_truncation(false),
#ifdef NVSHMEM_COMMS
use_mobius_fused_kernel(false),
#else
use_mobius_fused_kernel(true),
#endif
distance_pc_alpha0(0.0),
distance_pc_t0(-1)
{
for (int i=0; i<QUDA_MAX_DIM; i++) commDim[i] = 1;
}
// Pretty print the args struct
void print() {
printfQuda("Printing DslashParam\n");
printfQuda("type = %d\n", type);
printfQuda("kappa = %g\n", kappa);
printfQuda("mass = %g\n", mass);
printfQuda("laplace3D = %d\n", laplace3D);
printfQuda("covdev_mu = %d\n", covdev_mu);
printfQuda("covdev_shift = %d\n", covdev_shift);
printfQuda("m5 = %g\n", m5);
printfQuda("Ls = %d\n", Ls);
printfQuda("matpcType = %d\n", matpcType);
printfQuda("dagger = %d\n", dagger);
printfQuda("mu = %g\n", mu);
printfQuda("tm_rho = %g\n", tm_rho);
printfQuda("epsilon = %g\n", epsilon);
printfQuda("halo_precision = %d\n", halo_precision);
for (int i=0; i<QUDA_MAX_DIM; i++) printfQuda("commDim[%d] = %d\n", i, commDim[i]);
for (int i = 0; i < Ls; i++)
printfQuda(
"b_5[%d] = %e %e \t c_5[%d] = %e %e\n", i, b_5[i].real(), b_5[i].imag(), i, c_5[i].real(), c_5[i].imag());
printfQuda("setup_use_mma = %d\n", setup_use_mma);
printfQuda("dslash_use_mma = %d\n", dslash_use_mma);
printfQuda("allow_truncation = %d\n", allow_truncation);
printfQuda("use_mobius_fused_kernel = %s\n", use_mobius_fused_kernel ? "true" : "false");
printfQuda("distance_pc_alpha0 = %g\n", distance_pc_alpha0);
printfQuda("distance_pc_t0 = %d\n", distance_pc_t0);
}
};
// This is a free function:
// Dirac params structure
// inv_param structure
// pc -> preconditioned.
void setDiracParam(DiracParam &diracParam, QudaInvertParam *inv_param, bool pc);
// This is a free function.
void setDiracSloppyParam(DiracParam &diracParam, QudaInvertParam *inv_param, bool pc);
// forward declarations
class DiracMatrix; // What are the differences in these classes?
class DiracM;
class DiracMdagM;
class DiracMdagMLocal;
class DiracMMdag;
class DiracMdag;
class DiracG5M;
//Forward declaration of multigrid Transfer class
class Transfer;
// Abstract base class
class Dirac : public Object {
friend class DiracMatrix;
friend class DiracM;
friend class DiracMdagM;
friend class DiracMdagMLocal;
friend class DiracMMdag;
friend class DiracMdag;
friend class DiracG5M;
protected:
GaugeField *gauge;
double kappa;
double mass;
int laplace3D;
QudaMatPCType matpcType;
QudaParity this_parity;
QudaParity other_parity;
bool symmetric;
mutable QudaDagType dagger; // mutable to simplify implementation of Mdag
QudaDiracType type;
mutable QudaPrecision halo_precision; // only does something for DiracCoarse at present
mutable array<int, QUDA_MAX_DIM> commDim; // whether do comms or not
bool use_mobius_fused_kernel; // Whether or not use fused kernels for Mobius
double distance_pc_alpha0; // Used by distance preconditioning
int distance_pc_t0; // Used by distance preconditioning
mutable TimeProfile profile;
public:
Dirac(const DiracParam ¶m); // construct from params
Dirac(const Dirac &dirac); // Copy construct
virtual ~Dirac(); // virtual destructor as this is a base class
Dirac &operator=(const Dirac &dirac); // assignment
/**
@brief Enable / disable communications for the Dirac operator
@param[in] commDim_ Array of booleans which determines whether
communications are enabled
*/
void setCommDim(const int commDim_[QUDA_MAX_DIM]) const {
for (int i=0; i<QUDA_MAX_DIM; i++) { commDim[i] = commDim_[i]; }
}
/**
@brief Whether the Dirac object is the DiracCoarse.
*/
virtual bool isCoarse() const { return false; }
/**
@brief static function that returns if a Dirac type is staggered-type depending on a QudaDiracType
*/
static bool is_wilson_type(QudaDiracType);
/**
@brief static function that returns if a Dslash type is staggered-type depending on a QudaDslashType
*/
static bool is_wilson_type(QudaDslashType);
/**
@brief return if the operator is a Wilson-type 4-d operator
*/
bool isWilsonType() const { return Dirac::is_wilson_type(getDiracType()); }
/**
@brief static function that returns if a Dirac type is staggered-type depending on a QudaDiracType
*/
static bool is_staggered_type(QudaDiracType);
/**
@brief static function that returns if a Dslash type is staggered-type depending on a QudaDslashType
*/
static bool is_staggered_type(QudaDslashType);
/**
@brief return if the operator is a staggered operator
*/
bool isStaggered() const { return Dirac::is_staggered_type(getDiracType()); }
/**
@brief static function that returns if a Dirac type is asqtad depending on a QudaDiracType
*/
static bool is_asqtad(QudaDiracType);
/**
@brief static function that returns if a Dslash type is asqtaddepending on a QudaDslashType
*/
static bool is_asqtad(QudaDslashType);
/**
@brief return if the operator is a staggered operator
*/
bool isAsqtad() const { return Dirac::is_asqtad(getDiracType()); }
/**
@brief static function that returns if a Dirac type is a domain wall operator (5-dimensional) depending on a QudaDiracType
*/
static bool is_dwf(QudaDiracType);
/**
@brief static function that returns if a Dslash type is a domain wall operator (5-dimensional) depending on a QudaDslashType
*/
static bool is_dwf(QudaDslashType);
/**
@brief return if the operator is a domain wall operator, that is, 5-dimensional
*/
bool isDwf() const { return Dirac::is_dwf(getDiracType()); }
/**
@brief Check parity spinors are usable (check geometry ?)
*/
virtual void checkParitySpinor(cvector_ref<const ColorSpinorField> &, cvector_ref<const ColorSpinorField> &) const;
/**
@brief check full spinors are compatible (check geometry ?)
*/
virtual void checkFullSpinor(cvector_ref<const ColorSpinorField> &, cvector_ref<const ColorSpinorField> &) const;
/**
@brief check spinors do not alias
*/
void checkSpinorAlias(cvector_ref<const ColorSpinorField> &, cvector_ref<const ColorSpinorField> &) const;
/**
@brief Whether or not the operator has a single-parity Dslash
*/
virtual bool hasDslash() const { return true; }
/**
@brief apply 'dslash' operator for the DiracOp. This may be e.g. AD
*/
virtual void Dslash(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity) const = 0;
/**
@brief Xpay version of Dslash
*/
virtual void DslashXpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity, cvector_ref<const ColorSpinorField> &x, double k) const = 0;
/**
@brief Similar to the Xpay version of Dslash, but used only by the Laplace op for
smearing.
*/
virtual void SmearOp(cvector_ref<ColorSpinorField> &, cvector_ref<const ColorSpinorField> &, double, double, int,
QudaParity) const
{
errorQuda("Not implemented.");
}
/**
@brief Apply M for the dirac op. E.g. the Schur Complement operator
*/
virtual void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const = 0;
/**
@brief Apply MdagM operator which may be optimized
*/
virtual void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const = 0;
/**
@brief Apply the local MdagM operator: equivalent to applying
zero Dirichlet boundary condition to MdagM on each
rank. Depending on the number of stencil steps of the fermion
type, this may require additional effort to include the terms
that hop out of the boundary and then hop back.
*/
virtual void MdagMLocal(cvector_ref<ColorSpinorField> &, cvector_ref<const ColorSpinorField> &) const
{
errorQuda("Not implemented!\n");
}
/**
@brief Apply the local MdagM operator: equivalent to applying zero Dirichlet
boundary condition to MdagM on each rank. Depending on the number of
stencil steps of the fermion type, this may require additional effort
to include the terms that hop out of the boundary and then hop back.
*/
virtual void Dslash4(cvector_ref<ColorSpinorField> &, cvector_ref<const ColorSpinorField> &, QudaParity) const
{
errorQuda("Not implemented!");
}
/**
@brief Apply Mdag (daggered operator of M)
*/
virtual void Mdag(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const;
/**
@brief Apply Normal Operator
*/
virtual void MMdag(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const;
/**
@brief Prepare the source and solution vectors for solving given the solution type
@param[out] out Prepared solution vectors
@param[out] in Prepared source vectors vectors
*/
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const = 0;
/**
@brief Reconstruct the solution vectors given the solution type
@param[in,out] x Reconstructed solution vectors
@param[in] b Source vector we are solving against
*/
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const = 0;
// special prepare/recon methods that go into PreconditionedSolve in MG
virtual void prepareSpecialMG(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const
{
prepare(out, in, x, b, solType);
}
virtual void reconstructSpecialMG(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const
{
reconstruct(x, b, solType);
}
/**
@brief specifies whether or not there's a specialized prepare/reconstruct
used before/after transfering to/from the coarse level in MG
@return whether or not a specialized routine should be used
*/
virtual bool hasSpecialMG() const { return false; }
void setMass(double mass){ this->mass = mass;}
// Dirac operator factory
/**
@brief Creates a subclass from parameters
*/
static Dirac* create(const DiracParam ¶m);
/**
@brief accessor for Kappa (mass parameter)
*/
double Kappa() const { return kappa; }
/**
@brief accessor for Mass (in case of a factor of 2 for staggered)
*/
virtual double Mass() const { return mass; } // in case of factor of 2 convention for staggered
/**
@brief accessor for twist parameter -- overrride can return better value
*/
virtual double Mu() const { return 0.; }
/**
@brief accessor for mu factoo for MG/ -- override can return a better value
*/
virtual double MuFactor() const { return 0.; }
/**
@brief accessor for if we let MG coarsening drop we can drop improvements, for ex long links for small aggregation dimensions
*/
virtual bool AllowTruncation() const { return false; }
/**
@brief returns preconditioning type
*/
QudaMatPCType getMatPCType() const { return matpcType; }
/**
@brief returns the number of stencil applications per dslash application; 1 for operators with
a single hopping term (generally full operators), 2 for composite operators
that consist of two hopping terms (generally PC operators)
*/
virtual int getStencilSteps() const = 0;
/**
@brief sets whether operator is daggered or not
*/
void Dagger(QudaDagType dag) const { dagger = dag; }
/**
@brief Flips value of daggered
*/
void flipDagger() const { dagger = (dagger == QUDA_DAG_YES) ? QUDA_DAG_NO : QUDA_DAG_YES; }
/**
@brief is operator hermitian
*/
virtual bool hermitian() const { return false; }
/** @brief returns the Dirac type
@return Dirac type
*/
virtual QudaDiracType getDiracType() const = 0;
/** @brief returns the Dslash type
@return Dslash type
*/
QudaDslashType getDslashType() const { return dirac_to_dslash_type(getDiracType()); }
/**
@brief static function that returns the QudaDslashType corresponding to a QudaDiracType
*/
static QudaDslashType dirac_to_dslash_type(QudaDiracType);
/**
@brief Return the one-hop field for staggered operators for MG setup
@return Error for non-staggered operators
*/
virtual GaugeField *getStaggeredShortLinkField() const
{
errorQuda("Invalid dirac type %d", getDiracType());
return nullptr;
}
/**
@brief return the long link field for staggered operators for MG setup, if it exists
@return Error for non-improved staggered operators
*/
virtual GaugeField *getStaggeredLongLinkField() const
{
errorQuda("Invalid dirac type %d", getDiracType());
return nullptr;
}
/**
* @brief Update the internal gauge, fat gauge, long gauge, clover field pointer as appropriate.
* These are pointers as opposed to references to support passing in `nullptr`.
*
* @param gauge_in Updated gauge field
* @param fat_gauge_in Updated fat links
* @param long_gauge_in Updated long links
* @param clover_in Updated clover field
*/
virtual void updateFields(GaugeField *gauge_in, GaugeField *, GaugeField *, CloverField *) { gauge = gauge_in; }
/**
* @brief Create the coarse operator (virtual parent)
*
* @param Y[out] Coarse link field
* @param X[out] Coarse clover field
* @param T[in] Transfer operator defining the coarse grid
* @param kappa Kappa parameter for the coarse operator
* @param mass Mass parameter for the coarse operator (gets explicitly built into clover, hard coded to zero for
* non-staggered ops)
* @param mu TM mu parameter for the coarse operator
* @param mu_factor multiplicative factor for the mu parameter
* @param allow_truncation [in] whether or not we let coarsening drop improvements, for ex dropping long links for
* small aggregate sizes
*/
virtual void createCoarseOp(GaugeField &, GaugeField &, const Transfer &, double, double, double, double, bool) const
{errorQuda("Not implemented");}
QudaPrecision HaloPrecision() const { return halo_precision; }
void setHaloPrecision(QudaPrecision halo_precision_) const { halo_precision = halo_precision_; }
bool useDistancePC() const { return ((distance_pc_alpha0 != 0) && (distance_pc_t0 >= 0)); }
/**
@brief If managed memory and prefetch is enabled, prefetch
the gauge field and temporary spinors to the CPU or GPU
as requested. Overloads may also grab a clover term
@param[in] mem_space Memory space we are prefetching to
@param[in] stream Which stream to run the prefetch in (default 0)
*/
virtual void prefetch(QudaFieldLocation mem_space, qudaStream_t stream = device::get_default_stream()) const;
};
// Full Wilson
class DiracWilson : public Dirac {
protected:
void initConstants();
public:
DiracWilson(const DiracParam ¶m);
DiracWilson(const DiracWilson &dirac);
DiracWilson(const DiracParam ¶m, const int nDims); // to correctly adjust face for DW and non-deg twisted mass
DiracWilson& operator=(const DiracWilson &dirac);
virtual void Dslash(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity) const override;
virtual void DslashXpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity, cvector_ref<const ColorSpinorField> &x, double k) const override;
virtual void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 1; }
virtual QudaDiracType getDiracType() const override { return QUDA_WILSON_DIRAC; }
/**
* @brief Create the coarse Wilson operator.
*
* @details Takes the multigrid transfer class, which knows
* about the coarse grid blocking, as well as
* having prolongate and restrict member functions,
* and returns color matrices Y[0..2*dim-1] corresponding
* to the coarse grid hopping terms and X corresponding to
* the coarse grid "clover" term.
*
* @param Y[out] Coarse link field
* @param X[out] Coarse clover field
* @param T[in] Transfer operator defining the coarse grid
* @param mass Mass parameter for the coarse operator (hard coded to 0 when CoarseOp is called)
* @param kappa Kappa parameter for the coarse operator
* @param allow_truncation [in] whether or not we let coarsening drop improvements, none available for Wilson operator
*/
virtual void createCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, double kappa, double mass = 0.,
double mu = 0., double mu_factor = 0., bool allow_truncation = false) const override;
};
// Even-odd preconditioned Wilson
class DiracWilsonPC : public DiracWilson {
private:
public:
DiracWilsonPC(const DiracParam ¶m);
DiracWilsonPC(const DiracWilsonPC &dirac);
DiracWilsonPC& operator=(const DiracWilsonPC &dirac);
void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 2; }
virtual QudaDiracType getDiracType() const override { return QUDA_WILSONPC_DIRAC; }
};
// Full clover
class DiracClover : public DiracWilson {
protected:
CloverField *clover;
void checkParitySpinor(cvector_ref<const ColorSpinorField> &, cvector_ref<const ColorSpinorField> &) const override;
void initConstants();
public:
DiracClover(const DiracParam ¶m);
DiracClover(const DiracClover &dirac);
virtual ~DiracClover();
DiracClover& operator=(const DiracClover &dirac);
// Apply clover
void Clover(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in, QudaParity parity) const;
virtual void DslashXpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity, cvector_ref<const ColorSpinorField> &x, double k) const override;
virtual void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 1; }
virtual QudaDiracType getDiracType() const override { return QUDA_CLOVER_DIRAC; }
/**
* @brief Update the internal gauge, fat gauge, long gauge, clover field pointer as appropriate.
* These are pointers as opposed to references to support passing in `nullptr`.
*
* @param gauge_in Updated gauge field
* @param fat_gauge_in Updated fat links
* @param long_gauge_in Updated long links
* @param clover_in Updated clover field
*/
virtual void updateFields(GaugeField *gauge_in, GaugeField *, GaugeField *, CloverField *clover_in) override
{
DiracWilson::updateFields(gauge_in, nullptr, nullptr, nullptr);
clover = clover_in;
}
/**
* @brief Create the coarse clover operator
*
* @details Takes the multigrid transfer class, which knows
* about the coarse grid blocking, as well as
* having prolongate and restrict member functions,
* and returns color matrices Y[0..2*dim-1] corresponding
* to the coarse grid hopping terms and X corresponding to
* the coarse grid "clover" term.
*
* @param T[in] Transfer operator defining the coarse grid
* @param Y[out] Coarse link field
* @param X[out] Coarse clover field
* @param kappa Kappa parameter for the coarse operator
* @param mass Mass parameter for the coarse operator (hard coded to 0 when CoarseOp is called)
* @param allow_truncation [in] whether or not we let coarsening drop improvements, none available for clover operator
*/
void createCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, double kappa, double mass = 0., double mu = 0.,
double mu_factor = 0., bool allow_truncation = false) const override;
/**
@brief If managed memory and prefetch is enabled, prefetch
all relevant memory fields (gauge, clover, temporary spinors)
to the CPU or GPU as requested
@param[in] mem_space Memory space we are prefetching to
@param[in] stream Which stream to run the prefetch in (default 0)
*/
virtual void prefetch(QudaFieldLocation mem_space, qudaStream_t stream = device::get_default_stream()) const override;
};
// Even-odd preconditioned clover
class DiracCloverPC : public DiracClover {
public:
DiracCloverPC(const DiracParam ¶m);
DiracCloverPC(const DiracCloverPC &dirac);
virtual ~DiracCloverPC();
DiracCloverPC& operator=(const DiracCloverPC &dirac);
// Clover is inherited from parent
// Clover Inv is new
void CloverInv(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in, QudaParity parity) const;
// Dslash is redefined as A_pp^{-1} D_p\bar{p}
virtual void Dslash(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity) const override;
// out = x + k A_pp^{-1} D_p\bar{p}
virtual void DslashXpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity, cvector_ref<const ColorSpinorField> &x, double k) const override;
// Can implement: M as e.g. : i) tmp_e = A^{-1}_ee D_eo in_o (Dslash)
// ii) out_o = in_o + A_oo^{-1} D_oe tmp_e (AXPY)
void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
// squared op
void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 2; }
virtual QudaDiracType getDiracType() const override { return QUDA_CLOVERPC_DIRAC; }
/**
* @brief Create the coarse even-odd preconditioned clover
* operator. Unlike the Wilson operator, the coarsening of the
* preconditioned clover operator differs from that of the
* unpreconditioned clover operator, so we need to specialize it.
*
* @param T[in] Transfer operator defining the coarse grid
* @param Y[out] Coarse link field
* @param X[out] Coarse clover field
* @param kappa Kappa parameter for the coarse operator
* @param mass Mass parameter for the coarse operator (set to zero)
* @param allow_truncation [in] whether or not we let coarsening drop improvements, none available for clover operator
*/
void createCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, double kappa, double mass = 0., double mu = 0.,
double mu_factor = 0., bool allow_truncation = false) const override;
/**
@brief If managed memory and prefetch is enabled, prefetch
all relevant memory fields (gauge, clover, temporary spinors).
Will only grab the inverse clover unless the clover field
is needed for asymmetric preconditioning
to the CPU or GPU as requested
@param[in] mem_space Memory space we are prefetching to
@param[in] stream Which stream to run the prefetch in (default 0)
*/
virtual void prefetch(QudaFieldLocation mem_space, qudaStream_t stream = device::get_default_stream()) const override;
};
// Full clover with Hasenbusch Twist
//
// [ A_ee -k D_eo ]
// [ -k D_oe A_oo + i mu g_5 A_oo^2 ]
//
// A_oo + i mu g_5 A_oo^2 = A_oo( 1 + i mu g_5 A_oo)
class DiracCloverHasenbuschTwist : public DiracClover
{
protected:
double mu;
public:
DiracCloverHasenbuschTwist(const DiracParam ¶m);
DiracCloverHasenbuschTwist(const DiracCloverHasenbuschTwist &dirac);
virtual ~DiracCloverHasenbuschTwist();
DiracCloverHasenbuschTwist &operator=(const DiracCloverHasenbuschTwist &dirac);
virtual void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual int getStencilSteps() const override
{
// implemented as separate even, odd D_{eo} D_{oe}
return 2;
}
virtual QudaDiracType getDiracType() const override { return QUDA_CLOVER_HASENBUSCH_TWIST_DIRAC; }
/**
* @brief Create the coarse clover operator
*
* @param T[in] Transfer operator defining the coarse grid
* @param Y[out] Coarse link field
* @param X[out] Coarse clover field
* @param kappa Kappa parameter for the coarse operator
* @param mass Mass parameter for the coarse operator (hard coded to 0 when CoarseOp is called)
* @param allow_truncation [in] whether or not we let coarsening drop improvements, none available for clover
*/
void createCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, double kappa, double mass = 0., double mu = 0.,
double mu_factor = 0., bool allow_truncation = false) const override;
};
// Even-odd preconditioned clover
class DiracCloverHasenbuschTwistPC : public DiracCloverPC
{
protected:
double mu;
public:
DiracCloverHasenbuschTwistPC(const DiracParam ¶m);
DiracCloverHasenbuschTwistPC(const DiracCloverHasenbuschTwistPC &dirac);
virtual ~DiracCloverHasenbuschTwistPC();
DiracCloverHasenbuschTwistPC &operator=(const DiracCloverHasenbuschTwistPC &dirac);
// Clover is inherited from parent
// Clover Inv is inherited from parent
// Dslash is defined as A_pp^{-1} D_p\bar{p} and is inherited
// DslashXPay is inherited (for reconstructs and such)
// out = (1 +/- ig5 mu A)x + k A^{-1} D in
void DslashXpayTwistClovInv(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity, cvector_ref<const ColorSpinorField> &x, double k, double b) const;
// out = ( 1+/- i g5 mu A) x - D in
void DslashXpayTwistNoClovInv(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity, cvector_ref<const ColorSpinorField> &x, double k, double b) const;
// Can implement: M as e.g. : i) tmp_e = A^{-1}_ee D_eo in_o (Dslash)
// ii) out_o = in_o + A_oo^{-1} D_oe tmp_e (AXPY)
void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
// squared op
void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual int getStencilSteps() const override { return 2; }
virtual QudaDiracType getDiracType() const override { return QUDA_CLOVER_HASENBUSCH_TWISTPC_DIRAC; }
/**
* @brief Create the coarse even-odd preconditioned clover
* operator. Unlike the Wilson operator, the coarsening of the
* preconditioned clover operator differs from that of the
* unpreconditioned clover operator, so we need to specialize it.
*
* @param T[in] Transfer operator defining the coarse grid
* @param Y[out] Coarse link field
* @param X[out] Coarse clover field
* @param kappa Kappa parameter for the coarse operator
* @param mass Mass parameter for the coarse operator (set to zero)
* @param allow_truncation [in] whether or not we let coarsening drop improvements, none available for clover hasenbusch
*/
void createCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, double kappa, double mass = 0., double mu = 0.,
double mu_factor = 0., bool allow_truncation = false) const override;
};
// Full domain wall
class DiracDomainWall : public DiracWilson {
protected:
double m5;
double kappa5;
int Ls; // length of the fifth dimension
/**
@brief Check whether the input and output are valid 5-d fields
@param[in] out Output field set we checking
@param[in] in Input field set we checking
*/
void checkDWF(cvector_ref<const ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const;
public:
DiracDomainWall(const DiracParam ¶m);
DiracDomainWall(const DiracDomainWall &dirac);
virtual ~DiracDomainWall();
DiracDomainWall& operator=(const DiracDomainWall &dirac);
void Dslash(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity) const override;
void DslashXpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in, QudaParity parity,
cvector_ref<const ColorSpinorField> &x, double k) const override;
virtual void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 1; }
virtual QudaDiracType getDiracType() const override { return QUDA_DOMAIN_WALL_DIRAC; }
};
// 5d Even-odd preconditioned domain wall
class DiracDomainWallPC : public DiracDomainWall {
private:
public:
DiracDomainWallPC(const DiracParam ¶m);
DiracDomainWallPC(const DiracDomainWallPC &dirac);
virtual ~DiracDomainWallPC();
DiracDomainWallPC& operator=(const DiracDomainWallPC &dirac);
void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 2; }
virtual QudaDiracType getDiracType() const override { return QUDA_DOMAIN_WALLPC_DIRAC; }
};
// Full domain wall, but with 4-d parity ordered fields
class DiracDomainWall4D : public DiracDomainWall
{
public:
DiracDomainWall4D(const DiracParam ¶m);
DiracDomainWall4D(const DiracDomainWall4D &dirac);
virtual ~DiracDomainWall4D();
DiracDomainWall4D &operator=(const DiracDomainWall4D &dirac);
void Dslash4(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity) const override;
void Dslash5(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const;
void Dslash4Xpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in, QudaParity parity,
cvector_ref<const ColorSpinorField> &x, double k) const;
void Dslash5Xpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
cvector_ref<const ColorSpinorField> &x, double k) const;
void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 1; }
virtual QudaDiracType getDiracType() const override { return QUDA_DOMAIN_WALL_4D_DIRAC; }
};
// 4d Even-odd preconditioned domain wall
class DiracDomainWall4DPC : public DiracDomainWall4D
{
public:
DiracDomainWall4DPC(const DiracParam ¶m);
DiracDomainWall4DPC(const DiracDomainWall4DPC &dirac);
virtual ~DiracDomainWall4DPC();
DiracDomainWall4DPC &operator=(const DiracDomainWall4DPC &dirac);
void M5inv(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const;
void M5invXpay(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
cvector_ref<const ColorSpinorField> &x, double k) const;
void M(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
void MdagM(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in) const override;
virtual void prepare(cvector_ref<ColorSpinorField> &out, cvector_ref<ColorSpinorField> &in,
cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual void reconstruct(cvector_ref<ColorSpinorField> &x, cvector_ref<const ColorSpinorField> &b,
const QudaSolutionType solType) const override;
virtual int getStencilSteps() const override { return 2; }
virtual QudaDiracType getDiracType() const override { return QUDA_DOMAIN_WALL_4DPC_DIRAC; }
};
// Full Mobius
class DiracMobius : public DiracDomainWall {
protected:
//Mobius coefficients
Complex b_5[QUDA_MAX_DWF_LS];
Complex c_5[QUDA_MAX_DWF_LS];
/**
Whether we are using classical Mobius with constant real-valued
b and c coefficients, or zMobius with complex-valued variable
coefficients
*/
bool zMobius;
double mobius_kappa_b;
double mobius_kappa_c;
double mobius_kappa;
public:
DiracMobius(const DiracParam ¶m);
// DiracMobius(const DiracMobius &dirac);
// virtual ~DiracMobius();
// DiracMobius& operator=(const DiracMobius &dirac);
void Dslash4(cvector_ref<ColorSpinorField> &out, cvector_ref<const ColorSpinorField> &in,
QudaParity parity) const override;