Skip to content

Commit 78b1d25

Browse files
authored
[AOT] Fix too long filename generation (#8738)
This change addresses the issue that when there is a complex kernel with very long signature list, the generated filename possibly would get too long to be recognized by python pathlib. The out filename is constructed as `kernel_name`.`8-char_sig_hash`_`suffix`.`ext`. `suffix` represents signature hints in the form `param_id+c/d`, it holds all indexes to map to the signature list. This change tries to skip constant params in the signature list to shorten the `suffix`, since they do not carry hints or extra information. This example show how this change work on a kernel with 71 parameters in which there are 40 constants. Before ``` kernel_out_name.f84b6f9a_0d1d2d3d456d7d8910111213d14d15d1617d18d19d2021d22d23d2425d26d27d2829d30d31323334353637383940414243444546474849505152535455565758596061626364656667686970.h ``` After ``` kernel_out_name.f84b6f9a_0d1d2d3d6d7d13d14d15d17d18d19d21d22d23d25d26d27d29d30d.h ```
1 parent cb96f11 commit 78b1d25

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

python/triton/tools/compile.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,10 @@ def constexpr(s):
163163
# dump C stub code
164164
suffix = ''
165165
for i, ty in enumerate(signature.values()):
166-
suffix += str(i)
167166
if hints.get((i, ), None) == 1:
168-
suffix += 'c'
167+
suffix += f'{i}c'
169168
if hints.get((i, ), None) == 16:
170-
suffix += 'd'
169+
suffix += f'{i}d'
171170
func_name = '_'.join([out_name, sig_hash, suffix])
172171
asm = ccinfo.asm[backend.binary_ext] # store binary data once
173172

python/triton/tools/link.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self) -> None:
3434
# [kernel_name, c signature]
3535
self.linker_directives = re.compile("//[\\s]*tt-linker:[\\s]*([\\w]+):(.+):(.+)")
3636
# [name, hash, suffix]
37-
self.kernel_name = re.compile("^([\\w]+)_([\\w]+)_([\\w]+)$")
37+
self.kernel_name = re.compile("^([\\w]+)_([\\w]+)_([\\w]*)$")
3838
# [(type, name)]
3939
self.c_sig = re.compile("[\\s]*(\\w+)\\s(\\w+)[,]?")
4040
# [d|c]
@@ -88,22 +88,24 @@ def _match_suffix(self, suffix: str, c_sig: str):
8888
s2i = {"c": 1, "d": 16}
8989
num_specs = 0
9090
sizes = []
91-
# scan through suffix, first find the index,
92-
# then see if it is followed by d or c
91+
# scan through suffix, suffix only includes indexes followed by d or c.
9392
for i in range(len(args)):
94-
pos = suffix.find(str(i))
95-
if pos == -1:
96-
raise LinkerError(f"{suffix} is not a valid kernel suffix")
93+
pos = 0
94+
idx_matched = suffix.startswith(str(i))
95+
if not idx_matched:
96+
continue
9797
pos += len(str(i))
9898
if self.arg_suffix.match(suffix, pos):
9999
num_specs += 1
100100
sizes.extend([None] * (i - len(sizes)))
101101
sizes.append(s2i[suffix[pos]])
102102
pos += 1
103-
if i < len(args) - 1:
104-
suffix = suffix[pos:]
105-
else:
106-
sizes.extend([None] * (len(args) - len(sizes)))
103+
suffix = suffix[pos:]
104+
105+
if len(suffix) > 0:
106+
raise Exception(f"Has invalid extra suffix: {suffix}")
107+
sizes.extend([None] * (len(args) - len(sizes)))
108+
107109
return num_specs, sizes
108110

109111
def _add_kernel(self, name: str, ker: KernelLinkerMeta):

0 commit comments

Comments
 (0)