su2hmc
Loading...
Searching...
No Matches
Clover Force
Collaboration diagram for Clover Force:

Classes

struct  Bilinear_a
 Structure of arrays for Hermitian bilinear \(X_{\mu\nu}\) in memory. More...
struct  Bilinear
 Hermitian bilinear \(X_{\mu\nu}\) on the local stack. More...

Functions

void CalcXmunu (Bilinear_a Xmunu, Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, const unsigned short mu, const unsigned short nu)
 Gets \(X_{\mu\nu}\) for the clover force.
void Clov_Force (double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, unsigned int *iu, unsigned int *id, const float akappa)
 Gets the clover contribution to the force.
void cuCalcXmunu (Bilinear_a Xmunu, Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, const unsigned short mu, const unsigned short nu)
 CUDA wrapper for CalcXmunu. Only called during testing to be honest.
int cuClov_Force (double *dSdpi, Complex_f *ut[nc], Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, const unsigned int *iu, const unsigned int *id, const float akappa)
 CUDA wrapper for Clover_Force.
static void GetBilinear (Complex_f Z[nc *nc], Bilinear_a Xmn, unsigned int ind)
 Loads the compacted bilinear form into a \(2\times2\) complex valued matrix.
static void GLeft (Complex_f out[4], const Complex_f G[2], const Complex_f X[4])
 Multiplies \( X_{\mu\nu}\) by a gauge field from the left.
static void GRight (Complex_f out[4], const Complex_f G[2], const Complex_f X[4])
 Multiplies \( X_{\mu\nu}\) by a gauge field from the right.
static void GSandwich (Complex_f out[4], Complex_f tmp[4], const Complex_f Gl[2], const Complex_f X[4], const Complex_f Gr[2])
 Multiplies \( X_{\mu\nu}\) by a gauge field from the left and the right.
template<typename T>
__device__ void Device::cuByGenLeft (T a[nc], const unsigned short gen)
 Multiply leaf (or part of one) by generator from left.
template<typename T>
__device__ void Device::cuByGenRight (T a[nc], const unsigned short gen)
 Multiply leaf (or part of one) by generator from right.
template<typename T>
__device__ void Device::cuGLeft (T out[4], const T G[2], const T X[4])
 Multiplies \( X_{\mu\nu}\) by a gauge field from the left.
template<typename T>
__device__ void Device::cuGRight (T out[4], const T G[2], const T X[4])
 Multiplies \( X_{\mu\nu}\) by a gauge field from the right.
template<typename T>
__device__ void Device::cuGSandwich (T out[4], T tmp[4], const T Gl[2], const T X[4], const T Gr[2])
 Multiplies \( X_{\mu\nu}\) by a gauge field from the left and the right.
__device__ void Device::GetBilinear (Complex_f Z[nc *nc], Bilinear_a Xmn, unsigned int ind)
 Loads the compacted bilinear form into a \(2\times2\) complex valued matrix.
template<typename T>
__global__ void Kernels::cuCalcXmunu (Bilinear_a Xmunu, const complex< T > *X1, const complex< T > *X2, const __grid_constant__ complex< T > sigval_G[24], const __grid_constant__ unsigned short sigin_G[24], const __grid_constant__ unsigned short clov)
 Gets \(X_{\mu\nu}\) for the clover force.
template<typename T>
__global__ void Kernels::Clov_Force (double *dSdpi, const complex< T > *u11t, const complex< T > *u12t, const Bilinear_a Xmn, const unsigned int *iu, const unsigned int *id, const __grid_constant__ float akappa, const __grid_constant__ unsigned short mu, const __grid_constant__ unsigned short nu)
 cuGets the clover contribution to the force

Detailed Description

Function Documentation

◆ CalcXmunu()

void CalcXmunu ( Bilinear_a Xmunu,
Complex_f * X1,
Complex_f * X2,
const Complex_f * sigval,
const unsigned short * sigin,
const unsigned short mu,
const unsigned short nu )

Gets \(X_{\mu\nu}\) for the clover force.

Parameters
[out]XmunuAll Xmunu values
[in]X1Congrad output \(\left(M^\dagger M\right)\Phi\)
[in]X2\(M\left(M^\dagger M\right)^{-1}\Phi\)
[in]sigval\(\sigma_{\mu\nu}\) scaled by \(\frac{c_\text{SW}}{2}\)
[in]siginDirac index of \(\sigma_{\mu\nu}\)
[in]mu,nuLattice directions
Postcondition
Bilinears written to Xmunu

Definition at line 436 of file clover.c.

