1# Copied from TensorFlow's `tensorflow/tree/master/third_party/cpuinfo/BUILD 2# Licenced under Apache-2.0 License 3 4# cpuinfo, a library to detect information about the host CPU 5package(default_visibility = ["//visibility:public"]) 6 7licenses(["notice"]) 8 9exports_files(["LICENSE"]) 10 11C99OPTS = [ 12 "-std=gnu99", # gnu99, not c99, because dprintf is used 13 "-Wno-vla", 14 "-D_GNU_SOURCE=1", # to use CPU_SETSIZE 15 "-DCPUINFO_INTERNAL=", 16 "-DCPUINFO_PRIVATE=", 17] 18 19# Source code common to all platforms. 20COMMON_SRCS = [ 21 "src/api.c", 22 "src/init.c", 23 "src/cache.c", 24] 25 26# Architecture-specific sources and headers. 27X86_SRCS = [ 28 "src/x86/cache/descriptor.c", 29 "src/x86/cache/deterministic.c", 30 "src/x86/cache/init.c", 31 "src/x86/info.c", 32 "src/x86/init.c", 33 "src/x86/isa.c", 34 "src/x86/name.c", 35 "src/x86/topology.c", 36 "src/x86/uarch.c", 37 "src/x86/vendor.c", 38] 39 40ARM_SRCS = [ 41 "src/arm/cache.c", 42 "src/arm/uarch.c", 43] 44 45# Platform-specific sources and headers 46LINUX_SRCS = [ 47 "src/linux/cpulist.c", 48 "src/linux/multiline.c", 49 "src/linux/processors.c", 50 "src/linux/smallfile.c", 51] 52 53MOCK_LINUX_SRCS = [ 54 "src/linux/mockfile.c", 55] 56 57MACH_SRCS = [ 58 "src/mach/topology.c", 59] 60 61EMSCRIPTEN_SRCS = [ 62 "src/emscripten/init.c", 63] 64 65LINUX_X86_SRCS = [ 66 "src/x86/linux/cpuinfo.c", 67 "src/x86/linux/init.c", 68] 69 70LINUX_ARM_SRCS = [ 71 "src/arm/linux/chipset.c", 72 "src/arm/linux/clusters.c", 73 "src/arm/linux/cpuinfo.c", 74 "src/arm/linux/hwcap.c", 75 "src/arm/linux/init.c", 76 "src/arm/linux/midr.c", 77] 78 79LINUX_ARM32_SRCS = LINUX_ARM_SRCS + ["src/arm/linux/aarch32-isa.c"] 80 81LINUX_ARM64_SRCS = LINUX_ARM_SRCS + ["src/arm/linux/aarch64-isa.c"] 82 83ANDROID_ARM_SRCS = [ 84 "src/arm/android/properties.c", 85] 86 87WINDOWS_X86_SRCS = [ 88 "src/x86/windows/init.c", 89] 90 91MACH_X86_SRCS = [ 92 "src/x86/mach/init.c", 93] 94 95MACH_ARM_SRCS = [ 96 "src/arm/mach/init.c", 97] 98 99EMSCRIPTEN_SRCS = [ 100 "src/emscripten/init.c", 101] 102 103cc_library( 104 name = "cpuinfo_impl", 105 srcs = select({ 106 ":linux_x86_64": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS, 107 ":linux_arm": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 108 ":linux_armhf": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 109 ":linux_armv7a": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 110 ":linux_armeabi": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 111 ":linux_aarch64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS, 112 ":linux_mips64": COMMON_SRCS + LINUX_SRCS, 113 ":linux_riscv64": COMMON_SRCS + LINUX_SRCS, 114 ":linux_s390x": COMMON_SRCS + LINUX_SRCS, 115 ":macos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 116 ":macos_arm64": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 117 ":windows_x86_64": COMMON_SRCS + X86_SRCS + WINDOWS_X86_SRCS, 118 ":android_armv7": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS + ANDROID_ARM_SRCS, 119 ":android_arm64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS + ANDROID_ARM_SRCS, 120 ":android_x86": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS, 121 ":android_x86_64": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS, 122 ":ios_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 123 ":ios_x86": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 124 ":ios_armv7": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 125 ":ios_arm64": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 126 ":ios_arm64e": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 127 ":ios_sim_arm64": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 128 ":watchos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 129 ":watchos_x86": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 130 ":watchos_armv7k": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 131 ":watchos_arm64_32": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 132 ":tvos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 133 ":tvos_arm64": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 134 ":emscripten_wasm": COMMON_SRCS + EMSCRIPTEN_SRCS, 135 }), 136 copts = select({ 137 ":windows_x86_64": [], 138 "//conditions:default": C99OPTS, 139 }) + [ 140 "-Iexternal/cpuinfo/include", 141 "-Iexternal/cpuinfo/src", 142 ], 143 includes = [ 144 "include", 145 "src", 146 ], 147 linkstatic = select({ 148 # https://github.com/bazelbuild/bazel/issues/11552 149 ":macos_x86_64": False, 150 "//conditions:default": True, 151 }), 152 # Headers must be in textual_hdrs to allow us to set the standard to C99 153 textual_hdrs = [ 154 "include/cpuinfo.h", 155 "src/linux/api.h", 156 "src/mach/api.h", 157 "src/cpuinfo/common.h", 158 "src/cpuinfo/internal-api.h", 159 "src/cpuinfo/log.h", 160 "src/cpuinfo/utils.h", 161 "src/x86/api.h", 162 "src/x86/cpuid.h", 163 "src/x86/linux/api.h", 164 "src/arm/android/api.h", 165 "src/arm/linux/api.h", 166 "src/arm/linux/cp.h", 167 "src/arm/api.h", 168 "src/arm/midr.h", 169 ], 170 deps = [ 171 "@org_pytorch_cpuinfo//deps/clog", 172 ], 173) 174 175cc_library( 176 name = "cpuinfo", 177 hdrs = [ 178 "include/cpuinfo.h", 179 ], 180 strip_include_prefix = "include", 181 deps = [ 182 ":cpuinfo_impl", 183 ], 184) 185 186cc_library( 187 name = "cpuinfo_with_unstripped_include_path", 188 hdrs = [ 189 "include/cpuinfo.h", 190 ], 191 deps = [ 192 ":cpuinfo_impl", 193 ], 194) 195 196############################# Build configurations ############################# 197 198config_setting( 199 name = "linux_x86_64", 200 values = {"cpu": "k8"}, 201) 202 203config_setting( 204 name = "linux_arm", 205 values = {"cpu": "arm"}, 206) 207 208config_setting( 209 name = "linux_armhf", 210 values = {"cpu": "armhf"}, 211) 212 213config_setting( 214 name = "linux_armv7a", 215 values = {"cpu": "armv7a"}, 216) 217 218config_setting( 219 name = "linux_armeabi", 220 values = {"cpu": "armeabi"}, 221) 222 223config_setting( 224 name = "linux_aarch64", 225 values = {"cpu": "aarch64"}, 226) 227 228config_setting( 229 name = "linux_mips64", 230 values = {"cpu": "mips64"}, 231) 232 233config_setting( 234 name = "linux_riscv64", 235 values = {"cpu": "riscv64"}, 236) 237 238config_setting( 239 name = "linux_s390x", 240 values = {"cpu": "s390x"}, 241) 242 243config_setting( 244 name = "macos_x86_64", 245 values = { 246 "apple_platform_type": "macos", 247 "cpu": "darwin", 248 }, 249) 250 251config_setting( 252 name = "windows_x86_64", 253 values = {"cpu": "x64_windows"}, 254) 255 256config_setting( 257 name = "android_armv7", 258 values = { 259 "crosstool_top": "//external:android/crosstool", 260 "cpu": "armeabi-v7a", 261 }, 262 visibility = ["//visibility:public"], 263) 264 265config_setting( 266 name = "android_arm64", 267 values = { 268 "crosstool_top": "//external:android/crosstool", 269 "cpu": "arm64-v8a", 270 }, 271 visibility = ["//visibility:public"], 272) 273 274config_setting( 275 name = "android_x86", 276 values = { 277 "crosstool_top": "//external:android/crosstool", 278 "cpu": "x86", 279 }, 280 visibility = ["//visibility:public"], 281) 282 283config_setting( 284 name = "android_x86_64", 285 values = { 286 "crosstool_top": "//external:android/crosstool", 287 "cpu": "x86_64", 288 }, 289 visibility = ["//visibility:public"], 290) 291 292config_setting( 293 name = "ios_armv7", 294 values = { 295 "apple_platform_type": "ios", 296 "cpu": "ios_armv7", 297 }, 298) 299 300config_setting( 301 name = "ios_arm64", 302 values = { 303 "apple_platform_type": "ios", 304 "cpu": "ios_arm64", 305 }, 306) 307 308config_setting( 309 name = "ios_arm64e", 310 values = { 311 "apple_platform_type": "ios", 312 "cpu": "ios_arm64e", 313 }, 314) 315 316config_setting( 317 name = "macos_arm64", 318 values = { 319 "apple_platform_type": "macos", 320 "cpu": "darwin_arm64", 321 }, 322) 323 324config_setting( 325 name = "ios_x86", 326 values = { 327 "apple_platform_type": "ios", 328 "cpu": "ios_i386", 329 }, 330) 331 332config_setting( 333 name = "ios_x86_64", 334 values = { 335 "apple_platform_type": "ios", 336 "cpu": "ios_x86_64", 337 }, 338) 339 340config_setting( 341 name = "ios_sim_arm64", 342 values = { 343 "apple_platform_type": "ios", 344 "cpu": "ios_sim_arm64", 345 }, 346) 347 348config_setting( 349 name = "watchos_armv7k", 350 values = { 351 "apple_platform_type": "watchos", 352 "cpu": "watchos_armv7k", 353 }, 354) 355 356config_setting( 357 name = "watchos_arm64_32", 358 values = { 359 "apple_platform_type": "watchos", 360 "cpu": "watchos_arm64_32", 361 }, 362) 363 364config_setting( 365 name = "watchos_x86", 366 values = { 367 "apple_platform_type": "watchos", 368 "cpu": "watchos_i386", 369 }, 370) 371 372config_setting( 373 name = "watchos_x86_64", 374 values = { 375 "apple_platform_type": "watchos", 376 "cpu": "watchos_x86_64", 377 }, 378) 379 380config_setting( 381 name = "tvos_arm64", 382 values = { 383 "apple_platform_type": "tvos", 384 "cpu": "tvos_arm64", 385 }, 386) 387 388config_setting( 389 name = "tvos_x86_64", 390 values = { 391 "apple_platform_type": "tvos", 392 "cpu": "tvos_x86_64", 393 }, 394) 395 396config_setting( 397 name = "emscripten_wasm", 398 values = { 399 "cpu": "wasm", 400 }, 401) 402 403config_setting( 404 name = "emscripten_wasmsimd", 405 values = { 406 "cpu": "wasm", 407 "features": "wasm_simd", 408 }, 409) 410 411config_setting( 412 name = "emscripten_asmjs", 413 values = { 414 "cpu": "asmjs", 415 }, 416) 417