Skip to content

Commit 6cceab6

Browse files
authored
Dtype selective build: check if portable/optimized in deps (#11030)
Pull Request resolved: #10998 When dtype selective build is enabled, error out if `kernel_deps` contains portable/optimized ops, and `deps` also contains portable/optimized. The check is recursive, ie, if any item in `deps` transitively depends on portable/optimized. Differential Revision: [D74922471](https://our.internmc.facebook.com/intern/diff/D74922471/) ghstack-source-id: 285201954
1 parent 6a8d286 commit 6cceab6

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,23 @@ def executorch_generated_lib(
655655
If you have a custom kernel library, please remove `dtype_selective_build=True`
656656
and use regular selective build.
657657
""".format(kernel_deps))
658+
659+
# Dtype selective build requires that the portable/optimized kernel libraries are not passed into `deps`.
660+
if ("//executorch/kernels/portable:operators" in kernel_deps):
661+
index = 0
662+
for dep in deps:
663+
index = index + 1
664+
portable = name + "_check_portable_" + dep.split(":")[1] + str(index)
665+
message = "Dtype selective build requires that the portable library is not passed into `deps`. This will cause duplicate symbol errors in the build. Please remove it from `deps` and place it into `kernel_deps`"
666+
check_recursive_dependencies(portable, dep, "//executorch/kernels/portable:operators", message)
667+
if ("//executorch/kernels/optimized:optimized_operators" in kernel_deps):
668+
index = 0
669+
for dep in deps:
670+
index = index + 1
671+
optimized = name + "_check_optimized_" + dep.split(":")[1] + str(index)
672+
message = "Dtype selective build requires that the optimized library is not passed into `deps`. This will cause duplicate symbol errors in the build. Please remove it from `deps` and place it into `kernel_deps`"
673+
check_recursive_dependencies(optimized, dep, "//executorch/kernels/optimized:optimized_operators", message)
674+
658675

659676
aten_suffix = "_aten" if aten_mode else ""
660677

@@ -870,3 +887,31 @@ def executorch_ops_check(
870887
default_outs = ["."],
871888
**kwargs,
872889
)
890+
891+
def check_recursive_dependencies(
892+
name,
893+
parent,
894+
child,
895+
message = "",
896+
**kwargs,
897+
):
898+
"""
899+
Checks if child is a transitive dependency of parent and fails if it is.
900+
The query runs the equivalent of `buck2 uquery "allpaths(parent, child)".
901+
The path from parent->child is available in the out file and error message.
902+
"""
903+
message = "Dependency violation: '{}' should not depend on '{}'. {}".format(parent, child, message)
904+
905+
if parent == child:
906+
fail(message)
907+
908+
runtime.genrule(
909+
name = name,
910+
macros_only = False,
911+
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),
912+
define_static_target = False,
913+
# The path is saved to $OUT/dep.txt and can be accessed via genrule_name[result].
914+
outs = {"result": ["dep.txt"]},
915+
default_outs = ["."],
916+
platforms = kwargs.pop("platforms", get_default_executorch_platforms()),
917+
)

0 commit comments

Comments
 (0)