blob: 6efd072acd5b9c8178dd073437a48e83d0087033 [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/",
48 "/SVE2/"
49 ]
50
51excluded_files = ["TracePoint.cpp"]
52
53# Android bp template to render
54year = datetime.datetime.now().year
55
56bp_tm = Template(
57"""//
58// Copyright © 2020-""" + str(year) + """ Arm Ltd. All rights reserved.
59// SPDX-License-Identifier: MIT
60//
61
62// OpenCL sources are NOT required by ArmNN or its Android NNAPI driver and are used for CI purposes only.
63opencl_srcs = [
64 {% for cl_src in cl_srcs -%}
65 "{{ cl_src }}",
66 {% endfor %}
67]
68
69bootstrap_go_package {
70 name: "arm_compute_library_nn_driver",
71 pkgPath: "arm_compute_library_nn_driver",
72 deps: [
73 "blueprint",
74 "blueprint-pathtools",
75 "blueprint-proptools",
76 "soong",
77 "soong-android",
78 "soong-cc",
79 ],
80 srcs: [
81 "scripts/arm_compute_library_nn_driver.go",
82 ],
83 pluginFor: [ "soong_build" ],
84}
85
86arm_compute_library_defaults {
87 name: "acl-default-cppflags",
88 cppflags: [
89 "-std=c++14",
90 "-fexceptions",
91 "-DBOOST_NO_AUTO_PTR",
92 "-DEMBEDDED_KERNELS",
93 "-DARM_COMPUTE_ASSERTS_ENABLED",
94 "-DARM_COMPUTE_CPP_SCHEDULER",
95 "-DENABLE_NEON",
96 "-DARM_COMPUTE_ENABLE_NEON",
97 "-Wno-unused-parameter",
98 "-DNO_DOT_IN_TOOLCHAIN",
99 "-Wno-implicit-fallthrough",
Jakub Sujake812c0c2024-01-22 10:32:38 +0000100 "-fPIC"
Gunes Bayir66b4a6a2023-07-01 22:55:42 +0100101 ],
102 rtti: true,
103}
104
105cc_library_static {
106 name: "arm_compute_library",
107 defaults: ["acl-default-cppflags"],
108 proprietary: true,
109 local_include_dirs: ["build/android-arm64v8a/src/core",
110 "build/android-arm64v8a/src/core/CL",
Gunes Bayir0ee13af2024-02-07 15:34:45 +0000111 "compute_kernel_writer/include",
Gunes Bayir66b4a6a2023-07-01 22:55:42 +0100112 "src/core/common",
113 "src/core/helpers",
114 "src/core/NEON/kernels/arm_gemm",
115 "src/core/NEON/kernels/assembly",
116 "src/core/NEON/kernels/convolution/common",
117 "src/core/NEON/kernels/convolution/winograd",
118 "src/cpu/kernels/assembly"],
119 export_include_dirs: [".", "./include"],
120 srcs: [
121 {% for src in srcs -%}
122 "{{ src }}",
123 {% endfor %}
124 ],
125 arch: {
126 arm: {
127 srcs: [
128 {% for arm_src in arm_srcs -%}
129 "{{ arm_src }}",
130 {% endfor %}
131 ],
132 },
133 arm64: {
134 srcs: [
135 {% for arm64_src in arm64_srcs -%}
136 "{{ arm64_src }}",
137 {% endfor %}
138 ],
139 },
140 },
141 rtti: true,
142}
143""")
144
145
146def generate_bp_file(cpp_files, opencl_files):
147 arm_files = [f for f in cpp_files if "a32_" in f]
148 arm64_files = [f for f in cpp_files if any(a64 in f for a64 in ["a64_", "sve_", 'sme_', 'sme2_'])]
149 gen_files = [x for x in cpp_files if x not in arm_files + arm64_files]
150
151 arm_files.sort()
152 arm64_files.sort()
153 gen_files.sort()
154 opencl_files.sort()
155
156 bp_file = bp_tm.render(srcs=gen_files,
157 arm_srcs=arm_files,
158 arm64_srcs=arm64_files,
159 cl_srcs=opencl_files)
160 return bp_file
161
162
163def list_all_files(repo_path):
164 """ Gets the list of files to include to the Android.bp
165
166 :param repo_path: Path of the repository
167 :return: The filtered list of useful filess
168 """
169 if not repo_path.endswith('/'):
170 repo_path = repo_path + "/"
171
172 # Get cpp files
173 cpp_files = []
174 cl_files = []
175 for path, subdirs, files in os.walk(repo_path):
176 for file in files:
177 if file.endswith(".cpp"):
178 cpp_files.append(os.path.join(path, file))
179 elif file.endswith(".cl"):
180 cl_files.append(os.path.join(path, file))
181 # Include CL headers
182 if "src/core/CL/cl_kernels" in path and file.endswith(".h"):
183 cl_files.append(os.path.join(path, file))
184 # Filter out unused cpp files
185 filtered_cpp_files = []
186 for cpp_file in cpp_files:
187 if any(ep in cpp_file for ep in excluded_paths) or any(ef in cpp_file for ef in excluded_files):
188 continue
189 filtered_cpp_files.append(cpp_file.replace(repo_path, ""))
190 # Filter out unused cl files
191 filtered_cl_files = []
192 for cl_file in cl_files:
193 if any(ep in cl_file for ep in excluded_paths):
194 continue
195 filtered_cl_files.append(cl_file.replace(repo_path, ""))
196
197 return filtered_cpp_files, filtered_cl_files
198
199
200if __name__ == "__main__":
201 # Parse arguments
202 parser = argparse.ArgumentParser('Generate Android.bp file for ComputeLibrary')
203 parser.add_argument('--folder', default=".", metavar="folder", dest='folder', type=str, required=False, help='Compute Library source path')
204 parser.add_argument('--output_file', metavar="output_file", default='Android.bp', type=str, required=False, help='Specify Android bp output file')
205 args = parser.parse_args()
206
207 cpp_files, opencl_files = list_all_files(args.folder)
208 bp_file = generate_bp_file(cpp_files, opencl_files)
209
210 with open(args.output_file, 'w') as f:
211 f.write(bp_file)