From 9b075b0864694b576ba6cdf263e2d315fe0a95c9 Mon Sep 17 00:00:00 2001 From: lucylq Date: Tue, 20 May 2025 14:07:21 -0700 Subject: [PATCH] Dtype selective build: fail if portable/optimized not in kernel_deps Pull Request resolved: https://github.com/pytorch/executorch/pull/10990 https://github.com/pytorch/executorch/pull/10985 Try to make user error harder for dtype selective build. Currently, if dtype selective build cannot be enabled we silently fallback to regular dtype selective build. This diff: 1. Emits failure when there is nothing in kernel_deps and dtype_selective_build=True. 2. Remove dtype_selective_build=True for cases in (1). 3. Warning that dtype selective build is not enabled if user is not in xplat. ghstack-source-id: 285201952 Differential Revision: [D75027794](https://our.internmc.facebook.com/intern/diff/D75027794/) --- shim_et/xplat/executorch/codegen/codegen.bzl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/shim_et/xplat/executorch/codegen/codegen.bzl b/shim_et/xplat/executorch/codegen/codegen.bzl index f4996b6aaf7..f1c174cc502 100644 --- a/shim_et/xplat/executorch/codegen/codegen.bzl +++ b/shim_et/xplat/executorch/codegen/codegen.bzl @@ -641,6 +641,21 @@ def executorch_generated_lib( if not aten_mode and not functions_yaml_target and not custom_ops_yaml_target: fail("At least one of functions_yaml_target, custom_ops_yaml_target needs to be provided") + if dtype_selective_build: + if (not "//executorch/kernels/portable:operators" in kernel_deps) and (not "//executorch/kernels/optimized:optimized_operators" in kernel_deps): + fail(""" + !!WARNING!! Dtype selective build is available for the portable and optimized kernel libraries. + If you are using those, please add them to `kernel_deps` in `executorch_generated_lib`: + //executorch/kernels/portable:operators + //executorch/kernels/optimized:optimized_operators + This will tell the build system to rebuild portable/optimized with the dtype selective build header. + For examples, see: //executorch/examples/selective_build/targets.bzl + Currently, kernel_deps contains {}. + + If you have a custom kernel library, please remove `dtype_selective_build=True` + and use regular selective build. + """.format(kernel_deps)) + aten_suffix = "_aten" if aten_mode else "" # merge functions.yaml with fallback yaml