Skip to content

Commit 1f6a4e5

Browse files
committed
[CTS] Don't depend on Mako in for tests
When running only the CTS it should be possible to do so without first installing the requirements for building the specification.
1 parent aa857f3 commit 1f6a4e5

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

scripts/generate_kernel_header.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@
1212
import subprocess
1313
import sys
1414

15-
from mako.template import Template
16-
17-
HEADER_TEMPLATE = Template("""/*
15+
HEADER_TEMPLATE = """/*
1816
*
1917
* Copyright (C) 2023 Intel Corporation
2018
*
2119
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
2220
* See LICENSE.TXT
2321
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2422
*
25-
* @file ${file_name}.h
23+
* @file %s.h
2624
*
2725
*/
2826
@@ -33,26 +31,33 @@
3331
namespace uur {
3432
namespace device_binaries {
3533
std::map<std::string, std::vector<std::string>> program_kernel_map = {
36-
% for program, entry_points in kernel_name_dict.items():
37-
{"${program}", {
38-
% for entry_point in entry_points:
39-
"${entry_point}",
40-
% endfor
41-
}},
42-
% endfor
34+
%s
4335
};
4436
}
4537
}
46-
""")
38+
"""
39+
40+
PROGRAM_TEMPLATE = """\
41+
{"%s", {
42+
%s
43+
}},
44+
"""
4745

46+
ENTRY_POINT_TEMPLATE = """\
47+
"%s",
48+
"""
4849

4950
def generate_header(output_file, kernel_name_dict):
5051
"""Render the template and write it to the output file."""
5152
file_name = os.path.basename(output_file)
52-
rendered = HEADER_TEMPLATE.render(file_name=file_name,
53-
kernel_name_dict=kernel_name_dict)
53+
device_binaries = ""
54+
for program, entry_points in kernel_name_dict.items():
55+
content = ""
56+
for entry_point in entry_points:
57+
content += ENTRY_POINT_TEMPLATE % entry_point
58+
device_binaries += PROGRAM_TEMPLATE % (program, content)
59+
rendered = HEADER_TEMPLATE % (file_name, device_binaries)
5460
rendered = re.sub(r"\r\n", r"\n", rendered)
55-
5661
with open(output_file, "w") as fout:
5762
fout.write(rendered)
5863

@@ -81,7 +86,9 @@ def get_mangled_names(dpcxx_path, source_file, output_header):
8186
for line in definition_lines:
8287
if kernel_name_regex.search(line) is None:
8388
continue
84-
kernel_name = kernel_name_regex.search(line).group(1)
89+
match = kernel_name_regex.search(line)
90+
assert isinstance(match, re.Match)
91+
kernel_name = match.group(1)
8592
if "kernel_wrapper" not in kernel_name and "with_offset" not in kernel_name:
8693
entry_point_names.append(kernel_name)
8794

0 commit comments

Comments
 (0)