1load("@fbsource//xplat/executorch/backends/xnnpack/third-party:third_party_libs.bzl", "third_party_dep") 2load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") 3 4def _get_preprocessor_flags(): 5 """ 6 Disable if someone explictly specified a config option, 7 else Enable otherwise 8 """ 9 if native.read_config("executorch", "xnnpack_workspace_sharing", "0") == "0": 10 return [] 11 12 # Enable if not disabled through config 13 return ["-DENABLE_XNNPACK_SHARED_WORKSPACE"] 14 15def define_common_targets(): 16 runtime.cxx_library( 17 name = "dynamic_quant_utils", 18 srcs = [ 19 "runtime/utils/utils.cpp", 20 ], 21 exported_headers = ["runtime/utils/utils.h"], 22 deps = [ 23 "//executorch/runtime/core/exec_aten:lib", 24 "//executorch/runtime/backend:interface", 25 ], 26 visibility = [ 27 "//executorch/backends/xnnpack/...", 28 "@EXECUTORCH_CLIENTS", 29 ], 30 ) 31 32 runtime.cxx_library( 33 name = "xnnpack_backend", 34 srcs = native.glob([ 35 "runtime/*.cpp", 36 "runtime/profiling/*.cpp", 37 ]), 38 headers = native.glob([ 39 "runtime/*.h", 40 "runtime/profiling/*.h", 41 ]), 42 visibility = [ 43 "//executorch/exir/backend:backend_lib", 44 "//executorch/exir/backend/test/...", 45 "//executorch/backends/xnnpack/test/...", 46 "//executorch/extension/pybindings/...", 47 "@EXECUTORCH_CLIENTS", 48 ], 49 preprocessor_flags = [ 50 # Uncomment to enable per operator timings 51 # "-DENABLE_XNNPACK_PROFILING", 52 # Uncomment to enable using KleidiAI Kernels 53 # "-DENABLE_XNNPACK_KLEIDI" 54 ] + _get_preprocessor_flags(), 55 exported_deps = [ 56 "//executorch/runtime/backend:interface", 57 ], 58 deps = [ 59 third_party_dep("XNNPACK"), 60 "//executorch/backends/xnnpack/serialization:xnnpack_flatbuffer_header", 61 "//executorch/extension/threadpool:threadpool", 62 "//executorch/runtime/core/exec_aten/util:tensor_util", 63 ], 64 # XnnpackBackend.cpp needs to compile with executor as whole 65 # @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole) 66 link_whole = True, 67 ) 68