FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
deepflame-dev/src_gpu/dfMatrixDataBase.H at zt-dev · deepmodeling/deepflame-dev · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
deepmodeling
/
deepflame-dev
Public
forked from
deepflameCFD/deepflame-dev
Notifications
You must be signed in to change notification settings
Fork
77
Star
219
Code
Issues
27
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
deepflame-dev
/
src_gpu
/
dfMatrixDataBase.H
Copy path
More file actions
More file actions
Latest commit
History
History
History
325 lines (284 loc) · 10.2 KB
Breadcrumbs
deepflame-dev
/
src_gpu
/
dfMatrixDataBase.H
Copy path
File metadata and controls
325 lines (284 loc) · 10.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
pragma
once
#
include
<
stdio.h
>
#
include
<
unistd.h
>
#
include
"
cuda_profiler_api.h
"
#
include
<
cuda_runtime.h
>
#
include
"
nccl.h
"
#
include
"
mpi.h
"
#
include
"
nvtx3/nvToolsExt.h
"
#
include
<
vector
>
#
include
<
numeric
>
#
include
<
algorithm
>
#
include
<
map
>
#
include
<
iostream
>
#
include
<
ctime
>
#
include
<
cmath
>
#
include
<
unordered_map
>
#
include
"
AmgXSolver.H
"
#
include
<
amgx_c.h
>
//
#define DEBUG_
//
#define DEBUG_CHECK_LDU
extern
int
myRank;
#
define
GPU_DEBUG_
#
ifdef
GPU_DEBUG_
#
define
DEBUG_TRACE
fprintf
(stderr,
"
myRank[%d] %s %d
\n
"
, myRank, __FILE__, __LINE__);
#
else
#
define
DEBUG_TRACE
#
endif
const
double
SMALL
= std::numeric_limits<
double
>::epsilon();
static
const
char
*
_cudaGetErrorEnum
(cudaError_t error) {
return
cudaGetErrorName
(error);
}
template
<
typename
T>
void
check
(T result,
char
const
*
const
func,
const
char
*
const
file,
int
const
line) {
if
(result) {
fprintf
(stderr,
"
cuda error at %s:%d code=%d(%s)
\"
%s
\"
\n
"
, file, line,
static_cast
<
unsigned
int
>(result),
_cudaGetErrorEnum
(result), func);
exit
(
EXIT_FAILURE
);
}
}
#
define
checkCudaErrors
(
val
) check((val), #val, __FILE__, __LINE__)
inline
void
checkVectorEqual
(
int
count,
const
double
* basevec,
double
* vec,
double
max_relative_error,
bool
print =
false
) {
for
(
int
i =
0
; i < count; ++i)
{
double
abs_diff =
fabs
(basevec[i] - vec[i]);
double
rel_diff =
fabs
(basevec[i] - vec[i]) /
fabs
(basevec[i]);
if
(print && myRank ==
0
)
fprintf
(stderr,
"
myRank[%d] index %d, cpu data: %.24lf, gpu data: %.24lf, relative error: %.24lf
\n
"
, myRank, i, basevec[i
], vec[i], rel_diff);
//
if (abs_diff > 1e-12 && rel_diff > max_relative_error && !std::isinf(rel_diff))
if
(abs_diff >
1e-15
&& rel_diff > max_relative_error && myRank ==
0
)
fprintf
(stderr,
"
myRank[%d] mismatch index %d, cpu data: %.30lf, gpu data: %.30lf, relative error: %.16lf
\n
"
, myRank, i, basevec[i], vec[i], rel_diff);
}
}
enum
AMGXSetting {
u_setting,
p_setting
};
enum
location {
cpu,
gpu
};
enum
position {
internal,
boundary
};
enum
boundaryConditions{
zeroGradient,
fixedValue,
coupled,
empty,
gradientEnergy,
calculated,
cyclic,
processor,
extrapolated,
fixedEnergy,
processorCyclic
};
void
constructBoundarySelectorPerPatch
(
int
*patchTypeSelector,
const
std::string& patchTypeStr);
struct
dfMatrixDataBase
{
//
cuda resource
cudaStream_t stream;
//
communication info
MPI_Comm mpi_comm;
ncclComm_t nccl_comm;
ncclUniqueId nccl_id;
int
nRanks;
int
myRank;
int
localRank;
std::vector<
int
> neighbProcNo;
//
cyclic info
std::vector<
int
> cyclicNeighbor;
std::vector<
int
> patchSizeOffset;
//
constant values -- basic
int
num_cells =
0
;
int
num_total_cells =
0
;
int
num_surfaces =
0
;
int
num_boundary_surfaces =
0
;
int
num_proc_surfaces =
0
;
int
num_Nz =
0
;
int
num_patches =
0
;
int
num_species =
0
;
std::vector<
int
> patch_size;
std::vector<
int
> patch_type_calculated;
std::vector<
int
> patch_type_extropolated;
std::vector<
int
> patch_type_T;
double
rdelta_t
=
0
;
std::vector<
int
> lduCSRIndex;
//
constant values -- ldu bytesize
size_t
cell_value_bytes =
0
;
size_t
cell_value_vec_bytes =
0
;
size_t
cell_value_tsr_bytes =
0
;
size_t
cell_index_bytes =
0
;
size_t
surface_value_bytes =
0
;
size_t
surface_index_bytes =
0
;
size_t
surface_value_vec_bytes =
0
;
size_t
boundary_surface_value_bytes =
0
;
size_t
boundary_surface_value_vec_bytes =
0
;
size_t
boundary_surface_value_tsr_bytes =
0
;
size_t
boundary_surface_index_bytes =
0
;
//
constant values -- csr bytesize
size_t
csr_row_index_bytes =
0
;
size_t
csr_col_index_bytes =
0
;
size_t
csr_value_bytes =
0
;
size_t
csr_value_vec_bytes =
0
;
//
constant indexes
int
*d_owner =
nullptr
;
int
*d_neighbor =
nullptr
;
int
*d_diag_to_csr_index=
nullptr
;
int
*d_ldu_to_csr_index =
nullptr
;
int
*d_csr_row_index=
nullptr
;
int
*d_csr_col_index=
nullptr
;
//
amgx solvers
AmgXSolver *u_setting_solver =
nullptr
;
AmgXSolver *p_setting_solver =
nullptr
;
//
constant fields - internal
double
*d_sf =
nullptr
;
double
*d_mesh_dis =
nullptr
;
double
*d_mag_sf =
nullptr
;
double
*d_weight =
nullptr
;
double
*d_phi_weight =
nullptr
;
//
weight for mvConvection->fvmDiv
double
*d_delta_coeffs =
nullptr
;
double
*d_volume =
nullptr
;
double
*h_sf =
nullptr
;
double
*h_mesh_dis =
nullptr
;
//
constant fields - boundary
double
*d_boundary_sf =
nullptr
;
double
*d_boundary_mag_sf =
nullptr
;
double
*d_boundary_weight =
nullptr
;
double
*d_boundary_delta_coeffs =
nullptr
;
int
*d_boundary_face_cell =
nullptr
;
double
*h_boundary_sf =
nullptr
;
//
non-constant fields - internal
//
TODO: further estimate
//
fields solved by eqns - new
double
*d_rho =
nullptr
;
double
*d_u =
nullptr
;
double
*d_y =
nullptr
;
double
*d_he =
nullptr
;
double
*d_p =
nullptr
;
double
*d_k =
nullptr
;
//
fields solved by eqns - old
//
TODO: not all fields need to store oldTime
double
*d_rho_old =
nullptr
;
double
*d_k_old =
nullptr
;
double
*d_u_old =
nullptr
;
double
*d_p_old =
nullptr
;
double
*d_u_old_host_order =
nullptr
;
//
tmp
//
double *d_y_old = nullptr;
//
double *d_he_old = nullptr;
//
double *d_p_old = nullptr;
//
other shared fields between eqns
double
*d_phi =
nullptr
;
double
*d_phi_old =
nullptr
;
//
other shared fields between eqns - thermophysical
double
*d_thermo_psi =
nullptr
;
double
*d_hDiff_corr_flux =
nullptr
;
double
*d_diff_alphaD =
nullptr
;
double
*d_dpdt =
nullptr
;
double
*d_T =
nullptr
;
double
*h_T =
nullptr
;
double
*d_mu =
nullptr
;
double
*d_thermo_alpha =
nullptr
;
double
*d_thermo_rhoD =
nullptr
;
//
computed on GPU, used on CPU, need memcpyd2h - host
double
*h_rho =
nullptr
;
double
*h_rho_old =
nullptr
;
double
*h_u=
nullptr
;
double
*h_u_old=
nullptr
;
double
*h_y=
nullptr
;
double
*h_he=
nullptr
;
double
*h_k=
nullptr
;
double
*h_k_old =
nullptr
;
//
computed on CPU, used on GPU, need memcpyh2d - host
double
*h_p=
nullptr
;
double
*h_p_old =
nullptr
;
double
*h_phi=
nullptr
;
//
internal fields used between eqns
double
*d_rAU =
nullptr
;
double
*d_HbyA =
nullptr
;
//
turbulence fields
double
*d_turbulence_k =
nullptr
;
double
*d_turbulence_epsilon =
nullptr
;
//
non-constant fields - boundary
//
TODO: further estimate
//
fields solved by eqns - new
double
*d_boundary_rho =
nullptr
;
double
*d_boundary_u =
nullptr
;
double
*d_boundary_y =
nullptr
;
double
*d_boundary_he =
nullptr
;
double
*d_boundary_p =
nullptr
;
double
*d_boundary_p_old =
nullptr
;
double
*d_boundary_k =
nullptr
;
//
fields solved by eqns - old
double
*d_boundary_rho_old =
nullptr
;
double
*d_boundary_u_old =
nullptr
;
double
*d_boundary_u_old_host_order =
nullptr
;
//
tmp
//
double *d_boundary_y_old = nullptr;
//
double *d_boundary_he_old = nullptr;
//
double *d_boundary_p_old = nullptr;
//
other shared fields between eqns
double
*d_boundary_phi =
nullptr
;
double
*d_boundary_phi_old =
nullptr
;
//
other shared fields between eqns - thermophysical
double
*d_boundary_thermo_psi =
nullptr
;
double
*d_boundary_hDiff_corr_flux =
nullptr
;
double
*d_boundary_diff_alphaD =
nullptr
;
double
*d_boundary_T =
nullptr
;
double
*d_boundary_mu =
nullptr
;
double
*d_boundary_thermo_alpha =
nullptr
;
double
*d_boundary_thermo_rhoD =
nullptr
;
//
boundary fields used between eqns
double
*d_boundary_rAU =
nullptr
;
double
*d_boundary_HbyA =
nullptr
;
//
computed on GPU, used on CPU, need memcpyd2h - host
double
*h_boundary_rho =
nullptr
;
double
*h_boundary_rho_old =
nullptr
;
double
*h_boundary_u=
nullptr
;
double
*h_boundary_u_old=
nullptr
;
double
*h_boundary_y=
nullptr
;
double
*h_boundary_he=
nullptr
;
double
*h_boundary_k =
nullptr
;
//
computed on CPU, used on GPU, need memcpyh2d - host
double
*h_boundary_p=
nullptr
;
double
*h_boundary_p_old=
nullptr
;
double
*h_boundary_phi=
nullptr
;
double
*h_boundary_phi_old=
nullptr
;
std::unordered_map<std::string,
double
*> fieldPointerMap;
//
constructor
dfMatrixDataBase
();
//
deconstructor
~dfMatrixDataBase
();
//
member function
void
prepareCudaResources
();
void
cleanCudaResources
();
void
setCommInfo
(MPI_Comm mpi_comm, ncclComm_t nccl_comm, ncclUniqueId nccl_id,
int
nRanks,
int
myRank,
int
localRank, std::vector<
int
> &neighbProcNo);
void
setConstantValues
(
int
num_cells,
int
num_total_cells,
int
num_surfaces,
int
num_boundary_surfaces,
int
num_patches,
int
num_proc_surfaces,
std::vector<
int
> patch_size,
int
num_species,
double
rdelta_t
);
void
setConstantIndexes
(
const
int
*owner,
const
int
*neighbor,
const
int
*procRows,
const
int
*procCols,
int
globalOffset);
void
setAmgxSolvers
(
const
std::string &mode_string,
const
std::string &u_setting_path,
const
std::string &p_setting_path);
void
resetAmgxSolvers
();
void
solve
(
int
num_iteration, AMGXSetting setting,
double
*d_A,
double
*d_x,
double
*d_b);
void
setCyclicInfo
(std::vector<
int
> &cyclicNeighbor);
//
when use cyclic boundary
void
createConstantFieldsInternal
();
void
createConstantFieldsBoundary
();
void
initConstantFieldsInternal
(
const
double
*sf,
const
double
*mag_sf,
const
double
*weight,
const
double
*delta_coeffs,
const
double
*volume,
const
double
*mesh_distance);
void
initConstantFieldsBoundary
(
const
double
*boundary_sf,
const
double
*boundary_mag_sf,
const
double
*boundary_delta_coeffs,
const
double
*boundary_weight,
const
int
*boundary_face_cell,
std::vector<
int
> &patch_type_calculated, std::vector<
int
> &patch_type_extropolated);
void
createNonConstantFieldsInternal
();
void
createNonConstantFieldsBoundary
();
void
initNonConstantFieldsInternal
();
void
initNonConstantFieldsBoundary
();
void
preTimeStep
();
void
postTimeStep
();
//
getter
double
*
getFieldPointer
(
const
char
* fieldAlias, location loc, position pos);
};
Back
|
FazBrowse Home
|
New Git URL