Skip to content

Commit c85bd80

Browse files
authored
Merge branch 'main' into Arm-backend-Fix-buck2-files-after-moving-TOSA-partitioner
2 parents e39f0d4 + 01258d2 commit c85bd80

File tree

7 files changed

+92
-39
lines changed

7 files changed

+92
-39
lines changed

backends/arm/operator_support/to_copy_support.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
logger = logging.getLogger(__name__)
2222

23+
SupportedTypeDict = dict[torch.dtype, list[torch.dtype]]
24+
2325

2426
@register_tosa_support_check
2527
class ToCopySupported(SupportedTOSAOperatorCheck):
@@ -33,8 +35,6 @@ class ToCopySupported(SupportedTOSAOperatorCheck):
3335
TosaSpecification.create_from_string("TOSA-1.0+FP"),
3436
]
3537

36-
SupportedTypeDict = dict[torch.dtype, list[torch.dtype]]
37-
3838
@staticmethod
3939
def _merge_supported_types(
4040
# pyre-ignore[11]
@@ -53,11 +53,22 @@ def _merge_supported_types(
5353
torch.int8: [torch.bool, torch.int16, torch.int32],
5454
torch.int16: [torch.bool, torch.int8, torch.int32],
5555
torch.int32: [torch.bool, torch.int8, torch.int16],
56+
torch.int64: [torch.bool, torch.int8, torch.int16, torch.int32],
5657
}
5758
SUPPORTED_FLOAT_TYPES: SupportedTypeDict = {
5859
torch.int8: [torch.float16, torch.bfloat16, torch.float32],
5960
torch.int16: [torch.float16, torch.bfloat16, torch.float32],
6061
torch.int32: [torch.float16, torch.bfloat16, torch.float32],
62+
# INT64 inputs to casts *should* be ok, since they should be rejected by
63+
# CheckInt64InputsAndOutputs if the cast can't be done AOT.
64+
torch.int64: [
65+
torch.int8,
66+
torch.int16,
67+
torch.int32,
68+
torch.float16,
69+
torch.bfloat16,
70+
torch.float32,
71+
],
6172
torch.bfloat16: [torch.int8, torch.int16, torch.int32, torch.float32],
6273
torch.float16: [torch.int8, torch.int16, torch.int32, torch.float32],
6374
torch.float32: [
@@ -71,22 +82,20 @@ def _merge_supported_types(
7182
ALL_SUPPORTED_TYPES = _merge_supported_types(
7283
SUPPORTED_INT_TYPES, SUPPORTED_FLOAT_TYPES
7384
)
74-
POSSIBLE_TYPE_CONVERSIONS = {torch.int64: torch.int32}
7585

7686
def is_node_tosa_supported(
7787
self, node: fx.Node, tosa_spec: TosaSpecification
7888
) -> bool:
79-
supported_dtypes = (
80-
self.ALL_SUPPORTED_TYPES
81-
if tosa_spec.support_float()
82-
else self.SUPPORTED_INT_TYPES
83-
)
84-
# Take into account possible type conversions
85-
supported_dtypes.update(
86-
(k, supported_dtypes[v])
87-
for k, v in self.POSSIBLE_TYPE_CONVERSIONS.items()
88-
if v in supported_dtypes
89-
)
89+
90+
supported_dtypes: SupportedTypeDict = {}
91+
if tosa_spec.support_integer():
92+
supported_dtypes = self._merge_supported_types(
93+
self.SUPPORTED_INT_TYPES, supported_dtypes
94+
)
95+
if tosa_spec.support_float():
96+
supported_dtypes = self._merge_supported_types(
97+
self.SUPPORTED_FLOAT_TYPES, supported_dtypes
98+
)
9099

91100
if len(node.all_input_nodes) != 1:
92101
self.reporter.report_reject(
@@ -156,7 +165,7 @@ def is_node_tosa_supported(
156165
if "dim_order" in node.kwargs:
157166
dim_order = node.kwargs["dim_order"]
158167
# pyre-ignore[6]
159-
if dim_order != list(range(len(dim_order))): # type: ignore[arg-type]
168+
if dim_order is not None and dim_order != list(range(len(dim_order))): # type: ignore[arg-type]
160169
self.reporter.report_reject(
161170
node,
162171
(

backends/arm/scripts/run_fvp.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ if [[ ${target} == *"ethos-u55"* ]]; then
9292
-C mps3_board.uart0.shutdown_on_eot=1 \
9393
-a "${elf_file}" \
9494
${data_file} \
95-
--timelimit ${timeout} 2>&1 | tee ${log_file} || true # seconds
95+
--timelimit ${timeout} 2>&1 | sed 's/\r$//' | tee ${log_file} || true # seconds
9696
echo "[${BASH_SOURCE[0]}] Simulation complete, $?"
9797
elif [[ ${target} == *"ethos-u85"* ]]; then
9898
${nobuf} ${fvp_model} \
@@ -104,13 +104,28 @@ elif [[ ${target} == *"ethos-u85"* ]]; then
104104
-C mps4_board.uart0.shutdown_on_eot=1 \
105105
-a "${elf_file}" \
106106
${data_file} \
107-
--timelimit ${timeout} 2>&1 | tee ${log_file} || true # seconds
107+
--timelimit ${timeout} 2>&1 | sed 's/\r$//' | tee ${log_file} || true # seconds
108108
echo "[${BASH_SOURCE[0]}] Simulation complete, $?"
109109
else
110110
echo "Running ${elf_file} for ${target} is not supported"
111111
exit 1
112112
fi
113113

114+
echo "Checking for a etdump in log"
115+
! grep "#\[RUN THIS\]" ${log_file} >/dev/null
116+
if [ $? != 0 ]; then
117+
echo "Found ETDump in log!"
118+
echo "#!/bin/sh" > etdump_script.sh
119+
sed -n '/^#\[RUN THIS\]$/,/^#\[END\]$/p' ${log_file} >> etdump_script.sh
120+
# You can run etdump_script.sh if you do
121+
# $ chmod a+x etdump_script.sh
122+
# $ ./etdump_script.sh
123+
# But lets not trust the script as a bad patch would run bad code on your machine
124+
grep ">etdump.bin" etdump_script.sh | cut -d\" -f2- | cut -d\" -f1 >etdump.base64
125+
base64 -d etdump.base64 >etdump.bin
126+
python3 -m devtools.inspector.inspector_cli --etdump_path etdump.bin --source_time_scale cycles --target_time_scale cycles
127+
fi
128+
114129
echo "Checking for problems in log:"
115130
! grep -E "^(F|E|\\[critical\\]|Hard fault.|Info: Simulation is stopping. Reason: CPU time has been exceeded.).*$" ${log_file}
116131
if [ $? != 0 ]; then

backends/arm/test/models/stable_diffusion/test_T5EncoderModel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ class TestT5EncoderModel(unittest.TestCase):
3333
# .to_executorch step, i.e. after Arm partitioner.
3434
ops_after_partitioner = {
3535
"executorch_exir_dialects_edge__ops_aten__to_copy_default": 2,
36+
"executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default": 1,
3637
"executorch_exir_dialects_edge__ops_aten_view_copy_default": 1,
37-
"torch.ops.higher_order.executorch_call_delegate": 2,
38+
"torch.ops.higher_order.executorch_call_delegate": 3,
3839
}
3940

4041
def _prepare_inputs(

backends/arm/test/ops/test_to_copy.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ def test_copy_tosa_FP(test_data: Tuple):
7070
aten_op=[],
7171
exir_op=[],
7272
)
73+
# int to int cast is not supported in TOSA+FP profile
74+
if not new_dtype.is_floating_point and not torch.is_floating_point(test_tensor):
75+
pipeline.change_args(
76+
"check_count.exir",
77+
{
78+
"torch.ops.higher_order.executorch_call_delegate": 0,
79+
"executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default": 1,
80+
},
81+
)
82+
pipeline.pop_stage("run_method_and_compare_outputs")
7383
pipeline.run()
7484

7585

@@ -84,6 +94,15 @@ def test_copy_vgf_FP(test_data: Tuple):
8494
exir_op=[],
8595
tosa_version="TOSA-1.0+FP",
8696
)
97+
# int to int cast is not supported in TOSA+FP profile
98+
if not new_dtype.is_floating_point and not torch.is_floating_point(test_tensor):
99+
pipeline.change_args(
100+
"check_count.exir",
101+
{
102+
"torch.ops.higher_order.executorch_call_delegate": 0,
103+
"executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default": 1,
104+
},
105+
)
87106
pipeline.run()
88107

89108

backends/arm/test/passes/test_convert_int64_output_ops_to_int32.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,8 @@ def forward(self, x: torch.Tensor):
3232
test_data_suite_convert = {
3333
"fp32_input": lambda: (torch.rand((1, 2, 3, 4), dtype=torch.float32), torch.int64),
3434
"fp16_input": lambda: (torch.rand((1, 2, 3, 4), dtype=torch.float16), torch.int64),
35-
"int16_input": lambda: (
36-
torch.randint(-127, 128, (1, 2, 3, 4), dtype=torch.int16),
37-
torch.int64,
38-
),
39-
"int8_input": lambda: (
40-
torch.randint(-127, 128, (1, 2, 3, 4), dtype=torch.int8),
41-
torch.int64,
42-
),
4335
}
4436

45-
4637
test_data_suite_remove = {
4738
"int32_input": lambda: (
4839
torch.randint(-127, 128, (1, 2, 3, 4), dtype=torch.int32),
@@ -52,7 +43,7 @@ def forward(self, x: torch.Tensor):
5243

5344

5445
@common.parametrize("test_data", test_data_suite_convert)
55-
def test_convert_or_remove_casting_to_int64_covnert_tosa_FP(test_data: Tuple):
46+
def test_convert_or_remove_casting_to_int64_convert_tosa_FP(test_data: Tuple):
5647
test_tensor, target_dtype = test_data()
5748
module = CastingToInt64Model(target_dtype)
5849

examples/arm/executor_runner/arm_executor_runner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ void write_etdump(RunnerContext& ctx) {
852852
encoded_buf[encoded_len] = 0x00; // Ensure null termination
853853
ET_LOG(Info, "Writing etdump.bin [base64]");
854854
printf(
855-
"#---\necho \"%s\" | base64 -d >etdump.bin\npython3 -m devtools.inspector.inspector_cli --etdump_path etdump.bin --source_time_scale cycles --target_time_scale cycles\n#---\n",
855+
"#[RUN THIS]\necho \"%s\" | base64 -d >etdump.bin\npython3 -m devtools.inspector.inspector_cli --etdump_path etdump.bin --source_time_scale cycles --target_time_scale cycles\n#[END]\n",
856856
encoded_buf);
857857
} else {
858858
ET_LOG(

examples/arm/vgf_minimal_example.ipynb

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
"\n",
2424
"Before you begin:\n",
2525
"1. (In a clean virtual environment with a compatible Python version) Install executorch using `./install_executorch.sh`\n",
26-
"2. Install MLSDK and Tosa using `examples/arm/setup.sh --disable-ethos-u-deps --enable-mlsdk-deps (For further guidance, refer to https://docs.pytorch.org/executorch/main/tutorial-arm.html)\n",
26+
"2. Install MLSDK and Tosa using `examples/arm/setup.sh --disable-ethos-u-deps --enable-mlsdk-deps` (For further guidance, refer to https://docs.pytorch.org/executorch/main/tutorial-arm.html)\n",
2727
"3. Export vulkan environment variables and add MLSDK components to PATH and LD_LIBRARY_PATH using `examples/arm/ethos-u-scratch/setup_path.sh`\n",
2828
"\n",
2929
"With all commands executed from the base `executorch` folder.\n",
3030
"\n",
31-
"\n",
32-
"\n",
3331
"*Some scripts in this notebook produce long output logs: Configuring the 'Customizing Notebook Layout' settings to enable 'Output:scrolling' and setting 'Output:Text Line Limit' makes this more manageable*"
3432
]
3533
},
@@ -165,6 +163,17 @@
165163
"All of this happens behind the scenes in `to_edge_transform_and_lower`. Printing the graph module shows that what is left in the graph is two quantization nodes for `x` and `y` going into an `executorch_call_delegate` node, followed by a dequantization node."
166164
]
167165
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": null,
169+
"metadata": {},
170+
"outputs": [],
171+
"source": [
172+
"%%bash\n",
173+
"# Ensure the vulkan environment variables and MLSDK components are available on $PATH\n",
174+
"source ethos-u-scratch/setup_path.sh"
175+
]
176+
},
168177
{
169178
"cell_type": "code",
170179
"execution_count": null,
@@ -220,10 +229,21 @@
220229
"\n",
221230
"\n",
222231
"After the AOT compilation flow is done, we need to build the executor_runner target. For this example the generic version will be used.\n",
223-
"To do this, please ensure the following commands are executed before moving onto the next step.\n",
232+
"To do this, please ensure the following commands are executed before moving onto the next step."
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"execution_count": null,
238+
"metadata": {},
239+
"outputs": [],
240+
"source": [
241+
"%%bash\n",
242+
"# Ensure the vulkan environment variables and MLSDK components are available on $PATH\n",
243+
"source ethos-u-scratch/setup_path.sh\n",
224244
"\n",
225-
"Clean and configure the CMake build system. Compiled programs will appear in the executorch/cmake-out directory we create here.\n",
226-
"```\n",
245+
"# Compiled programs will appear in the executorch/cmake-out directory we create here.\n",
246+
"# Build example executor runner application to examples/arm/vgf_minimal_example\n",
227247
"cmake \\\n",
228248
" -DCMAKE_INSTALL_PREFIX=cmake-out \\\n",
229249
" -DCMAKE_BUILD_TYPE=Debug \\\n",
@@ -237,11 +257,9 @@
237257
" -DEXECUTORCH_BUILD_VGF=ON \\\n",
238258
" -DEXECUTORCH_ENABLE_LOGGING=ON \\\n",
239259
" -DPYTHON_EXECUTABLE=python \\\n",
240-
" -Bcmake-out .\n",
241-
"```\n",
260+
" -B../../cmake-out-vkml ../..\n",
242261
"\n",
243-
"Build the executor_runner target\n",
244-
"`cmake --build cmake-out --target executor_runner`\n"
262+
"cmake --build ../../cmake-out-vkml --target executor_runner"
245263
]
246264
},
247265
{

0 commit comments

Comments
 (0)