Skip to content

Commit 70227be

Browse files
authored
Merge pull request #228 from IntelPython/fix/npbench_configs
Fix npbench configurations
2 parents 77ba369 + 48d2997 commit 70227be

File tree

8 files changed

+72
-113
lines changed

8 files changed

+72
-113
lines changed

dpbench/config/reader.py

Lines changed: 33 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ def read_configs(
109109
postfixes=postfixes_tmp,
110110
)
111111

112-
if with_npbench:
113-
fix_npbench_configs(config.benchmarks)
114-
115112
return config
116113

117114

@@ -232,6 +229,8 @@ def setup_init(config: Benchmark, modules: list[str]) -> None:
232229
init_module = None
233230
if config.module_name in modules:
234231
init_module = config.module_name
232+
elif config.short_name in modules:
233+
init_module = config.short_name
235234
elif config.module_name + "_initialize" in modules:
236235
init_module = config.module_name + "_initialize"
237236

@@ -251,6 +250,34 @@ def setup_init(config: Benchmark, modules: list[str]) -> None:
251250
)
252251

253252

253+
def discover_module_name_and_postfix(module: str, config: Config):
254+
"""Discover real module name and postfix for the implementation.
255+
256+
Args:
257+
module: Name of the root python module (either python file or top level
258+
folder for sycl).
259+
config: Module config.
260+
261+
Returns: (module_name, postfix).
262+
"""
263+
postfix = ""
264+
module_name = ""
265+
266+
if module.endswith("sycl_native_ext"):
267+
module_name = (
268+
f"{module}.{config.module_name}_sycl._{config.module_name}_sycl"
269+
)
270+
postfix = "sycl"
271+
else:
272+
module_name = module
273+
if module.startswith(config.module_name):
274+
postfix = module[len(config.module_name) + 1 :]
275+
elif module.startswith(config.short_name):
276+
postfix = module[len(config.short_name) + 1 :]
277+
278+
return module_name, postfix
279+
280+
254281
def read_benchmark_implementations(
255282
config: Benchmark,
256283
known_implementations: list[Implementation],
@@ -289,17 +316,7 @@ def read_benchmark_implementations(
289316
setup_init(config, modules)
290317

291318
for module in modules:
292-
postfix = ""
293-
module_name = ""
294-
295-
if module.endswith("sycl_native_ext"):
296-
module_name = (
297-
f"{module}.{config.module_name}_sycl._{config.module_name}_sycl"
298-
)
299-
postfix = "sycl"
300-
else:
301-
module_name = module
302-
postfix = module[len(config.module_name) + 1 :]
319+
module_name, postfix = discover_module_name_and_postfix(module, config)
303320

304321
if postfixes and postfix not in postfixes:
305322
continue
@@ -318,6 +335,8 @@ def read_benchmark_implementations(
318335
impl_mod = importlib.import_module(package_path)
319336

320337
for func in [
338+
module,
339+
f"{module}_{postfix}",
321340
config.module_name,
322341
f"{config.module_name}_{postfix}",
323342
"kernel",
@@ -349,72 +368,3 @@ def get_benchmark_index(configs: list[Benchmark], module_name: str) -> int:
349368
),
350369
None,
351370
)
352-
353-
354-
def fix_npbench_configs(configs: list[Benchmark]):
355-
"""Applies configuration fixes for some npbench benchmarks.
356-
357-
Fixes required due to the difference in framework implementations.
358-
"""
359-
index = get_benchmark_index(configs, "mandelbrot1")
360-
if index is not None:
361-
configs[index] = modify_args(
362-
configs[index], modifier=lambda s: s.lower()
363-
)
364-
365-
index = get_benchmark_index(configs, "mandelbrot2")
366-
if index is not None:
367-
configs[index] = modify_args(
368-
configs[index],
369-
modifier=lambda s: "itermax" if s == "maxiter" else s.lower(),
370-
)
371-
372-
index = get_benchmark_index(configs, "conv2d")
373-
if index is not None:
374-
config = configs[index]
375-
376-
config.module_name = "conv2d_bias"
377-
configs[index] = config
378-
379-
for impl in config.implementations:
380-
impl.func_name = "conv2d_bias"
381-
382-
index = get_benchmark_index(configs, "nbody")
383-
if index is not None:
384-
configs[index].output_args.append("pos")
385-
configs[index].output_args.append("vel")
386-
387-
index = get_benchmark_index(configs, "scattering_self_energies")
388-
if index is not None:
389-
configs[index].output_args.append("Sigma")
390-
391-
index = get_benchmark_index(configs, "correlation")
392-
if index is not None:
393-
configs[index].output_args.append("data")
394-
395-
index = get_benchmark_index(configs, "doitgen")
396-
if index is not None:
397-
configs[index].output_args.append("A")
398-
399-
400-
def modify_args(config: Benchmark, modifier: Callable[[str], str]) -> Benchmark:
401-
"""Applies modifier to function argument names.
402-
403-
Current implementation applies modifier to
404-
- all presets keys, not preset names;
405-
- all input_args;
406-
- all array_args;
407-
- all output_args.
408-
"""
409-
config.parameters = Presets(
410-
{
411-
preset: {modifier(k): v for k, v in parameters.items()}
412-
for preset, parameters in config.parameters.items()
413-
}
414-
)
415-
416-
config.input_args = [modifier(arg) for arg in config.input_args]
417-
config.array_args = [modifier(arg) for arg in config.array_args]
418-
config.output_args = [modifier(arg) for arg in config.output_args]
419-
420-
return config

dpbench/configs/bench_info/npbench/conv2d_bias.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
name = "Conv2D with Bias"
88
short_name = "conv2d"
99
relative_path = "deep_learning/conv2d_bias"
10-
module_name = "conv2d"
10+
module_name = "conv2d_bias"
1111
func_name = "conv2d_bias"
1212
kind = "microbench"
1313
domain = "Learning"

dpbench/configs/bench_info/npbench/mandelbrot1.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ input_args = [
1818
"xmax",
1919
"ymin",
2020
"ymax",
21-
"XN",
22-
"YN",
21+
"xn",
22+
"yn",
2323
"maxiter",
2424
"horizon",
2525
]
@@ -30,39 +30,39 @@ norm_error = 0.001
3030
[benchmark.parameters.S]
3131
xmin = -1.75
3232
xmax = 0.25
33-
XN = 125
33+
xn = 125
3434
ymin = -1.0
3535
ymax = 1.0
36-
YN = 125
36+
yn = 125
3737
maxiter = 60
3838
horizon = 2.0
3939

4040
[benchmark.parameters.M]
4141
xmin = -1.75
4242
xmax = 0.25
43-
XN = 250
43+
xn = 250
4444
ymin = -1.0
4545
ymax = 1.0
46-
YN = 250
46+
yn = 250
4747
maxiter = 150
4848
horizon = 2.0
4949

5050
[benchmark.parameters.L]
5151
xmin = -2.0
5252
xmax = 0.5
53-
XN = 833
53+
xn = 833
5454
ymin = -1.25
5555
ymax = 1.25
56-
YN = 833
56+
yn = 833
5757
maxiter = 200
5858
horizon = 2.0
5959

6060
[benchmark.parameters.paper]
6161
xmin = -2.25
6262
xmax = 0.75
63-
XN = 1000
63+
xn = 1000
6464
ymin = -1.25
6565
ymax = 1.25
66-
YN = 1000
66+
yn = 1000
6767
maxiter = 200
6868
horizon = 2.0

dpbench/configs/bench_info/npbench/mandelbrot2.toml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ input_args = [
1818
"xmax",
1919
"ymin",
2020
"ymax",
21-
"XN",
22-
"YN",
23-
"maxiter",
21+
"xn",
22+
"yn",
23+
"itermax",
2424
"horizon",
2525
]
2626
array_args = []
@@ -30,39 +30,39 @@ norm_error = 0.001
3030
[benchmark.parameters.S]
3131
xmin = -2.0
3232
xmax = 0.5
33-
XN = 200
33+
xn = 200
3434
ymin = -1.25
3535
ymax = 1.25
36-
YN = 200
37-
maxiter = 40
36+
yn = 200
37+
itermax = 40
3838
horizon = 2.0
3939

4040
[benchmark.parameters.M]
4141
xmin = -2.0
4242
xmax = 0.5
43-
XN = 500
43+
xn = 500
4444
ymin = -1.25
4545
ymax = 1.25
46-
YN = 500
47-
maxiter = 80
46+
yn = 500
47+
itermax = 80
4848
horizon = 2.0
4949

5050
[benchmark.parameters.L]
5151
xmin = -2.25
5252
xmax = 0.75
53-
XN = 1000
53+
xn = 1000
5454
ymin = -1.5
5555
ymax = 1.5
56-
YN = 1000
57-
maxiter = 100
56+
yn = 1000
57+
itermax = 100
5858
horizon = 2.0
5959

6060
[benchmark.parameters.paper]
6161
xmin = -2.25
6262
xmax = 0.75
63-
XN = 1000
63+
xn = 1000
6464
ymin = -1.25
6565
ymax = 1.25
66-
YN = 1000
67-
maxiter = 200
66+
yn = 1000
67+
itermax = 200
6868
horizon = 2.0

dpbench/configs/bench_info/npbench/nbody.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ array_args = [
2828
"pos",
2929
"vel",
3030
]
31-
output_args = []
31+
output_args = [
32+
"pos",
33+
"vel",
34+
]
3235
norm_error = 0.1
3336

3437
[benchmark.parameters.S]

dpbench/configs/bench_info/npbench/scattering_self_energies.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ array_args = [
2626
"D",
2727
"Sigma",
2828
]
29-
output_args = []
29+
output_args = [
30+
"Sigma",
31+
]
3032

3133
[benchmark.parameters.S]
3234
Nkz = 2

dpbench/configs/bench_info/polybench/datamining/correlation.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ input_args = [
2121
array_args = [
2222
"data",
2323
]
24-
output_args = []
24+
output_args = [
25+
"data",
26+
]
2527

2628
[benchmark.parameters.S]
2729
M = 500

dpbench/configs/bench_info/polybench/linear-algebra/kernels/doitgen.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ array_args = [
2424
"A",
2525
"C4",
2626
]
27-
output_args = []
27+
output_args = [
28+
"A",
29+
]
2830

2931
[benchmark.parameters.S]
3032
NR = 60

0 commit comments

Comments
 (0)