Skip to content

Commit 0e1cc80

Browse files
authored
Merge branch 'main' into package
2 parents 8a47a5f + 9e6e7e7 commit 0e1cc80

File tree

19 files changed

+462
-96
lines changed

19 files changed

+462
-96
lines changed

.github/workflows/build_and_run.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
strategy:
18+
fail-fast: false
1819
matrix:
1920
python: ["3.9", "3.10"]
2021

@@ -56,26 +57,25 @@ jobs:
5657
run: |
5758
CC=icx CXX=icpx python setup.py develop -- -Dpybind11_DIR=$(python -m pybind11 --cmakedir) -DDPCTL_MODULE_PATH=$(python -m dpctl --cmakedir)
5859
59-
- name: Validate dpbench
60+
- name: Run benchmarks
6061
shell: bash -l {0}
6162
run: |
6263
export OCL_ICD_FILENAMES=libintelocl.so
63-
6464
export NUMBA_MLIR_GPU_RUNTIME=sycl
65-
6665
# Turn off numba-dpex autofall back
6766
export NUMBA_DPEX_FALLBACK_ON_CPU=0
6867
# Make sure numba-dpex is using native atomics in github CI
6968
export NUMBA_DPEX_ACTIVATE_ATOMICS_FP_NATIVE=1
7069
ls $(dirname $(dirname `which icx`))/bin-llvm || exit 1
7170
export NUMBA_DPEX_LLVM_SPIRV_ROOT=$(dirname $(dirname `which icx`))/bin-llvm
7271
73-
python -c "import dpbench; dpbench.run_benchmarks(repeat=2)" || exit 1
74-
# LD_PRELOAD="${CONDA_PREFIX}/lib/libmkl_intel_ilp64.so ${CONDA_PREFIX}/lib/libmkl_tbb_thread.so ${CONDA_PREFIX}/lib/libmkl_core.so" python -c "import dpbench; dpbench.all_benchmarks_passed_validation(\"dpbench.db\");"
75-
# res=` \
76-
# printf "%s" \
77-
# "$(python -c "import dpbench; \
78-
# res=int(dpbench.all_benchmarks_passed_validation(\"dpbench.db\")); \
79-
# print(\"Validation:\",res)" \
80-
# )" | grep Validation | cut -f 2 -d ":"` || exit 1
81-
# if [ ${res} == 0 ]; then exit 1; fi
72+
dpbench \
73+
-i python,numpy,dpnp,sycl,numba_n,numba_np,numba_npr,numba_dpex_k,numba_dpex_n,numba_dpex_p \
74+
run -r2 --no-print-results
75+
76+
- name: Generate report
77+
shell: bash -l {0}
78+
run: |
79+
dpbench \
80+
-i python,numpy,dpnp,sycl,numba_n,numba_np,numba_npr,numba_dpex_k,numba_dpex_n,numba_dpex_p \
81+
report || exit 1

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ repos:
5050
hooks:
5151
- id: pydocstyle
5252
# TODO: add packages one by one to enforce pydocstyle eventually
53-
files: (^dpbench/config/|^scripts/)
53+
files: (^dpbench/config/|^scripts/|^dpbench/console/)
5454
args: ["--convention=google"]
5555
# D417 does not work properly:
5656
# https://github.com/PyCQA/pydocstyle/issues/459

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ SPDX-License-Identifier: Apache-2.0
3535
```
3636
- To run, taking black_scholes for example:
3737
```bash
38-
$ python -c "import dpbench; dpbench.run_benchmark(\"black_scholes\")" 2> /dev/null
38+
$ dpbench -b black_scholes run
3939
```
4040
- Similarly, to run all the cases in DPBench:
4141
```bash
42-
$ python -c "import dpbench; dpbench.run_benchmarks()" 2> /dev/null
42+
$ dpbench -a run
4343
```
4444

4545
3. Device Customization
@@ -68,17 +68,19 @@ SPDX-License-Identifier: Apache-2.0
6868

6969
> **_NOTE:_** The `arch` option is deprecated and not used by dpbench.
7070

71-
To run with custimized framework JSON file, pass it as an argument to the `run_benchmark` or
71+
To run with customized framework JSON file, pass it as an argument to the `run_benchmark` or
7272
`run_benchmarks` functions.
7373

74+
TODO: current way not working anymore.
75+
7476
```bash
7577
$ python -c "import dpbench; dpbench.run_benchmark(\"black_scholes\", "<absolute path to json file>")"
7678
```
7779

7880
## Running numba-mlir benchmarks
7981
1. Setting up conda environment and installing dependencies:
8082

81-
Use same instructions as for usual dpbench setup, but do not install numba-dpex.
83+
Use same instructions as for usual dpbench setup.
8284

8385
Install latest `numba-mlir` dev package:
8486

@@ -88,12 +90,19 @@ SPDX-License-Identifier: Apache-2.0
8890

8991
Use same commands to setup and run dpbench:
9092

91-
$ python -c "import dpbench; dpbench.run_benchmark(\"black_scholes\")" 2> /dev/null
93+
```bash
94+
$ dpbench -b black_scholes run
95+
```
9296

9397
or, to run specific version:
9498

95-
$ python -c "import dpbench; dpbench.run_benchmark(\"black_scholes\",implementation_postfix=\"numba_mlir_k\")" 2> /dev/null
99+
100+
```bash
101+
$ dpbench -b black_scholes -i numba_mlir_k s run
102+
```
96103

97104
to run all `numba-mlir` benchmarks:
98105

99-
$ python -c "import dpbench; dpbench.run_benchmarks(implementations=[\"numba_mlir_n\",\"numba_mlir_p\",\"numba_mlir_k\"])" 2> /dev/null
106+
```bash
107+
$ dpbench -b black_scholes -i numba_mlir_k,numba_mlir_n,numba_mlir_p s run
108+
```

alembic.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[alembic]
88
# path to migration scripts
9-
script_location = alembic
9+
script_location = dpbench:migrations
1010

1111
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
1212
# Uncomment the line below if you want the files to be prepended with date and time

dpbench/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
5-
from .runner import run_benchmark, run_benchmarks
6-
7-
__all__ = [
8-
"run_benchmark",
9-
"run_benchmarks",
10-
]

dpbench/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .reader import read_configs
1818

1919
"""Use this variable for reading configurations"""
20-
GLOBAL: Config = read_configs()
20+
GLOBAL: Config = Config()
2121

2222
__all__ = [
2323
"GLOBAL",

dpbench/config/reader.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121

2222

2323
def read_configs( # noqa: C901: TODO: move modules into config
24-
benchmarks: list[str] = None,
25-
implementations: list[str] = None,
24+
benchmarks: set[str] = None,
25+
implementations: set[str] = None,
26+
no_dpbench: bool = False,
27+
with_npbench: bool = False,
28+
with_polybench: bool = False,
29+
load_implementations: bool = True,
2630
) -> Config:
2731
"""Read all configuration files and populate those settings into Config.
2832
@@ -53,11 +57,9 @@ def read_configs( # noqa: C901: TODO: move modules into config
5357
),
5458
]
5559

56-
no_dpbench = os.getenv("NO_DPBENCH")
5760
if no_dpbench:
5861
modules[0].benchmark_configs_path = ""
5962

60-
with_npbench = os.getenv("WITH_NPBENCH")
6163
if with_npbench:
6264
modules.append(
6365
Module(
@@ -69,7 +71,6 @@ def read_configs( # noqa: C901: TODO: move modules into config
6971
)
7072
)
7173

72-
with_polybench = os.getenv("WITH_POLYBENCH")
7374
if with_polybench:
7475
modules.append(
7576
Module(
@@ -92,7 +93,7 @@ def read_configs( # noqa: C901: TODO: move modules into config
9293
benchmarks=benchmarks,
9394
)
9495
if mod.framework_configs_path != "":
95-
read_frameworks(config, mod.framework_configs_path)
96+
read_frameworks(config, mod.framework_configs_path, implementations)
9697
if mod.precision_dtypes_path != "":
9798
read_precision_dtypes(config, mod.precision_dtypes_path)
9899
if mod.path != "":
@@ -102,13 +103,20 @@ def read_configs( # noqa: C901: TODO: move modules into config
102103
config.implementations += framework.postfixes
103104

104105
if implementations is None:
105-
implementations = [impl.postfix for impl in config.implementations]
106+
implementations = {impl.postfix for impl in config.implementations}
106107

107-
for benchmark in config.benchmarks:
108-
read_benchmark_implementations(
109-
benchmark,
110-
implementations,
111-
)
108+
if load_implementations:
109+
for benchmark in config.benchmarks:
110+
read_benchmark_implementations(
111+
benchmark,
112+
implementations,
113+
)
114+
115+
config.benchmarks = [
116+
benchmark
117+
for benchmark in config.benchmarks
118+
if len(benchmark.implementations) > 0
119+
]
112120

113121
return config
114122

@@ -118,7 +126,7 @@ def read_benchmarks(
118126
bench_info_dir: str,
119127
recursive: bool = False,
120128
parent_package: str = "dpbench.benchmarks",
121-
benchmarks: list[str] = None,
129+
benchmarks: set[str] = None,
122130
):
123131
"""Read and populate benchmark configuration files.
124132
@@ -163,12 +171,20 @@ def read_benchmarks(
163171
config.benchmarks.append(benchmark)
164172

165173

166-
def read_frameworks(config: Config, framework_info_dir: str) -> None:
174+
def read_frameworks(
175+
config: Config,
176+
framework_info_dir: str,
177+
implementations: set[str] = None,
178+
) -> None:
167179
"""Read and populate framework configuration files.
168180
169181
Args:
170182
config: Configuration object where settings should be populated.
171183
framework_info_dir: Path to the directory with configuration files.
184+
implementations: Set of the implementations to load. If framework
185+
does not have any implementation from this list - it won't be
186+
loaded. If set None or empty - all frameworks/implementations get
187+
loaded.
172188
"""
173189
for framework_info_file in os.listdir(framework_info_dir):
174190
if not framework_info_file.endswith(".toml"):
@@ -183,9 +199,20 @@ def read_frameworks(config: Config, framework_info_dir: str) -> None:
183199

184200
framework_info = tomli.loads(file_contents)
185201
framework_dict = framework_info.get("framework")
186-
if framework_dict:
187-
framework = Framework.from_dict(framework_dict)
188-
config.frameworks.append(framework)
202+
if not framework_dict:
203+
continue
204+
framework = Framework.from_dict(framework_dict)
205+
if implementations:
206+
framework.postfixes = [
207+
postfix
208+
for postfix in framework.postfixes
209+
if postfix.postfix in implementations
210+
]
211+
212+
if len(framework.postfixes) == 0:
213+
continue
214+
215+
config.frameworks.append(framework)
189216

190217

191218
def read_implementation_postfixes(
@@ -249,8 +276,8 @@ def setup_init(config: Benchmark, modules: list[str]) -> None:
249276
impl_mod = importlib.import_module(config.init.package_path)
250277

251278
if not hasattr(impl_mod, config.init.func_name):
252-
print(
253-
f"WARNING: could not find init function for {config.module_name}"
279+
logging.warn(
280+
f"could not find init function for {config.module_name}"
254281
)
255282

256283

@@ -284,7 +311,7 @@ def discover_module_name_and_postfix(module: str, config: Config):
284311

285312
def read_benchmark_implementations(
286313
config: Benchmark,
287-
implementations: list[str] = None,
314+
implementations: set[str] = None,
288315
) -> None:
289316
"""Read and discover implementation modules and functions.
290317
@@ -318,8 +345,10 @@ def read_benchmark_implementations(
318345
for module in modules:
319346
module_name, postfix = discover_module_name_and_postfix(module, config)
320347

321-
if (postfix not in implementations) or (
322-
config.init and config.init.module_name.endswith(module_name)
348+
if (
349+
implementations
350+
and (postfix not in implementations)
351+
or (config.init and config.init.module_name.endswith(module_name))
323352
):
324353
continue
325354

dpbench/console/_namespace.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Namespace class for parsed arguments."""
6+
7+
import argparse
8+
from typing import Union
9+
10+
11+
class Namespace(argparse.Namespace):
12+
"""Namespace class for parsed arguments."""
13+
14+
benchmarks: set[str]
15+
implementations: set[str]
16+
all_implementations: bool
17+
preset: str
18+
dpbench: bool
19+
npbench: bool
20+
polybench: bool
21+
print_results: bool
22+
validate: bool
23+
run_id: Union[int, None]
24+
last_run: bool
25+
results_db: str
26+
save: bool
27+
repeat: int
28+
timeout: float
29+
precision: Union[str, None]
30+
program: str

0 commit comments

Comments
 (0)