437 {
438 const char funcname[] = "Xmunu";
439#ifdef USE_GPU
440 cuCalcXmunu(Xmunu,X1,X2,sigval,sigin,mu,nu);
441#else
442 unsigned short clov;
443 //Get sign and index of @f$\sigma_{\mu\nu}@f$ correct
444 clov = (mu==0) ? nu-1 : mu+nu;
445#pragma omp parallel for simd aligned(X1,X2:AVX)
446 for(unsigned int i=0;i<kvol;i++){
447 //Buffer. Four registers
448 Bilinear Xmn;
449 Xmn.diag[0]=Xmn.diag[1]=0;Xmn.offd=0;
450 for(unsigned short idirac=0; idirac<ndirac*nc; idirac+=nc){
451 const unsigned short sind = sigin[clov*ndirac+(idirac>>1)]<<1;
452 const Complex_f sig = sigval[clov*ndirac+(idirac>>1)];
453#pragma unroll
454 for(unsigned short c1=0;c1<nc;c1++){
455 //Spinors (rows) So we only load from memory once.
456 const Complex_f X1s = X1[i+kvolHalo*(sind+c1)];
457 const Complex_f X2s = X2[i+kvolHalo*(sind+c1)];
458#pragma unroll
459 for(unsigned short c2=0;c2<nc;c2++){
460 //The second off diagonal term is the conjugate of the first
461 if(c1==1&&c2==0)
462 continue;
463 //Conjugated spinor (columns).
464 const Complex_f X1c = conjf(X1[i+kvolHalo*(idirac+c2)]);
465 const Complex_f X2c = conjf(X2[i+kvolHalo*(idirac+c2)]);
466 if(c1==c2)
467 Xmn.diag[c1]+=creal(sig*(X2s*X1c+X1s*X2c));
468 else
469 Xmn.offd+=sig*(X2s*X1c+X1s*X2c);
470
471 }
472 }
473 }
474 //And write back to global memory.
475#pragma unroll
476 //Write the diagonals
477 for(unsigned short c=0;c<nc;c++)
478 Xmunu.diag[i+kvolHalo*c]=Xmn.diag[c];
479 //And the off diagonal terms
480 Xmunu.offd[i]=Xmn.offd;
481 }
482#endif
483 return;
484}
void cuCalcXmunu(Bilinear_a Xmunu, Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, const unsigned short mu, const unsigned short nu)
CUDA wrapper for CalcXmunu. Only called during testing to be honest.
Definition cuclover.cu:757
#define nc
Colours.
Definition sizes.h:186
#define kvol
Sublattice volume.
Definition sizes.h:167
#define ndirac
Dirac indices.
Definition sizes.h:190
#define Complex_f
Single precision complex number.
Definition sizes.h:66
#define kvolHalo
Subvolume + halo size.
Definition sizes.h:238
Complex_f * offd
Complex valued off-diagonal terms. We only need to store one of these to get the other in .
Definition clover.h:34
float * diag
Real valued diagonal terms.
Definition clover.h:32
Hermitian bilinear on the local stack.
Definition clover.h:40
float diag[2]
Real valued diagonal terms.
Definition clover.h:42
Complex_f offd
Complex valued off-diagonal terms. We only need to store one of these to get the other in .
Definition clover.h:44
#define creal(z)
Extract Real Component using C standard notation.

References CalcXmunu(), Complex_f, creal, cuCalcXmunu(), Bilinear::diag, Bilinear_a::diag, kvol, kvolHalo, nc, ndirac, Bilinear::offd, and Bilinear_a::offd.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clov_Force() [1/2]

void Clov_Force ( double * dSdpi,
Complex_f * ut[2],
Complex_f * X1,
Complex_f * X2,
const Complex_f * sigval,
const unsigned short * sigin,
unsigned int * iu,
unsigned int * id,
const float akappa )

Gets the clover contribution to the force.

Parameters
[in,out]dSdpiForce
[in]utGauge fields
[in]X1Congrad output \(\left(M^\dagger M\right)\Phi\)
[in]X2\(M\left(M^\dagger M\right)^{-1}\Phi\)
[in]sigval\(\sigma_{\mu\nu}\) scaled by \(\frac{c_\text{SW}}{2}\)
[in]siginDirac index of \(\sigma_{\mu\nu}\)
[in]iu,idNeighbouring sites
[in]akappaHopping parameter
Postcondition
Force contribution added to dSdpi

Definition at line 533 of file clover.c.

