Skip to content

Commit fca26a9

Browse files
allnesaobolensk
andauthored
Convert all scripts (#306)
- [x] Convert all scripts (exception - perf generator) - [x] Separate windows builds and tests --------- Co-authored-by: Arseniy Obolenskiy <[email protected]>
1 parent df56014 commit fca26a9

12 files changed

+441
-320
lines changed

Diff for: .github/workflows/main.yml

+225-156
Large diffs are not rendered by default.

Diff for: scripts/generate_perf_results.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@echo off
22
mkdir build\perf_stat_dir
3-
scripts\run_perf_collector.bat > build\perf_stat_dir\perf_log.txt
3+
python3 scripts/run_tests.py --running-type="performance" > build\perf_stat_dir\perf_log.txt
44
python scripts\create_perf_table.py --input build\perf_stat_dir\perf_log.txt --output build\perf_stat_dir

Diff for: scripts/generate_perf_results.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
mkdir -p build/perf_stat_dir
2-
source scripts/run_perf_collector.sh | tee build/perf_stat_dir/perf_log.txt
2+
python3 scripts/run_tests.py --running-type="performance" | tee build/perf_stat_dir/perf_log.txt
33
python3 scripts/create_perf_table.py --input build/perf_stat_dir/perf_log.txt --output build/perf_stat_dir

Diff for: scripts/run.bat

-13
This file was deleted.

Diff for: scripts/run_mpi.sh

-24
This file was deleted.

Diff for: scripts/run_perf_collector.bat

-6
This file was deleted.

Diff for: scripts/run_perf_collector.sh

-22
This file was deleted.

Diff for: scripts/run_perf_count_checker.sh

-58
This file was deleted.

Diff for: scripts/run_perf_counter.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import subprocess
2+
import re
3+
import sys
4+
from pathlib import Path
5+
6+
7+
def init_cmd_args():
8+
import argparse
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument(
11+
"--required-tests-number",
12+
required=True,
13+
type=int,
14+
help="Specify the number of tests to run (must be an integer)."
15+
)
16+
args = parser.parse_args()
17+
_args_dict = vars(args)
18+
return _args_dict
19+
20+
21+
def get_project_path():
22+
script_path = Path(__file__).resolve()
23+
script_dir = script_path.parent
24+
return script_dir.parent
25+
26+
27+
def run_script(_script_path):
28+
result = subprocess.run(
29+
f"{sys.executable} {_script_path} --running-type=performance-list", shell=True, capture_output=True, text=True)
30+
if result.returncode != 0:
31+
raise Exception(f"Subprocess return {result.returncode}.")
32+
33+
return result.stdout.splitlines()
34+
35+
36+
if __name__ == "__main__":
37+
args_dict = init_cmd_args()
38+
tests_list = run_script(Path(get_project_path()) / "scripts/run_tests.py")
39+
tests_number = len(tests_list)
40+
41+
pattern = r".*all\.|.*_mpi\.|.*_omp\.|.*_seq\.|.*_stl\.|.*_tbb\."
42+
test_matches = [test_name for test_name in tests_list if re.match(pattern, test_name)]
43+
required_tests_number = (args_dict["required_tests_number"] + 1) * len(test_matches)
44+
45+
if tests_number != required_tests_number:
46+
raise Exception(f"Count of all tests {tests_number} != count of required tests {required_tests_number}.")

Diff for: scripts/run_tests.py

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import os
2+
import subprocess
3+
import platform
4+
from pathlib import Path
5+
6+
7+
def init_cmd_args():
8+
import argparse
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument(
11+
"--running-type",
12+
required=True,
13+
choices=["threads", "processes", "performance", "performance-list"],
14+
help="Specify the execution mode. Choose 'threads' for multithreading or 'processes' for multiprocessing."
15+
)
16+
parser.add_argument(
17+
"--additional-mpi-args",
18+
required=False,
19+
default="",
20+
help="Additional MPI arguments to pass to the mpirun command (optional)."
21+
)
22+
args = parser.parse_args()
23+
_args_dict = vars(args)
24+
return _args_dict
25+
26+
27+
class PPCRunner:
28+
def __init__(self):
29+
self.work_dir = None
30+
self.valgrind_cmd = "valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all"
31+
32+
if platform.system() == "Windows":
33+
self.ocv_script_name = "setup_vars_opencv4.cmd"
34+
self.ocv_script_path = Path("build/ppc_opencv/install/") / self.ocv_script_name
35+
else:
36+
self.ocv_script_name = "setup_vars_opencv4.sh"
37+
self.ocv_script_path = Path("build/ppc_opencv/install/bin/") / self.ocv_script_name
38+
39+
if platform.system() == "Windows":
40+
self.mpi_exec = "mpiexec"
41+
else:
42+
self.mpi_exec = "mpirun"
43+
44+
@staticmethod
45+
def __get_project_path():
46+
script_path = Path(__file__).resolve() # Absolute path of the script
47+
script_dir = script_path.parent # Directory containing the script
48+
return script_dir.parent
49+
50+
@staticmethod
51+
def __source_script(script_path):
52+
if platform.system() == "Windows":
53+
return
54+
command = f"bash -c 'source {script_path} && env'"
55+
result = subprocess.run(command, stdout=subprocess.PIPE, shell=True, text=True)
56+
if result.returncode == 0:
57+
# Parse the output environment variables
58+
env_vars = {}
59+
for line in result.stdout.splitlines():
60+
if '=' in line:
61+
key, value = line.split("=", 1)
62+
env_vars[key] = value
63+
return env_vars
64+
else:
65+
print(f"Failed to source script: {script_path}")
66+
return {}
67+
68+
def setup_env(self):
69+
if os.path.isfile(Path(self.__get_project_path()) / self.ocv_script_path):
70+
_work_dir = Path(self.__get_project_path()) / "build/bin"
71+
env_vars = self.__source_script(Path(self.__get_project_path()) / self.ocv_script_path)
72+
else:
73+
_work_dir = Path(self.__get_project_path()) / "install/bin"
74+
env_vars = self.__source_script(Path(_work_dir) / self.ocv_script_name)
75+
76+
self.work_dir = Path(_work_dir)
77+
if not platform.system() == "Windows":
78+
os.environ.update(env_vars)
79+
80+
@staticmethod
81+
def __run_exec(command):
82+
result = subprocess.run(command, shell=True, env=os.environ)
83+
if result.returncode != 0:
84+
raise Exception(f"Subprocess return {result.returncode}.")
85+
86+
@staticmethod
87+
def __get_gtest_settings(repeats_count):
88+
command = "--gtest_also_run_disabled_tests "
89+
command += f"--gtest_repeat={repeats_count} "
90+
command += "--gtest_recreate_environments_when_repeating "
91+
command += "--gtest_color=0 "
92+
return command
93+
94+
def run_threads(self):
95+
if platform.system() == "Linux" and not os.environ.get("ASAN_RUN"):
96+
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'seq_func_tests'} {self.__get_gtest_settings(1)}")
97+
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'stl_func_tests'} {self.__get_gtest_settings(1)}")
98+
99+
self.__run_exec(f"{self.work_dir / 'seq_func_tests'} {self.__get_gtest_settings(3)}")
100+
self.__run_exec(f"{self.work_dir / 'stl_func_tests'} {self.__get_gtest_settings(3)}")
101+
self.__run_exec(f"{self.work_dir / 'tbb_func_tests'} {self.__get_gtest_settings(3)}")
102+
103+
if os.environ.get("CLANG_BUILD") == "1":
104+
return
105+
self.__run_exec(f"{self.work_dir / 'omp_func_tests'} {self.__get_gtest_settings(3)}")
106+
107+
def run_core(self):
108+
if platform.system() == "Linux" and not os.environ.get("ASAN_RUN"):
109+
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(1)}")
110+
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'ref_func_tests'} {self.__get_gtest_settings(1)}")
111+
112+
self.__run_exec(f"{self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(3)}")
113+
self.__run_exec(f"{self.work_dir / 'ref_func_tests'} {self.__get_gtest_settings(3)}")
114+
115+
def run_processes(self, additional_mpi_args):
116+
if os.environ.get("CLANG_BUILD") == "1":
117+
return
118+
119+
proc_count = os.environ.get("PROC_COUNT")
120+
if proc_count is None:
121+
raise EnvironmentError("Required environment variable 'PROC_COUNT' is not set.")
122+
123+
mpi_running = f"{self.mpi_exec} {additional_mpi_args} -np {proc_count}"
124+
if not os.environ.get("ASAN_RUN"):
125+
self.__run_exec(f"{mpi_running} {self.work_dir / 'all_func_tests'} {self.__get_gtest_settings(10)}")
126+
self.__run_exec(f"{mpi_running} {self.work_dir / 'mpi_func_tests'} {self.__get_gtest_settings(10)}")
127+
128+
def run_performance(self):
129+
if not os.environ.get("ASAN_RUN"):
130+
mpi_running = ""
131+
if platform.system() in ("Linux", "Windows"):
132+
mpi_running = f"{self.mpi_exec} -np 4"
133+
elif platform.system() == "Darwin":
134+
mpi_running = f"{self.mpi_exec} -np 2"
135+
self.__run_exec(f"{mpi_running} {self.work_dir / 'all_perf_tests'} {self.__get_gtest_settings(1)}")
136+
self.__run_exec(f"{mpi_running} {self.work_dir / 'mpi_perf_tests'} {self.__get_gtest_settings(1)}")
137+
138+
self.__run_exec(f"{self.work_dir / 'omp_perf_tests'} {self.__get_gtest_settings(1)}")
139+
self.__run_exec(f"{self.work_dir / 'seq_perf_tests'} {self.__get_gtest_settings(1)}")
140+
self.__run_exec(f"{self.work_dir / 'stl_perf_tests'} {self.__get_gtest_settings(1)}")
141+
self.__run_exec(f"{self.work_dir / 'tbb_perf_tests'} {self.__get_gtest_settings(1)}")
142+
143+
def run_performance_list(self):
144+
for task_type in ["all", "mpi", "omp", "seq", "stl", "tbb"]:
145+
self.__run_exec(f"{self.work_dir / f'{task_type}_perf_tests'} --gtest_list_tests")
146+
147+
148+
if __name__ == "__main__":
149+
args_dict = init_cmd_args()
150+
151+
ppc_runner = PPCRunner()
152+
ppc_runner.setup_env()
153+
154+
if args_dict["running_type"] in ["threads", "processes"]:
155+
ppc_runner.run_core()
156+
157+
if args_dict["running_type"] == "threads":
158+
ppc_runner.run_threads()
159+
elif args_dict["running_type"] == "processes":
160+
ppc_runner.run_processes(args_dict["additional_mpi_args"])
161+
elif args_dict["running_type"] == "performance":
162+
ppc_runner.run_performance()
163+
elif args_dict["running_type"] == "performance-list":
164+
ppc_runner.run_performance_list()
165+
else:
166+
raise Exception("running-type is wrong!")

Diff for: scripts/run_threads.sh

-26
This file was deleted.

0 commit comments

Comments
 (0)