26 """Generates build files for either bazel or cmake experimental builds using filelist.json
28 python scripts/generate_build_files.py --bazel
29 python scripts/generate_build_files.py --cmake
31 Writes generated file to the bazel BUILD file located under src/ if using --bazel flag.
32 Writes generated file to the CMake CMakeLists.txt file located under src/ if using --cmake flag.
41 files = {
"common": []}
44 if backend
not in filelist:
48 for operator
in operators:
49 if operator
in filelist[backend][
'operators']:
50 files[
'common'] += filelist[backend][
'operators'][operator][
"files"][
"common"]
52 if tech
in filelist[backend][
'operators'][operator][
"files"]:
58 tech_files = filelist[backend][
'operators'][operator][
"files"][tech]
59 files[tech] += tech_files.get(
'common', [])
61 files[tech] += tech_files.get(attr, [])
64 return {k: list(
set(v))
for k, v
in files.items()}
69 for operator
in operators:
70 if operator
in filelist[backend][
'operators']:
72 if 'deps' in filelist[backend][
'operators'][operator]:
73 ops.update(filelist[backend][
'operators'][operator][
'deps'])
75 print(
"Operator {0} is unsupported on {1} backend!".
format(
84 are_ops_resolved =
False
85 while not are_ops_resolved:
87 filelist, resolved_operators, backend)
88 if len(resolution_pass) != len(resolved_operators):
89 resolved_operators.update(resolution_pass)
91 are_ops_resolved =
True
93 return resolved_operators
96 return """# Copyright (c) 2023-2024 Arm Limited.
98 # SPDX-License-Identifier: MIT
100 # Permission is hereby granted, free of charge, to any person obtaining a copy
101 # of this software and associated documentation files (the "Software"), to
102 # deal in the Software without restriction, including without limitation the
103 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
104 # sell copies of the Software, and to permit persons to whom the Software is
105 # furnished to do so, subject to the following conditions:
107 # The above copyright notice and this permission notice shall be included in all
108 # copies or substantial portions of the Software.
110 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
111 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
112 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
113 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
114 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
115 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
120 line_separator =
'",\n\t"'
122 template = f
"""{get_template_header()}
125 name = "arm_compute_graph_srcs",
126 srcs = ["{line_separator.join(srcs_graph)}"] +
130 visibility = ["//visibility:public"]
134 name = "arm_compute_sve2_srcs",
135 srcs = ["{line_separator.join(srcs_sve2)}"] +
139 visibility = ["//visibility:public"]
143 name = "arm_compute_sve_srcs",
144 srcs = ["{line_separator.join(srcs_sve)}"] +
148 visibility = ["//visibility:public"]
152 name = "arm_compute_srcs",
153 srcs = ["{line_separator.join(srcs_core)}"] +
157 visibility = ["//visibility:public"]
166 line_separator =
'\n\t'
168 template = f
"""{get_template_header()}
173 {line_separator.join(srcs_graph)}
179 {line_separator.join(srcs_sve)}
185 {line_separator.join(srcs_sve2)}
191 {line_separator.join(srcs_core)}
199 with open(
"filelist.json")
as fp:
200 filelist = json.load(fp)
203 lib_files = filelist[
'common']
206 lib_files += filelist[
'logging']
209 lib_files += filelist[
'c_api'][
'common']
210 lib_files += filelist[
'c_api'][
'operators']
213 lib_files += filelist[
'scheduler'][
'single']
215 lib_files += filelist[
'scheduler'][
'threads']
216 lib_files += filelist[
'scheduler'][
'omp']
219 graph_files = glob.glob(
'src/graph/*.cpp')
220 graph_files += glob.glob(
'src/graph/*/*.cpp')
227 lib_files += filelist[
'cpu'][
'common']
228 simd = [
'neon',
'sve',
'sve2']
231 data_types = [
"qasymm8",
"qasymm8_signed",
"qsymm16",
232 "fp16",
"fp32",
"integer"]
233 data_layouts = [
"nhwc",
"nchw"]
234 fixed_format_kernels = [
"fixed_format_kernels"]
235 attrs = data_types + data_layouts + \
236 fixed_format_kernels + [
"estate64"]
239 cpu_operators = filelist[
'cpu'][
'operators'].keys()
241 filelist, cpu_operators,
'cpu')
243 filelist, cpu_ops_to_build,
'cpu', simd, attrs)
246 lib_files += cpu_files.get(
'common', [])
249 lib_files += cpu_files.get(
'neon', [])
252 lib_files_sve = cpu_files.get(
'sve', [])
255 lib_files_sve2 = cpu_files.get(
'sve2', [])
257 graph_files += glob.glob(
'src/graph/backends/NEON/*.cpp')
261 graph_files = sorted([path.replace(
"src/",
"")
for path
in graph_files])
262 lib_files_sve = sorted([path.replace(
"src/",
"")
for path
in lib_files_sve])
263 lib_files_sve2 = sorted([path.replace(
"src/",
"")
for path
in lib_files_sve2])
264 lib_files = sorted([path.replace(
"src/",
"")
for path
in lib_files])
266 return graph_files, lib_files_sve, lib_files_sve2, lib_files
269 if "__main__" in __name__:
271 parser = argparse.ArgumentParser()
272 parser.add_argument(
"--bazel", action=
"store_true")
273 parser.add_argument(
"--cmake", action=
"store_true")
274 args = parser.parse_args()
280 graph_files += [
"//utils:CommonGraphOptions.cpp"]
283 graph_files, lib_files_sve, lib_files_sve2, lib_files)
284 with open(
"src/BUILD.bazel",
"w")
as fp:
285 fp.write(bazel_build_string)
289 graph_files, lib_files_sve, lib_files_sve2, lib_files)
290 with open(
"src/CMakeLists.txt",
"w")
as fp:
291 fp.write(cmake_build_string)
293 if not args.cmake
and not args.bazel:
294 print(
"Supply either --bazel or --cmake flag to generate build files for corresponding build")