From cf39b4794c5e43fc7f3bac45408ce8e9dca9e4e5 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 21 Mar 2025 13:56:20 -0700 Subject: [PATCH] [ExecuTorch] Add //examples/portable/executor_runner:executor_runner_opt Pull Request resolved: https://github.com/pytorch/executorch/pull/9291 Attempt to add a Buck target that's analogous to the CMake build's executor_runner -- has all CPU ops that you need etc. The base executor_runner target is commented as intentionally having minimal deps, hence the separate target. This is sort of a companion to https://github.com/pytorch/executorch/pull/9248, except that that PR is for CMake only and this PR is for Buck only. ghstack-source-id: 273335947 @exported-using-ghexport Differential Revision: [D71220489](https://our.internmc.facebook.com/intern/diff/D71220489/) --- examples/portable/executor_runner/targets.bzl | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/examples/portable/executor_runner/targets.bzl b/examples/portable/executor_runner/targets.bzl index 9cddaa4ed77..3d29472300f 100644 --- a/examples/portable/executor_runner/targets.bzl +++ b/examples/portable/executor_runner/targets.bzl @@ -1,4 +1,5 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_oss_build_kwargs", "runtime") +load("@fbsource//xplat/executorch/codegen:codegen.bzl", "executorch_generated_lib") def define_common_targets(): """Defines targets that should be shared between fbcode and xplat. @@ -27,6 +28,26 @@ def define_common_targets(): ], ) + runtime.cxx_library( + name = "executor_runner_lib_with_threadpool", + srcs = ["executor_runner.cpp"], + deps = [ + "//executorch/runtime/executor:program", + "//executorch/extension/data_loader:file_data_loader", + "//executorch/extension/evalue_util:print_evalue", + "//executorch/extension/runner_util:inputs", + "//executorch/extension/threadpool:cpuinfo_utils", + "//executorch/extension/threadpool:threadpool", + ], + external_deps = [ + "gflags", + ], + define_static_target = True, + visibility = [ + "//executorch/examples/...", + ], + ) + register_custom_op = native.read_config("executorch", "register_custom_op", "0") register_quantized_ops = native.read_config("executorch", "register_quantized_ops", "0") @@ -52,3 +73,36 @@ def define_common_targets(): define_static_target = True, **get_oss_build_kwargs() ) + + executorch_generated_lib( + name = "generated_op_lib_for_runner", + deps = [ + "//executorch/kernels/optimized:optimized_operators", + "//executorch/kernels/optimized:optimized_oplist", + "//executorch/kernels/portable:executorch_aten_ops", + "//executorch/kernels/portable:executorch_custom_ops", + "//executorch/kernels/portable:operators", + ], + custom_ops_aten_kernel_deps = [ + "//executorch/kernels/portable:operators_aten", + ], + functions_yaml_target = "//executorch/kernels/optimized:optimized.yaml", + custom_ops_yaml_target = "//executorch/kernels/portable:custom_ops.yaml", + fallback_yaml_target = "//executorch/kernels/portable:functions.yaml", + define_static_targets = True, + ) + + # Test driver for models, should have all fast CPU kernels + # (XNNPACK, custom SDPA, etc.) available. + runtime.cxx_binary( + name = "executor_runner_opt", + srcs = [], + deps = [ + ":executor_runner_lib_with_threadpool", + ":generated_op_lib_for_runner", + "//executorch/backends/xnnpack:xnnpack_backend", + "//executorch/configurations:executor_cpu_optimized", + "//executorch/extension/llm/custom_ops:custom_ops", + "//executorch/kernels/quantized:generated_lib", + ], + )