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