blob: d5b268f522f3c532b02cc8cc1584cbd98bb919f8 [file] [log] [blame]
Gunes Bayir66b4a6a2023-07-01 22:55:42 +01001#!/usr/bin/env python3
2
Jakub Sujake812c0c2024-01-22 10:32:38 +00003# Copyright (c) 2023-2024 Arm Limited.
Gunes Bayir66b4a6a2023-07-01 22:55:42 +01004#
5# SPDX-License-Identifier: MIT
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to
9# deal in the Software without restriction, including without limitation the
10# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11# sell copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in all
15# copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
24
25import argparse
26import os
27from jinja2 import Template
28import datetime
29
30# Paths to exclude
31excluded_paths = ["build",
Jakub Sujake812c0c2024-01-22 10:32:38 +000032 "compute_kernel_writer/",
33 "src/dynamic_fusion/runtime/gpu/cl/ckw_driver/",
34 "src/dynamic_fusion/sketch/gpu/ckw_driver/",
Gunes Bayir66b4a6a2023-07-01 22:55:42 +010035 "docs/",
36 "documentation/",
37 "examples/",
38 "opencl-1.2-stubs/",
39 "release_repository/",
40 "opengles-3.1-stubs/",
41 "scripts/",
42 "tests/",
43 "/GLES_COMPUTE/",
44 "/graph/",
45 "/sve/",
46 "/SVE/",
47 "/sve2/",
Viet-Hoa Do77bbe2e2023-12-06 11:01:15 +000048 "/SVE2/",
49 "/sme/",
50 "/sme2/",
Gunes Bayir66b4a6a2023-07-01 22:55:42 +010051 ]
52
53excluded_files = ["TracePoint.cpp"]
54
55# Android bp template to render
56year = datetime.datetime.now().year
57
58bp_tm = Template(
59"""//
60// Copyright © 2020-""" + str(year) + """ Arm Ltd. All rights reserved.
61// SPDX-License-Identifier: MIT
62//
63
64// OpenCL sources are NOT required by ArmNN or its Android NNAPI driver and are used for CI purposes only.
65opencl_srcs = [
66 {% for cl_src in cl_srcs -%}
67 "{{ cl_src }}",
68 {% endfor %}
69]
70
71bootstrap_go_package {
72 name: "arm_compute_library_nn_driver",
73 pkgPath: "arm_compute_library_nn_driver",
74 deps: [
75 "blueprint",
76 "blueprint-pathtools",
77 "blueprint-proptools",
78 "soong",
79 "soong-android",
80 "soong-cc",
81 ],
82 srcs: [
83 "scripts/arm_compute_library_nn_driver.go",
84 ],
85 pluginFor: [ "soong_build" ],
86}
87
88arm_compute_library_defaults {
89 name: "acl-default-cppflags",
90 cppflags: [
91 "-std=c++14",
92 "-fexceptions",
93 "-DBOOST_NO_AUTO_PTR",
94 "-DEMBEDDED_KERNELS",
95 "-DARM_COMPUTE_ASSERTS_ENABLED",
96 "-DARM_COMPUTE_CPP_SCHEDULER",
97 "-DENABLE_NEON",
98 "-DARM_COMPUTE_ENABLE_NEON",
99 "-Wno-unused-parameter",
100 "-DNO_DOT_IN_TOOLCHAIN",
101 "-Wno-implicit-fallthrough",
Jakub Sujake812c0c2024-01-22 10:32:38 +0000102 "-fPIC"
Gunes Bayir66b4a6a2023-07-01 22:55:42 +0100103 ],
104 rtti: true,
105}
106
107cc_library_static {
108 name: "arm_compute_library",
109 defaults: ["acl-default-cppflags"],
110 proprietary: true,
111 local_include_dirs: ["build/android-arm64v8a/src/core",
112 "build/android-arm64v8a/src/core/CL",
Gunes Bayir0ee13af2024-02-07 15:34:45 +0000113 "compute_kernel_writer/include",
Gunes Bayir66b4a6a2023-07-01 22:55:42 +0100114 "src/core/common",
115 "src/core/helpers",
116 "src/core/NEON/kernels/arm_gemm",
117 "src/core/NEON/kernels/assembly",
118 "src/core/NEON/kernels/convolution/common",
119 "src/core/NEON/kernels/convolution/winograd",
120 "src/cpu/kernels/assembly"],
121 export_include_dirs: [".", "./include"],
122 srcs: [
123 {% for src in srcs -%}
124 "{{ src }}",
125 {% endfor %}
126 ],
127 arch: {
128 arm: {
129 srcs: [
130 {% for arm_src in arm_srcs -%}
131 "{{ arm_src }}",
132 {% endfor %}
133 ],
134 },
135 arm64: {
136 srcs: [
137 {% for arm64_src in arm64_srcs -%}
138 "{{ arm64_src }}",
139 {% endfor %}
140 ],
141 },
142 },
143 rtti: true,
144}
145""")
146
147
148def generate_bp_file(cpp_files, opencl_files):
149 arm_files = [f for f in cpp_files if "a32_" in f]
150 arm64_files = [f for f in cpp_files if any(a64 in f for a64 in ["a64_", "sve_", 'sme_', 'sme2_'])]
151 gen_files = [x for x in cpp_files if x not in arm_files + arm64_files]
152
153 arm_files.sort()
154 arm64_files.sort()
155 gen_files.sort()
156 opencl_files.sort()
157
158 bp_file = bp_tm.render(srcs=gen_files,
159 arm_srcs=arm_files,
160 arm64_srcs=arm64_files,
161 cl_srcs=opencl_files)
162 return bp_file
163
164
165def list_all_files(repo_path):
166 """ Gets the list of files to include to the Android.bp
167
168 :param repo_path: Path of the repository
169 :return: The filtered list of useful filess
170 """
171 if not repo_path.endswith('/'):
172 repo_path = repo_path + "/"
173
174 # Get cpp files
175 cpp_files = []
176 cl_files = []
177 for path, subdirs, files in os.walk(repo_path):
178 for file in files:
179 if file.endswith(".cpp"):
180 cpp_files.append(os.path.join(path, file))
181 elif file.endswith(".cl"):
182 cl_files.append(os.path.join(path, file))
183 # Include CL headers
184 if "src/core/CL/cl_kernels" in path and file.endswith(".h"):
185 cl_files.append(os.path.join(path, file))
186 # Filter out unused cpp files
187 filtered_cpp_files = []
188 for cpp_file in cpp_files:
189 if any(ep in cpp_file for ep in excluded_paths) or any(ef in cpp_file for ef in excluded_files):
190 continue
191 filtered_cpp_files.append(cpp_file.replace(repo_path, ""))
192 # Filter out unused cl files
193 filtered_cl_files = []
194 for cl_file in cl_files:
195 if any(ep in cl_file for ep in excluded_paths):
196 continue
197 filtered_cl_files.append(cl_file.replace(repo_path, ""))
198
199 return filtered_cpp_files, filtered_cl_files
200
201
202if __name__ == "__main__":
203 # Parse arguments
204 parser = argparse.ArgumentParser('Generate Android.bp file for ComputeLibrary')
205 parser.add_argument('--folder', default=".", metavar="folder", dest='folder', type=str, required=False, help='Compute Library source path')
206 parser.add_argument('--output_file', metavar="output_file", default='Android.bp', type=str, required=False, help='Specify Android bp output file')
207 args = parser.parse_args()
208
209 cpp_files, opencl_files = list_all_files(args.folder)
210 bp_file = generate_bp_file(cpp_files, opencl_files)
211
212 with open(args.output_file, 'w') as f:
213 f.write(bp_file)