534 {
535 const char funcname[] = "Clov_Force";
536#ifdef USE_GPU
537 cuClov_Force(dSdpi,ut,X1,X2,sigval,sigin,iu,id,akappa);
538#else
539 //Allocate the @f$X_{\mu\nu}@f$ array
540 unsigned short nclov=6; unsigned short clov=0;
541 Bilinear_a Xmn[nclov];
542 //And get the @f$X_{\mu\nu}@f$ values
543 //Loop over @f$\mu@f$ and @f$\nu@f$. Symmetry means we actually only need half the terms
544 for(unsigned short mu=0;mu<ndim-1;mu++)
545 for(unsigned short nu=mu+1;nu<ndim;nu++)
546 if(mu!=nu){
547 clov = (mu==0) ? nu-1 : mu+nu;
548 Xmn[clov].diag=(float *)aligned_alloc(AVX,2*kvolHalo*sizeof(float));
549 Xmn[clov].offd=(Complex_f *)aligned_alloc(AVX,kvolHalo*sizeof(Complex_f));
550 CalcXmunu(Xmn[clov],X1,X2,sigval,sigin,mu,nu);
551#if(nproc>1)
552 SHalo_swap_all(Xmn[clov].diag,2);
553 CHalo_swap_all(Xmn[clov].offd,1);
554#endif
555 }
556 for(unsigned short mu=0;mu<ndim;mu++)
557 for(unsigned short nu=0;nu<ndim;nu++)
558 if(mu!=nu){
559 if(mu<nu)
560 clov = (mu==0) ? nu-1 : mu+nu;
561 else
562 clov = (nu==0) ? mu-1 : mu+nu;
563#pragma omp parallel for
564 for(unsigned int i=0;i<kvol;i++){
565 //This is where it gets messy. Using HiRep/OpenQCD labelling for different intermediate values
566 //But recycling to reduce register pressure on GPU
567 //First up, W0, W1 and W6 match their Documentation values
568 Complex_f W0[2], W1[2], W6[2];
569 //Get the correct site.
570 unsigned int ind = id[i+kvol*nu];
571 //Gauge field @f$U_\nu\left(i-\hat{\nu}\right)
572 W1[0]=ut[0][ind+kvolHalo*nu]; W1[1]=ut[1][ind+kvolHalo*nu];
573
574 //@f$Z_2=X_{\mu\nu}\left(x-\hat{\nu}\right)@f$
575 Complex_f Z[nc*nc];
576 GetBilinear(Z,Xmn[clov],ind);
577
578 //W0 is @f$U^\dagger_\mu\left(x-\hat{nu}\right)@f$
579 W0[0]=conjf(ut[0][ind+kvolHalo*mu]); W0[1]=-ut[1][ind+kvolHalo*mu];
580
581 //Need a temporary Z buffers for the intermediate result
582 Complex_f Zbuff1[nc*nc], Zbuff2[nc*nc];
583 GSandwich(Zbuff1,Zbuff2,W0,Z,W1);
584
585 //@f$W_6=W_0 W_1@f$
586 W6[0]=W0[0]*W1[0]-W0[1]*conjf(W1[1]); W6[1]=W0[0]*W1[1]+W0[1]*conjf(W1[0]);
587
588 //Z_3 is the @f$X_{\mu\nu}\left(x+\hat{\mu}-\hat{\nu}\right)@f$. Store in Z
589 ind=iu[ind+kvol*mu];
590 GetBilinear(Z,Xmn[clov],ind);
591
592 //Need a second Zbuffer for another intermediate result.
593 GRight(Zbuff2,W6,Z);
594 //Sum the two results into Zbuff1. Then scale by -W5
595#pragma unroll
596 for(unsigned short c=0;c<nc*nc;c++)
597 Zbuff1[c]+=Zbuff2[c];
598 //W5 is @f$U^\dagger_\nu\left(x+\hat{\mu}-\hat{\nu}\right)@f$
599 Complex_f W5[2];
600 W5[0]=conjf(ut[0][ind+kvolHalo*nu]); W5[1]=-ut[1][ind+kvolHalo*nu];
601 //Now multiply by @f$W_5@f$ from the left into Zbuff2
602 GLeft(Zbuff2,W5,Zbuff1);
603
604 //Intermediate results from the four parts of the sum.
605 Complex_f F_int[4];
606#pragma unroll
607 for(unsigned short c=0;c<nc*nc;c++)
608 //Negative as it is @f$-W_5@f$
609 F_int[c]=-Zbuff2[c];
610
611 //Now we repeat for the last term in the sum. Recycling along the way.
612 //First store @f$W_2=U_\nu\left(x+\hat{\mu}\right)@f$ into W0.
613 ind=iu[i+kvol*mu];
614 W0[0]=ut[0][ind+kvolHalo*nu]; W0[1]=ut[1][ind+kvolHalo*nu];
615 //@f$W_3=U^\dagger_\mu\left(x+\hat{\nu}\right)@f$. Storing it in W1
616 ind=iu[i+kvol*nu];
617 W1[0]=conjf(ut[0][ind+kvolHalo*mu]); W1[1]=-ut[1][ind+kvolHalo*mu];
618 //@f$Z_4=X_{\mu\nu}\left(x+\hat{\mu}+\hat{\nu}\right)@f$. Storing in Z
619 ind=iu[ind+kvol*mu];
620 GetBilinear(Z,Xmn[clov],ind);
621 //Calculate and write into Zbuff1
622 GSandwich(Zbuff1,Zbuff2,W0,Z,W1);
623
624 //@f$W_7=W_0 W_1@f$
625 Complex_f W7[2];
626 W7[0]=W0[0]*W1[0]-W0[1]*conjf(W1[1]); W7[1]=W0[0]*W1[1]+W0[1]*conjf(W1[0]);
627 //@f$Z_5=X_{\mu\nu}\left(x+\hat{\nu}\right)@f$
628 ind=iu[i+kvol*nu];
629 GetBilinear(Z,Xmn[clov],ind);
630 //And calculate the second term
631 GLeft(Zbuff2,W7,Z);
632 //Sum the two results into Zbuff1.
633#pragma unroll
634 for(unsigned short c=0;c<nc*nc;c++)
635 Zbuff1[c]+=Zbuff2[c];
636
637 //W4 is @f$U^\dagger_\nu\left(x\right)@f$
638 Complex_f W4[2];
639 W4[0]=conjf(ut[0][i+kvolHalo*nu]); W4[1]=-ut[1][i+kvolHalo*nu];
640 //Now multiply by @f$W_4@f$ from the right into Zbuff2
641 GRight(Zbuff2,W4,Zbuff1);
642
643 //Intermediate results from the four parts of the sum.
644#pragma unroll
645 for(unsigned short c=0;c<nc*nc;c++)
646 F_int[c]+=Zbuff2[c];
647 //The last thing we need is @f$W_8=W_7W_4-W_5W_6@f$. Do it in parts and store intermediates in W0 and W1
648 W0[0]=W7[0]*W4[0]-W7[1]*conjf(W4[1]); W0[1]=W7[0]*W4[1]+W7[1]*conjf(W4[0]);
649 W1[0]=W5[0]*W6[0]-W5[1]*conjf(W6[1]); W1[1]=W5[0]*W6[1]+W5[1]*conjf(W6[0]);
650 //Store W8 in W0
651 W0[0]-=W1[0]; W0[1]-=W1[1];
652
653 //Now load @f$Z_0=X_{\mu\nu}(x)@f$
654 GetBilinear(Z,Xmn[clov],i);
655 GLeft(Zbuff1,W0,Z);
656 //And sum intermediate
657#pragma unroll
658 for(unsigned short c=0;c<nc*nc;c++)
659 F_int[c]+=Zbuff1[c];
660
661 //Now load @f$Z_1=X_{\mu\nu}\left(x+\hat{mu})@f$
662 ind=iu[i+kvol*mu];
663 GetBilinear(Z,Xmn[clov],ind);
664 GRight(Zbuff1,W0,Z);
665 //And sum intermediate
666#pragma unroll
667 for(unsigned short c=0;c<nc*nc;c++){
668 F_int[c]+=Zbuff1[c];
669 //See if this works...
670 F_int[c]*=-I;
671 }
672
673 //Excellent. Now we just need to multiply by the derivative term
674 W0[0]=ut[0][i+kvolHalo*mu]; W0[1]=ut[1][i+kvolHalo*mu];
675 for(unsigned short gen=0;gen<nadj;gen++){
676 W1[0]=W0[0]; W1[1]=W0[1];
677 ByGenLeft(W1,gen);
678 GLeft(Zbuff1,W1,F_int);
679 //Sum of the real part of the trace.
680 float dSdpis=crealf(Zbuff1[0])+crealf(Zbuff1[3]);
681 if(mu<nu)
682 dSdpi[i+kvol*(gen*ndim+mu)] -=akappa*dSdpis/4.0f;
683 else
684 dSdpi[i+kvol*(gen*ndim+mu)] +=akappa*dSdpis/4.0f;
685 }
686 }
687 }
688 for(clov=0;clov<nclov;clov++){
689 free(Xmn[clov].diag); free(Xmn[clov].offd);
690 }
691#endif
692 return;
693}
static void GRight(Complex_f out[4], const Complex_f G[2], const Complex_f X[4])
Multiplies by a gauge field from the right.
Definition clover.c:509
void CalcXmunu(Bilinear_a Xmunu, Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, const unsigned short mu, const unsigned short nu)
Gets for the clover force.
Definition clover.c:436
static void GLeft(Complex_f out[4], const Complex_f G[2], const Complex_f X[4])
Multiplies by a gauge field from the left.
Definition clover.c:494
int cuClov_Force(double *dSdpi, Complex_f *ut[nc], Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, const unsigned int *iu, const unsigned int *id, const float akappa)
CUDA wrapper for Clover_Force.
Definition cuclover.cu:764
static void GSandwich(Complex_f out[4], Complex_f tmp[4], const Complex_f Gl[2], const Complex_f X[4], const Complex_f Gr[2])
Multiplies by a gauge field from the left and the right.
Definition clover.c:527
static void GetBilinear(Complex_f Z[nc *nc], Bilinear_a Xmn, unsigned int ind)
Loads the compacted bilinear form into a complex valued matrix.
Definition clover.c:431
void ByGenLeft(Complex_f a[nc], const unsigned short gen)
Multiply leaf (or part of one) by generator from left.
Definition clover.c:9
int CHalo_swap_all(Complex_f *c, int ncpt)
Calls the functions to send data to both the up and down halos.
int SHalo_swap_all(float *d, int ncpt)
Calls the functions to send data to both the up and down halos.
#define AVX
Alignment of arrays. 64 for AVX-512, 32 for AVX/AVX2. 16 for SSE. Since AVX is standard on modern x86...
Definition sizes.h:283
#define nadj
adjacent spatial indices
Definition sizes.h:188
#define ndim
Dimensions.
Definition sizes.h:192
Structure of arrays for Hermitian bilinear in memory.
Definition clover.h:30
#define I
Define I in double precision using C standard notation.

