Peano
Loading...
Searching...
No Matches
kernel-benchmarks-discontinuous-galerkin-dsl.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import os
4import argparse
5
6import peano4.api
7import exahype2
8
9from CCZ4Solver import CCZ4Solver_RKDG_GlobalAdaptiveTimeStepWithEnclaveTasking
10
11parser = argparse.ArgumentParser(
12 description="ExaHyPE 2 - CCZ4 Discontinuous Galerkin Kernel Benchmarking Script"
13)
14parser.add_argument(
15 "-m",
16 "--build-mode",
17 choices=peano4.api.output.CompileModes,
18 default=peano4.api.output.CompileModes[0], # Release
19 help="|".join(peano4.api.output.CompileModes),
20)
21parser.add_argument(
22 "-t",
23 "--num-threads",
24 default=1,
25 type=int,
26 help="Number of launching threads",
27)
28parser.add_argument(
29 "-dg",
30 "--dg_order",
31 default=4,
32 type=int,
33 help="Number of finite volumes per axis (dimension) per patch.",
34)
35parser.add_argument(
36 "-p",
37 "--num-patches",
38 nargs="+",
39 default=[32, 64, 128, 256],
40 type=int,
41 help="Number of patches to study",
42)
43parser.add_argument(
44 "-samples",
45 "--samples",
46 default=10,
47 type=int,
48 help="Number of samples per measurement",
49)
50parser.add_argument(
51 "-a",
52 "--accuracy",
53 default=0.0,
54 type=float,
55 help="Floating point accuracy to which the different kernel variants have to match (absolute). Pass in 0 to disable correctness check. Pass in values < 0 to use machine epsilon (default).",
56)
57parser.add_argument(
58 "-e",
59 "--eval-eig",
60 action="store_true",
61 help="Evaluate max. eigenvalue",
62)
63parser.add_argument(
64 "--enable-mlir",
65 dest="enable_mlir",
66 action="store_true",
67 help="Enable MLIR kernel compilation support",
68)
69parser.add_argument(
70 "--enable-cpp",
71 dest="enable_cpp",
72 action="store_true",
73 help="Enable CPP kernels",
74)
75parser.add_argument(
76 "-cpu",
77 "--cpu",
78 action="store_true",
79 help="Assess host kernels",
80)
81parser.add_argument(
82 "-gpu",
83 "--gpu",
84 action="store_true",
85 help="Assess device kernels",
86)
87parser.add_argument(
88 "-serial",
89 "--serial",
90 action="store_true",
91 help="Assess serial kernels",
92)
93parser.add_argument(
94 "-parallel",
95 "--parallel",
96 action="store_true",
97 help="Assess parallel kernels",
98)
99parser.add_argument(
100 "-fpe",
101 "--fpe",
102 action="store_true",
103 help="Enable a floating-point exception handler.",
104)
105parser.add_argument(
106 "-f",
107 "--function",
108 dest="function_to_benchmark",
109 choices=["cellIntegral", "riemannProblem"],
110 default="cellIntegral",
111 help="Set which function to benchmark.",
112)
113
114args = parser.parse_args()
115
117 name="DG",
118 rk_order=args.dg_order,
119 polynomials=exahype2.solvers.GaussLegendreBasis(args.dg_order),
120 min_cell_h=0.001, # max_cell_size -> arbitrary value
121 max_cell_h=0.001, # min_cell_size -> arbitrary value
122 pde_terms_without_state=True,
123)
124
125project = exahype2.Project(
126 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
127 project_name="KernelBenchmarksDiscontinuousGalerkinDSL",
128 directory=".",
129 executable=f"KernelBenchmarksDiscontinuousGalerkinDSL.{args.build_mode}",
130)
131dg_solver.add_all_solver_constants()
132project.add_solver(dg_solver)
133
134project.set_global_simulation_parameters(
135 dimensions=3,
136 size=[1.0, 1.0, 1.0],
137 offset=[0.0, 0.0, 0.0],
138 min_end_time=0.1,
139 max_end_time=0.1,
140 first_plot_time_stamp=0.0,
141 time_in_between_plots=0.0,
142 periodic_BC=[False, False, False]
143)
144
145project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
146project = project.generate_Peano4_project(verbose=True)
147
148accuracy = args.accuracy
149if accuracy < 0:
150 import numpy
151 accuracy = default = numpy.finfo(float).eps
152project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
153
154project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
155
156formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
157project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
158
159project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
160
161if args.fpe:
162 project.constants.export_boolean("EnableFPE", True)
163else:
164 project.constants.export_boolean("EnableFPE", False)
165
166# CPU is enabled by default if neither CPU nor GPU are specified
167if args.cpu == False and args.gpu == False:
168 project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
169else:
170 if args.cpu: project.output.makefile.add_CXX_flag("-DASSESS_HOST_KERNELS")
171 if args.gpu: project.output.makefile.add_CXX_flag("-DASSESS_DEVICE_KERNELS")
172
173if args.serial == False and args.parallel == False:
174 project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
175 project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
176else:
177 if args.serial: project.output.makefile.add_CXX_flag("-DASSESS_SERIAL_KERNELS")
178 if args.parallel: project.output.makefile.add_CXX_flag("-DASSESS_PARALLEL_KERNELS")
179
180project.constants.export_boolean("EvaluateFlux", False)
181project.constants.export_boolean("EvaluateNonconservativeProduct", True)
182project.constants.export_boolean("EvaluateSource", True)
183project.constants.export_boolean("EvaluatePointSources", False)
184project.constants.export_boolean("EvaluateMaximumEigenvalueAfterTimeStep", True if args.eval_eig else False) # Reduction
185
186project.constants.define_value("NonconservativeProductMacro", "1")
187
188project.constants.define_value("GAMMA", str(1.0))
189
190if args.function_to_benchmark == "cellIntegral":
191 project.output.makefile.add_CXX_flag("-DASSESS_CELL_INTEGRAL_KERNELS")
192elif args.function_to_benchmark == "riemannProblem":
193 project.constants.define_value("BenchmarkRiemannProblem", "1")
194
195benchmark_main_file = "../../kernel-benchmarks/KernelBenchmarksDiscontinuousGalerkinDSL-main.cpp"
196os.system("cp {} KernelBenchmarksDiscontinuousGalerkinDSL-main.cpp".format(benchmark_main_file))
197
198dg_solver.add_makefile_parameters(
199 project, "../../../../applications/exahype2/ccz4"
200)
201
202project.output.makefile.add_CXX_flag("-DGRAV=9.81")
203
204# MLIR Integration Support
205if args.enable_mlir:
206 print(f"Enabling MLIR kernel compilation support for 3D...")
207
208 # Set environment variable for dimension detection
209 import os
210 os.environ['MLIR_DIMENSIONS'] = "3"
211
212 # Add MLIR-specific files and flags
213 project.output.makefile.add_cpp_file("MLIRbridge.cpp")
214 project.output.makefile.add_CXX_flag("-DUSE_MLIR")
215
216 # NOTE: As we are using LLVM toolings for MLIR, we link against LLVM's OpenMP library
217 project.output.makefile.add_linker_flag("-lomp")
218 project.output.makefile.add_linker_flag("-lomptarget")
219 if args.gpu:
220 print("Enabling MLIR GPU kernel compilation support")
221 project.output.makefile.d["MLIR_GPU"] = True
222 project.output.makefile.add_CXX_flag("-DMLIR_GPU")
223 project.output.makefile.add_linker_flag("-ldl")
224 project.output.makefile.add_linker_flag("-pthread")
225
226 # NOTE: The current MLIR GPU linearization and lowering pipeline uses the base MLIR
227 # but may use the OMP version in future. Update here, as appropriate
228 project.output.makefile.d["MLIR_SOURCES_GPU"] = f"dg_cellIntegral3d.mlir"
229 project.output.makefile.d["MLIR_LL_FILE_GPU"] = f"dg_cellIntegral3d_gpu.ll"
230 project.output.makefile.d["MLIR_OBJECT_GPU"] = f"dg_cellIntegral3d_mlir_gpu.o"
231
232 if project.output.makefile.d["GPU_VENDOR"] == "NVIDIA":
233 project.output.makefile.d["MLIR_GPU_NVIDIA"] = True
234 project.output.makefile.add_CXX_flag("-DMLIR_GPU_NVIDIA")
235 CUDA_HOME = os.path.dirname(subprocess.check_output("which nvcc", shell=True).decode().strip())
236 project.output.makefile.add_cpp_file("MLIRbridgeCUDAfunctions.cpp")
237 project.output.makefile.add_linker_flag("-lcuda")
238 project.output.makefile.add_linker_flag("-lcudart")
239 project.output.makefile.add_linker_flag("-lmlir_cuda_runtime")
240 project.output.makefile.add_linker_flag(f"-L{CUDA_HOME}/../targets/sbsa-linux/lib")
241 cuda_bridge_header_file = "../../../../python/exahype2/dslhype/MLIRbridgeCUDAfunctions.h"
242 cuda_bridge_file = "../../../../python/exahype2/dslhype/MLIRbridgeCUDAfunctions.cpp"
243 os.system("cp {} MLIRbridgeCUDAfunctions.h".format(cuda_bridge_header_file))
244 os.system("cp {} MLIRbridgeCUDAfunctions.cpp".format(cuda_bridge_file))
245 elif project.output.makefile.d["GPU_VENDOR"] == "AMD":
246 project.output.makefile.d["MLIR_GPU_AMD"] = True
247 project.output.makefile.add_CXX_flag("-DMLIR_GPU_AMD")
248 ROCM_HOME = os.path.dirname(subprocess.check_output("which hipcc", shell=True).decode().strip()) + "/.."
249 os.environ["ROCM_HOME"] = ROCM_HOME
250 project.output.makefile.add_cpp_file("MLIRbridgeHIPfunctions.cpp")
251 project.output.makefile.add_CXX_flag("-D__HIP_PLATFORM_AMD__")
252 project.output.makefile.add_linker_flag("-lamdhip64")
253 project.output.makefile.add_CXX_flag(f"-I{ROCM_HOME}/include")
254 project.output.makefile.add_linker_flag("-lmlir_rocm_runtime")
255 hip_bridge_header_file = "../../../../python/exahype2/dslhype/MLIRbridgeHIPfunctions.h"
256 hip_bridge_file = "../../../../python/exahype2/dslhype/MLIRbridgeHIPfunctions.cpp"
257 os.system("cp {} MLIRbridgeHIPfunctions.h".format(hip_bridge_header_file))
258 os.system("cp {} MLIRbridgeHIPfunctions.cpp".format(hip_bridge_file))
259 else:
260 raise RuntimeError("Unknown GPU vendor, please set it when configuring Peano with --with-gpu-vendor")
261
262 project.output.makefile.d["MLIR_ENABLED"] = True
263 project.output.makefile.d["MLIR_PHYSICS_FILE"] = f"ccz4_physics.mlir"
264 project.output.makefile.d["MLIR_SOURCES"] = f"dg_cellIntegral3d.mlir"
265 project.output.makefile.d["MLIR_LL_FILE"] = f"dg_cellIntegral3d.ll"
266 project.output.makefile.d["MLIR_OBJECT"] = f"dg_cellIntegral3d_mlir.o"
267 project.output.makefile.d["MLIR_SOURCES_OMP"] = f"dg_cellIntegral3d_omp.mlir"
268 project.output.makefile.d["MLIR_LL_FILE_OMP"] = f"dg_cellIntegral3d_omp.ll"
269 project.output.makefile.d["MLIR_OBJECT_OMP"] = f"dg_cellIntegral3d_mlir_omp.o"
270
271 project.output.makefile.add_CXX_flag("-DASSESS_MLIR_KERNELS")
272
273# CPP is enabled by default if MLIR is not enabled
274if args.enable_cpp or not args.enable_mlir:
275 project.output.makefile.add_CXX_flag("-DASSESS_CPP_KERNELS")
276
277project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
278
279print(project)
280print(dg_solver)
CCZ4 solver using Runge-Kutta Discontinuous Galerkin and global adaptive time stepping incl enclave t...