Peano
Loading...
Searching...
No Matches
kernel-throughput.py
Go to the documentation of this file.
1import os
2import argparse
3import numpy as np
4
5import peano4.api
6import exaparty
7import exaparty.api.sphtools as sphtools
8import dastgen2
9
10import shutil
11
12
13
16
17Kernels_GPU = ["drift_gpu", "kick1_gpu", "kick2_gpu", "density_gpu", "force_gpu"]
18Kernels = [ "drift", "kick1", "kick2", "density", "force" ] + Kernels_GPU
19
20if __name__ == "__main__":
21 parser = argparse.ArgumentParser(description="SPH kernel benchmarking script")
22 parser.add_argument(
23 "-j",
24 "--parallel-builds",
25 dest="j",
26 type=int,
27 default=-1,
28 help="Parallel builds",
29 )
30 parser.add_argument(
31 "-v",
32 "--verbose",
33 dest="verbose",
34 action="store_true",
35 default=False,
36 help="Verbose",
37 )
38 parser.add_argument(
39 "-d",
40 "--dimensions",
41 dest="dimensions",
42 required=True,
43 type=int,
44 help="Dimensions of problem",
45 )
46 parser.add_argument(
47 "-maxp",
48 "--max-particle-number",
49 dest="max_particle_number",
50 default=65536,
51 type=int,
52 help="Max number of particles to be tested",
53 )
54 parser.add_argument(
55 "-minp",
56 "--min-particle-number",
57 dest="min_particle_number",
58 default=1,
59 type=int,
60 help="Min number of particles to be tested",
61 )
62 parser.add_argument(
63 "-s",
64 "--samples",
65 dest="samples",
66 default=16,
67 type=int,
68 help="Number of overall samples",
69 )
70 parser.add_argument(
71 "-wis",
72 "--work-item-size",
73 dest="work_item_size",
74 default=1024,
75 type=int,
76 help="Size of a work item",
77 )
78 parser.add_argument(
79 "-wir",
80 "--work-item-repeats",
81 dest="work_item_repeats",
82 default=1,
83 type=int,
84 help="Size of a work item",
85 )
86 parser.add_argument(
87 "-o",
88 "--output",
89 dest="output_file",
90 default="kernel-benchmarks",
91 help="Executable file name",
92 )
93 parser.add_argument(
94 "-pd",
95 "--peano-dir",
96 dest="peanodir",
97 default="../../../..",
98 help="Peano4 directory",
99 )
100 parser.add_argument(
101 "-m",
102 "--mode",
103 dest="mode",
104 choices=["release", "stats", "trace", "asserts", "debug"],
105 default="release",
106 help="Pick build type",
107 )
108 parser.add_argument(
109 "--enable-kernel",
110 dest="kernels",
111 choices=Kernels,
112 default=Kernels,
113 nargs="+",
114 help="Pick kernels that have to be tested",
115 )
116 parser.add_argument(
117 "--cpu-only",
118 dest="cpu_only",
119 action="store_true",
120 default=False,
121 help="Run only CPU benchmarks",
122 )
123 parser.add_argument(
124 "--gpu-only",
125 dest="gpu_only",
126 action="store_true",
127 default=False,
128 help="Run only GPU benchmarks",
129 )
130 parser.add_argument(
131 "--enable-soa-conversion",
132 dest="soa_conversion",
133 choices=['true', 'false', 'ignore'],
134 default='ignore',
135 help="Enable compiler-driver AoS to SoA conversions. Triggers adding flags to the compiler call, while ignore adds nothing and can therefore be used with unpatched compilers, too"
136 )
137 parser.add_argument(
138 "--validate",
139 dest="validate",
140 choices=['true', 'false'],
141 default='true',
142 help="Validate that results of all kernels yield the same result"
143 )
144 args = parser.parse_args()
145
146
149
150 project_namespace = ["benchmarks", "exaparty", "hydro", "kernel_throughput"]
151
153 namespace=project_namespace, project_name="Benchmarks", executable=args.output_file
154 )
155
156 # Initialise the SPH particle --------------------------------------------------
157 # If multiple particle species are present, we can specify the parameters
158 # independently for each case.
159
160 name = "HydroPart"
161
162 dimensions = args.dimensions
163 hydro_dimensions = 2 # dimensions for the hydro
164
166 name=name,
167 dimensions_hydro=hydro_dimensions,
168 cfl_factor=0.01,
169 initial_time_step_size=0.01,
170 constant_time_step_size=True,
171 exaparty_project_namespace=project_namespace,
172 particles_per_cell=100,
173 min_h=1.0,
174 max_h=1.0,
175 )
176
177
183
184 # HYDRO_DIMENSION can be smaller than the Peano4 dimensions
185 HYDRO_DIMENSIONS = hydro_dimensions
186
187 # Time integration parameters
188 # GLOBAL_TIME_STEP_SIZE = args.timestep_size
189 # CFL_CONSTANT = args.cfl_factor
190
191 # EoS parameter ---------------------------------------------------------------
192 gamma_hydro_list = [str(5 / 3), str(7 / 5), str(4 / 3), str(2 / 1)]
193 gamma_hydro_list_symbols = [
194 "HYDRO_GAMMA_5_3",
195 "HYDRO_GAMMA_7_5",
196 "HYDRO_GAMMA_4_3",
197 "HYDRO_GAMMA_2_1",
198 ]
199 GAMMA = gamma_hydro_list[0]
200 GAMMA_HYDRO_SYMBOL = gamma_hydro_list_symbols[0]
201
202 # SPH kernel -------------------------------------------------------
203
204 kernel = "quartic_spline"
205 KERNEL_SYMBOL = sphtools.sph_kernel_macro_name[kernel]
206 KERNEL_SUPPORT_RAD = sphtools.sph_kernel_H_over_h[HYDRO_DIMENSIONS - 1][kernel]
207
208 particle.h_hydro_max = 0.01
209
210
216 particle.data.expose_all_attributes_in_header_file()
217 particle_set = project.add_particle_species(particle)
218
219
225 if args.mode == "release":
226 build_mode = peano4.api.output.CompileMode.RELEASE
227 if args.mode == "stats":
228 build_mode = peano4.api.output.CompileMode.STATS
229 if args.mode == "asserts":
230 build_mode = peano4.api.output.CompileMode.ASSERTS
231 if args.mode == "trace":
232 build_mode = peano4.api.output.CompileMode.TRACE
233 if args.mode == "debug":
234 build_mode = peano4.api.output.CompileMode.DEBUG
235
236 # Set Peano4 simulation parameters ---------------------------------------------
237 offset = [0, 0, 0]
238 domain_size = [1, 1, 1]
239 periodic_boundary_conditions = [False, False, False]
240
241 project.set_global_simulation_parameters(
242 dimensions=dimensions,
243 offset=offset,
244 domain_size=domain_size,
245 min_end_time=1.0,
246 max_end_time=0.0,
247 first_plot_time_stamp=0.0,
248 time_in_between_plots=0.0,
249 periodic_BC=periodic_boundary_conditions,
250 plotter_precision=8,
251 )
252
253 project.set_Peano4_installation(args.peanodir, build_mode)
254
255
256
267
268 peano4_project = project.generate_Peano4_project(verbose=args.verbose)
269
270 # Some sanity checks ----------------------------------------------------------
271 if GAMMA not in gamma_hydro_list:
272 print(f"Please check the value of GAMMA. You have chosen: {GAMMA}")
273
274 # Export Constants.h file ------------------------------------------------------
275 peano4_project.constants.export_const_with_type(
276 "HYDRO_DIMENSIONS", str(HYDRO_DIMENSIONS), "double"
277 )
278 # peano4_project.constants.export_const_with_type(
279 # "HYDRO_PART_NUMBER", str(HYDRO_PART_NUMBER), "double"
280 # )
281 # peano4_project.constants.export_const_with_type(
282 # "GLOBAL_TIME_STEP_SIZE", str(GLOBAL_TIME_STEP_SIZE), "double"
283 # )
284 peano4_project.constants.export_const_with_type("GAMMA", GAMMA, "double")
285
286 # Export symbols for compilation (e.g. for SPH kernel) -----------------------
287 peano4_project.output.makefile.add_CXX_flag(
288 "-D" + "HYDRO_DIMENSION=" + str(HYDRO_DIMENSIONS)
289 )
290 peano4_project.output.makefile.add_CXX_flag("-D" + GAMMA_HYDRO_SYMBOL)
291 peano4_project.output.makefile.add_CXX_flag("-D" + KERNEL_SYMBOL)
292
293 if args.validate == 'true':
294 peano4_project.output.makefile.add_CXX_flag("-DValidateSWIFTKernelOutcomes")
295
296 if args.soa_conversion == 'true':
297 peano4_project.output.makefile.add_CXX_flag("-fsoa-conversion-attributes")
298 elif args.soa_conversion == 'false':
299 peano4_project.output.makefile.add_CXX_flag("-fno-soa-conversion-attributes")
300 else:
301 pass # do not add any flags that an unsuspecting compiler might be unaware of
302
303 peano4_project.output.makefile.add_cpp_file( "NohProblem.cpp" )
304
305 peano4_project.constants.export_const_with_type("Benchmark_MaxParticles", str(args.max_particle_number), "int")
306 peano4_project.constants.export_const_with_type("Benchmark_MinParticles", str(args.min_particle_number), "int")
307 peano4_project.constants.export_const_with_type("Benchmark_Samples", str(args.samples), "int")
308 peano4_project.constants.export_const_with_type("Benchmark_WorkItemSize", str(args.work_item_size), "int")
309 peano4_project.constants.export_const_with_type("Benchmark_WorkItemRepeats", str(args.work_item_repeats), "int")
310
311 cpu_only = args.cpu_only
312 gpu_only = args.gpu_only
313
314 if cpu_only and gpu_only:
315 print("Can't have both 'cpu only' and 'gpu only'. Pick one!")
316 exit(1)
317
318 for kernel in Kernels:
319 enabled = (cpu_only and 'gpu' not in kernel) or (gpu_only and 'gpu' in kernel) or (not cpu_only and not gpu_only)
320 peano4_project.constants.export_boolean("Benchmark_Test" + kernel, enabled and kernel in args.kernels )
321
322
323
324
329 peano4_project.output.makefile.add_cpp_file("BenchmarkDriver.cpp")
330
331 dirs = ["vertexdata/", "repositories/", "globaldata/", "observers/", "Constants.h"]
332 for dir in dirs:
333 shutil.rmtree(dir, ignore_errors=True)
334
335 peano4_project.generate(
336 overwrite=peano4.api.output.Overwrite.Default, throw_away_data_after_generation=True
337 )
338 peano4_project.build(make_clean_first=True, number_of_parallel_builds=args.j)
ExaParty project.
Definition Project.py:27
This file is part of the ExaParty project.
Definition __init__.py:1