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 | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 75 | wasm_srcs = [], |
| 76 | wasmsimd_srcs = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 77 | copts = [], |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 78 | gcc_copts = [], |
| 79 | msvc_copts = [], |
| 80 | mingw_copts = [], |
| 81 | msys_copts = [], |
| 82 | gcc_x86_copts = [], |
| 83 | msvc_x86_32_copts = [], |
| 84 | msvc_x86_64_copts = [], |
Marat Dukhan | bc69ed6 | 2020-06-09 21:34:56 -0700 | [diff] [blame] | 85 | apple_aarch32_copts = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 86 | aarch32_copts = [], |
| 87 | aarch64_copts = [], |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 88 | wasm_copts = [], |
| 89 | wasmsimd_copts = [], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 90 | optimized_copts = ["-O2"], |
| 91 | hdrs = [], |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 92 | defines = [], |
| 93 | includes = [], |
| 94 | deps = [], |
| 95 | visibility = []): |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 96 | """C/C++/assembly library with architecture-specific configuration. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 97 | |
| 98 | Define a static library with architecture- and instruction-specific |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 99 | source files and/or compiler flags. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 100 | |
| 101 | Args: |
| 102 | name: The name of the library target to define. |
| 103 | srcs: The list of architecture-independent source files. |
| 104 | x86_srcs: The list of x86-specific source files. |
| 105 | aarch32_srcs: The list of AArch32-specific source files. |
| 106 | aarch64_srcs: The list of AArch64-specific source files. |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 107 | wasm_srcs: The list of WebAssembly/MVP-specific source files. |
| 108 | wasmsimd_srcs: The list of WebAssembly/SIMD-specific source files. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 109 | copts: The list of compiler flags to use in all builds. -I flags for |
| 110 | include/ and src/ directories of XNNPACK are always prepended |
| 111 | before these user-specified flags. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 112 | gcc_copts: The list of compiler flags to use with GCC-like compilers. |
| 113 | msvc_copts: The list of compiler flags to use with MSVC compiler. |
| 114 | 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] | 115 | msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC |
| 116 | compilers. |
| 117 | gcc_x86_copts: The list of GCC-like compiler flags to use in x86 (32-bit |
| 118 | and 64-bit) builds. |
| 119 | msvc_x86_32_copts: The list of MSVC compiler flags to use in x86 (32-bit) |
| 120 | builds. |
| 121 | msvc_x86_64_copts: The list of MSVC compiler flags to use in x86 (64-bit) |
| 122 | builds. |
| 123 | apple_aarch32_copts: The list of compiler flags to use in AArch32 builds |
| 124 | with Apple Clang. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 125 | aarch32_copts: The list of compiler flags to use in AArch32 builds. |
| 126 | aarch64_copts: The list of compiler flags to use in AArch64 builds. |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 127 | wasm_copts: The list of compiler flags to use in WebAssembly/MVP builds. |
| 128 | wasmsimd_copts: The list of compiler flags to use in WebAssembly/SIMD |
| 129 | builds. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 130 | optimized_copts: The list of compiler flags to use in optimized builds. |
| 131 | Defaults to -O2. |
| 132 | hdrs: The list of header files published by this library to be textually |
| 133 | included by sources in dependent rules. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 134 | defines: List of predefines macros to be added to the compile line. |
| 135 | includes: List of include dirs to be added to the compile line. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 136 | deps: The list of other libraries to be linked. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 137 | visibility: The list of packages that can depend on this target. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 138 | """ |
| 139 | native.cc_library( |
| 140 | name = name, |
| 141 | srcs = srcs + select({ |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame^] | 142 | ":linux_k8": x86_srcs, |
| 143 | ":linux_arm": aarch32_srcs, |
| 144 | ":linux_armeabi": aarch32_srcs, |
| 145 | ":linux_armhf": aarch32_srcs, |
| 146 | ":linux_armv7a": aarch32_srcs, |
| 147 | ":linux_aarch64": aarch64_srcs, |
| 148 | ":macos_x86_64": x86_srcs, |
| 149 | ":windows_x86_64_clang": x86_srcs, |
| 150 | ":windows_x86_64_mingw": x86_srcs, |
| 151 | ":windows_x86_64_msys": x86_srcs, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 152 | ":windows_x86_64": x86_srcs, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame^] | 153 | ":android_armv7": aarch32_srcs, |
| 154 | ":android_arm64": aarch64_srcs, |
| 155 | ":android_x86": x86_srcs, |
| 156 | ":android_x86_64": x86_srcs, |
| 157 | ":ios_armv7": aarch32_srcs, |
| 158 | ":ios_arm64": aarch64_srcs, |
| 159 | ":ios_arm64e": aarch64_srcs, |
| 160 | ":ios_x86": x86_srcs, |
| 161 | ":ios_x86_64": x86_srcs, |
| 162 | ":watchos_armv7k": aarch32_srcs, |
| 163 | ":watchos_arm64_32": aarch64_srcs, |
| 164 | ":watchos_x86": x86_srcs, |
| 165 | ":watchos_x86_64": x86_srcs, |
| 166 | ":tvos_arm64": aarch64_srcs, |
| 167 | ":tvos_x86_64": x86_srcs, |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 168 | ":emscripten_wasm": wasm_srcs, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame^] | 169 | ":emscripten_wasmsimd": wasmsimd_srcs, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 170 | "//conditions:default": [], |
| 171 | }), |
| 172 | copts = [ |
| 173 | "-Iinclude", |
| 174 | "-Isrc", |
| 175 | ] + copts + select({ |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 176 | ":linux_k8": gcc_x86_copts, |
Marat Dukhan | 582094e | 2020-04-30 17:21:25 -0700 | [diff] [blame] | 177 | ":linux_arm": aarch32_copts, |
Marat Dukhan | f0bd4de | 2020-06-15 15:53:19 -0700 | [diff] [blame] | 178 | ":linux_armeabi": aarch32_copts, |
Terry Heo | 68eef3f | 2020-04-13 22:53:52 -0700 | [diff] [blame] | 179 | ":linux_armhf": aarch32_copts, |
Marat Dukhan | 2456789 | 2020-06-10 13:15:48 -0700 | [diff] [blame] | 180 | ":linux_armv7a": aarch32_copts, |
Marat Dukhan | 582094e | 2020-04-30 17:21:25 -0700 | [diff] [blame] | 181 | ":linux_aarch64": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 182 | ":macos_x86_64": gcc_x86_copts, |
| 183 | ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_x86_copts], |
| 184 | ":windows_x86_64_mingw": mingw_copts + gcc_x86_copts, |
| 185 | ":windows_x86_64_msys": msys_copts + gcc_x86_copts, |
| 186 | ":windows_x86_64": msvc_x86_64_copts, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 187 | ":android_armv7": aarch32_copts, |
| 188 | ":android_arm64": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 189 | ":android_x86": gcc_x86_copts, |
| 190 | ":android_x86_64": gcc_x86_copts, |
Marat Dukhan | bc69ed6 | 2020-06-09 21:34:56 -0700 | [diff] [blame] | 191 | ":ios_armv7": apple_aarch32_copts, |
Marat Dukhan | 1498d1d | 2020-02-11 20:00:05 -0800 | [diff] [blame] | 192 | ":ios_arm64": aarch64_copts, |
| 193 | ":ios_arm64e": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 194 | ":ios_x86": gcc_x86_copts, |
| 195 | ":ios_x86_64": gcc_x86_copts, |
Marat Dukhan | bc69ed6 | 2020-06-09 21:34:56 -0700 | [diff] [blame] | 196 | ":watchos_armv7k": apple_aarch32_copts, |
Marat Dukhan | 1498d1d | 2020-02-11 20:00:05 -0800 | [diff] [blame] | 197 | ":watchos_arm64_32": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 198 | ":watchos_x86": gcc_x86_copts, |
| 199 | ":watchos_x86_64": gcc_x86_copts, |
Marat Dukhan | 1498d1d | 2020-02-11 20:00:05 -0800 | [diff] [blame] | 200 | ":tvos_arm64": aarch64_copts, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 201 | ":tvos_x86_64": gcc_x86_copts, |
Marat Dukhan | cf056b2 | 2019-10-07 10:26:29 -0700 | [diff] [blame] | 202 | ":emscripten_wasm": wasm_copts, |
| 203 | ":emscripten_wasmsimd": wasmsimd_copts, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 204 | "//conditions:default": [], |
| 205 | }) + select({ |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 206 | ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts], |
| 207 | ":windows_x86_64_mingw": gcc_copts, |
| 208 | ":windows_x86_64_msys": gcc_copts, |
| 209 | ":windows_x86_64": msvc_copts, |
| 210 | "//conditions:default": gcc_copts, |
| 211 | }) + select({ |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 212 | ":optimized_build": optimized_copts, |
| 213 | "//conditions:default": [], |
| 214 | }), |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 215 | defines = defines, |
| 216 | deps = deps, |
| 217 | includes = ["include", "src"] + includes, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 218 | linkstatic = True, |
| 219 | linkopts = select({ |
| 220 | ":linux_k8": ["-lpthread"], |
Marat Dukhan | 582094e | 2020-04-30 17:21:25 -0700 | [diff] [blame] | 221 | ":linux_arm": ["-lpthread"], |
Marat Dukhan | f0bd4de | 2020-06-15 15:53:19 -0700 | [diff] [blame] | 222 | ":linux_armeabi": ["-lpthread"], |
Terry Heo | 68eef3f | 2020-04-13 22:53:52 -0700 | [diff] [blame] | 223 | ":linux_armhf": ["-lpthread"], |
Marat Dukhan | 2456789 | 2020-06-10 13:15:48 -0700 | [diff] [blame] | 224 | ":linux_armv7a": ["-lpthread"], |
Marat Dukhan | 582094e | 2020-04-30 17:21:25 -0700 | [diff] [blame] | 225 | ":linux_aarch64": ["-lpthread"], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 226 | ":android": ["-lm"], |
| 227 | "//conditions:default": [], |
| 228 | }), |
| 229 | textual_hdrs = hdrs, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 230 | visibility = visibility, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 231 | ) |
| 232 | |
| 233 | def xnnpack_aggregate_library( |
| 234 | name, |
| 235 | generic_deps = [], |
| 236 | x86_deps = [], |
| 237 | aarch32_deps = [], |
| 238 | aarch64_deps = [], |
| 239 | wasm_deps = [], |
| 240 | wasmsimd_deps = []): |
| 241 | """Static library that aggregates architecture-specific dependencies. |
| 242 | |
| 243 | Args: |
| 244 | name: The name of the library target to define. |
| 245 | generic_deps: The list of libraries to link on all architectures. |
| 246 | x86_deps: The list of libraries to link in x86 and x86-64 builds. |
| 247 | aarch32_deps: The list of libraries to link in AArch32 builds. |
| 248 | aarch64_deps: The list of libraries to link in AArch32 builds. |
| 249 | wasm_deps: The list of libraries to link in WebAssembly (MVP) builds. |
| 250 | wasmsimd_deps: The list of libraries to link in WebAssembly SIMD builds. |
| 251 | """ |
| 252 | |
| 253 | native.cc_library( |
| 254 | name = name, |
| 255 | linkstatic = True, |
| 256 | deps = generic_deps + select({ |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame^] | 257 | ":linux_k8": x86_deps, |
| 258 | ":linux_arm": aarch32_deps, |
| 259 | ":linux_armeabi": aarch32_deps, |
| 260 | ":linux_armhf": aarch32_deps, |
| 261 | ":linux_armv7a": aarch32_deps, |
| 262 | ":linux_aarch64": aarch64_deps, |
| 263 | ":macos_x86_64": x86_deps, |
| 264 | ":windows_x86_64_clang": x86_deps, |
| 265 | ":windows_x86_64_mingw": x86_deps, |
| 266 | ":windows_x86_64_msys": x86_deps, |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 267 | ":windows_x86_64": x86_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame^] | 268 | ":android_armv7": aarch32_deps, |
| 269 | ":android_arm64": aarch64_deps, |
| 270 | ":android_x86": x86_deps, |
| 271 | ":android_x86_64": x86_deps, |
| 272 | ":ios_armv7": aarch32_deps, |
| 273 | ":ios_arm64": aarch64_deps, |
| 274 | ":ios_arm64e": aarch64_deps, |
| 275 | ":ios_x86": x86_deps, |
| 276 | ":ios_x86_64": x86_deps, |
| 277 | ":watchos_armv7k": aarch32_deps, |
| 278 | ":watchos_arm64_32": aarch64_deps, |
| 279 | ":watchos_x86": x86_deps, |
| 280 | ":watchos_x86_64": x86_deps, |
| 281 | ":tvos_arm64": aarch64_deps, |
| 282 | ":tvos_x86_64": x86_deps, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 283 | ":emscripten_wasm": wasm_deps, |
Marat Dukhan | 3de5dfa | 2020-12-10 11:19:47 -0800 | [diff] [blame^] | 284 | ":emscripten_wasmsimd": wasmsimd_deps, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 285 | }), |
| 286 | ) |
| 287 | |
Artsiom Ablavatski | c1aa297 | 2020-12-08 11:23:34 -0800 | [diff] [blame] | 288 | def xnnpack_unit_test(name, srcs, copts = [], mingw_copts = [], msys_copts = [], deps = [], tags = [], automatic = True, timeout = "short"): |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 289 | """Unit test binary based on Google Test. |
| 290 | |
| 291 | Args: |
| 292 | name: The name of the test target to define. |
| 293 | srcs: The list of source and header files. |
| 294 | copts: The list of additional compiler flags for the target. -I flags |
| 295 | for include/ and src/ directories of XNNPACK are always prepended |
| 296 | before these user-specified flags. |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 297 | mingw_copts: The list of compiler flags to use with MinGW GCC compilers. |
| 298 | 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] | 299 | deps: The list of additional libraries to be linked. Google Test library |
| 300 | (with main() function) is always added as a dependency and does not |
| 301 | need to be explicitly specified. |
Artsiom Ablavatski | c1aa297 | 2020-12-08 11:23:34 -0800 | [diff] [blame] | 302 | tags: List of arbitrary text tags. |
| 303 | automatic: Whether to create the test or testable binary. |
| 304 | timeout: How long the test is expected to run before returning. |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 305 | """ |
| 306 | |
Marat Dukhan | 22eed3d | 2020-05-11 20:13:37 -0700 | [diff] [blame] | 307 | if automatic: |
| 308 | native.cc_test( |
| 309 | name = name, |
| 310 | srcs = srcs, |
| 311 | copts = xnnpack_std_cxxopts() + [ |
| 312 | "-Iinclude", |
| 313 | "-Isrc", |
| 314 | ] + select({ |
| 315 | ":windows_x86_64_mingw": mingw_copts, |
| 316 | ":windows_x86_64_msys": msys_copts, |
| 317 | "//conditions:default": [], |
| 318 | }) + select({ |
| 319 | ":windows_x86_64_clang": ["/clang:-Wno-unused-function"], |
| 320 | ":windows_x86_64_mingw": ["-Wno-unused-function"], |
| 321 | ":windows_x86_64_msys": ["-Wno-unused-function"], |
| 322 | ":windows_x86_64": [], |
| 323 | "//conditions:default": ["-Wno-unused-function"], |
| 324 | }) + copts, |
| 325 | linkopts = select({ |
| 326 | ":emscripten": xnnpack_emscripten_test_linkopts(), |
| 327 | "//conditions:default": [], |
| 328 | }), |
| 329 | linkstatic = True, |
| 330 | deps = [ |
| 331 | "@com_google_googletest//:gtest_main", |
| 332 | ] + deps + select({ |
| 333 | ":emscripten": xnnpack_emscripten_deps(), |
| 334 | "//conditions:default": [], |
| 335 | }), |
| 336 | tags = tags, |
Artsiom Ablavatski | c1aa297 | 2020-12-08 11:23:34 -0800 | [diff] [blame] | 337 | timeout = timeout, |
Marat Dukhan | 22eed3d | 2020-05-11 20:13:37 -0700 | [diff] [blame] | 338 | ) |
| 339 | else: |
| 340 | native.cc_binary( |
| 341 | name = name, |
| 342 | srcs = srcs, |
| 343 | copts = xnnpack_std_cxxopts() + [ |
| 344 | "-Iinclude", |
| 345 | "-Isrc", |
| 346 | ] + select({ |
| 347 | ":windows_x86_64_mingw": mingw_copts, |
| 348 | ":windows_x86_64_msys": msys_copts, |
| 349 | "//conditions:default": [], |
| 350 | }) + select({ |
| 351 | ":windows_x86_64_clang": ["/clang:-Wno-unused-function"], |
| 352 | ":windows_x86_64_mingw": ["-Wno-unused-function"], |
| 353 | ":windows_x86_64_msys": ["-Wno-unused-function"], |
| 354 | ":windows_x86_64": [], |
| 355 | "//conditions:default": ["-Wno-unused-function"], |
| 356 | }) + copts, |
| 357 | linkopts = select({ |
| 358 | ":emscripten": xnnpack_emscripten_test_linkopts(), |
| 359 | "//conditions:default": [], |
| 360 | }), |
| 361 | linkstatic = True, |
| 362 | deps = [ |
| 363 | "@com_google_googletest//:gtest_main", |
| 364 | ] + deps + select({ |
| 365 | ":emscripten": xnnpack_emscripten_deps(), |
| 366 | "//conditions:default": [], |
| 367 | }), |
| 368 | testonly = True, |
| 369 | tags = tags, |
| 370 | ) |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 371 | |
| 372 | def xnnpack_binary(name, srcs, copts = [], deps = []): |
| 373 | """Minimal binary |
| 374 | |
| 375 | Args: |
| 376 | name: The name of the binary target to define. |
| 377 | srcs: The list of source and header files. |
| 378 | copts: The list of additional compiler flags for the target. -I flags |
| 379 | for include/ and src/ directories of XNNPACK are always prepended |
| 380 | before these user-specified flags. |
| 381 | deps: The list of libraries to be linked. |
| 382 | """ |
| 383 | native.cc_binary( |
| 384 | name = name, |
| 385 | srcs = srcs, |
| 386 | copts = [ |
| 387 | "-Iinclude", |
| 388 | "-Isrc", |
| 389 | ] + copts, |
| 390 | linkopts = select({ |
| 391 | ":emscripten": xnnpack_emscripten_minimal_linkopts(), |
| 392 | "//conditions:default": [], |
| 393 | }), |
| 394 | linkstatic = True, |
| 395 | deps = deps, |
| 396 | ) |
| 397 | |
Marat Dukhan | a98efa1 | 2020-05-04 17:07:49 -0700 | [diff] [blame] | 398 | def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []): |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 399 | """Microbenchmark binary based on Google Benchmark |
| 400 | |
| 401 | Args: |
| 402 | name: The name of the binary target to define. |
| 403 | srcs: The list of source and header files. |
| 404 | copts: The list of additional compiler flags for the target. -I flags |
| 405 | for include/ and src/ directories of XNNPACK are always prepended |
| 406 | before these user-specified flags. |
| 407 | deps: The list of additional libraries to be linked. Google Benchmark |
| 408 | library is always added as a dependency and does not need to be |
| 409 | explicitly specified. |
| 410 | """ |
| 411 | native.cc_binary( |
| 412 | name = name, |
| 413 | srcs = srcs, |
| 414 | copts = xnnpack_std_cxxopts() + [ |
| 415 | "-Iinclude", |
| 416 | "-Isrc", |
Marat Dukhan | a98efa1 | 2020-05-04 17:07:49 -0700 | [diff] [blame] | 417 | ] + select({ |
| 418 | ":windows_x86_64_clang": ["/clang:-Wno-unused-function"], |
| 419 | ":windows_x86_64_mingw": ["-Wno-unused-function"], |
| 420 | ":windows_x86_64_msys": ["-Wno-unused-function"], |
| 421 | ":windows_x86_64": [], |
| 422 | "//conditions:default": ["-Wno-unused-function"], |
| 423 | }) + copts, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 424 | linkopts = select({ |
| 425 | ":emscripten": xnnpack_emscripten_benchmark_linkopts(), |
Marat Dukhan | 10a3808 | 2020-04-17 03:58:35 -0700 | [diff] [blame] | 426 | ":windows_x86_64_mingw": ["-lshlwapi"], |
| 427 | ":windows_x86_64_msys": ["-lshlwapi"], |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 428 | "//conditions:default": [], |
| 429 | }), |
| 430 | linkstatic = True, |
| 431 | deps = [ |
| 432 | "@com_google_benchmark//:benchmark", |
| 433 | ] + deps + select({ |
| 434 | ":emscripten": xnnpack_emscripten_deps(), |
| 435 | "//conditions:default": [], |
| 436 | }), |
Marat Dukhan | 8ea0b07 | 2020-04-23 16:12:18 -0700 | [diff] [blame] | 437 | tags = tags, |
Marat Dukhan | 08c4a43 | 2019-10-03 09:29:21 -0700 | [diff] [blame] | 438 | ) |