su2hmc
Loading...
Searching...
No Matches
cubosonic.cu
Go to the documentation of this file.
1
7#include <su2hmc.h>
8#include <matrices.h>
9#include <thrust/reduce.h>
10//#include <thrust/execution_policy.h>
11
13namespace Device{
26 __device__ void cuSU2plaq(const Complex_f * __restrict__ u11t, const Complex_f * __restrict__ u12t,
27 Complex_f * __restrict__ Sigma11, Complex_f * __restrict__ Sigma12, const unsigned int * __restrict__ iu,
28 const unsigned int i, const unsigned short mu, const unsigned short nu){
29 const unsigned int uidm = iu[i+kvol*mu];
30 unsigned int ind=i+kvolHalo*mu;
31 //Need a second index in the nu direction for the first step
32 unsigned int indn=uidm+kvolHalo*nu;
33 *Sigma11=u11t[ind]*u11t[indn]-u12t[ind]*conj(u12t[indn]);
34 *Sigma12=u11t[ind]*u12t[indn]+u12t[ind]*conj(u11t[indn]);
35
36 const int uidn = iu[i+kvol*nu];
37 ind=uidn+kvolHalo*mu;
38 Complex_f a11=*Sigma11*conj(u11t[ind])+*Sigma12*conj(u12t[ind]);
39 Complex_f a12=-*Sigma11*u12t[ind]+*Sigma12*u11t[ind];
40
41 ind=i+kvol*nu;
42 *Sigma11=a11*conj(u11t[ind])+a12*conj(u12t[ind]);
43 *Sigma12=-a11*u12t[ind]+a12*u11t[ind];
44 return;
45 }
46}
47
48namespace Kernels{
49 using namespace Device;
60 __global__ __launch_bounds__(__BSIZE__) void Average_Plaquette(float * __restrict__ hgs_d,
61 float * __restrict__ hgt_d, const Complex_f * __restrict__ u11t, const Complex_f * __restrict__ u12t,
62 const unsigned int * __restrict__ iu){
63 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
64 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
65 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
66 const unsigned int threadId= blockId * bsize+(threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
67
68 Complex_f Sigma11,Sigma12;
69 for(unsigned int i=threadId;i<kvol;i+=bsize*gsize){
70 float hg_c[2];
71 hg_c[0]=0; hg_c[1]=0;
72
73 for(unsigned short mu=1;mu<ndim;mu++)
74 for(unsigned short nu=0;nu<mu;nu++){
75 //This is threadsafe as the @f$\mu@f$ and @f$\nu@f$ loops are not distributed across threads
76 cuSU2plaq(u11t,u12t,&Sigma11,&Sigma12,iu,i,mu,nu);
77 switch(mu){
78 //Time component
79 case(ndim-1):
80 hg_c[0] -= creal(Sigma11);
81 break;
82 //Space component
83 default:
84 hg_c[1] -= creal(Sigma11);
85 break;
86 }
87 }
88 hgt_d[i]=hg_c[0]; hgs_d[i]=hg_c[1];
89 }
90 }
91
100 __global__ __launch_bounds__(__BSIZE__) void Polyakov(Complex_f * __restrict__ Sigma11,
101 Complex_f * __restrict__ Sigma12, const Complex_f * __restrict__ u11t,
102 const Complex_f * __restrict__ u12t){
103 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
104 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
105 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
106 const unsigned int threadId= blockId * bsize+(threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
107 for(unsigned int i=threadId;i<kvol3;i+=gsize*bsize){
108 Complex_f Sig[2]; Sig[0]=Sigma11[i]; Sig[1]=Sigma12[i];
109 Complex_f u[2];
110 for(unsigned int it=1;it<ksizet;it++){
111 const unsigned int indexu=it*kvol3+i;
112 u[0]=u11t[indexu+3*kvolHalo];u[1]=u12t[indexu+3*kvolHalo];
113 Complex_f a11=Sig[0]*u[0]-Sig[1]*conj(u[1]);
114 //Instead of having to store a second buffer just assign it directly
115 Sig[1]=Sig[0]*u[1]+Sig[1]*conj(u[0]);
116 Sig[0]=a11;
117 }
118 Sigma11[i]=Sig[0]; Sigma12[i]=Sig[1];
119 }
120 }
121}
122
123using namespace Kernels;
125__host__ void cuAverage_Plaquette(double *hgs, double *hgt, Complex_f *u11t, Complex_f *u12t, unsigned int *iu,dim3 dimGrid, dim3 dimBlock){
126 // float *hgs_d, *hgt_d;
127 int device=-1;
128 cudaGetDevice(&device);
129 float *hgs_d, *hgt_d;
130 //Thrust want things in a weird format for the reduction, thus we oblige
131 cudaMallocAsync((void **)&hgs_d,kvol*sizeof(float),NULL);
132 thrust::device_ptr<float> hgs_T = thrust::device_pointer_cast(hgs_d);
133 cudaMallocAsync((void **)&hgt_d,kvol*sizeof(float),NULL);
134 thrust::device_ptr<float> hgt_T = thrust::device_pointer_cast(hgt_d);
135
136 Kernels::Average_Plaquette<<<dimGrid,dimBlock,0,NULL>>>(hgs_d, hgt_d, u11t, u12t, iu);
138
139 *hgs= (double)thrust::reduce(hgs_T,hgs_T+kvol,(float)0);
140 *hgt= (double)thrust::reduce(hgt_T,hgt_T+kvol,(float)0);
142
143 cudaFreeAsync(hgs_d,streams[0]); cudaFreeAsync(hgt_d,streams[1]);
144}
145void cuPolyakov(Complex_f *Sigma[2], Complex_f *ut[2], dim3 dimGrid, dim3 dimBlock){
146 int device=-1;
147 cudaGetDevice(&device);
148 cudaMallocManaged((void **)&Sigma[0],kvol3*sizeof(Complex_f),cudaMemAttachGlobal);
149#ifdef _DEBUG
150 cudaMallocManaged((void **)&Sigma[1],kvol3*sizeof(Complex_f),cudaMemAttachGlobal);
151#else
152 cudaMallocAsync((void **)&Sigma[1],kvol3*sizeof(Complex_f),streams[0]);
153#endif
154 //Extract the time component from each site and save in corresponding Sigma
155 cublasCcopy(cublas_handle,kvol3, (cuComplex *)(ut[0])+3*kvolHalo, 1, (cuComplex *)Sigma[0], 1);
156 cublasCcopy(cublas_handle,kvol3, (cuComplex *)(ut[1])+3*kvolHalo, 1, (cuComplex *)Sigma[1], 1);
157
159 Kernels::Polyakov<<<dimGrid,dimBlock>>>(Sigma[0],Sigma[1],ut[0],ut[1]);
160 //cudaMemPrefetchAsync(Sigma[0],kvol3*sizeof(Complex_f),cudaCpuDeviceId,streams[0]);
161#ifdef _DEBUG
162 cudaFree(Sigma[1]);
163#else
164 cudaFreeAsync(Sigma[1],streams[1]);
165#endif
167}
void cuPolyakov(Complex_f *Sigma[2], Complex_f *ut[2], dim3 dimGrid, dim3 dimBlock)
Calculate the Polyakov loop (no prizes for guessing that one...).
Definition cubosonic.cu:145
__device__ void cuSU2plaq(const Complex_f *u11t, const Complex_f *u12t, Complex_f *Sigma11, Complex_f *Sigma12, const unsigned int *iu, const unsigned int i, const unsigned short mu, const unsigned short nu)
Calculates the SU2 plaquette.
Definition cubosonic.cu:26
__global__ void Polyakov(Complex_f *Sigma11, Complex_f *Sigma12, const Complex_f *u11t, const Complex_f *u12t)
Calculate the Polyakov loop (no prizes for guessing that one...).
Definition cubosonic.cu:100
void cuAverage_Plaquette(double *hgs, double *hgt, Complex_f *u11t, Complex_f *u12t, unsigned int *iu, dim3 dimGrid, dim3 dimBlock)
Calculates the gauge action using new (how new?) lookup table Follows a routine called qedplaq in som...
Definition cubosonic.cu:125
__global__ void Average_Plaquette(float *hgs_d, float *hgt_d, const Complex_f *u11t, const Complex_f *u12t, const unsigned int *iu)
Calculates the gauge action using new (how new?) lookup table Follows a routine called qedplaq in som...
Definition cubosonic.cu:60
__device__ __forceinline__ T conj(const T &z)
Complex Conjugation.
Definition cusu2hmc.cu:33
Matrix multiplication and related declarations.
CUDA Device code.
Definition cubosonic.cu:13
CUDA Kernels.
Definition cubosonic.cu:48
#define ksizet
Sublattice t extent.
Definition sizes.h:162
#define kvol
Sublattice volume.
Definition sizes.h:167
#define __BSIZE__
Default block size.
Definition sizes.h:48
#define cudaDeviceSynchronise()
Get rid of that bastardised yankee English.
Definition sizes.h:57
#define kvol3
Sublattice spatial volume.
Definition sizes.h:169
#define Complex_f
Single precision complex number.
Definition sizes.h:66
dim3 dimGrid
Default grid size. First component is normally nt. Second and third depend whatever is needed to get ...
Definition cusu2hmc.cu:27
#define ndim
Dimensions.
Definition sizes.h:192
#define kvolHalo
Subvolume + halo size.
Definition sizes.h:238
dim3 dimBlock
Default block size. Usually 128.
Definition cusu2hmc.cu:25
Function declarations for most of the routines.
cudaStream_t streams[ndirac *ndim *nadj]
An array of concurrent GPU streams to keep it busy.
Definition cusu2hmc.cu:29
#define creal(z)
Extract Real Component using C standard notation.