References AVX, ByGenLeft(), CalcXmunu(), CHalo_swap_all(), Clov_Force(), Complex_f, cuClov_Force(), Bilinear_a::diag, GetBilinear(), GLeft(), GRight(), GSandwich(), I, kvol, kvolHalo, nadj, nc, ndim, Bilinear_a::offd, and SHalo_swap_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clov_Force() [2/2]

template<typename T>
__global__ void Kernels::Clov_Force ( double * dSdpi,
const complex< T > * u11t,
const complex< T > * u12t,
const Bilinear_a Xmn,
const unsigned int * iu,
const unsigned int * id,
const __grid_constant__ float akappa,
const __grid_constant__ unsigned short mu,
const __grid_constant__ unsigned short nu )

cuGets the clover contribution to the force

Parameters
[out]dSdpiForce.
[in]u11t,u12tGauge fields
[in]XmnPseudofermion bilinear contraction
[in]sigval\(\sigma_{\mu\nu}\) scaled by \(\frac{c_\text{SW}}{2}\)
[in]siginDirac index of \(\sigma_{\mu\nu}\)
[in]iu,idNeighbouring sites
[in]akappaHopping Parameter
[in]mu,nuClover direction
Postcondition
Clover force is added to dSdpi

Definition at line 444 of file cuclover.cu.

