1# 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 69bool_flag( 70 name = "enable_bf16_validation", 71 build_setting_default = False, 72 visibility = ["//visibility:public"], 73) 74 75#--------------------------------------------------------------------- 76# Flag variables 77config_setting( 78 name = "debug_flag", 79 flag_values = { 80 ":debug": "true", 81 }, 82) 83 84config_setting( 85 name = "Werror_flag", 86 flag_values = { 87 ":Werror": "true", 88 }, 89) 90 91config_setting( 92 name = "logging_flag", 93 flag_values = { 94 ":logging": "true", 95 }, 96) 97 98config_setting( 99 name = "openmp_flag", 100 flag_values = { 101 ":openmp": "true", 102 }, 103) 104 105config_setting( 106 name = "cppthreads_flag", 107 flag_values = { 108 ":cppthreads": "true", 109 }, 110) 111 112config_setting( 113 name = "bf16_validation_flag", 114 flag_values = { 115 ":enable_bf16_validation": "true", 116 }, 117) 118 119 120#--------------------------------------------------------------------- 121# Common defines used for all targets 122cc_library( 123 name = "common_defines", 124 defines = [ 125 "ENABLE_NEON", 126 "ARM_COMPUTE_CPU_ENABLED", 127 "ARM_COMPUTE_ENABLE_NEON", 128 "ARM_COMPUTE_ENABLE_FP16", 129 "ARM_COMPUTE_ENABLE_I8MM", 130 "ENABLE_FP16_KERNELS", 131 "ENABLE_FP32_KERNELS", 132 "ENABLE_QASYMM8_KERNELS", 133 "ENABLE_QASYMM8_SIGNED_KERNELS", 134 "ENABLE_QSYMM16_KERNELS", 135 "ENABLE_INTEGER_KERNELS", 136 "ENABLE_NHWC_KERNELS", 137 "ENABLE_NCHW_KERNELS", 138 "DARM_COMPUTE_GRAPH_ENABLED", 139 "ARM_COMPUTE_ENABLE_SVEF32MM", 140 "ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS", 141 "ENABLE_SVE", 142 "ARM_COMPUTE_ENABLE_SVE", 143 "_GLIBCXX_USE_NANOSLEEP" 144 ] + select({ 145 "//:debug_flag": [ 146 "ARM_COMPUTE_DEBUG_ENABLED", 147 "ARM_COMPUTE_ASSERTS_ENABLED", 148 ], 149 "//conditions:default": [], 150 }) + 151 select({ 152 "//:logging_flag": ["ARM_COMPUTE_LOGGING_ENABLED"], 153 "//conditions:default": [], 154 }) + 155 select({ 156 "//:cppthreads_flag": ["ARM_COMPUTE_CPP_SCHEDULER"], 157 "//conditions:default": [], 158 }) + 159 select({ 160 "//:openmp_flag": ["ARM_COMPUTE_OPENMP_SCHEDULER"], 161 "//conditions:default": [], 162 }), 163 visibility = ["//visibility:public"], 164) 165 166#--------------------------------------------------------------------- 167# Rule for creating file "arm_compute_version.embed" 168genrule( 169 name = "create_version_file", 170 srcs = [".git/HEAD"], 171 outs = ["arm_compute_version.embed"], 172 cmd = "$(location //scripts:print_version_file) bazel-build-options `cat $(location :.git/HEAD)` > $@", 173 tools = ["//scripts:print_version_file"], 174 visibility = ["//visibility:public"], 175) 176 177#--------------------------------------------------------------------- 178# Graph library 179 180cc_library( 181 name = "arm_compute_graph", 182 srcs = ["//src:arm_compute_graph_srcs"], 183 copts = [ 184 "-march=armv8.2-a+fp16", # What arch is it we should go for here? 185 ] + select({ 186 "//:debug_flag": [ 187 "-O0", 188 "-g", 189 "-gdwarf-2", 190 ], 191 "//conditions:default": ["-O3"], 192 }) + 193 select({ 194 "//:openmp_flag": ["-fopenmp"], 195 "//conditions:default": [], 196 }) + 197 select({ 198 "//:Werror_flag": ["-Werror"], 199 "//conditions:default": [], 200 }), 201 visibility = ["//visibility:public"], 202 deps = [ 203 "arm_compute", 204 "//:common_defines", 205 "//arm_compute:graph_headers", 206 ], 207 alwayslink = True, 208) 209 210#--------------------------------------------------------------------- 211# SVE2 library 212 213cc_library( 214 name = "arm_compute_sve2", 215 srcs = ["//src:arm_compute_sve2_srcs"], 216 copts = [ 217 "-march=armv8.6-a+sve2+fp16+dotprod", # What arch is it we should go for here? 218 ] + select({ 219 "//:debug_flag": [ 220 "-O0", 221 "-g", 222 "-gdwarf-2", 223 ], 224 "//conditions:default": ["-O3"], 225 }) + 226 select({ 227 "//:openmp_flag": ["-fopenmp"], 228 "//conditions:default": [], 229 }) + 230 select({ 231 "//:Werror_flag": ["-Werror"], 232 "//conditions:default": [], 233 }), 234 includes = [ 235 "src/core/NEON/kernels/arm_conv", 236 "src/core/NEON/kernels/arm_gemm", 237 "src/core/NEON/kernels/assembly", 238 "src/core/cpu/kernels/assembly", 239 "src/cpu/kernels/assembly", 240 ], 241 linkopts = select({ 242 "//:openmp_flag": ["-fopenmp"], 243 "//conditions:default": [], 244 }), 245 local_defines = [ 246 "ARM_COMPUTE_ENABLE_SVE2", 247 "ARM_COMPUTE_ENABLE_BF16" 248 ], 249 deps = [ 250 "//:common_defines", 251 "//arm_compute:core_headers", 252 "//arm_compute:runtime_headers", 253 "//include", 254 "//support", 255 ], 256 alwayslink = True, 257) 258 259#--------------------------------------------------------------------- 260# SVE library 261 262cc_library( 263 name = "arm_compute_sve", 264 srcs = ["//src:arm_compute_sve_srcs"], 265 copts = [ 266 "-march=armv8.2-a+sve+fp16+dotprod", # What arch is it we should go for here? 267 ] + select({ 268 "//:debug_flag": [ 269 "-O0", 270 "-g", 271 "-gdwarf-2", 272 ], 273 "//conditions:default": ["-O3"], 274 }) + 275 select({ 276 "//:openmp_flag": ["-fopenmp"], 277 "//conditions:default": [], 278 }) + 279 select({ 280 "//:Werror_flag": ["-Werror"], 281 "//conditions:default": [], 282 }), 283 includes = [ 284 "src/core/NEON/kernels/arm_conv", 285 "src/core/NEON/kernels/arm_gemm", 286 "src/core/NEON/kernels/assembly", 287 "src/core/cpu/kernels/assembly", 288 "src/cpu/kernels/assembly", 289 ], 290 linkopts = select({ 291 "//:openmp_flag": ["-fopenmp"], 292 "//conditions:default": [], 293 }), 294 local_defines = [ 295 "ARM_COMPUTE_ENABLE_BF16", 296 ], 297 deps = [ 298 "//:common_defines", 299 "//arm_compute:core_headers", 300 "//arm_compute:runtime_headers", 301 "//include", 302 "//support", 303 ], 304 alwayslink = True, 305) 306 307#--------------------------------------------------------------------- 308# Core and Runtime library 309 310cc_library( 311 name = "arm_compute", 312 srcs = ["//src:arm_compute_srcs"], 313 hdrs = glob([ 314 "core/NEON/kernels/**/*.h", 315 "core/NEON/kernels/**/*.hpp", 316 "**/*.inl", 317 ]) + [ 318 "//:create_version_file", 319 ], 320 copts = [ 321 "-march=armv8.2-a+fp16", # What arch is it we should go for here? 322 ] + select({ 323 "//:debug_flag": [ 324 "-O0", 325 "-g", 326 "-gdwarf-2", 327 ], 328 "//conditions:default": ["-O3"], 329 }) + 330 select({ 331 "//:openmp_flag": ["-fopenmp"], 332 "//conditions:default": [], 333 }) + 334 select({ 335 "//:Werror_flag": ["-Werror"], 336 "//conditions:default": [], 337 }), 338 includes = [ 339 "arm_compute/runtime", 340 "src/core/NEON/kernels/assembly", 341 "src/core/NEON/kernels/convolution/common", 342 "src/core/NEON/kernels/convolution/winograd", 343 "src/core/cpu/kernels/assembly", 344 "src/cpu/kernels/assembly", 345 ], 346 linkopts = select({ 347 "//:openmp_flag": ["-fopenmp"], 348 "//conditions:default": [], 349 }), 350 local_defines = [ 351 "ARM_COMPUTE_ENABLE_BF16", 352 ], 353 visibility = ["//visibility:public"], 354 deps = [ 355 "//:common_defines", 356 "//arm_compute:core_headers", 357 "//arm_compute:graph_headers", 358 "//arm_compute:runtime_headers", 359 "//include", 360 "//support", 361 "//utils", 362 "//:arm_compute_sve", 363 "//:arm_compute_sve2" 364 ], 365 alwayslink = True, 366) 367