Skip to content

Commit 86eef61

Browse files
committed
Update base for Update on "[slimtensor] Add storage and device property getters to common_shims_slim"
Add storage and device property getter AOTI shim functions to the header-only common_shims_slim library: 1. `aoti_torch_get_storage_offset()` - Returns the storage offset (SlimTensor: real offset, ETensor: always 0) 2. `aoti_torch_get_storage_size()` - Returns storage size in bytes 3. `aoti_torch_get_device_type()` - Returns device type (SlimTensor: real type, ETensor: CPU=0) 4. `aoti_torch_get_device_index()` - Returns device index (SlimTensor: real index, ETensor: 0) Differential Revision: [D90126251](https://our.internmc.facebook.com/intern/diff/D90126251/) [ghstack-poisoned]
2 parents 3f18b91 + f680623 commit 86eef61

File tree

193 files changed

+2951
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+2951
-44
lines changed

.buckconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
[buildfile]
55
name = TARGETS
6+
name_v2 = TARGETS,BUCK
67

78
[repositories]
89
root = .

backends/apple/coreml/BUCK

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Any targets that should be shared between fbcode and xplat must be defined in
2+
# targets.bzl. This file can contain xplat-only targets.
3+
4+
load(
5+
"@fbsource//tools/build_defs:default_platform_defs.bzl",
6+
"APPLE",
7+
)
8+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
9+
load("@fbsource//xplat/executorch/runtime/core:targets.bzl", "build_sdk")
10+
11+
oncall("executorch")
12+
13+
runtime.cxx_library(
14+
name = "coreml",
15+
srcs = [
16+
"runtime/delegate/ETCoreMLAsset.mm",
17+
"runtime/delegate/ETCoreMLAssetManager.mm",
18+
"runtime/delegate/ETCoreMLDefaultModelExecutor.mm",
19+
"runtime/delegate/ETCoreMLLogging.mm",
20+
"runtime/delegate/ETCoreMLModel.mm",
21+
"runtime/delegate/ETCoreMLModelCompiler.mm",
22+
"runtime/delegate/ETCoreMLModelLoader.mm",
23+
"runtime/delegate/ETCoreMLModelManager.mm",
24+
"runtime/delegate/ETCoreMLStrings.mm",
25+
"runtime/delegate/MLModel_Prewarm.mm",
26+
"runtime/delegate/MLMultiArray_Copy.mm",
27+
"runtime/delegate/asset.mm",
28+
"runtime/delegate/backend_delegate.mm",
29+
"runtime/delegate/coreml_backend_delegate.mm",
30+
"runtime/delegate/multiarray.mm",
31+
"runtime/delegate/executorch_operations.mm",
32+
"runtime/delegate/serde_json.mm",
33+
"runtime/inmemoryfs/inmemory_filesystem.cpp",
34+
"runtime/inmemoryfs/inmemory_filesystem_utils.mm",
35+
"runtime/inmemoryfs/memory_buffer.cpp",
36+
"runtime/inmemoryfs/memory_stream.cpp",
37+
"runtime/inmemoryfs/reversed_memory_stream.cpp",
38+
"runtime/kvstore/database.cpp",
39+
"runtime/kvstore/json_key_value_store.cpp",
40+
"runtime/kvstore/key_value_store.cpp",
41+
"runtime/kvstore/sqlite_error.cpp",
42+
"runtime/kvstore/statement.cpp",
43+
"runtime/util/json_util.cpp",
44+
"runtime/util/objc_json_serde.mm",
45+
] + (glob([
46+
"runtime/sdk/*.mm",
47+
]) if build_sdk() else []),
48+
headers = glob([
49+
"runtime/include/coreml_backend/delegate.h",
50+
"runtime/kvstore/*.hpp",
51+
"runtime/inmemoryfs/*.hpp",
52+
"runtime/delegate/*.h",
53+
"runtime/delegate/*.hpp",
54+
"runtime/util/*.h",
55+
"runtime/util/*.hpp",
56+
]) + (glob([
57+
"runtime/sdk/*.h",
58+
]) if build_sdk() else []),
59+
compiler_flags = [
60+
"-fobjc-arc",
61+
"-fno-exceptions",
62+
"-fno-rtti",
63+
"-Wno-null-character",
64+
"-Wno-receiver-expr",
65+
"-Wno-error",
66+
],
67+
define_static_target = True,
68+
header_namespace = "backends/apple/coreml",
69+
exported_headers = ["runtime/delegate/executorch_operations.h", "runtime/include/coreml_backend/delegate.h"],
70+
fbobjc_ios_target_sdk_version = "13.0",
71+
fbobjc_frameworks = [
72+
"Accelerate",
73+
"CoreML",
74+
"Foundation",
75+
],
76+
include_directories = [
77+
"runtime/include",
78+
"runtime/kvstore",
79+
"runtime/inmemoryfs",
80+
"runtime/delegate",
81+
"runtime/util",
82+
] + ([
83+
"runtime/sdk",
84+
] if build_sdk() else []),
85+
fbobjc_libraries = [
86+
"libsqlite3",
87+
],
88+
link_whole = True,
89+
platforms = [APPLE],
90+
visibility = ["PUBLIC"],
91+
deps = [
92+
"//executorch/runtime/backend:interface",
93+
"//executorch/runtime/core:core",
94+
"//executorch/runtime/kernel:kernel_includes",
95+
] + ([
96+
":proto",
97+
] if build_sdk() else []),
98+
)
99+
100+
_PROTOS = [
101+
"ArrayFeatureExtractor",
102+
"AudioFeaturePrint",
103+
"BayesianProbitRegressor",
104+
"CategoricalMapping",
105+
"ClassConfidenceThresholding",
106+
"CustomModel",
107+
"DataStructures",
108+
"DictVectorizer",
109+
"FeatureTypes",
110+
"FeatureVectorizer",
111+
"Gazetteer",
112+
"GLMClassifier",
113+
"GLMRegressor",
114+
"Identity",
115+
"Imputer",
116+
"ItemSimilarityRecommender",
117+
"LinkedModel",
118+
"MIL",
119+
"Model",
120+
"NearestNeighbors",
121+
"NeuralNetwork",
122+
"NonMaximumSuppression",
123+
"Normalizer",
124+
"OneHotEncoder",
125+
"Parameters",
126+
"Scaler",
127+
"SoundAnalysisPreprocessing",
128+
"SVM",
129+
"TextClassifier",
130+
"TreeEnsemble",
131+
"VisionFeaturePrint",
132+
"WordEmbedding",
133+
"WordTagger",
134+
]
135+
136+
runtime.cxx_library(
137+
name = "proto",
138+
srcs = [
139+
"fbsource//third-party/pypi/coremltools:exported-cpp-protoc[{}.pb.cc]".format(name)
140+
for name in _PROTOS
141+
],
142+
exported_headers = {
143+
"format/{}.pb.h".format(name): "fbsource//third-party/pypi/coremltools:exported-cpp-protoc[{}.pb.h]".format(name)
144+
for name in _PROTOS
145+
},
146+
compiler_flags = [
147+
"-Wno-global-constructors",
148+
],
149+
public_include_directories = [
150+
"",
151+
],
152+
deps = [
153+
"//third-party/protobuf:fb-protobuf-lite",
154+
],
155+
)

backends/apple/mps/BUCK

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (c) 2023 Apple Inc. All rights reserved.
3+
# Provided subject to the LICENSE file in the top level directory.
4+
#
5+
6+
# Any targets that should be shared between fbcode and xplat must be defined in
7+
# targets.bzl. This file can contain xplat-only targets.
8+
9+
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "APPLE")
10+
load(":targets.bzl", "define_common_targets")
11+
12+
oncall("executorch")
13+
14+
define_common_targets(
15+
is_xplat = True,
16+
platforms = [APPLE],
17+
)