447 {
448
449 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
450 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
451 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
452 const unsigned int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
453 const unsigned int gthreadId= blockId * bsize+bthreadId;
454 //And get the @f$X_{\mu\nu}@f$ values
455 //Loop over @f$\mu@f$ and @f$\nu@f$,
456 for(unsigned int i=gthreadId;i<kvol;i+=gsize*bsize){
457 //Buffer for intermediate force calculation. One for each generator.
458 //This is where it gets messy. Using HiRep/OpenQCD labelling for different intermediate values
459 //But recycling to reduce register pressure on GPU
460 //First up, W0, W1 and W6 match their Documentation values
461 complex<T> W0[2]; complex<T> W1[2]; complex<T> W6[2];
462 //Get the correct site. Originally ind and stood for up and down. Then I realised only one was needed
463 //at a time and am too lazy to change it everywhere.
464 unsigned int ind = id[i+kvol*nu];
465 //Gauge field @f$U_\nu\left(i-\hat{\nu}\right)
466 W1[0]=u11t[ind+kvolHalo*nu]; W1[1]=u12t[ind+kvolHalo*nu];
467
468 //@f$Z_2=X_{\mu\nu}\left(i-\hat{\nu}\right)@f$
469 complex<T> Z[nc*nc];
470 Device::GetBilinear(Z,Xmn,ind);
471
472 //W0 is @f$U^\dagger_\mu@f(x-\hat{nu}\right)@f$
473 W0[0]=conj(u11t[ind+kvolHalo*mu]); W0[1]=-u12t[ind+kvolHalo*mu];
474
475 //Need a temporary Z buffers for the intermediate result
476 complex<T> Zbuff1[nc*nc];complex<T> Zbuff2[nc*nc];
477 Device::cuGSandwich(Zbuff1,Zbuff2,W0,Z,W1);
478
479 //@f$W_6=W_0 W_1@f$
480 W6[0]=W0[0]*W1[0]-W0[1]*conj(W1[1]); W6[1]=W0[0]*W1[1]+W0[1]*conj(W1[0]);
481
482 //Z3 is the @f$X_{\mu\nu}\left(x+\hat{\mu}-\hat{\nu}\right)@f$. Store in Z
483 ind=iu[ind+kvol*mu];
484 Device::GetBilinear(Z,Xmn,ind);
485
486 //Need a second Zbuffer for another intermediate result.
487 Device::cuGRight(Zbuff2,W6,Z);
488 //Sum the two results into Zbuff1. Then scale by -W5
489#pragma unroll
490 for(unsigned short c=0;c<nc*nc;c++)
491 Zbuff1[c]+=Zbuff2[c];
492 //W5 is @f$U^\dagger_\nu\left(x+\hat{\mu}-\hat{\nu}\right)@f$
493 complex<T> W5[2];
494 W5[0]=conj(u11t[ind+kvolHalo*nu]); W5[1]=-u12t[ind+kvolHalo*nu];
495 //Now multiply by @f$W_5@f$ from the left into Zbuff2
496 Device::cuGLeft(Zbuff2,W5,Zbuff1);
497
498 //Intermediate results from the four parts of the sum.
499 complex<T> F_int[4];
500#pragma unroll
501 for(unsigned short c=0;c<nc*nc;c++)
502 //Negative as it is @f$-W_5@f$
503 F_int[c]=-Zbuff2[c];
504
505 //Now we repeat for the last term in the sum. Recycling along the way.
506 //First store @f$W_2=U_\nu\left(x+\hat{\mu}\right)@f$ into W0.
507 ind=iu[i+kvol*mu];
508 W0[0]=u11t[ind+kvolHalo*nu]; W0[1]=u12t[ind+kvolHalo*nu];
509 //@f$W_3=U^\dagger_\mu\left(x+\hat{\nu}\right). Storing it in W1
510 ind=iu[i+kvol*nu];
511 W1[0]=conj(u11t[ind+kvolHalo*mu]); W1[1]=-u12t[ind+kvolHalo*mu];
512 //@f$Z_4=X_{\mu\nu}\left(x+\hat{\mu}+\hat{\nu}\right)@f$. Storing in Z
513 ind=iu[ind+kvol*mu];
514 Device::GetBilinear(Z,Xmn,ind);
515 //Calculate and write into Zbuff1
516 Device::cuGSandwich(Zbuff1,Zbuff2,W0,Z,W1);
517
518 //@f$W_7=W_0 W_1@f$
519 complex<T> W7[2];
520 W7[0]=W0[0]*W1[0]-W0[1]*conj(W1[1]); W7[1]=W0[0]*W1[1]+W0[1]*conj(W1[0]);
521 //@f$Z_5=X_{\mu\nu}\left(x+\hat{\nu}\right)@f$
522 ind=iu[i+kvol*nu];
523 Device::GetBilinear(Z,Xmn,ind);
524 //And calculate the second term
525 Device::cuGLeft(Zbuff2,W7,Z);
526 //Sum the two results into Zbuff1.
527#pragma unroll
528 for(unsigned short c=0;c<nc*nc;c++)
529 Zbuff1[c]+=Zbuff2[c];
530 //W4 is @f$U^\dagger_\nu\left(x\right)@f$
531 complex<T> W4[2];
532 W4[0]=conj(u11t[i+kvolHalo*nu]); W4[1]=-u12t[i+kvolHalo*nu];
533 //Now multiply by @f$W_4@f$ from the right into Zbuff2
534 Device::cuGRight(Zbuff2,W4,Zbuff1);
535
536 //Intermediate results from the four parts of the sum.
537#pragma unroll
538 for(unsigned short c=0;c<nc*nc;c++)
539 F_int[c]+=Zbuff2[c];
540 //The last thing we need is @f$W_8=W_7W_4-W_5W_6@f$. Do it in parts and store intermediates in W0 and W1
541 W0[0]=W7[0]*W4[0]-W7[1]*conj(W4[1]); W0[1]=W7[0]*W4[1]+W7[1]*conj(W4[0]);
542 W1[0]=W5[0]*W6[0]-W5[1]*conj(W6[1]); W1[1]=W5[0]*W6[1]+W5[1]*conj(W6[0]);
543 //Store W8 in W0
544 W0[0]-=W1[0]; W0[1]-=W1[1];
545
546 //Now load @f$@Z_0=X_{\mu\nu}(x)@f$
547 Device::GetBilinear(Z,Xmn,i);
548 Device::cuGLeft(Zbuff1,W0,Z);
549 //And sum intermediate
550#pragma unroll
551 for(unsigned short c=0;c<nc*nc;c++)
552 F_int[c]+=Zbuff1[c];
553
554 //Now load @f$@Z_1=X_{\mu\nu}(x)@f$
555 ind=iu[i+kvol*mu];
556 Device::GetBilinear(Z,Xmn,ind);
557 Device::cuGRight(Zbuff1,W0,Z);
558 //And sum intermediate
559#pragma unroll
560 for(unsigned short c=0;c<nc*nc;c++){
561 F_int[c]+=Zbuff1[c];
562 F_int[c]*=-I_f;
563 }
564
565 //Excellent. Now we just need to multiply by the derivative term
566 W0[0]=u11t[i+kvolHalo*mu]; W0[1]=u12t[i+kvolHalo*mu];
567 for(unsigned short gen=0;gen<nadj;gen++){
568 W1[0]=W0[0]; W1[1]=W0[1];
569 cuByGenLeft(W1,gen);
570 Device::cuGLeft(Zbuff1,W1,F_int);
571 //Sum of the real part of the trace.
572 float dSdpis=creal(Zbuff1[0])+creal(Zbuff1[3]);
573 //tmp lets us control the number of registers explictly
574 if(mu<nu)
575 dSdpi[i+kvol*(gen*ndim+mu)] -=akappa*dSdpis/4.0f;
576 else
577 dSdpi[i+kvol*(gen*ndim+mu)] +=akappa*dSdpis/4.0f;
578
579 }
580 }
581 return;
582 }
__device__ void GetBilinear(Complex_f Z[nc *nc], Bilinear_a Xmn, unsigned int ind)
Loads the compacted bilinear form into a complex valued matrix.
Definition cuclover.cu:275
__device__ void cuByGenLeft(T a[nc], const unsigned short gen)
Multiply leaf (or part of one) by generator from left.
Definition cuclover.cu:24
__device__ void cuGSandwich(T out[4], T tmp[4], const T Gl[2], const T X[4], const T Gr[2])
Multiplies by a gauge field from the left and the right.
Definition cuclover.cu:260
__device__ void cuGLeft(T out[4], const T G[2], const T X[4])
Multiplies by a gauge field from the left.
Definition cuclover.cu:227
__device__ void cuGRight(T out[4], const T G[2], const T X[4])
Multiplies by a gauge field from the right.
Definition cuclover.cu:243
__device__ __forceinline__ T conj(const T &z)
Complex Conjugation.
Definition cusu2hmc.cu:33
#define I_f
Define I in single precision.

