29 a[0] = T(-a[1].imag(), -a[1].real());
30 a[1] = T( tmp.imag(), tmp.real());
39 a[0] = T(-a[0].imag(), a[0].real());
40 a[1] = T(-a[1].imag(), a[1].real());
61 a[0] = T(-a[1].imag(), a[1].real());
62 a[1] = T(-tmp.imag(), tmp.real());
70 a[0] = T(-a[0].imag(), a[0].real());
71 a[1] = T( a[1].imag(), -a[1].real());
91 __device__
void Half_Leaf(complex<T> Leaves[
nc],
const complex<T> * __restrict__ u11t,
92 const complex<T> * __restrict__ u12t, complex<T> a[
nc],
const unsigned int * __restrict__ iu,
93 const unsigned int * __restrict__
id,
const unsigned int i,
const unsigned short mu,
const unsigned short nu,
94 const unsigned short leaf){
96 unsigned int ind;
unsigned int double_ind=
id[nu*
kvol+ind];
112 double_ind=iu[nu*
kvol+ind];
115 Leaves[1]=-a[0]*u12t[double_ind+
kvolHalo*mu]+a[1]*u11t[double_ind+
kvolHalo*mu];
134 double_ind=
id[nu*
kvol+ind];
138 Leaves[1]=-a[0]*u12t[double_ind+
kvolHalo*nu]+a[1]*u11t[double_ind+
kvolHalo*nu];
154 template <
typename T>
155 __device__
void Leaf(
const complex<T> * __restrict__ u11t,
const complex<T> * __restrict__ u12t,
156 complex<T> Leaves[
nc],
const unsigned int * __restrict__ iu,
const unsigned int * __restrict__
id,
157 const unsigned int i,
const unsigned short mu,
const unsigned short nu,
const unsigned short leaf){
159 Half_Leaf(Leaves,u11t,u12t,a,iu,
id,i,mu,nu,leaf);
160 unsigned int ind,double_ind;
190 double_ind=iu[mu*
kvol+ind];
203 double_ind=
id[mu*
kvol+ind];
226 template <
typename T>
227 __device__
void cuGLeft(T out[4],
const T G[2],
const T X[4]){
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];
242 template <
typename T>
243 __device__
void cuGRight(T out[4],
const T G[2],
const T X[4]){
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];
259 template <
typename T>
260 __device__
void cuGSandwich(T out[4],T tmp[4],
const T Gl[2],
const T X[4],
const T Gr[2]){
277 Z[1]=Xmn.
offd[ind]; Z[2]=
conj(Z[1]);
284 using namespace Device;
296 template <
typename T>
298 const complex<T> * __restrict__ u11t,
const complex<T> * __restrict__ u12t,
299 const unsigned int * __restrict__ iu,
const unsigned int * __restrict__
id,
300 const __grid_constant__
unsigned short mu,
const __grid_constant__
unsigned short nu){
302 const volatile int gsize = gridDim.x*gridDim.y*gridDim.z;
303 const volatile int bsize = blockDim.x*blockDim.y*blockDim.z;
304 const volatile int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
305 const volatile int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
306 const volatile int gthreadId= blockId * bsize+bthreadId;
308 complex<T> Leaves[
nc], a[
nc];
309 for(
unsigned short leaf=0;leaf<
ndim;leaf++)
310 for(
unsigned int i=gthreadId;i<
kvol;i+=gsize*bsize){
311 Half_Leaf(Leaves,u11t,u12t,a,iu,
id,i,mu,nu,leaf);
312 hLeaves0[i+
kvol*leaf]=Leaves[0]; hLeaves1[i+
kvol*leaf]=Leaves[1];
328 template <
typename T>
329 __global__ __launch_bounds__(
__BSIZE__)
void Full_Clover(complex<T> * __restrict__ clover1, complex<T> * __restrict__ clover2,\
330 const complex<T> * __restrict__ u11t,
const complex<T> * __restrict__ u12t,
331 const unsigned int * __restrict__ iu,
const unsigned int * __restrict__
id,
const __grid_constant__
int mu,
332 const __grid_constant__
int nu){
333 const volatile int gsize = gridDim.x*gridDim.y*gridDim.z;
334 const volatile int bsize = blockDim.x*blockDim.y*blockDim.z;
335 const volatile int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
336 const volatile int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
337 const volatile int gthreadId= blockId * bsize+bthreadId;
339 complex<T> Leaves[2];
340 for(
unsigned int i=gthreadId;i<
kvol;i+=gsize*bsize){
341 clover1[i]=0;clover2[i]=0;
342 for(
unsigned short leaf=0;leaf<
ndim;leaf++)
345 Leaf(u11t,u12t,Leaves,iu,
id,i,mu,nu,leaf);
346 clover1[i]+=Leaves[0]; clover2[i]+=Leaves[1];
354 clover1[i]=clover1[i].imag(); clover1[i]*=(1.0f/4.0f);
358 clover2[i]+=clover2[i]; clover2[i]*=(-
I_f/8.0f);
376 template <
typename T>
378 const complex<T> * __restrict__ X2,
const __grid_constant__ complex<T> sigval_G[24],
379 const __grid_constant__
unsigned short sigin_G[24],
const __grid_constant__
unsigned short clov){
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;
387 __shared__ complex<T> sigval[24]; __shared__
unsigned short sigin[24];
389 for(
unsigned short i=gthreadId%
__BSIZE__;i<24;i+=bsize){
390 sigval[i]=sigval_G[i];
395 for(
unsigned int i=gthreadId;i<
kvol;i+=gsize*bsize){
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++){
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++){
411 const complex<T> X1c =
conj(X1[i+
kvolHalo*(idirac+c2)]);
412 const complex<T> X2c =
conj(X2[i+
kvolHalo*(idirac+c2)]);
414 Xmn.
diag[c1]+=(T)(sig*(X2s*X1c+X1s*X2c)).real();
416 Xmn.
offd+=sig*(X2s*X1c+X1s*X2c);
421 for(
unsigned short c=0;c<
nc;c++)
443 template <
typename T>
444 __global__ __launch_bounds__(
__BSIZE__)
void Clov_Force(
double * __restrict__ dSdpi,
const complex<T> * __restrict__ u11t,
445 const complex<T> * __restrict__ u12t,
const Bilinear_a Xmn,
const unsigned int * __restrict__ iu,
446 const unsigned int * __restrict__
id,
const __grid_constant__
float akappa,
447 const __grid_constant__
unsigned short mu,
const __grid_constant__
unsigned short nu){
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;
456 for(
unsigned int i=gthreadId;i<
kvol;i+=gsize*bsize){
461 complex<T> W0[2]; complex<T> W1[2]; complex<T> W6[2];
464 unsigned int ind =
id[i+
kvol*nu];
476 complex<T> Zbuff1[
nc*
nc];complex<T> Zbuff2[
nc*
nc];
480 W6[0]=W0[0]*W1[0]-W0[1]*
conj(W1[1]); W6[1]=W0[0]*W1[1]+W0[1]*
conj(W1[0]);
490 for(
unsigned short c=0;c<
nc*
nc;c++)
491 Zbuff1[c]+=Zbuff2[c];
501 for(
unsigned short c=0;c<
nc*
nc;c++)
520 W7[0]=W0[0]*W1[0]-W0[1]*
conj(W1[1]); W7[1]=W0[0]*W1[1]+W0[1]*
conj(W1[0]);
528 for(
unsigned short c=0;c<
nc*
nc;c++)
529 Zbuff1[c]+=Zbuff2[c];
538 for(
unsigned short c=0;c<
nc*
nc;c++)
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]);
544 W0[0]-=W1[0]; W0[1]-=W1[1];
551 for(
unsigned short c=0;c<
nc*
nc;c++)
560 for(
unsigned short c=0;c<
nc*
nc;c++){
567 for(
unsigned short gen=0;gen<
nadj;gen++){
568 W1[0]=W0[0]; W1[1]=W0[1];
572 float dSdpis=
creal(Zbuff1[0])+
creal(Zbuff1[3]);
575 dSdpi[i+
kvol*(gen*
ndim+mu)] -=akappa*dSdpis/4.0f;
577 dSdpi[i+
kvol*(gen*
ndim+mu)] +=akappa*dSdpis/4.0f;
599 template <
typename T>
600 __global__ __launch_bounds__(
__BSIZE__)
void ByClover(complex<T> * phi,
const complex<T> * __restrict__ r,
601 const complex<T> * __restrict__ clover1,
602 const complex<T> * __restrict__ clover2,
const __grid_constant__ complex<T> sigval_G[24],
603 const __grid_constant__
float akappa,
604 const __grid_constant__
unsigned short sigin_G[24],
const __grid_constant__
bool dag){
605 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
606 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
607 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
608 const unsigned int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
609 const unsigned int gthreadId= blockId * bsize+bthreadId;
610 __shared__ complex<T> sigval[24]; __shared__
unsigned short sigin[24];
612 for(
unsigned short i=gthreadId%
__BSIZE__;i<24;i+=bsize){
613 sigval[i]=sigval_G[i];
618 for(
unsigned int i=gthreadId;i<
kvol;i+=bsize*gsize){
622 for(
unsigned short igorkov=0; igorkov<
ngorkov; igorkov++)
623 for(
unsigned short c=0; c<
nc; c++){
627 complex<T> clov_s[
nc];
628 for(
unsigned short clov=0;clov<6;clov++){
629 clov_s[0]=clover1[clov*
kvol+i]; clov_s[1]=clover2[clov*
kvol+i];
631 for(
unsigned short igorkov=0; igorkov<
ngorkov; igorkov++){
633 const unsigned short idirac = igorkov&3;
634 const unsigned short sind = (igorkov<4) ? sigin[clov*
ndirac+idirac] : sigin[clov*
ndirac+idirac]+4;
636 for(
unsigned short c=0; c<
nc; c++)
639 phi_s[igorkov][0]+=sigval[clov*
ndirac+idirac]*(
creal(clov_s[0])*r_s[0]+clov_s[1]*r_s[1]);
641 phi_s[igorkov][1]+=sigval[clov*
ndirac+idirac]*(
conj(clov_s[1])*r_s[0]-
creal(clov_s[0])*r_s[1]);
645 for(
unsigned short igorkov=0; igorkov<
ngorkov; igorkov++)
646 for(
unsigned short c=0; c<
nc; c++){
649 phi[i+
kvol*(
nc*igorkov+c)]+=akappa*phi_s[igorkov][c];
651 phi[i+
kvolHalo*(
nc*igorkov+c)]+=akappa*phi_s[igorkov][c];
671 template <
typename T>
672 __global__ __launch_bounds__(
__BSIZE__)
void HbyClover(complex<T> * phi,
const complex<T> * __restrict__ r,
673 const complex<T> * __restrict__ clover1,
const complex<T> * __restrict__ clover2,
674 const __grid_constant__ complex<T> sigval[24],
const __grid_constant__
float akappa,
675 const __grid_constant__
unsigned short sigin[24],
const __grid_constant__
bool dag){
676 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
677 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
678 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
679 const unsigned int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
680 const unsigned int gthreadId= blockId * bsize+bthreadId;
682 for(
unsigned int i=gthreadId;i<
kvol;i+=bsize*gsize){
686 for(
unsigned short idirac=0; idirac<
ndirac*
nc; idirac+=
nc)
688 for(
unsigned short c=0; c<
nc; c++){
692 for(
unsigned short clov=0;clov<6;clov++){
693 const T clov_a=
creal(clover1[clov*
kvol+i]);
694 const complex<T> clov_b=clover2[clov*
kvol+i];
697 for(
unsigned short idirac=0; idirac<
ndirac*
nc; idirac+=
nc){
698 const complex<T> sig=sigval[clov*
ndirac+(idirac>>1)];
699 const unsigned int sind = i+
kvolHalo*(sigin[clov*
ndirac+(idirac>>1)] << (
nc-1));
700 const complex<T> r_s[
nc]={r[sind],r[sind+
kvolHalo]};
702 phi_s[idirac+0]+=sig*(clov_a*r_s[0]+clov_b*r_s[1]);
704 phi_s[idirac+1]+=sig*(
conj(clov_b)*r_s[0]-clov_a*r_s[1]);
708 for(
unsigned short idirac=0; idirac<
ndirac*
nc; idirac++)
711 phi[i+
kvol*(idirac)]+=akappa*phi_s[idirac];
713 phi[i+
kvolHalo*(idirac)]+=akappa*phi_s[idirac];
723 const char funcname[]=
"cuClover";
725 cudaMallocManaged((
void **)&clover[0],6*
kvol*
sizeof(
Complex_f),cudaMemAttachGlobal);
726 cudaMallocManaged((
void **)&clover[1],6*
kvol*
sizeof(
Complex_f),cudaMemAttachGlobal);
731 for(
unsigned short mu=0;mu<
ndim-1;mu++)
732 for(
unsigned short nu=mu+1;nu<
ndim;nu++)
735 unsigned short clov = (mu==0) ? nu-1 :mu+nu;
739 ut[0],ut[1],iu,id,mu,nu);
758 const unsigned short mu,
const unsigned short nu){
760 unsigned short clov = (mu==0) ? nu-1 : mu+nu;
765 const unsigned short *sigin,
const unsigned int *iu,
const unsigned int *
id,
const float akappa){
766 const char funcname[]=
"Clov_Force";
768 const unsigned short nclov = (
ndim-1)*(
ndim-2);
772 for(
unsigned short mu=0;mu<
ndim-1;mu++)
773 for(
unsigned short nu=mu;nu<
ndim;nu++)
776 unsigned short clov = (mu==0) ? nu-1 : mu+nu;
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]);
784 for(
unsigned short mu=0;mu<
ndim;mu++)
785 for(
unsigned short nu=0;nu<
ndim;nu++)
787 unsigned short clov=0;
789 clov = (mu==0) ? nu-1 : mu+nu;
791 clov = (nu==0) ? mu-1 : mu+nu;
793 Kernels::Clov_Force<<<dimGrid,dimBlock,0,streams[mu]>>>(dSdpi,ut[0],ut[1],Xmn[clov],iu,id,akappa,mu,nu);
797 for(
unsigned short clov=0;clov<nclov;clov++){
798 cudaFreeAsync(Xmn[clov].diag,NULL); cudaFreeAsync(Xmn[clov].offd,NULL);
Routines needed for Clover improved wilson fermions.
__device__ void GetBilinear(Complex_f Z[nc *nc], Bilinear_a Xmn, unsigned int ind)
Loads the compacted bilinear form into a complex valued matrix.
__device__ void cuByGenLeft(T a[nc], const unsigned short gen)
Multiply leaf (or part of one) by generator from left.
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.
__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
__device__ void cuByGenRight(T a[nc], const unsigned short gen)
Multiply leaf (or part of one) by generator from right.
__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.
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.
__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.
__device__ void cuGLeft(T out[4], const T G[2], const T X[4])
Multiplies by a gauge field from the left.
__device__ void cuGRight(T out[4], const T G[2], const T X[4])
Multiplies by a gauge field from the right.
void cuHbyClover(Complex *phi, Complex *r, Complex *clover[nc], Complex *sigval, const float akappa, unsigned short *sigin, bool dag)
CUDA wrapper for HbyClover.
void cuByClover_f(Complex_f *phi, Complex_f *r, Complex_f *clover[nc], Complex_f *sigval, const float akappa, unsigned short *sigin, bool dag)
CUDA wrapper for ByClover_f.
void cuHbyClover_f(Complex_f *phi, Complex_f *r, Complex_f *clover[nc], Complex_f *sigval, const float akappa, unsigned short *sigin, bool dag)
CUDA wrapper for HbyClover_f.
void cuByClover(Complex *phi, Complex *r, Complex *clover[nc], Complex *sigval, const float akappa, unsigned short *sigin, bool dag)
CUDA wrapper for ByClover.
__global__ void HbyClover(complex< T > *phi, const complex< T > *r, const complex< T > *clover1, const complex< T > *clover2, const __grid_constant__ complex< T > sigval[24], const __grid_constant__ float akappa, const __grid_constant__ unsigned short sigin[24], const __grid_constant__ bool dag)
Clover analogue of the Hdslash operation. The H in front is for half, as we only act on the fermions ...
__global__ void ByClover(complex< T > *phi, const complex< T > *r, const complex< T > *clover1, const complex< T > *clover2, const __grid_constant__ complex< T > sigval_G[24], const __grid_constant__ float akappa, const __grid_constant__ unsigned short sigin_G[24], const __grid_constant__ bool dag)
Clover analogue of the Dslash operation. This version acts on all flavours similar to Dslash and Dsla...
int cuClover(Complex_f *clover[nc], Complex_f *ut[nc], unsigned int *iu, unsigned int *id)
CUDA wrapper for calculating the clovers in all directions at all sites .
__global__ void Half_Leaves(complex< T > *hLeaves0, complex< T > *hLeaves1, const complex< T > *u11t, const complex< T > *u12t, const unsigned int *iu, const unsigned int *id, const __grid_constant__ unsigned short mu, const __grid_constant__ unsigned short nu)
Calculates the products of the first two links in a plaquette.
__global__ void Full_Clover(complex< T > *clover1, complex< T > *clover2, const complex< T > *u11t, const complex< T > *u12t, const unsigned int *iu, const unsigned int *id, const __grid_constant__ int mu, const __grid_constant__ int nu)
Calculates the clovers in all directions at all sites .
__device__ void Half_Leaf(complex< T > Leaves[nc], const complex< T > *u11t, const complex< T > *u12t, complex< T > a[nc], const unsigned int *iu, const unsigned int *id, const unsigned int i, const unsigned short mu, const unsigned short nu, const unsigned short leaf)
Calculates the first half of the leaf for a clover term. We split it so that the force term can reuse...
__device__ void Leaf(const complex< T > *u11t, const complex< T > *u12t, complex< T > Leaves[nc], const unsigned int *iu, const unsigned int *id, const unsigned int i, const unsigned short mu, const unsigned short nu, const unsigned short leaf)
Calculates a leaf for a clover term.
__device__ __forceinline__ T conj(const T &z)
Complex Conjugation.
#define ngorkov
Gor'kov indices.
#define nadj
adjacent spatial indices
#define kvol
Sublattice volume.
#define Complex
Double precision complex number.
#define __BSIZE__
Default block size.
#define ndirac
Dirac indices.
#define cudaDeviceSynchronise()
Get rid of that bastardised yankee English.
#define Complex_f
Single precision complex number.
#define kvolHalo
Subvolume + halo size.
Structure of arrays for Hermitian bilinear in memory.
Complex_f * offd
Complex valued off-diagonal terms. We only need to store one of these to get the other in .
float * diag
Real valued diagonal terms.
Hermitian bilinear on the local stack.
float diag[2]
Real valued diagonal terms.
Complex_f offd
Complex valued off-diagonal terms. We only need to store one of these to get the other in .
cudaStream_t streams[ndirac *ndim *nadj]
An array of concurrent GPU streams to keep it busy.
#define creal(z)
Extract Real Component using C standard notation.
#define I_f
Define I in single precision.