-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
217 lines (157 loc) · 5.11 KB
/
main.c
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
#include <cuda.h>
#include <cuda_runtime.h>
#include "cublas.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "cudaglobal.h"
#include "mixed_solve.h"
#include <math.h>
extern "C" {
#include su3.h
#include gauge_io.h
}
#define ACCUM_N 2048
#define DOTPROD_DIM 128
//#define GF_8
int g_numofgpu;
#ifdef GF_8
dev_su3_8 * dev_gf;
dev_su3_8 * h2d_gf;
#else
dev_su3_2v * dev_gf;
dev_su3_2v * h2d_gf;
#endif
#ifdef GF_8
dev_su3_8 * dev_trafo;
dev_su3_8 * h2d_trafo;
#else
dev_su3_2v * dev_trafo;
dev_su3_2v * h2d_trafo;
#endif
int * nn;
size_t output_size;
int* dev_grid;
float * dev_output;
__device__ int dev_LX,dev_LY,dev_LZ,dev_T,dev_VOLUME;
/* texture for gauge field */
texture<float4,1, cudaReadModeElementType> gf_tex;
const textureReference* gf_texRefPtr = NULL;
cudaChannelFormatDesc gf_channelDesc;
/* texture for trafo field */
texture<float4,1, cudaReadModeElementType> trafo_tex;
const textureReference* trafo_texRefPtr = NULL;
cudaChannelFormatDesc trafo_channelDesc;
// get 2 first rows of gf float4 type
//
//
void su3to2vf4(su3** gf, dev_su3_2v* h2d_gf){
int i,j;
for (i=0;i<VOLUME;i++){
for(j=0;j<4;j++){
//first row
h2d_gf[3*(4*i+j)].x = (REAL) gf[i][j].c00.re;
h2d_gf[3*(4*i+j)].y = (REAL) gf[i][j].c00.im;
h2d_gf[3*(4*i+j)].z = (REAL) gf[i][j].c01.re;
h2d_gf[3*(4*i+j)].w = (REAL) gf[i][j].c01.im;
h2d_gf[3*(4*i+j)+1].x = (REAL) gf[i][j].c02.re;
h2d_gf[3*(4*i+j)+1].y = (REAL) gf[i][j].c02.im;
//second row
h2d_gf[3*(4*i+j)+1].z = (REAL) gf[i][j].c10.re;
h2d_gf[3*(4*i+j)+1].w = (REAL) gf[i][j].c10.im;
h2d_gf[3*(4*i+j)+2].x = (REAL) gf[i][j].c11.re;
h2d_gf[3*(4*i+j)+2].y = (REAL) gf[i][j].c11.im;
h2d_gf[3*(4*i+j)+2].z = (REAL) gf[i][j].c12.re;
h2d_gf[3*(4*i+j)+2].w = (REAL) gf[i][j].c12.im;
}
}
}
// bring gf into the form
// a2 a3, theta_a1, theta_c1, b1
//
void su3to8(su3** gf, dev_su3_8* h2d_gf){
int i,j;
for (i=0;i<VOLUME;i++){
for(j=0;j<4;j++){
// a2, a3
h2d_gf[2*(4*i+j)].x = (REAL) gf[i][j].c01.re;
h2d_gf[2*(4*i+j)].y = (REAL) gf[i][j].c01.im;
h2d_gf[2*(4*i+j)].z = (REAL) gf[i][j].c02.re;
h2d_gf[2*(4*i+j)].w = (REAL) gf[i][j].c02.im;
// theta_a1, theta_c1
// use atan2 for this: following the reference, atan2 should give an angle -pi < phi < +pi
h2d_gf[2*(4*i+j)+1].x = (REAL)( atan2((REAL) gf[i][j].c00.im,(REAL) gf[i][j].c00.re ));
h2d_gf[2*(4*i+j)+1].y = (REAL) ( atan2((REAL) gf[i][j].c20.im,(REAL)gf[i][j].c20.re ));
// b1
h2d_gf[2*(4*i+j)+1].z = (REAL) gf[i][j].c10.re ;
h2d_gf[2*(4*i+j)+1].w = (REAL) gf[i][j].c10.im ;
}
}
}
void init_gaugefixing(su3** gf, su3** trafo){
cudaError_t cudaerr;
// the gauge field
#ifdef GF_8
/* allocate 8 floats of gf = 2*4*VOLUME float4's*/
size_t dev_gfsize = 2*4*VOLUME * sizeof(dev_su3_8);
#else
/* allocate 2 rows of gf = 3*4*VOLUME float4's*/
size_t dev_gfsize = 3*4*VOLUME * sizeof(dev_su3_2v);
#endif
if((cudaerr=cudaMalloc((void **) &dev_gf, dev_gfsize)) != cudaSuccess){
printf("Error in init_mixedsolve(): Memory allocation of gauge field failed. Aborting...\n");
exit(200);
} // Allocate array on device
else{
printf("Allocated gauge field on device\n");
}
#ifdef GF_8
h2d_gf = (dev_su3_8 *)malloc(dev_gfsize); // Allocate REAL conversion gf on host
su3to8(gf,h2d_gf);
#else
h2d_gf = (dev_su3_2v *)malloc(dev_gfsize); // Allocate REAL conversion gf on host
su3to2vf4(gf,h2d_gf);
#endif
cudaMemcpy(dev_gf, h2d_gf, dev_gfsize, cudaMemcpyHostToDevice);
// the trafo fields
#ifdef GF_8
/* allocate 8 floats of trafo = 2*VOLUME float4's*/
size_t dev_gfsize = 2*VOLUME * sizeof(dev_su3_8);
#else
/* allocate 2 rows of gf = 3*4*VOLUME float4's*/
size_t dev_gfsize = 3*VOLUME * sizeof(dev_su3_2v);
#endif
if((cudaerr=cudaMalloc((void **) &dev_trafo, dev_gfsize)) != cudaSuccess){
printf("Error in init_mixedsolve(): Memory allocation of gauge field failed. Aborting...\n");
exit(200);
} // Allocate array on device
else{
printf("Allocated gauge field on device\n");
}
#ifdef GF_8
h2d_trafo = (dev_su3_8 *)malloc(dev_gfsize); // Allocate REAL conversion gf on host
su3to8(trafo,h2d_trafo);
#else
h2d_trafo = (dev_su3_2v *)malloc(dev_gfsize); // Allocate REAL conversion gf on host
su3to2vf4(trafo,h2d_trafo);
#endif
cudaMemcpy(dev_trafo, h2d_trafo, dev_gfsize, cudaMemcpyHostToDevice);
//grid
size_t nnsize = 8*VOLUME*sizeof(int);
nn = (int *) malloc(nnsize);
cudaMalloc((void **) &dev_nn, nnsize);
initnn();
//shownn();
//showcompare_gf(T-1, LX-1, LY-1, LZ-1, 3);
cudaMemcpy(dev_nn, nn, nnsize, cudaMemcpyHostToDevice);
//free again
free(nn);
output_size = LZ*T*sizeof(float); // parallel in t and z direction
cudaMalloc((void **) &dev_output, output_size); // output array
float * host_output = (float*) malloc(output_size);
int grid[5];
grid[0]=LX; grid[1]=LY; grid[2]=LZ; grid[3]=T; grid[4]=VOLUME;
cudaMalloc((void **) &dev_grid, 5*sizeof(int));
cudaMemcpy(dev_grid, &(grid[0]), 5*sizeof(int), cudaMemcpyHostToDevice);
}