References __BSIZE__, Clov_Force(), conj(), creal, Device::cuByGenLeft(), Device::cuGLeft(), Device::cuGRight(), Device::cuGSandwich(), Device::GetBilinear(), I_f, kvol, kvolHalo, nadj, nc, and ndim.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuByGenLeft()

template<typename T>
__device__ void Device::cuByGenLeft ( T a[nc],
const unsigned short gen )

Multiply leaf (or part of one) by generator from left.

The leaves contributing to each force term need to be scaled by the generator, but the generator appears at different points in each leaf. This routine multiples by the generator from the left side.

Parameters
[in,out]aThe leaf or partial leaf. Result saved in place
[in]genWhat generator are we multiplying by?

\(i\sigma_x\)

\(i\sigma_y\)

\(i\sigma_z\)

Definition at line 24 of file cuclover.cu.

24 {
25 T tmp = a[0];
26 switch(gen){
28 case(0):
29 a[0] = T(-a[1].imag(), -a[1].real());
30 a[1] = T( tmp.imag(), tmp.real());
31 break;
33 case(1):
34 a[0] = -conj(a[1]);
35 a[1] = conj(tmp);
36 break;
38 case(2):
39 a[0] = T(-a[0].imag(), a[0].real());
40 a[1] = T(-a[1].imag(), a[1].real());
41 break;
42 }
43 return;
44 }

References conj(), cuByGenLeft(), and nc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuByGenRight()

template<typename T>
__device__ void Device::cuByGenRight ( T a[nc],
const unsigned short gen )

Multiply leaf (or part of one) by generator from right.

The leaves contributing to each force term need to be scaled by the generator, but the generator appears at different points in each leaf. This routine multiples by the generator from the right side.

Parameters
[in,out]aThe leaf or partial leaf. Result saved in place
[in]genWhat generator are we multiplying by?

\(i\sigma_x\)

\(i\sigma_y\)

\(i\sigma_z\)

Definition at line 56 of file cuclover.cu.

56 {
57 T tmp = a[0];
58 switch(gen){
60 case(0):
61 a[0] = T(-a[1].imag(), a[1].real());
62 a[1] = T(-tmp.imag(), tmp.real());
63 break;
65 case(1):
66 a[0]=-a[1]; a[1]=tmp;
67 break;
69 case(2):
70 a[0] = T(-a[0].imag(), a[0].real());
71 a[1] = T( a[1].imag(), -a[1].real());
72 break;
73 }
74 return;
75 }

References cuByGenRight(), and nc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuCalcXmunu() [1/2]

void cuCalcXmunu ( Bilinear_a Xmunu,
Complex_f * X1,
Complex_f * X2,
const Complex_f * sigval,
const unsigned short * sigin,
const unsigned short mu,
const unsigned short nu )

CUDA wrapper for CalcXmunu. Only called during testing to be honest.

Parameters
[out]XmunuAll Xmunu values
[in]X1Congrad output \(\left(M^\dagger M\right)\Phi\)
[in]X2\(M\left(M^\dagger M\right)^{-1}\Phi\)
[in]sigval\(\sigma_{\mu\nu}\) scaled by \(\frac{c_\text{SW}}{2}\)
[in]siginDirac index of \(\sigma_{\mu\nu}\)
[in]mu,nuLattice directions
Postcondition
Bilinears written to Xmunu

Definition at line 757 of file cuclover.cu.

758 {
759 //Get sign and index of @f$\sigma_{\mu\nu}@f correct
760 unsigned short clov = (mu==0) ? nu-1 : mu+nu;
761 Kernels::cuCalcXmunu<<<dimGrid,dimBlock,0,streams[clov]>>>(Xmunu,X1,X2,sigval,sigin,clov);
762 return;
763}
__global__ void cuCalcXmunu(Bilinear_a Xmunu, const complex< T > *X1, const complex< T > *X2, const __grid_constant__ complex< T > sigval_G[24], const __grid_constant__ unsigned short sigin_G[24], const __grid_constant__ unsigned short clov)
Gets for the clover force.
Definition cuclover.cu:377

References Complex_f, cuCalcXmunu(), and Kernels::cuCalcXmunu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuCalcXmunu() [2/2]

template<typename T>
__global__ void Kernels::cuCalcXmunu ( Bilinear_a Xmunu,
const complex< T > * X1,
const complex< T > * X2,
const __grid_constant__ complex< T > sigval_G[24],
const __grid_constant__ unsigned short sigin_G[24],
const __grid_constant__ unsigned short clov )

Gets \(X_{\mu\nu}\) for the clover force.

Parameters
[out]XmunuAll Xmunu values
[in]X1Congrad output \(\left(M^\dagger M\right)\Phi\)
[in]X2\(M\left(M^\dagger M\right)^{-1}\Phi\)
[in]sigval_G\(\sigma_{\mu\nu}\) scaled by \(\frac{c_\text{SW}}{2}\)
[in]sigin_GDirac index of \(\sigma_{\mu\nu}\)
[in]clovIndex of clover being used
Postcondition
Contents of Xmunu overwritten

Definition at line 377 of file cuclover.cu.

