Peano
Loading...
Searching...
No Matches
generate-submission-script-cpu-parallel.py
Go to the documentation of this file.
1from itertools import combinations
2import os
3from pathlib import Path
4
5# Configurable Options
6application = "euler"
7solver = "rusanov"
8machine = "sapphire_rapid"
9runtime_hours = 24
10patch_sizes = [3, 6, 16]
11numbers_of_threads = [1, 2, 4, 8, 16, 32, 64]
12number_of_samples = 10
13
14numbers_of_patches = {
15 3: ["1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"],
16 6: ["1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"],
17 16: ["1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"]
18}
19
20partition = "dine2"
21account = "do015"
22set_environment = f"source {Path.home()}/set_env_x86_cpu_only.sh"
23cores = 64
24memory = "1TB"
25
26# First stage of passes
27#optional_passes = {
28# "taskloop": "--enable-omp-tasks --omp-task-version=taskloop",
29# "task": "--enable-omp-tasks --omp-task-version=task",
30# "taskloop_single-region": "--enable-omp-tasks --omp-task-version=taskloop --omp-single-region",
31# "task_single-region": "--enable-omp-tasks --omp-task-version=task --omp-single-region"
32#}
33
34# Second stage of passes
35optional_passes = {
36 "taskloop_single-region_memref-flattening": "--enable-memref-flattening --enable-omp-tasks --omp-task-version=taskloop --omp-single-region",
37 "taskloop_single-region_function-inlining": "--enable-function-inlining --enable-omp-tasks --omp-task-version=taskloop --omp-single-region",
38 "taskloop_single-region_memory-fusion": "--enable-memory-fusion --enable-omp-tasks --omp-task-version=taskloop --omp-single-region",
39 "taskloop_single-region_loop-fusion": "--enable-loop-fusion --enable-omp-tasks --omp-task-version=taskloop --omp-single-region",
40 "taskloop_single-region_perfect-loop-nesting": "--enable-imperfect-nested-loops-to-perfect --enable-omp-tasks --omp-task-version=taskloop --omp-single-region"
41}
42
43output_name = f"{application}_kernel_benchmark"
44job_name = f"{application}_kernel_benchmark"
45output_root = f"{Path.home()}/Peano/benchmarks/exahype2/kernel-benchmarks/"
46script_name = f"submit_kernel_benchmark-cpu-parallel-{application}-{solver}.sh"
47
48if solver == "fd4":
49 benchmark_script_name = "kernel-benchmarks-fd4-dsl.py"
50 benchmark_app_name = "KernelBenchmarksFD4DSL.Release"
51if solver == "rusanov":
52 benchmark_script_name = "kernel-benchmarks-fv-rusanov-dsl.py"
53 benchmark_app_name = "KernelBenchmarksFVRusanovDSL.Release"
54
55def generate_submission_script_fragment(use_cpp: bool, patch_size: int, number_of_patches: list[str], passes: list[str], output_directory: str):
56 if use_cpp:
57 print_statement = f"""echo "Patch Size: {patch_size}, C++" """
58 else:
59 print_statement = f"""echo "Patch Size: {patch_size}, MLIR, {", ".join(passes)}" """
60 pass_flags = [optional_passes[enabled_pass] for enabled_pass in passes]
61 return f"""{print_statement}
62python {benchmark_script_name} -d 3 -cpu {"--enable-cpp" if use_cpp else "--enable-mlir"} -parallel -ps {patch_size} -p {" ".join(number_of_patches)} -samples {number_of_samples} {" ".join(pass_flags)}
63for number_of_threads in "${{numbers_of_threads[@]}}"; do
64 echo "Number of threads: ${{number_of_threads}}"
65 export OMP_NUM_THREADS=${{number_of_threads}}
66 ./{benchmark_app_name} > {output_directory}/patch_size_{patch_size}_threads_${{number_of_threads}}.txt
67done
68"""
69compile_scripts = []
70run_scripts = []
71submission_scripts = []
72
73for patch_size in patch_sizes:
74 number_of_patches = numbers_of_patches[patch_size]
75
76 pass_list = []
77 for i in range(0, len(optional_passes) + 1):
78 for combination in list(combinations(optional_passes, i)):
79 pass_list.append(combination)
80
81# # CPP
82# output_directory = output_root + f"results/{application}/{solver}/cpu_parallel/{machine}/cpp"
83# if not os.path.exists(output_directory):
84# os.makedirs(output_directory)
85# submission_scripts.append(generate_submission_script_fragment(True, patch_size, number_of_patches, [], output_directory))
86#
87# # MLIR No Passes
88# output_directory = output_root + f"results/{application}/{solver}/cpu_parallel/{machine}/no-passes"
89# if not os.path.exists(output_directory):
90# os.makedirs(output_directory)
91# submission_scripts.append(generate_submission_script_fragment(False, patch_size, number_of_patches, [], output_directory))
92
93 # MLIR Passes
94 for optional_pass in optional_passes.keys():
95 output_directory = output_root + f"results/{application}/{solver}/cpu_parallel/{machine}/{optional_pass}"
96 if not os.path.exists(output_directory):
97 os.makedirs(output_directory)
98 submission_scripts.append(generate_submission_script_fragment(False, patch_size, number_of_patches, [optional_pass], output_directory))
99
100with open(script_name, "w") as file:
101 file.write(f"""#!/bin/bash -l
102
103#SBATCH -o {output_name}.out
104#SBATCH -e {output_name}.err
105#SBATCH -t {runtime_hours}:00:00
106#SBATCH --nodes=1
107#SBATCH -J {job_name}
108#SBATCH -c {cores}
109#SBATCH -p {partition}
110#SBATCH -A {account}
111#SBATCH --mem={memory}
112
113export PATH=~/Peano/src/exahype2/mlir/build/bin/:$PATH
114export PYTHONPATH=~/Peano/python/:~/Peano/applications/exahype2/ccz4/:~/Peano/src/
115{set_environment}
116
117numbers_of_threads=({" ".join([str(number_of_threads) for number_of_threads in numbers_of_threads])})
118""")
119 for script in submission_scripts:
120 file.write(script + "\n")
121
generate_submission_script_fragment(bool use_cpp, int patch_size, list[str] number_of_patches, list[str] passes, str output_directory)