17Kernels_GPU = [
"drift_gpu",
"kick1_gpu",
"kick2_gpu",
"density_gpu",
"force_gpu"]
18Kernels = [
"drift",
"kick1",
"kick2",
"density",
"force" ] + Kernels_GPU
20if __name__ ==
"__main__":
21 parser = argparse.ArgumentParser(description=
"SPH kernel benchmarking script")
28 help=
"Parallel builds",
44 help=
"Dimensions of problem",
48 "--max-particle-number",
49 dest=
"max_particle_number",
52 help=
"Max number of particles to be tested",
56 "--min-particle-number",
57 dest=
"min_particle_number",
60 help=
"Min number of particles to be tested",
68 help=
"Number of overall samples",
73 dest=
"work_item_size",
76 help=
"Size of a work item",
80 "--work-item-repeats",
81 dest=
"work_item_repeats",
84 help=
"Size of a work item",
90 default=
"kernel-benchmarks",
91 help=
"Executable file name",
97 default=
"../../../..",
98 help=
"Peano4 directory",
104 choices=[
"release",
"stats",
"trace",
"asserts",
"debug"],
106 help=
"Pick build type",
114 help=
"Pick kernels that have to be tested",
121 help=
"Run only CPU benchmarks",
128 help=
"Run only GPU benchmarks",
131 "--enable-soa-conversion",
132 dest=
"soa_conversion",
133 choices=[
'true',
'false',
'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"
140 choices=[
'true',
'false'],
142 help=
"Validate that results of all kernels yield the same result"
144 args = parser.parse_args()
150 project_namespace = [
"benchmarks",
"exaparty",
"hydro",
"kernel_throughput"]
153 namespace=project_namespace, project_name=
"Benchmarks", executable=args.output_file
162 dimensions = args.dimensions
167 dimensions_hydro=hydro_dimensions,
169 initial_time_step_size=0.01,
170 constant_time_step_size=
True,
171 exaparty_project_namespace=project_namespace,
172 particles_per_cell=100,
185 HYDRO_DIMENSIONS = hydro_dimensions
192 gamma_hydro_list = [str(5 / 3), str(7 / 5), str(4 / 3), str(2 / 1)]
193 gamma_hydro_list_symbols = [
199 GAMMA = gamma_hydro_list[0]
200 GAMMA_HYDRO_SYMBOL = gamma_hydro_list_symbols[0]
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]
208 particle.h_hydro_max = 0.01
216 particle.data.expose_all_attributes_in_header_file()
217 particle_set = project.add_particle_species(particle)
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
238 domain_size = [1, 1, 1]
239 periodic_boundary_conditions = [
False,
False,
False]
241 project.set_global_simulation_parameters(
242 dimensions=dimensions,
244 domain_size=domain_size,
247 first_plot_time_stamp=0.0,
248 time_in_between_plots=0.0,
249 periodic_BC=periodic_boundary_conditions,
253 project.set_Peano4_installation(args.peanodir, build_mode)
268 peano4_project = project.generate_Peano4_project(verbose=args.verbose)
271 if GAMMA
not in gamma_hydro_list:
272 print(f
"Please check the value of GAMMA. You have chosen: {GAMMA}")
275 peano4_project.constants.export_const_with_type(
276 "HYDRO_DIMENSIONS", str(HYDRO_DIMENSIONS),
"double"
284 peano4_project.constants.export_const_with_type(
"GAMMA", GAMMA,
"double")
287 peano4_project.output.makefile.add_CXX_flag(
288 "-D" +
"HYDRO_DIMENSION=" + str(HYDRO_DIMENSIONS)
290 peano4_project.output.makefile.add_CXX_flag(
"-D" + GAMMA_HYDRO_SYMBOL)
291 peano4_project.output.makefile.add_CXX_flag(
"-D" + KERNEL_SYMBOL)
293 if args.validate ==
'true':
294 peano4_project.output.makefile.add_CXX_flag(
"-DValidateSWIFTKernelOutcomes")
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")
303 peano4_project.output.makefile.add_cpp_file(
"NohProblem.cpp" )
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")
311 cpu_only = args.cpu_only
312 gpu_only = args.gpu_only
314 if cpu_only
and gpu_only:
315 print(
"Can't have both 'cpu only' and 'gpu only'. Pick one!")
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 )
329 peano4_project.output.makefile.add_cpp_file(
"BenchmarkDriver.cpp")
331 dirs = [
"vertexdata/",
"repositories/",
"globaldata/",
"observers/",
"Constants.h"]
333 shutil.rmtree(dir, ignore_errors=
True)
335 peano4_project.generate(
336 overwrite=peano4.api.output.Overwrite.Default, throw_away_data_after_generation=
True
338 peano4_project.build(make_clean_first=
True, number_of_parallel_builds=args.j)