Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 1 | """Build definitions and rules for XNNPACK.""" |
| 2 | |
| 3 | load(":emscripten.bzl", "xnnpack_emscripten_benchmark_linkopts", "xnnpack_emscripten_deps", "xnnpack_emscripten_minimal_linkopts", "xnnpack_emscripten_test_linkopts") |
| 4 | |
| 5 | def xnnpack_visibility(): |
| 6 | """Visibility of :XNNPACK target. |
| 7 | |
| 8 | All other targets have private visibility, and can not have external |
| 9 | dependencies. |
| 10 | """ |
Marat Dukhan | 9d056a4 | 2019-10-03 12:13:35 -0700 | [diff] [blame] | 11 | return ["//visibility:public"] |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 12 | |
| 13 | def xnnpack_min_size_copts(): |
| 14 | """Compiler flags for size-optimized builds.""" |
| 15 | return ["-Os"] |
| 16 | |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 17 | def xnnpack_gcc_std_copts(): |
| 18 | """GCC-like compiler flags to specify language standard for C sources.""" |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 19 | return ["-std=c99"] |
| 20 | |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 21 | def xnnpack_msvc_std_copts(): |
| 22 | """MSVC compiler flags to specify language standard for C sources.""" |
| 23 | return ["/Drestrict="] |
| 24 | |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 25 | def xnnpack_std_cxxopts(): |
| 26 | """Compiler flags to specify language standard for C++ sources.""" |
| 27 | return ["-std=gnu++11"] |
| 28 | |
| 29 | def xnnpack_optional_ruy_copts(): |
| 30 | """Compiler flags to optionally enable Ruy benchmarks.""" |
| 31 | return [] |
| 32 | |
| 33 | def xnnpack_optional_gemmlowp_copts(): |
| 34 | """Compiler flags to optionally enable Gemmlowp benchmarks.""" |
| 35 | return [] |
| 36 | |
| 37 | def xnnpack_optional_tflite_copts(): |
| 38 | """Compiler flags to optionally enable TensorFlow Lite benchmarks.""" |
| 39 | return [] |
| 40 | |
| 41 | def xnnpack_optional_armcl_copts(): |
| 42 | """Compiler flags to optionally enable ARM ComputeLibrary benchmarks.""" |
| 43 | return [] |
| 44 | |
Marat Dukhan | 8d3c693 | 2020-03-06 20:27:27 -0800 | [diff] [blame] | 45 | def xnnpack_optional_dnnl_copts(): |
| 46 | """Compiler flags to optionally enable Intel DNNL benchmarks.""" |
| 47 | return [] |
| 48 | |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 49 | def xnnpack_optional_ruy_deps(): |
| 50 | """Optional Ruy dependencies.""" |
| 51 | return [] |
| 52 | |
| 53 | def xnnpack_optional_gemmlowp_deps(): |
| 54 | """Optional Gemmlowp dependencies.""" |
| 55 | return [] |
| 56 | |
| 57 | def xnnpack_optional_tflite_deps(): |
| 58 | """Optional TensorFlow Lite dependencies.""" |
| 59 | return [] |
| 60 | |
| 61 | def xnnpack_optional_armcl_deps(): |
| 62 | """Optional ARM ComputeLibrary dependencies.""" |
| 63 | return [] |
| 64 | |
Marat Dukhan | 8d3c693 | 2020-03-06 20:27:27 -0800 | [diff] [blame] | 65 | def xnnpack_optional_dnnl_deps(): |
| 66 | """Optional Intel DNNL dependencies.""" |
| 67 | return [] |
| 68 | |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 69 | def xnnpack_cc_library( |
| 70 | name, |
| 71 | srcs = [], |
| 72 | x86_srcs = [], |
| 73 | aarch32_srcs = [], |
| 74 | aarch64_srcs = [], |
Marat Dukhan | 0ad4737 | 2022-01-04 16:05:25 -0800 | [diff] [blame] | 75 | riscv_srcs = [], |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 76 | wasm_srcs = [], |
| 77 | wasmsimd_srcs = [], |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 78 | wasmrelaxedsimd_srcs = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 79 | copts = [], |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 80 | gcc_copts = [], |
| 81 | msvc_copts = [], |
| 82 | mingw_copts = [], |
| 83 | msys_copts = [], |
| 84 | gcc_x86_copts = [], |
| 85 | msvc_x86_32_copts = [], |
| 86 | msvc_x86_64_copts = [], |
Marat Dukhan | bc69ed6 | 2020-06-09 21:34:56 -0700 | [diff] [blame] | 87 | apple_aarch32_copts = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 88 | aarch32_copts = [], |
| 89 | aarch64_copts = [], |
Marat Dukhan | 0ad4737 | 2022-01-04 16:05:25 -0800 | [diff] [blame] | 90 | riscv_copts = [], |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 91 | wasm_copts = [], |
| 92 | wasmsimd_copts = [], |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 93 | wasmrelaxedsimd_copts = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 94 | optimized_copts = ["-O2"], |
| 95 | hdrs = [], |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 96 | defines = [], |
| 97 | includes = [], |
| 98 | deps = [], |
Zhi An Ng | d90af6f | 2022-01-10 14:36:26 -0800 | [diff] [blame] | 99 | visibility = [], |
| 100 | testonly = False): |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 101 | """C/C++/assembly library with architecture-specific configuration. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 102 | |
| 103 | Define a static library with architecture- and instruction-specific |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 104 | source files and/or compiler flags. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 105 | |
| 106 | Args: |
| 107 | name: The name of the library target to define. |
| 108 | srcs: The list of architecture-independent source files. |
| 109 | x86_srcs: The list of x86-specific source files. |
| 110 | aarch32_srcs: The list of AArch32-specific source files. |
| 111 | aarch64_srcs: The list of AArch64-specific source files. |
Marat Dukhan | 0ad4737 | 2022-01-04 16:05:25 -0800 | [diff] [blame] | 112 | riscv_srcs: The list of RISC-V-specific source files. |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 113 | wasm_srcs: The list of WebAssembly 1.0-specific source files. |
| 114 | wasmsimd_srcs: The list of WebAssembly SIMD-specific source files. |
| 115 | wasmrelaxedsimd_srcs: The list of WebAssembly Relaxed SIMD-specific |
| 116 | source files. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 117 | copts: The list of compiler flags to use in all builds. -I flags for |
| 118 | include/ and src/ directories of XNNPACK are always prepended |
| 119 | before these user-specified flags. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 120 | gcc_copts: The list of compiler flags to use with GCC-like compilers. |
| 121 | msvc_copts: The list of compiler flags to use with MSVC compiler. |
| 122 | mingw_copts: The list of compiler flags to use with MinGW GCC compilers. |
Marat Dukhan | bc69ed6 | 2020-06-09 21:34:56 -0700 | [diff] [blame] | 123 | msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC |
| 124 | compilers. |
| 125 | gcc_x86_copts: The list of GCC-like compiler flags to use in x86 (32-bit |
| 126 | and 64-bit) builds. |
| 127 | msvc_x86_32_copts: The list of MSVC compiler flags to use in x86 (32-bit) |
| 128 | builds. |
| 129 | msvc_x86_64_copts: The list of MSVC compiler flags to use in x86 (64-bit) |
| 130 | builds. |
| 131 | apple_aarch32_copts: The list of compiler flags to use in AArch32 builds |
| 132 | with Apple Clang. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 133 | aarch32_copts: The list of compiler flags to use in AArch32 builds. |
| 134 | aarch64_copts: The list of compiler flags to use in AArch64 builds. |
Marat Dukhan | 0ad4737 | 2022-01-04 16:05:25 -0800 | [diff] [blame] | 135 | riscv_copts: The list of compiler flags to use in RISC-V builds. |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 136 | wasm_copts: The list of compiler flags to use in WebAssembly 1.0 builds. |
| 137 | wasmsimd_copts: The list of compiler flags to use in WebAssembly SIMD |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 138 | builds. |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 139 | wasmrelaxedsimd_copts: The list of compiler flags to use in WebAssembly |
| 140 | Relaxed SIMD builds. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 141 | optimized_copts: The list of compiler flags to use in optimized builds. |
| 142 | Defaults to -O2. |
| 143 | hdrs: The list of header files published by this library to be textually |
| 144 | included by sources in dependent rules. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 145 | defines: List of predefines macros to be added to the compile line. |
| 146 | includes: List of include dirs to be added to the compile line. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 147 | deps: The list of other libraries to be linked. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 148 | visibility: The list of packages that can depend on this target. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 149 | """ |
| 150 | native.cc_library( |
| 151 | name = name, |
| 152 | srcs = srcs + select({ |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 153 | ":linux_k8": x86_srcs, |
| 154 | ":linux_arm": aarch32_srcs, |
| 155 | ":linux_armeabi": aarch32_srcs, |
| 156 | ":linux_armhf": aarch32_srcs, |
| 157 | ":linux_armv7a": aarch32_srcs, |
Marat Dukhan | 52e4443 | 2021-08-20 11:58:11 -0700 | [diff] [blame] | 158 | ":linux_arm64": aarch64_srcs, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 159 | ":macos_x86_64": x86_srcs, |
Simon Maurer | 3b403c2 | 2021-03-03 14:24:02 +0100 | [diff] [blame] | 160 | ":macos_arm64": aarch64_srcs, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 161 | ":windows_x86_64_clang": x86_srcs, |
| 162 | ":windows_x86_64_mingw": x86_srcs, |
| 163 | ":windows_x86_64_msys": x86_srcs, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 164 | ":windows_x86_64": x86_srcs, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 165 | ":android_armv7": aarch32_srcs, |
| 166 | ":android_arm64": aarch64_srcs, |
| 167 | ":android_x86": x86_srcs, |
| 168 | ":android_x86_64": x86_srcs, |
| 169 | ":ios_armv7": aarch32_srcs, |
| 170 | ":ios_arm64": aarch64_srcs, |
| 171 | ":ios_arm64e": aarch64_srcs, |
| 172 | ":ios_x86": x86_srcs, |
| 173 | ":ios_x86_64": x86_srcs, |
| 174 | ":watchos_armv7k": aarch32_srcs, |
| 175 | ":watchos_arm64_32": aarch64_srcs, |
| 176 | ":watchos_x86": x86_srcs, |
| 177 | ":watchos_x86_64": x86_srcs, |
| 178 | ":tvos_arm64": aarch64_srcs, |
| 179 | ":tvos_x86_64": x86_srcs, |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 180 | ":emscripten_wasm": wasm_srcs, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 181 | ":emscripten_wasmsimd": wasmsimd_srcs, |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 182 | ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_srcs, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 183 | "//conditions:default": [], |
| 184 | }), |
| 185 | copts = [ |
| 186 | "-Iinclude", |
| 187 | "-Isrc", |
| 188 | ] + copts + select({ |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 189 | ":linux_k8": gcc_x86_copts, |
Marat Dukhan | 582094e | 2020-04-30 17:21:25 -0700 | [diff] [blame] | 190 | ":linux_arm": aarch32_copts, |
Marat Dukhan | f0bd4de | 2020-06-15 15:53:19 -0700 | [diff] [blame] | 191 | ":linux_armeabi": aarch32_copts, |
Terry Heo | 68eef3f | 2020-04-13 22:53:52 -0700 | [diff] [blame] | 192 | ":linux_armhf": aarch32_copts, |
Marat Dukhan | 2456789 | 2020-06-10 13:15:48 -0700 | [diff] [blame] | 193 | ":linux_armv7a": aarch32_copts, |
Marat Dukhan | 52e4443 | 2021-08-20 11:58:11 -0700 | [diff] [blame] | 194 | ":linux_arm64": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 195 | ":macos_x86_64": gcc_x86_copts, |
Simon Maurer | 3b403c2 | 2021-03-03 14:24:02 +0100 | [diff] [blame] | 196 | ":macos_arm64": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 197 | ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_x86_copts], |
| 198 | ":windows_x86_64_mingw": mingw_copts + gcc_x86_copts, |
| 199 | ":windows_x86_64_msys": msys_copts + gcc_x86_copts, |
| 200 | ":windows_x86_64": msvc_x86_64_copts, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 201 | ":android_armv7": aarch32_copts, |
| 202 | ":android_arm64": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 203 | ":android_x86": gcc_x86_copts, |
| 204 | ":android_x86_64": gcc_x86_copts, |
Marat Dukhan | bc69ed6 | 2020-06-09 21:34:56 -0700 | [diff] [blame] | 205 | ":ios_armv7": apple_aarch32_copts, |
Marat Dukhan | 1498d1d | 2020-02-11 20:00:05 -0800 | [diff] [blame] | 206 | ":ios_arm64": aarch64_copts, |
| 207 | ":ios_arm64e": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 208 | ":ios_x86": gcc_x86_copts, |
| 209 | ":ios_x86_64": gcc_x86_copts, |
Marat Dukhan | bc69ed6 | 2020-06-09 21:34:56 -0700 | [diff] [blame] | 210 | ":watchos_armv7k": apple_aarch32_copts, |
Marat Dukhan | 1498d1d | 2020-02-11 20:00:05 -0800 | [diff] [blame] | 211 | ":watchos_arm64_32": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 212 | ":watchos_x86": gcc_x86_copts, |
| 213 | ":watchos_x86_64": gcc_x86_copts, |
Marat Dukhan | 1498d1d | 2020-02-11 20:00:05 -0800 | [diff] [blame] | 214 | ":tvos_arm64": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 215 | ":tvos_x86_64": gcc_x86_copts, |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 216 | ":emscripten_wasm": wasm_copts, |
| 217 | ":emscripten_wasmsimd": wasmsimd_copts, |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 218 | ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_copts, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 219 | "//conditions:default": [], |
| 220 | }) + select({ |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 221 | ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts], |
| 222 | ":windows_x86_64_mingw": gcc_copts, |
| 223 | ":windows_x86_64_msys": gcc_copts, |
| 224 | ":windows_x86_64": msvc_copts, |
| 225 | "//conditions:default": gcc_copts, |
| 226 | }) + select({ |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 227 | ":optimized_build": optimized_copts, |
| 228 | "//conditions:default": [], |
| 229 | }), |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 230 | defines = defines, |
| 231 | deps = deps, |
| 232 | includes = ["include", "src"] + includes, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 233 | linkstatic = True, |
| 234 | linkopts = select({ |
| 235 | ":linux_k8": ["-lpthread"], |
Marat Dukhan | 582094e | 2020-04-30 17:21:25 -0700 | [diff] [blame] | 236 | ":linux_arm": ["-lpthread"], |
Marat Dukhan | f0bd4de | 2020-06-15 15:53:19 -0700 | [diff] [blame] | 237 | ":linux_armeabi": ["-lpthread"], |
Terry Heo | 68eef3f | 2020-04-13 22:53:52 -0700 | [diff] [blame] | 238 | ":linux_armhf": ["-lpthread"], |
Marat Dukhan | 2456789 | 2020-06-10 13:15:48 -0700 | [diff] [blame] | 239 | ":linux_armv7a": ["-lpthread"], |
Marat Dukhan | 52e4443 | 2021-08-20 11:58:11 -0700 | [diff] [blame] | 240 | ":linux_arm64": ["-lpthread"], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 241 | ":android": ["-lm"], |
| 242 | "//conditions:default": [], |
| 243 | }), |
| 244 | textual_hdrs = hdrs, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 245 | visibility = visibility, |
Zhi An Ng | d90af6f | 2022-01-10 14:36:26 -0800 | [diff] [blame] | 246 | testonly = testonly, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 247 | ) |
| 248 | |
| 249 | def xnnpack_aggregate_library( |
| 250 | name, |
| 251 | generic_deps = [], |
| 252 | x86_deps = [], |
Marat Dukhan | 6e8c0ce | 2021-04-13 14:35:08 -0700 | [diff] [blame] | 253 | aarch32_ios_deps = [], |
| 254 | aarch32_nonios_deps = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 255 | aarch64_deps = [], |
Marat Dukhan | 0ad4737 | 2022-01-04 16:05:25 -0800 | [diff] [blame] | 256 | riscv_deps = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 257 | wasm_deps = [], |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 258 | wasmsimd_deps = [], |
| 259 | wasmrelaxedsimd_deps = []): |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 260 | """Static library that aggregates architecture-specific dependencies. |
| 261 | |
| 262 | Args: |
| 263 | name: The name of the library target to define. |
| 264 | generic_deps: The list of libraries to link on all architectures. |
| 265 | x86_deps: The list of libraries to link in x86 and x86-64 builds. |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 266 | aarch32_ios_deps: The list of libraries to link in AArch32 iOS (incl |
| 267 | WatchOS) builds. |
| 268 | aarch32_nonios_deps: The list of libraries to link in AArch32 non-iOS |
| 269 | builds. |
Marat Dukhan | 0ad4737 | 2022-01-04 16:05:25 -0800 | [diff] [blame] | 270 | aarch64_deps: The list of libraries to link in AArch64 builds. |
| 271 | riscv_deps: The list of libraries to link in RISC-V builds. |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 272 | wasm_deps: The list of libraries to link in WebAssembly 1.0 builds. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 273 | wasmsimd_deps: The list of libraries to link in WebAssembly SIMD builds. |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 274 | wasmrelaxedsimd_deps: The list of libraries to link in WebAssembly |
| 275 | Relaxed SIMD builds. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 276 | """ |
| 277 | |
| 278 | native.cc_library( |
| 279 | name = name, |
| 280 | linkstatic = True, |
| 281 | deps = generic_deps + select({ |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 282 | ":linux_k8": x86_deps, |
Marat Dukhan | 6e8c0ce | 2021-04-13 14:35:08 -0700 | [diff] [blame] | 283 | ":linux_arm": aarch32_nonios_deps, |
| 284 | ":linux_armeabi": aarch32_nonios_deps, |
| 285 | ":linux_armhf": aarch32_nonios_deps, |
| 286 | ":linux_armv7a": aarch32_nonios_deps, |
Marat Dukhan | 52e4443 | 2021-08-20 11:58:11 -0700 | [diff] [blame] | 287 | ":linux_arm64": aarch64_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 288 | ":macos_x86_64": x86_deps, |
Simon Maurer | 3b403c2 | 2021-03-03 14:24:02 +0100 | [diff] [blame] | 289 | ":macos_arm64": aarch64_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 290 | ":windows_x86_64_clang": x86_deps, |
| 291 | ":windows_x86_64_mingw": x86_deps, |
| 292 | ":windows_x86_64_msys": x86_deps, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 293 | ":windows_x86_64": x86_deps, |
Marat Dukhan | 6e8c0ce | 2021-04-13 14:35:08 -0700 | [diff] [blame] | 294 | ":android_armv7": aarch32_nonios_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 295 | ":android_arm64": aarch64_deps, |
| 296 | ":android_x86": x86_deps, |
| 297 | ":android_x86_64": x86_deps, |
Marat Dukhan | 6e8c0ce | 2021-04-13 14:35:08 -0700 | [diff] [blame] | 298 | ":ios_armv7": aarch32_ios_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 299 | ":ios_arm64": aarch64_deps, |
| 300 | ":ios_arm64e": aarch64_deps, |
| 301 | ":ios_x86": x86_deps, |
| 302 | ":ios_x86_64": x86_deps, |
Marat Dukhan | 6e8c0ce | 2021-04-13 14:35:08 -0700 | [diff] [blame] | 303 | ":watchos_armv7k": aarch32_ios_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 304 | ":watchos_arm64_32": aarch64_deps, |
| 305 | ":watchos_x86": x86_deps, |
| 306 | ":watchos_x86_64": x86_deps, |
| 307 | ":tvos_arm64": aarch64_deps, |
| 308 | ":tvos_x86_64": x86_deps, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 309 | ":emscripten_wasm": wasm_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame] | 310 | ":emscripten_wasmsimd": wasmsimd_deps, |
Marat Dukhan | 19bfefe | 2021-12-21 19:16:06 -0800 | [diff] [blame] | 311 | ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_deps, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 312 | }), |
| 313 | ) |
| 314 | |
Alan Kelly | 6621058 | 2021-11-23 00:57:36 -0800 | [diff] [blame] | 315 | def xnnpack_unit_test(name, srcs, copts = [], mingw_copts = [], msys_copts = [], deps = [], tags = [], automatic = True, timeout = "short", shard_count = 1): |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 316 | """Unit test binary based on Google Test. |
| 317 | |
| 318 | Args: |
| 319 | name: The name of the test target to define. |
| 320 | srcs: The list of source and header files. |
| 321 | copts: The list of additional compiler flags for the target. -I flags |
| 322 | for include/ and src/ directories of XNNPACK are always prepended |
| 323 | before these user-specified flags. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 324 | mingw_copts: The list of compiler flags to use with MinGW GCC compilers. |
| 325 | msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC compilers. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 326 | deps: The list of additional libraries to be linked. Google Test library |
| 327 | (with main() function) is always added as a dependency and does not |
| 328 | need to be explicitly specified. |
Artsiom Ablavatski | c1aa297 | 2020-12-08 11:23:34 -0800 | [diff] [blame] | 329 | tags: List of arbitrary text tags. |
| 330 | automatic: Whether to create the test or testable binary. |
| 331 | timeout: How long the test is expected to run before returning. |
Alan Kelly | 6621058 | 2021-11-23 00:57:36 -0800 | [diff] [blame] | 332 | shard_count: Specifies the number of parallel shards to use to run the test. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 333 | """ |
| 334 | |
Marat Dukhan | 22eed3d | 2020-05-11 20:13:37 -0700 | [diff] [blame] | 335 | if automatic: |
| 336 | native.cc_test( |
| 337 | name = name, |
| 338 | srcs = srcs, |
| 339 | copts = xnnpack_std_cxxopts() + [ |
| 340 | "-Iinclude", |
| 341 | "-Isrc", |
| 342 | ] + select({ |
| 343 | ":windows_x86_64_mingw": mingw_copts, |
| 344 | ":windows_x86_64_msys": msys_copts, |
| 345 | "//conditions:default": [], |
| 346 | }) + select({ |
| 347 | ":windows_x86_64_clang": ["/clang:-Wno-unused-function"], |
| 348 | ":windows_x86_64_mingw": ["-Wno-unused-function"], |
| 349 | ":windows_x86_64_msys": ["-Wno-unused-function"], |
| 350 | ":windows_x86_64": [], |
| 351 | "//conditions:default": ["-Wno-unused-function"], |
| 352 | }) + copts, |
| 353 | linkopts = select({ |
| 354 | ":emscripten": xnnpack_emscripten_test_linkopts(), |
| 355 | "//conditions:default": [], |
| 356 | }), |
| 357 | linkstatic = True, |
| 358 | deps = [ |
| 359 | "@com_google_googletest//:gtest_main", |
| 360 | ] + deps + select({ |
| 361 | ":emscripten": xnnpack_emscripten_deps(), |
| 362 | "//conditions:default": [], |
| 363 | }), |
| 364 | tags = tags, |
Artsiom Ablavatski | c1aa297 | 2020-12-08 11:23:34 -0800 | [diff] [blame] | 365 | timeout = timeout, |
Alan Kelly | 6621058 | 2021-11-23 00:57:36 -0800 | [diff] [blame] | 366 | shard_count = shard_count, |
Marat Dukhan | 22eed3d | 2020-05-11 20:13:37 -0700 | [diff] [blame] | 367 | ) |
| 368 | else: |
| 369 | native.cc_binary( |
| 370 | name = name, |
| 371 | srcs = srcs, |
| 372 | copts = xnnpack_std_cxxopts() + [ |
| 373 | "-Iinclude", |
| 374 | "-Isrc", |
| 375 | ] + select({ |
| 376 | ":windows_x86_64_mingw": mingw_copts, |
| 377 | ":windows_x86_64_msys": msys_copts, |
| 378 | "//conditions:default": [], |
| 379 | }) + select({ |
| 380 | ":windows_x86_64_clang": ["/clang:-Wno-unused-function"], |
| 381 | ":windows_x86_64_mingw": ["-Wno-unused-function"], |
| 382 | ":windows_x86_64_msys": ["-Wno-unused-function"], |
| 383 | ":windows_x86_64": [], |
| 384 | "//conditions:default": ["-Wno-unused-function"], |
| 385 | }) + copts, |
| 386 | linkopts = select({ |
| 387 | ":emscripten": xnnpack_emscripten_test_linkopts(), |
| 388 | "//conditions:default": [], |
| 389 | }), |
| 390 | linkstatic = True, |
| 391 | deps = [ |
| 392 | "@com_google_googletest//:gtest_main", |
| 393 | ] + deps + select({ |
| 394 | ":emscripten": xnnpack_emscripten_deps(), |
| 395 | "//conditions:default": [], |
| 396 | }), |
| 397 | testonly = True, |
| 398 | tags = tags, |
| 399 | ) |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 400 | |
| 401 | def xnnpack_binary(name, srcs, copts = [], deps = []): |
| 402 | """Minimal binary |
| 403 | |
| 404 | Args: |
| 405 | name: The name of the binary target to define. |
| 406 | srcs: The list of source and header files. |
| 407 | copts: The list of additional compiler flags for the target. -I flags |
| 408 | for include/ and src/ directories of XNNPACK are always prepended |
| 409 | before these user-specified flags. |
| 410 | deps: The list of libraries to be linked. |
| 411 | """ |
| 412 | native.cc_binary( |
| 413 | name = name, |
| 414 | srcs = srcs, |
| 415 | copts = [ |
| 416 | "-Iinclude", |
| 417 | "-Isrc", |
| 418 | ] + copts, |
| 419 | linkopts = select({ |
| 420 | ":emscripten": xnnpack_emscripten_minimal_linkopts(), |
| 421 | "//conditions:default": [], |
| 422 | }), |
| 423 | linkstatic = True, |
| 424 | deps = deps, |
| 425 | ) |
| 426 | |
Marat Dukhan | a98efa1 | 2020-05-04 17:07:49 -0700 | [diff] [blame] | 427 | def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []): |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 428 | """Microbenchmark binary based on Google Benchmark |
| 429 | |
| 430 | Args: |
| 431 | name: The name of the binary target to define. |
| 432 | srcs: The list of source and header files. |
| 433 | copts: The list of additional compiler flags for the target. -I flags |
| 434 | for include/ and src/ directories of XNNPACK are always prepended |
| 435 | before these user-specified flags. |
| 436 | deps: The list of additional libraries to be linked. Google Benchmark |
| 437 | library is always added as a dependency and does not need to be |
| 438 | explicitly specified. |
| 439 | """ |
| 440 | native.cc_binary( |
| 441 | name = name, |
| 442 | srcs = srcs, |
| 443 | copts = xnnpack_std_cxxopts() + [ |
| 444 | "-Iinclude", |
| 445 | "-Isrc", |
Marat Dukhan | a98efa1 | 2020-05-04 17:07:49 -0700 | [diff] [blame] | 446 | ] + select({ |
| 447 | ":windows_x86_64_clang": ["/clang:-Wno-unused-function"], |
| 448 | ":windows_x86_64_mingw": ["-Wno-unused-function"], |
| 449 | ":windows_x86_64_msys": ["-Wno-unused-function"], |
| 450 | ":windows_x86_64": [], |
| 451 | "//conditions:default": ["-Wno-unused-function"], |
| 452 | }) + copts, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 453 | linkopts = select({ |
| 454 | ":emscripten": xnnpack_emscripten_benchmark_linkopts(), |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 455 | ":windows_x86_64_mingw": ["-lshlwapi"], |
| 456 | ":windows_x86_64_msys": ["-lshlwapi"], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 457 | "//conditions:default": [], |
| 458 | }), |
| 459 | linkstatic = True, |
| 460 | deps = [ |
| 461 | "@com_google_benchmark//:benchmark", |
| 462 | ] + deps + select({ |
| 463 | ":emscripten": xnnpack_emscripten_deps(), |
| 464 | "//conditions:default": [], |
| 465 | }), |
Marat Dukhan | 8ea0b07 | 2020-04-23 16:12:18 -0700 | [diff] [blame] | 466 | tags = tags, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 467 | ) |