Skip to content

Commit 4a00cac

Browse files
committed
Update
[ghstack-poisoned]
2 parents 7c78357 + 3091007 commit 4a00cac

Some content is hidden

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

64 files changed

+642
-550
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,5 @@ build_llama_runner() {
6060

6161
cmake --build cmake-android-out/examples/models/llama -j4 --config Release
6262
}
63-
install_flatc_from_source
6463
install_executorch_and_backend_lib
6564
build_llama_runner

.ci/scripts/utils.sh

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,6 @@ install_pytorch_and_domains() {
8080
sccache --show-stats || true
8181
}
8282

83-
install_flatc_from_source() {
84-
# NB: This function could be used to install flatbuffer from source
85-
pushd third-party/flatbuffers || return
86-
87-
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
88-
if [ "$(uname)" == "Darwin" ]; then
89-
CMAKE_JOBS=$(( $(sysctl -n hw.ncpu) - 1 ))
90-
else
91-
CMAKE_JOBS=$(( $(nproc) - 1 ))
92-
fi
93-
cmake --build . -j "${CMAKE_JOBS}"
94-
95-
# Copy the flatc binary to conda path
96-
EXEC_PATH=$(dirname "$(which python)")
97-
cp flatc "${EXEC_PATH}"
98-
99-
popd || return
100-
}
101-
10283
build_executorch_runner_buck2() {
10384
# Build executorch runtime with retry as this step is flaky on macos CI
10485
retry buck2 build //examples/portable/executor_runner:executor_runner
@@ -111,9 +92,14 @@ build_executorch_runner_cmake() {
11192
mkdir "${CMAKE_OUTPUT_DIR}"
11293

11394
pushd "${CMAKE_OUTPUT_DIR}" || return
95+
if [[ $1 == "Debug" ]]; then
96+
CXXFLAGS="-fsanitize=address,undefined"
97+
else
98+
CXXFLAGS=""
99+
fi
114100
# This command uses buck2 to gather source files and buck2 could crash flakily
115101
# on MacOS
116-
retry cmake -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" -DCMAKE_BUILD_TYPE="${1:-Release}" ..
102+
CXXFLAGS="$CXXFLAGS" retry cmake -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" -DCMAKE_BUILD_TYPE="${1:-Release}" ..
117103
popd || return
118104

119105
if [ "$(uname)" == "Darwin" ]; then

CMakeLists.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ endif()
460460
# tools like `flatc`, along with example executables like `executor_runner` and
461461
# libraries that it uses, like `gflags`. Disabling this can be helpful when
462462
# cross-compiling, but some required tools that would have been built need to be
463-
# provided directly (via, for example, FLATC_EXECUTABLE).
463+
# provided directly.
464464
cmake_dependent_option(
465465
EXECUTORCH_BUILD_HOST_TARGETS "Build host-only targets." ON
466466
"NOT CMAKE_TOOLCHAIN_IOS" OFF
@@ -471,10 +471,9 @@ cmake_dependent_option(
471471
#
472472
cmake_dependent_option(
473473
EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON
474-
"NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF
474+
"NOT FLATC_EXECUTABLE" OFF
475475
)
476476

477-
478477
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "")
479478
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "")
480479
set(FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "")
@@ -507,6 +506,8 @@ if(EXECUTORCH_BUILD_FLATC)
507506
-DFLATBUFFERS_BUILD_TESTS=${FLATBUFFERS_BUILD_TESTS}
508507
-DFLATBUFFERS_INSTALL=${FLATBUFFERS_INSTALL}
509508
-DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${FLATBUFFERS_MAX_ALIGNMENT}"
509+
# If building for iOS, "unset" these variables to rely on the host (macOS) defaults.
510+
$<$<AND:$<BOOL:${CMAKE_TOOLCHAIN_IOS}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
510511
INSTALL_COMMAND ""
511512
BUILD_BYPRODUCTS <BINARY_DIR>/flatc
512513
)
@@ -515,6 +516,8 @@ if(EXECUTORCH_BUILD_FLATC)
515516
# flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
516517
# config, but from CMake's perspective the build type is always Debug.
517518
set(FLATC_EXECUTABLE ${BINARY_DIR}/$<CONFIG>/flatc.exe)
519+
elseif(CMAKE_GENERATOR STREQUAL "Xcode")
520+
set(FLATC_EXECUTABLE ${BINARY_DIR}/$<CONFIG>/flatc)
518521
else()
519522
set(FLATC_EXECUTABLE ${BINARY_DIR}/flatc)
520523
endif()
@@ -528,12 +531,7 @@ if(NOT FLATC_EXECUTABLE)
528531
find_program(FLATC_EXECUTABLE flatc)
529532

530533
if(NOT FLATC_EXECUTABLE)
531-
message(
532-
FATAL_ERROR
533-
"FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled. "
534-
"Note that EXECUTORCH_BUILD_FLATC may be disabled implicitly when "
535-
"cross-compiling or when EXECUTORCH_BUILD_HOST_TARGETS is disabled."
536-
)
534+
message(FATAL_ERROR "FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled.")
537535
endif()
538536
endif()
539537

backends/apple/coreml/scripts/build_tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ cmake "$EXECUTORCH_ROOT_PATH" -B"$CMAKE_EXECUTORCH_BUILD_DIR_PATH" \
3232
-DCMAKE_TOOLCHAIN_FILE="$IOS_TOOLCHAIN_PATH" \
3333
-DPLATFORM=MAC_UNIVERSAL \
3434
-DDEPLOYMENT_TARGET=13.0 \
35-
-DFLATC_EXECUTABLE="$(which flatc)" \
3635
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
3736
-DEXECUTORCH_BUILD_XNNPACK=OFF \
3837
-DEXECUTORCH_BUILD_GFLAGS=OFF

backends/apple/mps/runtime/MPSDevice.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ static inline MTLLanguageVersion getMetalLanguageVersion(const id<MTLDevice>& de
2222
// MPS Advanced Indexing needs at least Metal 2.0 (support for Argument Buffers and function constants)
2323
// host_name attribute needs at least Metal 2.2 and ulong needs Metal 2.3 (supported on MacOS 11+)
2424
MTLLanguageVersion languageVersion = MTLLanguageVersion2_3;
25-
#if defined(__MAC_13_0)
26-
if (macOS13Plus) {
27-
languageVersion = MTLLanguageVersion3_0;
25+
if (@available(iOS 16, macOS 13, *)) {
26+
if (macOS13Plus) {
27+
languageVersion = MTLLanguageVersion3_0;
28+
}
2829
}
29-
#endif
3030

3131
ET_CHECK_MSG([device supportsFamily:MTLGPUFamilyMac2], "Missing Metal support for MTLGPUFamilyMac2");
3232
return languageVersion;

backends/apple/mps/runtime/operations/IndexingOps.mm

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,32 @@
206206

207207
Error
208208
MPSGraphBuilder::mpsScatterOp(NodePtr nodePtr) {
209-
auto graphNode = nodePtr->mpsnode_union_as_MPSScatter();
210-
ET_LOG(
211-
Debug, "%s %d: %d",
212-
__FUNCTION__, graphNode->input1_id(), graphNode->output_id()
213-
);
209+
if (@available(iOS 15.4, macOS 12.3, *)) {
210+
auto graphNode = nodePtr->mpsnode_union_as_MPSScatter();
211+
ET_LOG(
212+
Debug, "%s %d: %d",
213+
__FUNCTION__, graphNode->input1_id(), graphNode->output_id()
214+
);
214215

215-
int64_t dim = graphNode->dim();
216-
MPSGraphTensor* inputTensor = getMPSGraphTensor(graphNode->input1_id());
217-
MPSGraphTensor* indicesTensor = getMPSGraphTensor(graphNode->idx_id());
218-
MPSGraphTensor* updatesTensor = getMPSGraphTensor(graphNode->src_id());
216+
int64_t dim = graphNode->dim();
217+
MPSGraphTensor* inputTensor = getMPSGraphTensor(graphNode->input1_id());
218+
MPSGraphTensor* indicesTensor = getMPSGraphTensor(graphNode->idx_id());
219+
MPSGraphTensor* updatesTensor = getMPSGraphTensor(graphNode->src_id());
219220

220-
_idToMPSGraphTensor[graphNode->output_id()] =
221-
[_mpsGraph scatterAlongAxis:dim
222-
withDataTensor:inputTensor
223-
updatesTensor:updatesTensor
224-
indicesTensor:indicesTensor
225-
mode:MPSGraphScatterModeSet
226-
name:nil];
227-
return Error::Ok;
221+
_idToMPSGraphTensor[graphNode->output_id()] =
222+
[_mpsGraph scatterAlongAxis:dim
223+
withDataTensor:inputTensor
224+
updatesTensor:updatesTensor
225+
indicesTensor:indicesTensor
226+
mode:MPSGraphScatterModeSet
227+
name:nil];
228+
229+
return Error::Ok;
230+
} else {
231+
ET_LOG(Error, "MPS: scatter op is not supported on iOS < 15.4 and macOS < 12.3");
232+
233+
return Error::NotSupported;
234+
}
228235
}
229236

230237

backends/arm/scripts/build_executorch.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ if [ "$build_with_etdump" = true ] ; then
8484
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
8585
-DEXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT=ON \
8686
-DFLATCC_ALLOW_WERROR=OFF \
87-
-DFLATC_EXECUTABLE="$(which flatc)" \
8887
-B"${et_build_host_dir}" \
8988
"${et_root_dir}"
9089

@@ -133,7 +132,6 @@ cmake \
133132
-DEXECUTORCH_ENABLE_LOGGING=ON \
134133
${build_devtools_flags} \
135134
${build_with_etdump_flags} \
136-
-DFLATC_EXECUTABLE="$(which flatc)" \
137135
-B"${et_build_dir}" \
138136
"${et_root_dir}"
139137

backends/arm/test/TARGETS

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ python_library(
1919
srcs = ["runner_utils.py"],
2020
deps = [
2121
":conftest",
22-
"//executorch/backends/xnnpack/test/tester:tester",
2322
"//executorch/backends/arm:arm_backend",
2423
"//executorch/exir:lib",
2524
"//executorch/exir/backend:compile_spec_schema",
@@ -31,10 +30,7 @@ python_library(
3130
srcs = ["common.py"],
3231
deps = [
3332
":runner_utils",
34-
"//executorch/backends/xnnpack/test/tester:tester",
35-
"//executorch/backends/arm:arm_backend",
36-
"//executorch/exir:lib",
37-
"//executorch/exir/backend:compile_spec_schema",
33+
"//executorch/backends/arm:tosa_specification",
3834
"fbsource//third-party/pypi/pytest:pytest",
3935
]
4036
)
@@ -43,12 +39,11 @@ python_library(
4339
name = "arm_tester",
4440
srcs = glob(["tester/*.py"]),
4541
deps = [
46-
":runner_utils",
4742
":common",
48-
"//executorch/backends/arm:tosa_mapping",
49-
"//executorch/backends/arm:tosa_specification",
50-
"//executorch/backends/arm/quantizer:arm_quantizer",
43+
"//executorch/backends/xnnpack/test/tester:tester",
5144
"//executorch/backends/arm:arm_partitioner",
45+
"//executorch/backends/arm/quantizer:arm_quantizer",
46+
"//executorch/backends/arm:tosa_mapping",
5247
"//executorch/devtools/backend_debug:delegation_info",
5348
"fbsource//third-party/pypi/tabulate:tabulate",
5449
]

backends/arm/test/common.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from datetime import datetime
1111

1212
from pathlib import Path
13-
from typing import Any
13+
from typing import Any, Optional
1414

1515
import pytest
1616
from executorch.backends.arm.arm_backend import ArmCompileSpecBuilder
@@ -91,63 +91,96 @@ def get_tosa_compile_spec_unbuilt(
9191

9292

9393
def get_u55_compile_spec(
94-
custom_path=None,
94+
macs: int = 128,
95+
system_config: str = "Ethos_U55_High_End_Embedded",
96+
memory_mode: str = "Shared_Sram",
97+
extra_flags: str = "--debug-force-regor --output-format=raw",
98+
custom_path: Optional[str] = None,
9599
) -> list[CompileSpec]:
96100
"""
97-
Default compile spec for Ethos-U55 tests.
101+
Compile spec for Ethos-U55.
98102
"""
99103
return get_u55_compile_spec_unbuilt(
104+
macs=macs,
105+
system_config=system_config,
106+
memory_mode=memory_mode,
107+
extra_flags=extra_flags,
100108
custom_path=custom_path,
101109
).build()
102110

103111

104112
def get_u85_compile_spec(
113+
macs: int = 128,
114+
system_config="Ethos_U85_SYS_DRAM_Mid",
115+
memory_mode="Shared_Sram",
116+
extra_flags="--output-format=raw",
105117
custom_path=None,
106118
) -> list[CompileSpec]:
107119
"""
108-
Default compile spec for Ethos-U85 tests.
120+
Compile spec for Ethos-U85.
109121
"""
110122
return get_u85_compile_spec_unbuilt( # type: ignore[attr-defined]
123+
macs=macs,
124+
system_config=system_config,
125+
memory_mode=memory_mode,
126+
extra_flags=extra_flags,
111127
custom_path=custom_path,
112128
).build()
113129

114130

115131
def get_u55_compile_spec_unbuilt(
116-
custom_path=None,
132+
macs: int,
133+
system_config: str,
134+
memory_mode: str,
135+
extra_flags: str,
136+
custom_path: Optional[str],
117137
) -> ArmCompileSpecBuilder:
118138
"""Get the ArmCompileSpecBuilder for the Ethos-U55 tests, to modify
119139
the compile spec before calling .build() to finalize it.
120140
"""
121141
artifact_path = custom_path or tempfile.mkdtemp(prefix="arm_u55_")
122142
if not os.path.exists(artifact_path):
123143
os.makedirs(artifact_path, exist_ok=True)
144+
145+
# https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela/-/blob/main/OPTIONS.md
146+
assert macs in [32, 64, 128, 256], "Unsupported MACs value"
147+
124148
compile_spec = (
125149
ArmCompileSpecBuilder()
126150
.ethosu_compile_spec(
127-
"ethos-u55-128",
128-
system_config="Ethos_U55_High_End_Embedded",
129-
memory_mode="Shared_Sram",
130-
extra_flags="--debug-force-regor --output-format=raw",
151+
f"ethos-u55-{macs}",
152+
system_config=system_config,
153+
memory_mode=memory_mode,
154+
extra_flags=extra_flags,
131155
)
132156
.dump_intermediate_artifacts_to(artifact_path)
133157
)
134158
return compile_spec
135159

136160

137161
def get_u85_compile_spec_unbuilt(
138-
custom_path=None,
162+
macs: int,
163+
system_config: str,
164+
memory_mode: str,
165+
extra_flags: str,
166+
custom_path: Optional[str],
139167
) -> list[CompileSpec]:
140168
"""Get the ArmCompileSpecBuilder for the Ethos-U85 tests, to modify
141169
the compile spec before calling .build() to finalize it.
142170
"""
143171
artifact_path = custom_path or tempfile.mkdtemp(prefix="arm_u85_")
172+
if not os.path.exists(artifact_path):
173+
os.makedirs(artifact_path, exist_ok=True)
174+
175+
assert macs in [128, 256, 512, 1024, 2048], "Unsupported MACs value"
176+
144177
compile_spec = (
145178
ArmCompileSpecBuilder()
146179
.ethosu_compile_spec(
147-
"ethos-u85-128",
148-
system_config="Ethos_U85_SYS_DRAM_Mid",
149-
memory_mode="Shared_Sram",
150-
extra_flags="--output-format=raw",
180+
f"ethos-u85-{macs}",
181+
system_config=system_config,
182+
memory_mode=memory_mode,
183+
extra_flags=extra_flags,
151184
)
152185
.dump_intermediate_artifacts_to(artifact_path)
153186
)

backends/arm/test/passes/test_rescale_pass.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from executorch.backends.arm.test import common, conftest
1414
from executorch.backends.arm.test.tester.arm_tester import ArmTester
1515
from parameterized import parameterized
16-
from torch.testing._internal import optests
1716

1817

1918
def test_rescale_op():
@@ -64,7 +63,7 @@ def test_nonzero_zp_for_int32():
6463
),
6564
]
6665
for sample_input in sample_inputs:
67-
with pytest.raises(optests.generate_tests.OpCheckError):
66+
with pytest.raises(Exception, match="opcheck"):
6867
torch.library.opcheck(torch.ops.tosa._rescale, sample_input)
6968

7069

@@ -87,7 +86,7 @@ def test_zp_outside_range():
8786
),
8887
]
8988
for sample_input in sample_inputs:
90-
with pytest.raises(optests.generate_tests.OpCheckError):
89+
with pytest.raises(Exception, match="opcheck"):
9190
torch.library.opcheck(torch.ops.tosa._rescale, sample_input)
9291

9392

0 commit comments

Comments
 (0)