backends/arm/runtime/BUCK

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("targets.bzl", "define_common_targets")
2+
3+
oncall("odai_jarvis")
4+
5+
define_common_targets()

backends/cadence/aot/compiler_funcs.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@
1919
QuantArgs = tuple[float, int, int, int, torch.dtype]
2020

2121

22+
def extract_input_shapes_from_graph(
23+
module: GraphModule,
24+
) -> dict[int, tuple[int, ...]]:
25+
"""
26+
Extract input shapes from the FX graph placeholder nodes.
27+
28+
Returns a dict mapping input index to expected shape tuple.
29+
"""
30+
input_shapes: dict[int, tuple[int, ...]] = {}
31+
idx = 0
32+
for node in module.graph.nodes:
33+
if node.op == "placeholder":
34+
# Get the tensor_meta from the node if available
35+
if "val" in node.meta:
36+
val = node.meta["val"]
37+
if isinstance(val, torch.Tensor):
38+
input_shapes[idx] = tuple(val.shape)
39+
elif hasattr(val, "shape"):
40+
input_shapes[idx] = tuple(val.shape)
41+
idx += 1
42+
return input_shapes
43+
44+
2245
@torch.no_grad()
2346
def trace(
2447
model: torch.nn.Module,
@@ -138,6 +161,9 @@ def __init__(
138161
super().__init__()
139162
self.module: GraphModule = module
140163
self.quant_args: dict[int, QuantArgs] = {}
164+
self.expected_shapes: dict[int, tuple[int, ...]] = (
165+
extract_input_shapes_from_graph(module)
166+
)
141167

142168
if input_args is not None:
143169
logger.warning(
@@ -151,6 +177,20 @@ def __init__(
151177

152178
def forward(self, *args: torch.Tensor) -> Any:
153179
"""Run inference, dequantizing configured inputs."""
180+
# Validate input shapes for quantized inputs
181+
for index in self.quant_args:
182+
if index >= len(args):
183+
continue
184+
actual_shape = tuple(args[index].shape)
185+
if index not in self.expected_shapes:
186+
continue
187+
expected_shape = self.expected_shapes[index]
188+
if actual_shape != expected_shape:
189+
raise ValueError(
190+
f"Shape mismatch for quantized input at index {index}: "
191+
f"expected {expected_shape}, got {actual_shape}"
192+
)
193+
154194
dequantized_args = []
155195
for index, node in enumerate(args):
156196
if index in self.quant_args:

backends/cadence/common/BUCK

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@fbsource//tools/build_defs:platform_defs.bzl", "CXX")
2+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
3+
4+
oncall("odai_jarvis")
5+
6+
runtime.cxx_library(
7+
name = "xt_macros",
8+
exported_headers=["xt_macros.h"],
9+
platforms = CXX,
10+
visibility = ["PUBLIC"],
11+
compatible_with = ["ovr_config//cpu:xtensa"],
12+
deps = [
13+
"//executorch/runtime/core/exec_aten/util:tensor_util",
14+
]
15+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("targets.bzl", "define_common_targets")
2+
3+
oncall("odai_jarvis")
4+
5+
define_common_targets()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("@fbcode//on_device_ai/Assistant/Jarvis/build:cxx_wrapper.bzl", "jarvis_wrapper")
2+
load("@fbsource//arvr/firmware/ar/build_defs:xtensa.bzl", "XTENSA_TEST_REMOTE_EXECUTION_ASIC")
3+
load("@fbsource//tools/build_defs:platform_defs.bzl", "CXX")
4+
load("@fbsource//tools/target_determinator/macros:ci.bzl", "ci")
5+
6+
oncall("odai_jarvis")
7+
8+
jarvis_wrapper.cxx_test(
9+
name = "test_op_add",
10+
srcs = [
11+
"test_op_add.cpp",
12+
],
13+
compatible_backends = ["g3"],
14+
labels = [ci.skip_target()],
15+
remote_execution = XTENSA_TEST_REMOTE_EXECUTION_ASIC,
16+
compiler_flags = [
17+
"-Wno-ignored-attributes",
18+
],
19+
platforms = CXX,
20+
visibility = [
21+
"fbsource//xplat/executorch/backends/cadence/...",
22+
"fbcode//executorch/backends/cadence/...",
23+
],
24+
deps = [
25+
"fbsource//xplat/executorch/backends/cadence/fusion_g3/operators:op_add",
26+
"fbsource//xplat/executorch/backends/cadence/runtime:et_pal",
27+
"fbsource//xplat/executorch/kernels/test:gtest_utils",
28+
"fbsource//xplat/executorch/runtime/core/exec_aten/testing_util:tensor_util",
29+
],
30+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("targets.bzl", "define_common_targets")
2+
3+
oncall("odai_jarvis")
4+
5+
define_common_targets()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("targets.bzl", "define_common_targets")
2+
3+
oncall("odai_jarvis")
4+
5+
define_common_targets()

0 commit comments

Comments
 (0)