379 {
380 const char funcname[] = "Xmunu";
381 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
382 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
383 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
384 const unsigned int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
385 const unsigned int gthreadId= blockId * bsize+bthreadId;
386
387 __shared__ complex<T> sigval[24]; __shared__ unsigned short sigin[24];
388#pragma unroll
389 for(unsigned short i=gthreadId%__BSIZE__;i<24;i+=bsize){
390 sigval[i]=sigval_G[i];
391 sigin[i]=sigin_G[i];
392 }
393 __syncthreads();
394 //Get sign and index of @f$\sigma_{\mu\nu}@f correct
395 for(unsigned int i=gthreadId;i<kvol;i+=gsize*bsize){
396 //Buffer. Four registers
397 Bilinear Xmn;
398 Xmn.diag[0]=Xmn.diag[1]=0;Xmn.offd=0;
399 for(unsigned short idirac=0; idirac<ndirac*nc; idirac+=nc){
400 const unsigned short sind = sigin[clov*ndirac+(idirac>>1)]<<1;
401 const complex<T> sig = sigval[clov*ndirac+(idirac>>1)];
402 for(unsigned short c1=0;c1<nc;c1++){
403 //Spinors (rows) So we only load from memory once.
404 const complex<T> X1s = X1[i+kvolHalo*(sind+c1)];
405 const complex<T> X2s = X2[i+kvolHalo*(sind+c1)];
406 for(unsigned short c2=0;c2<nc;c2++){
407 //The second off diagonal term is the conjugate of the first
408 if(c1==1&&c2==0)
409 continue;
410 //Conjugated spinor (columns).
411 const complex<T> X1c = conj(X1[i+kvolHalo*(idirac+c2)]);
412 const complex<T> X2c = conj(X2[i+kvolHalo*(idirac+c2)]);
413 if(c1==c2)
414 Xmn.diag[c1]+=(T)(sig*(X2s*X1c+X1s*X2c)).real();
415 else
416 Xmn.offd+=sig*(X2s*X1c+X1s*X2c);
417 }
418 }
419 }
420 //Write the diagonals
421 for(unsigned short c=0;c<nc;c++)
422 Xmunu.diag[i+kvolHalo*c]=Xmn.diag[c];
423 //And the off diagonal terms
424 Xmunu.offd[i]=Xmn.offd;
425 }
426 return;
427 }
#define __BSIZE__
Default block size.
Definition sizes.h:48

References __BSIZE__, conj(), cuCalcXmunu(), Bilinear::diag, Bilinear_a::diag, kvol, kvolHalo, nc, ndirac, Bilinear::offd, and Bilinear_a::offd.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuClov_Force()

int cuClov_Force ( double * dSdpi,
Complex_f * ut[nc],
Complex_f * X1,
Complex_f * X2,
const Complex_f * sigval,
const unsigned short * sigin,
const unsigned int * iu,
const unsigned int * id,
const float akappa )

CUDA wrapper for Clover_Force.

Parameters
[in,out]dSdpiForce
[in]utGauge fields
[in]X1\(\left(M^\dagger M\right)^{-1} \Psi\)
[in]X2\(M\left(M^\dagger M\right)^{-1} \Psi\)
[in]sigval\( \sigma_{\mu\nu}\) entries scaled by \(c_sw\)
[in]siginWhat element of the spinor is multiplied by row idirac each sigma matrix?
[in]iu,idUp/down indices
[in]akappaHopping parameter
Returns
Zero on success, integer error code otherwise
Postcondition
Force contribution added to dSdpi

Definition at line 764 of file cuclover.cu.

765 {
766 const char funcname[]="Clov_Force";
767
768 const unsigned short nclov = (ndim-1)*(ndim-2);
769 //Too many pointers here but not bothered doing it correctly. Overhead is basically zero.
770 Bilinear_a Xmn[nclov];
771 //Allocate half-leaf memory. We will have one stream for each direction
772 for(unsigned short mu=0;mu<ndim-1;mu++)
773 for(unsigned short nu=mu;nu<ndim;nu++)
774 if(mu!=nu){
775 //Get sign and index of @f$\sigma_{\mu\nu}@f correct
776 unsigned short clov = (mu==0) ? nu-1 : mu+nu;
777 //Allocate and evaluate @f$X_{\mu\nu}@f$ terms
778 cudaMallocAsync((void **)&Xmn[clov].diag,nc*kvol*sizeof(float),streams[clov]);
779 cudaMallocAsync((void **)&Xmn[clov].offd,nc*kvol*sizeof(complex<float>),streams[clov]);
780 Kernels::cuCalcXmunu<<<dimGrid,dimBlock,0,streams[clov]>>>(Xmn[clov],X1,X2,sigval,sigin,clov);
781 }
783
784 for(unsigned short mu=0;mu<ndim;mu++)
785 for(unsigned short nu=0;nu<ndim;nu++)
786 if(mu!=nu){
787 unsigned short clov=0;
788 if(mu<nu)
789 clov = (mu==0) ? nu-1 : mu+nu;
790 else
791 clov = (nu==0) ? mu-1 : mu+nu;
792 //Compute force for @f$\mu\nu@f$ and @f$\nu\mu@f$
793 Kernels::Clov_Force<<<dimGrid,dimBlock,0,streams[mu]>>>(dSdpi,ut[0],ut[1],Xmn[clov],iu,id,akappa,mu,nu);
794
795 }
797 for(unsigned short clov=0;clov<nclov;clov++){
798 cudaFreeAsync(Xmn[clov].diag,NULL); cudaFreeAsync(Xmn[clov].offd,NULL);
799 }
801 return 0;
802}
__global__ void Clov_Force(double *dSdpi, const complex< T > *u11t, const complex< T > *u12t, const Bilinear_a Xmn, const unsigned int *iu, const unsigned int *id, const __grid_constant__ float akappa, const __grid_constant__ unsigned short mu, const __grid_constant__ unsigned short nu)
cuGets the clover contribution to the force
Definition cuclover.cu:444
#define cudaDeviceSynchronise()
Get rid of that bastardised yankee English.
Definition sizes.h:57
cudaStream_t streams[ndirac *ndim *nadj]
An array of concurrent GPU streams to keep it busy.
Definition cusu2hmc.cu:29

References Kernels::Clov_Force(), Complex_f, Kernels::cuCalcXmunu(), cuClov_Force(), cudaDeviceSynchronise, kvol, nc, ndim, and streams.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuGLeft()

template<typename T>
__device__ void Device::cuGLeft ( T out[4],
const T G[2],
const T X[4] )

Multiplies \( X_{\mu\nu}\) by a gauge field from the left.

Parameters
[out]outResult
[in]X\(X_{\mu\nu}(x)\)
[in]GGauge field

