Skip to content

Commit afe6a6a

Browse files
committed
Dtype selective build: check if portable/optimized in deps
When dtype selective build is enabled: Show a warning if kernel_deps does not contain portable/optimized Error out if deps contains portable/optimized, and it is also in kernel_deps. Differential Revision: [D74922471](https://our.internmc.facebook.com/intern/diff/D74922471/) [ghstack-poisoned]
1 parent ce37a0a commit afe6a6a

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

examples/portable/executor_runner/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def define_common_targets():
8484
"//executorch/kernels/optimized:optimized_oplist",
8585
"//executorch/kernels/portable:executorch_aten_ops",
8686
"//executorch/kernels/portable:executorch_custom_ops",
87-
"//executorch/kernels/portable:operators",
8887
],
88+
kernel_deps = ["//executorch/kernels/portable:operators",],
8989
custom_ops_aten_kernel_deps = [
9090
"//executorch/kernels/portable:operators_aten",
9191
],

shim_et/xplat/executorch/codegen/codegen.bzl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def executorch_generated_lib(
647647
!!WARNING!! Dtype_selective_build is only available in xplat.
648648
Proceeding without dtype selective build for lib: {}.""".format(name))
649649

650-
# Dtype selective build is enabled on portable and optimized kernel libraries.
650+
# Dtype selective build is enabled on portable and optimized kernel libraries.
651651
if (not "//executorch/kernels/portable:operators" in kernel_deps) and (not "//executorch/kernels/optimized:optimized_operators" in kernel_deps):
652652
warning("""
653653
!!WARNING!! Dtype_selective_build is enabled but kernel_deps does not contain portable or optimized dependencies.
@@ -660,6 +660,23 @@ def executorch_generated_lib(
660660
661661
Proceeding without dtype selective build.
662662
""".format(kernel_deps))
663+
664+
# Dtype selective build requires that the portable/optimized kernel libraries are not passed into `deps`.
665+
if ("//executorch/kernels/portable:operators" in kernel_deps):
666+
index = 0
667+
for dep in deps:
668+
index = index + 1
669+
portable = name + "_check_portable_" + dep.split(":")[1] + str(index)
670+
message = "Dtype selective build requires that the portable library is not passed into `deps`. Please remove it from `deps` and place it into `kernel_deps`"
671+
check_recursive_dependencies(portable, dep, "//executorch/kernels/portable:operators", message)
672+
if ("//executorch/kernels/optimized:optimized_operators" in kernel_deps):
673+
index = 0
674+
for dep in deps:
675+
index = index + 1
676+
optimized = name + "_check_optimized_" + dep.split(":")[1] + str(index)
677+
message = "Dtype selective build requires that the optimized library is not passed into `deps`. Please remove it from `deps` and place it into `kernel_deps`"
678+
check_recursive_dependencies(optimized, dep, "//executorch/kernels/optimized:optimized_operators", message)
679+
663680

664681
aten_suffix = "_aten" if aten_mode else ""
665682

@@ -875,3 +892,31 @@ def executorch_ops_check(
875892
default_outs = ["."],
876893
**kwargs,
877894
)
895+
896+
def check_recursive_dependencies(
897+
name,
898+
parent,
899+
child,
900+
message = "",
901+
**kwargs,
902+
):
903+
"""
904+
Checks if child is a transitive dependency of parent and fails if it is.
905+
The query runs the equivalent of `buck2 uquery "allpaths(parent, child)".
906+
The path from parent->child is available in the out file and error message.
907+
"""
908+
message = "Dependency violation: '{}' should not depend on '{}'. {}".format(parent, child, message)
909+
910+
if parent == child:
911+
fail(message)
912+
913+
runtime.genrule(
914+
name = name,
915+
macros_only = False,
916+
cmd = 'mkdir -p $OUT;paths="$(query_targets allpaths({}, {}))"; echo "$paths" > $OUT/dep.txt; if [ -z "$paths" ]; then echo "Dependencies look good"; else echo {}. This will cause duplicate symbol errors when building with dtype selective build. The dependency path is: "$paths"; fail; fi'.format(parent, child, message),
917+
define_static_target = False,
918+
# The path is saved to $OUT/dep.txt and can be accessed via genrule_name[result].
919+
outs = {"result": ["dep.txt"]},
920+
default_outs = ["."],
921+
platforms = kwargs.pop("platforms", get_default_executorch_platforms()),
922+
)

0 commit comments

Comments
 (0)