Skip to content

Commit 26362bd

Browse files
authored
Prevent duplicate convbench configs clobbering eachother when compiled (#66)
Achieved by: - Deduplication of tag-config pairs in the list of configs. (To this end, equality and hashing support for configs is added.) - Using different filenames when compiling the same config with different tags. Fixes convbench CI failures caused by a race condition, and should also be a significant efficiency improvement (40% of tag-config pairs were duplicates).
1 parent 759cd6f commit 26362bd

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

iree_kernel_benchmark/convbench/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import argparse
99
import sys
1010
import re
11+
from collections import OrderedDict
1112
from ..utils import *
1213
from .conv_utils import *
1314
from .problems import get_conv_configs, get_tk_conv_configs, get_conv_test_configs
@@ -17,14 +18,14 @@
1718

1819
def compile_conv_iree(tag, config, kernel_dir, vmfb_dir, extra_compiler_args):
1920
mlir_file, vmfb_file, dump_path = compile_conv_config(
20-
config, kernel_dir, vmfb_dir, extra_compiler_args
21+
tag, config, kernel_dir, vmfb_dir, extra_compiler_args
2122
)
2223
return (tag, config, mlir_file, vmfb_file, dump_path)
2324

2425

2526
def compile_conv_wave(tag, config, kernel_dir, vmfb_dir, extra_compiler_args):
2627
mlir_file, vmfb_file, dump_path = compile_wave_conv_config(
27-
config, kernel_dir, vmfb_dir, extra_compiler_args
28+
tag, config, kernel_dir, vmfb_dir, extra_compiler_args
2829
)
2930
return (tag, config, mlir_file, vmfb_file, dump_path)
3031

@@ -83,6 +84,9 @@ def compile_conv_wave(tag, config, kernel_dir, vmfb_dir, extra_compiler_args):
8384
configs = get_tk_conv_configs() if args.tk else get_conv_configs()
8485
print(f"Generated {len(configs)} conv configs.")
8586

87+
configs = list(OrderedDict({config: None for config in configs}))
88+
print(f"Deduplicated to {len(configs)} conv configs.")
89+
8690
if args.filter_config is not None:
8791
filter_regex = re.compile(args.filter_config)
8892
configs = list(

iree_kernel_benchmark/convbench/conv_utils.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ def get_name(self) -> str:
4848
+ str(self.S)
4949
)
5050

51+
def __eq__(self, other):
52+
if not isinstance(other, ConvConfig):
53+
return NotImplemented
54+
return self.get_name() == other.get_name()
55+
56+
def __hash__(self):
57+
return hash(self.get_name())
58+
5159
def get_img_shape(self) -> str:
5260
if "nhwc" in self.OP:
5361
in_h = self.H * self.S + self.P - 1
@@ -188,12 +196,19 @@ def generate_mlir(config: ConvConfig):
188196

189197

190198
def compile_conv_config(
191-
config: ConvConfig, kernel_dir: Path, vmfb_dir: Path, extra_compiler_args: list[str]
199+
tag: str,
200+
config: ConvConfig,
201+
kernel_dir: Path,
202+
vmfb_dir: Path,
203+
extra_compiler_args: list[str],
192204
) -> tuple[Path, Optional[Path]]:
193-
mlir_file = kernel_dir / (config.get_name() + ".mlir")
194-
vmfb_file = vmfb_dir / (config.get_name() + ".vmfb")
195-
dump_file = kernel_dir / (config.get_name() + ".stderr.mlir")
196-
files_path = vmfb_dir / config.get_name()
205+
# Name with tag is used for filenames so that duplicate configs with
206+
# different tags will not clobber eachother.
207+
name_with_tag = tag + "-" + config.get_name()
208+
mlir_file = kernel_dir / (name_with_tag + ".mlir")
209+
vmfb_file = vmfb_dir / (name_with_tag + ".vmfb")
210+
dump_file = kernel_dir / (name_with_tag + ".stderr.mlir")
211+
files_path = vmfb_dir / name_with_tag
197212

198213
# Generate mlir content
199214
mlir_content = generate_mlir(config)

iree_kernel_benchmark/convbench/wave_conv_utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@
2525

2626

2727
def compile_wave_conv_config(
28-
config: ConvConfig, kernel_dir: Path, vmfb_dir: Path, extra_compiler_args: list[str]
28+
tag: str,
29+
config: ConvConfig,
30+
kernel_dir: Path,
31+
vmfb_dir: Path,
32+
extra_compiler_args: list[str],
2933
) -> tuple[Path, Optional[Path]]:
3034
if not TURBINE_AVAILABLE:
3135
raise ValueError("iree.turbine package is not available")
3236

33-
mlir_file = kernel_dir / (config.get_name() + ".mlir")
34-
vmfb_file = vmfb_dir / (config.get_name() + ".vmfb")
35-
files_path = vmfb_dir / config.get_name()
37+
# Name with tag is used for filenames so that duplicate configs with
38+
# different tags will not clobber eachother.
39+
name_with_tag = tag + "-" + config.get_name()
40+
mlir_file = kernel_dir / (name_with_tag + ".mlir")
41+
vmfb_file = vmfb_dir / (name_with_tag + ".vmfb")
42+
files_path = vmfb_dir / name_with_tag
3643

3744
try:
3845
_compile_conv(config, mlir_file, vmfb_file)

0 commit comments

Comments
 (0)