Definition at line 227 of file cuclover.cu.

227 {
228 out[0]=G[0]*X[0]+G[1]*X[2];
229 out[1]=G[0]*X[1]+G[1]*X[3];
230 out[2]=-conj(G[1])*X[0]+conj(G[0])*X[2];
231 out[3]=-conj(G[1])*X[1]+conj(G[0])*X[3];
232 return;
233 }

References conj(), and cuGLeft().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuGRight()

template<typename T>
__device__ void Device::cuGRight ( T out[4],
const T G[2],
const T X[4] )

Multiplies \( X_{\mu\nu}\) by a gauge field from the right.

Parameters
[out]outResult
[in]X\(X_{\mu\nu}(x)\)
[in]GGauge field

Definition at line 243 of file cuclover.cu.

243 {
244 out[0]=G[0]*X[0]-conj(G[1])*X[1];
245 out[1]=G[1]*X[0]+conj(G[0])*X[1];
246 out[2]=G[0]*X[2]-conj(G[1])*X[3];
247 out[3]=G[1]*X[2]+conj(G[0])*X[3];
248 return;
249 }

References conj(), and cuGRight().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cuGSandwich()

template<typename T>
__device__ void Device::cuGSandwich ( T out[4],
T tmp[4],
const T Gl[2],
const T X[4],
const T Gr[2] )

Multiplies \( X_{\mu\nu}\) by a gauge field from the left and the right.

Parameters
[out]outResult
[in]tmpBuffer for intermediate result. Passing as an argument to reduce register pressure.
[in]X\(X_{\mu\nu}(x)\)
[in]Gl,GrLeft/Right Gauge fields

Definition at line 260 of file cuclover.cu.

260 {
261 cuGRight(tmp,Gr,X);
262 cuGLeft(out,Gl,tmp);
263 return;
264 }

References cuGLeft(), cuGRight(), and cuGSandwich().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBilinear() [1/2]

__device__ void Device::GetBilinear ( Complex_f Z[nc *nc],
Bilinear_a Xmn,
unsigned int ind )

Loads the compacted bilinear form into a \(2\times2\) complex valued matrix.

Parameters
[out]ZComplex matrix on stack
[in]XmnHermitian form of \(X_{\mu\nu}\) in memory
[in]indIndex of \(X_{\mu\nu}\) we're interested in
Postcondition
Contents of Z are replaced by bilinear from memory

Definition at line 275 of file cuclover.cu.

275 {
276 Z[0]=Xmn.diag[ind]; Z[3]=Xmn.diag[ind+kvolHalo];
277 Z[1]=Xmn.offd[ind]; Z[2]=conj(Z[1]);
278 return;
279 }

References Complex_f, conj(), Bilinear_a::diag, GetBilinear(), kvolHalo, nc, and Bilinear_a::offd.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBilinear() [2/2]

void GetBilinear ( Complex_f Z[nc *nc],
Bilinear_a Xmn,
unsigned int ind )
inlinestatic

Loads the compacted bilinear form into a \(2\times2\) complex valued matrix.

Parameters
[out]ZComplex matrix on stack
[in]XmnHermitian form of \(X_{\mu\nu}\) in memory
[in]indIndex of \(X_{\mu\nu}\) we're interested in
Postcondition
Contents of Z are replaced by bilinear from memory

Definition at line 431 of file clover.c.

431 {
432 Z[0]=Xmn.diag[ind]; Z[3]=Xmn.diag[ind+kvolHalo];
433 Z[1]=Xmn.offd[ind]; Z[2]=conjf(Z[1]);
434 return;
435}

References Complex_f, Bilinear_a::diag, GetBilinear(), kvolHalo, nc, and Bilinear_a::offd.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GLeft()

void GLeft ( Complex_f out[4],
const Complex_f G[2],
const Complex_f X[4] )
inlinestatic

Multiplies \( X_{\mu\nu}\) by a gauge field from the left.

Parameters
[out]outResult
[in]X\(X_{\mu\nu}(x)\)
[in]GGauge field

Definition at line 494 of file clover.c.

494 {
495 out[0]=G[0]*X[0]+G[1]*X[2];
496 out[1]=G[0]*X[1]+G[1]*X[3];
497 out[2]=-conj(G[1])*X[0]+conj(G[0])*X[2];
498 out[3]=-conj(G[1])*X[1]+conj(G[0])*X[3];
499 return;
500}

References Complex_f, conj(), and GLeft().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GRight()

void GRight ( Complex_f out[4],
const Complex_f G[2],
const Complex_f X[4] )
inlinestatic

Multiplies \( X_{\mu\nu}\) by a gauge field from the right.

Parameters
[out]outResult
[in]X\(X_{\mu\nu}(x)\)
[in]GGauge field

Definition at line 509 of file clover.c.

509 {
510 out[0]=G[0]*X[0]-conj(G[1])*X[1];
511 out[1]=G[1]*X[0]+conj(G[0])*X[1];
512 out[2]=G[0]*X[2]-conj(G[1])*X[3];
513 out[3]=G[1]*X[2]+conj(G[0])*X[3];
514 return;
515}

References Complex_f, conj(), and GRight().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSandwich()

void GSandwich ( Complex_f out[4],
Complex_f tmp[4],
const Complex_f Gl[2],
const Complex_f X[4],
const Complex_f Gr[2] )
inlinestatic

Multiplies \( X_{\mu\nu}\) by a gauge field from the left and the right.

Parameters
[out]outResult
[in,out]tmpBuffer for intermediate result. Passing as an argument to reduce register pressure.
[in]X\(X_{\mu\nu}(x)\)
[in]Gl,GrLeft/Right Gauge fields
Postcondition
Contents of tmp will be changed during the call

Definition at line 527 of file clover.c.

527 {
528 GRight(tmp,Gr,X);
529 GLeft(out,Gl,tmp);
530 return;
531}

References Complex_f, GLeft(), GRight(), and GSandwich().

Here is the call graph for this function:
Here is the caller graph for this function: