Skip to content

Commit ee66dc5

Browse files
Dando18Daniel Nichols
andauthored
Support relocatable and standalone ParEval (#54)
* add build config flag to run all * update test-serial-outputs to match newest prompts * run drivers in driver root for relocatable runs --------- Co-authored-by: Daniel Nichols <[email protected]>
1 parent 8f93530 commit ee66dc5

File tree

5 files changed

+707
-29
lines changed

5 files changed

+707
-29
lines changed

drivers/build-configs.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"serial": {"CXX": "g++", "CXXFLAGS": "-std=c++17 -O3"},
3+
"omp": {"CXX": "g++", "CXXFLAGS": "-std=c++17 -O3 -fopenmp"},
4+
"mpi": {"CXX": "mpicxx", "CXXFLAGS": "-std=c++17 -O3"},
5+
"mpi+omp": {"CXX": "mpicxx", "CXXFLAGS": "-std=c++17 -O3 -fopenmp"},
6+
"kokkos": {"CXX": "g++", "CXXFLAGS": "-std=c++17 -O3 -fopenmp -I../tpl/kokkos/build/include ../tpl/kokkos/build/lib64/libkokkoscore.a ../tpl/kokkos/build/lib64/libkokkoscontainers.a ../tpl/kokkos/build/lib64/libkokkossimd.a"},
7+
"cuda": {"CXX": "nvcc", "CXXFLAGS": "-std=c++17 --generate-code arch=compute_80,code=sm_80 -O3 -Xcompiler \"-std=c++17 -O3\""},
8+
"hip": {"CXX": "hipcc", "CXXFLAGS": "-std=c++17 -O3 -Xcompiler \"-std=c++17\" -Xcompiler \"-O3\" -Wno-unused-result"}
9+
}

drivers/cpp/cpp_driver_wrapper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
def build_kokkos(driver_src: PathLike, output_root: PathLike, problem_size: str = "(1<<20)"):
4242
""" Custom steps for the Kokkos programs, since they require cmake """
4343
# cp cmake file into the output directory
44-
cmake_path = "cpp/KokkosCMakeLists.txt"
44+
cmake_path = os.path.join("cpp", "KokkosCMakeLists.txt")
4545
cmake_dest = os.path.join(output_root, "CMakeLists.txt")
4646
run_command(f"cp {cmake_path} {cmake_dest}", dry=False)
4747

@@ -57,6 +57,8 @@ class CppDriverWrapper(DriverWrapper):
5757

5858
def __init__(self, **kwargs):
5959
super().__init__(**kwargs)
60+
61+
self.build_configs = self.build_configs or COMPILER_SETTINGS
6062
self.model_driver_file = os.path.join("cpp", "models", DRIVER_MAP[self.parallelism_model])
6163

6264
def write_source(self, content: str, fpath: PathLike) -> bool:
@@ -125,7 +127,7 @@ def test_single_output(self, prompt: str, output: str, test_driver_file: PathLik
125127

126128
# compile and run the output
127129
exec_path = os.path.join(tmpdir, "a.out")
128-
compiler_kwargs = copy.deepcopy(COMPILER_SETTINGS[self.parallelism_model])
130+
compiler_kwargs = copy.deepcopy(self.build_configs[self.parallelism_model])
129131
compiler_kwargs["problem_size"] = problem_size # for kokkos
130132
compiler_kwargs["CXXFLAGS"] += f" -I{tmpdir} -DDRIVER_PROBLEM_SIZE=\"{problem_size}\""
131133
build_result = self.compile(self.model_driver_file, test_driver_file, output_path=exec_path, **compiler_kwargs)

drivers/driver_wrapper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def __init__(
167167
self,
168168
parallelism_model: str = "serial",
169169
launch_configs: dict = {"format": "{exec_path} {args}", "params": [{}]},
170+
build_configs: Optional[dict] = None,
170171
problem_sizes: dict = {},
171172
scratch_dir: Optional[PathLike] = None,
172173
build_timeout: int = 20,
@@ -180,6 +181,7 @@ def __init__(
180181
self.validator = VALIDATORS[parallelism_model]
181182
self.scratch_dir = scratch_dir
182183
self.launch_configs = launch_configs[parallelism_model]
184+
self.build_configs = build_configs
183185
self.problem_sizes = problem_sizes
184186
self.build_timeout = build_timeout
185187
self.run_timeout = run_timeout
@@ -213,15 +215,15 @@ def test_single_output(self, prompt: str, output: str, test_driver_file: PathLik
213215

214216
def test_all_outputs_in_prompt(self, prompt: dict) -> dict:
215217
""" Run all the generated outputs in the given prompt. """
216-
root = prompt["language"]
218+
lang = prompt["language"]
217219
type = prompt["problem_type"]
218220
name = prompt["name"]
219221
ext = LANGUAGE_EXTENSIONS[prompt["language"]]
220-
if root == "cpp" and self.parallelism_model in ["cuda", "hip"]:
222+
if lang == "cpp" and self.parallelism_model in ["cuda", "hip"]:
221223
ext = ".cu"
222-
driver_root = f"{name}"
224+
driver_dirname = f"{name}"
223225
driver_base = DRIVER_MAP[self.parallelism_model]
224-
test_driver_file = os.path.join(root, "benchmarks", type, driver_root, driver_base + ext)
226+
test_driver_file = os.path.join(lang, "benchmarks", type, driver_dirname, driver_base + ext)
225227
problem_size = self.problem_sizes.get(name, {}).get(self.parallelism_model, "(1<<18)")
226228

227229
outputs = []

drivers/run-all.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"""
66
# std imports
77
from argparse import ArgumentParser
8+
import contextlib
89
import json
910
import logging
1011
import os
11-
import tempfile
1212
from typing import Optional
1313

1414
# tpl imports
@@ -30,8 +30,11 @@ def get_args():
3030
parser.add_argument("input_json", type=str, help="Input JSON file containing the test cases.")
3131
parser.add_argument("-o", "--output", type=str, help="Output JSON file containing the results.")
3232
parser.add_argument("--scratch-dir", type=str, help="If provided, put scratch files here.")
33+
parser.add_argument("--driver-root", type=str, help="Where to look for the driver files, if not in cwd.")
3334
parser.add_argument("--launch-configs", type=str, default="launch-configs.json",
3435
help="config for how to run samples.")
36+
parser.add_argument("--build-configs", type=str, default="build-configs.json",
37+
help="config for how to build samples. If not provided, will use the default build settings for each model.")
3538
parser.add_argument("--problem-sizes", type=str, default="problem-sizes.json",
3639
help="config for how to run samples.")
3740
parser.add_argument("--yes-to-all", action="store_true", help="If provided, automatically answer yes to all prompts.")
@@ -56,11 +59,19 @@ def get_args():
5659
parser.add_argument("--log-runs", action="store_true", help="Display the stderr and stdout of runs.")
5760
return parser.parse_args()
5861

59-
def get_driver(prompt: dict, scratch_dir: Optional[os.PathLike], launch_configs: dict, problem_sizes: dict, dry: bool, **kwargs) -> DriverWrapper:
62+
def get_driver(
63+
prompt: dict,
64+
scratch_dir: Optional[os.PathLike],
65+
launch_configs: dict,
66+
build_configs: dict,
67+
problem_sizes: dict,
68+
dry: bool,
69+
**kwargs
70+
) -> DriverWrapper:
6071
""" Get the language drive wrapper for this prompt """
6172
driver_cls = LANGUAGE_DRIVERS[prompt["language"]]
6273
return driver_cls(parallelism_model=prompt["parallelism_model"], launch_configs=launch_configs,
63-
problem_sizes=problem_sizes, scratch_dir=scratch_dir, dry=dry, **kwargs)
74+
build_configs=build_configs, problem_sizes=problem_sizes, scratch_dir=scratch_dir, dry=dry, **kwargs)
6475

6576
def already_has_results(prompt: dict) -> bool:
6677
""" Check if a prompt already has results stored in it. """
@@ -102,10 +113,25 @@ def main():
102113
launch_configs = load_json(args.launch_configs)
103114
logging.info(f"Loaded launch configs from {args.launch_configs}.")
104115

116+
# load build configs
117+
build_configs = load_json(args.build_configs)
118+
logging.info(f"Loaded build configs from {args.build_configs}.")
119+
105120
# load problem sizes
106121
problem_sizes = load_json(args.problem_sizes)
107122
logging.info(f"Loaded problem sizes from {args.problem_sizes}.")
108123

124+
# set driver root; If provided, use user argument. If it's not provided, then check if the PAREVAL_ROOT environment
125+
# variable is set, then use "${PAREVAL_ROOT}/drivers" as the root. If neither is set, then use the location of
126+
# this script as the root.
127+
if args.driver_root:
128+
DRIVER_ROOT = args.driver_root
129+
elif "PAREVAL_ROOT" in os.environ:
130+
DRIVER_ROOT = os.path.join(os.environ["PAREVAL_ROOT"], "drivers")
131+
else:
132+
DRIVER_ROOT = os.path.dirname(os.path.abspath(__file__))
133+
logging.info(f"Using driver root: {DRIVER_ROOT}")
134+
109135
# gather the list of parallelism models to test
110136
models_to_test = args.include_models if args.include_models else ["serial", "omp", "mpi", "mpi+omp", "kokkos", "cuda", "hip"]
111137
if args.exclude_models:
@@ -139,15 +165,18 @@ def main():
139165
prompt,
140166
args.scratch_dir,
141167
launch_configs,
168+
build_configs,
142169
problem_sizes,
143170
args.dry,
144171
display_build_errors=args.log_build_errors,
145172
display_runs=args.log_runs,
146173
early_exit_runs=args.early_exit_runs,
147174
build_timeout=args.build_timeout,
148-
run_timeout=args.run_timeout
175+
run_timeout=args.run_timeout,
149176
)
150-
driver.test_all_outputs_in_prompt(prompt)
177+
178+
with contextlib.chdir(DRIVER_ROOT):
179+
driver.test_all_outputs_in_prompt(prompt)
151180

152181
# go ahead and write out outputs now
153182
if args.output and args.output != '-':

0 commit comments

Comments
 (0)