blob: d33cf6b8bb9452aaf8b7d90438a8e198d6863b54 [file] [log] [blame]
David Svantessone0c42ef2022-12-15 16:25:57 +00001# Copyright (c) 2023 Arm Limited.
2#
3# SPDX-License-Identifier: MIT
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to
7# deal in the Software without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22
23load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
24load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
25
26#---------------------------------------------------------------------
27# Config setting for Tensorflow build
28config_setting(
29 name = "build_with_acl",
30 define_values = {
31 "build_with_acl": "true",
32 },
33 visibility = ["//visibility:public"],
34)
35
36#---------------------------------------------------------------------
37# Flags for build options. Example: --//:debug=true
38# All flags have aliases in .bazelrc so can use for example --debug=true when building
39bool_flag(
40 name = "debug",
41 build_setting_default = False,
42 visibility = ["//visibility:public"],
43)
44
45bool_flag(
46 name = "Werror",
47 build_setting_default = False,
48 visibility = ["//visibility:public"],
49)
50
51bool_flag(
52 name = "logging",
53 build_setting_default = False,
54 visibility = ["//visibility:public"],
55)
56
57bool_flag(
58 name = "openmp",
59 build_setting_default = True,
60 visibility = ["//visibility:public"],
61)
62
63bool_flag(
64 name = "cppthreads",
65 build_setting_default = False,
66 visibility = ["//visibility:public"],
67)
68
69#---------------------------------------------------------------------
70# Flag variables
71config_setting(
72 name = "debug_flag",
73 flag_values = {
74 ":debug": "true",
75 },
76)
77
78config_setting(
79 name = "Werror_flag",
80 flag_values = {
81 ":Werror": "true",
82 },
83)
84
85config_setting(
86 name = "logging_flag",
87 flag_values = {
88 ":logging": "true",
89 },
90)
91
92config_setting(
93 name = "openmp_flag",
94 flag_values = {
95 ":openmp": "true",
96 },
97)
98
99config_setting(
100 name = "cppthreads_flag",
101 flag_values = {
102 ":cppthreads": "true",
103 },
104)
105
106#---------------------------------------------------------------------
107# Common defines used for all targets
108cc_library(
109 name = "common_defines",
110 defines = [
111 "ENABLE_NEON",
112 "ARM_COMPUTE_CPU_ENABLED",
113 "ARM_COMPUTE_ENABLE_NEON",
114 "ARM_COMPUTE_ENABLE_FP16",
115 "ARM_COMPUTE_ENABLE_BF16",
116 "ARM_COMPUTE_ENABLE_I8MM",
117 "ENABLE_FP16_KERNELS",
118 "ENABLE_FP32_KERNELS",
119 "ENABLE_QASYMM8_KERNELS",
120 "ENABLE_QASYMM8_SIGNED_KERNELS",
121 "ENABLE_QSYMM16_KERNELS",
122 "ENABLE_INTEGER_KERNELS",
123 "ENABLE_NHWC_KERNELS",
124 "ENABLE_NCHW_KERNELS",
125 "DARM_COMPUTE_GRAPH_ENABLED",
126 "ARM_COMPUTE_ENABLE_SVEF32MM",
127 "ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS",
128 ] + select({
129 "//:debug_flag": [
130 "ARM_COMPUTE_DEBUG_ENABLED",
131 "ARM_COMPUTE_ASSERTS_ENABLED",
132 ],
133 "//conditions:default": [],
134 }) +
135 select({
136 "//:logging_flag": ["ARM_COMPUTE_LOGGING_ENABLED"],
137 "//conditions:default": [],
138 }) +
139 select({
140 "//:cppthreads_flag": ["ARM_COMPUTE_CPP_SCHEDULER"],
141 "//conditions:default": [],
142 }) +
143 select({
144 "//:openmp_flag": ["ARM_COMPUTE_OPENMP_SCHEDULER"],
145 "//conditions:default": [],
146 }),
147 visibility = ["//visibility:public"],
148)
149
150#---------------------------------------------------------------------
151# Rule for creating file "arm_compute_version.embed"
152genrule(
153 name = "create_version_file",
154 srcs = [".git/HEAD"],
155 outs = ["arm_compute_version.embed"],
156 cmd = "$(location //scripts:print_version_file) bazel-build-options `cat $(location :.git/HEAD)` > $@",
157 tools = ["//scripts:print_version_file"],
158 visibility = ["//visibility:public"],
159)
160
161#---------------------------------------------------------------------
162# Graph library
163
164cc_library(
165 name = "arm_compute_graph",
166 srcs = ["//src:arm_compute_graph_srcs"],
167 copts = [
168 "-march=armv8.2-a+fp16", # What arch is it we should go for here?
169 ] + select({
170 "//:debug_flag": [
171 "-O0",
172 "-g",
173 "-gdwarf-2",
174 ],
175 "//conditions:default": ["-O3"],
176 }) +
177 select({
178 "//:openmp_flag": ["-fopenmp"],
179 "//conditions:default": [],
180 }) +
181 select({
182 "//:Werror_flag": ["-Werror"],
183 "//conditions:default": [],
184 }),
185 visibility = ["//visibility:public"],
186 deps = [
187 "arm_compute",
188 "//:common_defines",
189 "//arm_compute:graph_headers",
190 ],
191 alwayslink = True,
192)
193
194#---------------------------------------------------------------------
195# SVE2 library
196
197cc_library(
198 name = "arm_compute_sve2",
199 srcs = ["//src:arm_compute_sve2_srcs"],
200 copts = [
201 "-march=armv8.6-a+sve2+fp16+dotprod", # What arch is it we should go for here?
202 ] + select({
203 "//:debug_flag": [
204 "-O0",
205 "-g",
206 "-gdwarf-2",
207 ],
208 "//conditions:default": ["-O3"],
209 }) +
210 select({
211 "//:openmp_flag": ["-fopenmp"],
212 "//conditions:default": [],
213 }) +
214 select({
215 "//:Werror_flag": ["-Werror"],
216 "//conditions:default": [],
217 }),
218 includes = [
219 "src/core/NEON/kernels/arm_conv",
220 "src/core/NEON/kernels/arm_gemm",
221 "src/core/NEON/kernels/assembly",
222 "src/core/cpu/kernels/assembly",
223 "src/cpu/kernels/assembly",
224 ],
225 linkopts = select({
226 "//:openmp_flag": ["-fopenmp"],
227 "//conditions:default": [],
228 }),
229 local_defines = [
230 "ENABLE_SVE",
231 "ARM_COMPUTE_ENABLE_SVE",
232 "ARM_COMPUTE_ENABLE_SVE2",
233 ],
234 deps = [
235 "//:common_defines",
236 "//arm_compute:core_headers",
237 "//arm_compute:runtime_headers",
238 "//include",
239 "//support",
240 ],
241 alwayslink = True,
242)
243
244#---------------------------------------------------------------------
245# SVE library
246
247cc_library(
248 name = "arm_compute_sve",
249 srcs = ["//src:arm_compute_sve_srcs"],
250 copts = [
251 "-march=armv8.2-a+sve+fp16+dotprod", # What arch is it we should go for here?
252 ] + select({
253 "//:debug_flag": [
254 "-O0",
255 "-g",
256 "-gdwarf-2",
257 ],
258 "//conditions:default": ["-O3"],
259 }) +
260 select({
261 "//:openmp_flag": ["-fopenmp"],
262 "//conditions:default": [],
263 }) +
264 select({
265 "//:Werror_flag": ["-Werror"],
266 "//conditions:default": [],
267 }),
268 includes = [
269 "src/core/NEON/kernels/arm_conv",
270 "src/core/NEON/kernels/arm_gemm",
271 "src/core/NEON/kernels/assembly",
272 "src/core/cpu/kernels/assembly",
273 "src/cpu/kernels/assembly",
274 ],
275 linkopts = select({
276 "//:openmp_flag": ["-fopenmp"],
277 "//conditions:default": [],
278 }),
279 local_defines = [
280 "ENABLE_SVE",
281 "ARM_COMPUTE_ENABLE_SVE",
282 ],
283 deps = [
284 "//:common_defines",
285 "//arm_compute:core_headers",
286 "//arm_compute:runtime_headers",
287 "//include",
288 "//support",
289 ],
290 alwayslink = True,
291)
292
293#---------------------------------------------------------------------
294# Core and Runtime library
295
296cc_library(
297 name = "arm_compute",
298 srcs = ["//src:arm_compute_srcs"],
299 hdrs = glob([
300 "core/NEON/kernels/**/*.h",
301 "core/NEON/kernels/**/*.hpp",
302 "**/*.inl",
303 ]) + [
304 "//:create_version_file",
305 ],
306 copts = [
307 "-march=armv8.2-a+fp16", # What arch is it we should go for here?
308 ] + select({
309 "//:debug_flag": [
310 "-O0",
311 "-g",
312 "-gdwarf-2",
313 ],
314 "//conditions:default": ["-O3"],
315 }) +
316 select({
317 "//:openmp_flag": ["-fopenmp"],
318 "//conditions:default": [],
319 }) +
320 select({
321 "//:Werror_flag": ["-Werror"],
322 "//conditions:default": [],
323 }),
324 includes = [
325 "arm_compute/runtime",
326 "src/core/NEON/kernels/assembly",
327 "src/core/NEON/kernels/convolution/common",
328 "src/core/NEON/kernels/convolution/winograd",
329 "src/core/cpu/kernels/assembly",
330 "src/cpu/kernels/assembly",
331 ],
332 linkopts = select({
333 "//:openmp_flag": ["-fopenmp"],
334 "//conditions:default": [],
335 }),
336 visibility = ["//visibility:public"],
337 deps = [
338 "//:common_defines",
339 "//arm_compute:core_headers",
340 "//arm_compute:graph_headers",
341 "//arm_compute:runtime_headers",
342 "//include",
343 "//support",
344 "//utils",
345 ],
346 alwayslink = True,
347)