Skip to content

Commit 337c463

Browse files
committed
Update on "Arm backend: Add 16A8W support and test for mul operation"
Add 16A8W quantization support and test for the mul operation in ExecutorTorch ARM backend. This follows the pattern established for linear operations, extending int16 support to mul operations. Changes: - Add INT16 dtype validation support in op_mul.py - Add test_mul_tensor_16a8w_tosa_INT test function - Enable test_mul.py in test targets configuration The 16A8W configuration uses 16-bit activations with 8-bit weights, enabling higher precision for activations while maintaining weight efficiency. Differential Revision: [D80510628](https://our.internmc.facebook.com/intern/diff/D80510628/) cc digantdesai freddan80 per zingo oscarandersson8218 [ghstack-poisoned]
2 parents 222f96f + 4d892f9 commit 337c463

File tree

18 files changed

+204
-144
lines changed

18 files changed

+204
-144
lines changed

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,7 @@ if(EXECUTORCH_BUILD_KERNELS_TORCHAO)
699699
${EXECUTORCH_ROOT}/backends/xnnpack/third-party/pthreadpool/include
700700
${EXECUTORCH_ROOT}/backends/xnnpack/third-party/cpuinfo/include
701701
)
702-
add_subdirectory(
703-
${CMAKE_CURRENT_SOURCE_DIR}/third-party/ao/torchao/experimental
704-
)
702+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/ao/torchao/csrc/cpu)
705703
unset(EXECUTORCH_INCLUDE_DIRS)
706704

707705
executorch_target_link_options_shared_lib(torchao_ops_executorch)

backends/arm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For more information on TOSA see https://www.mlplatform.org/tosa/tosa_spec.html
3434
## Layout of key components
3535

3636
Export:
37-
* `tosa_backend.py` - The TOSA conversion flow all other backends rely on.
37+
* `tosa/backend.py` - The TOSA conversion flow all other backends rely on.
3838
* `ethosu/backend.py` - Main entrypoint for the EthosUBackend.
3939
* `vgf_backend.py` - Main entrypoint for VgfBackend.
4040
* For more information see the section on [Arm Backend Architecture](#arm-backend-architecture).

backends/arm/TARGETS

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ python_library(
3737
python_library(
3838
name = "arm_partitioner",
3939
srcs = [
40-
"tosa_backend.py",
41-
"tosa_partitioner.py",
40+
"tosa/backend.py",
41+
"tosa/partitioner.py",
4242
"vgf_backend.py",
4343
"vgf_partitioner.py",
4444
],
4545
deps = [
4646
":arm_backend",
4747
":constants",
48+
"//executorch/backends/arm/debug:schema",
4849
"//executorch/backends/arm/operator_support:operator_support",
4950
"//executorch/backends/arm/_passes:passes",
5051
"//executorch/exir:lib",
@@ -76,9 +77,9 @@ python_library(
7677
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/tosa:tosa",
7778
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/tosa:tosa",
7879
"//executorch/backends/arm/operators:node_visitor",
79-
"//executorch/backends/arm:tosa_mapping",
80-
"//executorch/backends/arm:tosa_quant_utils",
81-
"//executorch/backends/arm:tosa_utils",
80+
"//executorch/backends/arm/tosa:mapping",
81+
"//executorch/backends/arm/tosa:quant_utils",
82+
"//executorch/backends/arm/tosa:utils",
8283
"//executorch/exir:lib",
8384
],
8485
)
@@ -91,54 +92,6 @@ python_library(
9192
"fbsource//third-party/pypi/ethos-u-vela:ethos-u-vela",
9293
],
9394
)
94-
python_library(
95-
name = "tosa_mapping",
96-
srcs = [
97-
"tosa_mapping.py",
98-
],
99-
deps = [
100-
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/serializer:serializer",
101-
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/serializer:serializer",
102-
"//caffe2:torch",
103-
],
104-
)
105-
python_library(
106-
name = "tosa_quant_utils",
107-
srcs = [
108-
"tosa_quant_utils.py",
109-
],
110-
deps = [
111-
"fbsource//third-party/pypi/numpy:numpy",
112-
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/serializer:serializer",
113-
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/serializer:serializer",
114-
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/tosa:tosa",
115-
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/tosa:tosa",
116-
":constants",
117-
":tosa_mapping",
118-
"//executorch/exir/dialects:lib",
119-
],
120-
)
121-
python_library(
122-
name = "tosa_specification",
123-
srcs = [
124-
"tosa_specification.py",
125-
],
126-
deps = [
127-
"fbsource//third-party/pypi/packaging:packaging",
128-
"//executorch/exir/backend:compile_spec_schema",
129-
],
130-
)
131-
python_library(
132-
name = "tosa_utils",
133-
srcs = [
134-
"tosa_utils.py",
135-
],
136-
deps = [
137-
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/serializer:serializer",
138-
":tosa_quant_utils",
139-
"//executorch/backends/arm/operators:node_visitor",
140-
],
141-
)
14295
python_library(
14396
name = "arm_model_evaluator",
14497
srcs = [

backends/arm/_passes/TARGETS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ python_library(
66
deps = [
77
"//executorch/backends/arm:common",
88
"//executorch/backends/arm:constants",
9-
"//executorch/backends/arm:tosa_quant_utils",
10-
"//executorch/backends/arm:tosa_utils",
9+
"//executorch/backends/arm/tosa:quant_utils",
10+
"//executorch/backends/arm/tosa:utils",
1111
"//executorch/backends/arm/tosa/dialect:lib",
1212
"//executorch/backends/transforms:fuse_view_copy",
1313
"//executorch/backends/transforms:remove_getitem_op",

backends/arm/debug/TARGETS

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# @noautodeps
2+
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
3+
4+
python_library(
5+
name = "schema",
6+
srcs = [
7+
"__init__.py",
8+
"schema.py",
9+
],
10+
deps = [
11+
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/serializer:serializer",
12+
"//caffe2:torch",
13+
],
14+
)

backends/arm/operator_support/TARGETS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ python_library(
66
deps = [
77
"//executorch/backends/arm:constants",
88
"//executorch/backends/arm/_passes:passes",
9-
"//executorch/backends/arm:tosa_specification",
9+
"//executorch/backends/arm/tosa:tosa",
1010
"//executorch/backends/transforms:remove_getitem_op",
1111
"//executorch/backends/xnnpack/_passes:xnnpack_passes",
1212
"//executorch/exir:lib",

backends/arm/operators/TARGETS

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ python_library(
55
name = "node_visitor",
66
srcs = ["node_visitor.py"],
77
deps = [
8-
"//executorch/backends/arm:tosa_mapping",
9-
"//executorch/backends/arm:tosa_specification",
8+
"//executorch/backends/arm/debug:schema",
9+
"//executorch/backends/arm/tosa:mapping",
10+
"//executorch/backends/arm/tosa:tosa",
1011
],
1112
)
1213

@@ -23,9 +24,9 @@ python_library(
2324
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/tosa:tosa",
2425
":node_visitor",
2526
":operator_validation_utils",
26-
"//executorch/backends/arm:tosa_mapping",
27-
"//executorch/backends/arm:tosa_quant_utils",
28-
"//executorch/backends/arm:tosa_utils",
27+
"//executorch/backends/arm/tosa:mapping",
28+
"//executorch/backends/arm/tosa:quant_utils",
29+
"//executorch/backends/arm/tosa:utils",
2930
"//executorch/backends/arm/_passes:passes",
3031
"//executorch/exir:lib",
3132
],
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Important to check for unset variables since this script is always sourced from setup.sh
8+
set -u
9+
10+
# Check if the script is being sourced
11+
(return 0 2>/dev/null)
12+
if [[ $? -ne 0 ]]; then
13+
echo "Error: This script must be sourced."
14+
exit 1
15+
fi
16+
17+
vulkan_sdk_version="1.4.321.1"
18+
vulkan_sdk_base_dir="vulkan_sdk"
19+
20+
# MLSDK dependencies
21+
mlsdk_manifest_dir="ml-sdk-for-vulkan-manifest"
22+
vulkan_sdk_bin_dir="${vulkan_sdk_base_dir}/${vulkan_sdk_version}/${ARCH}/bin"
23+
24+
25+
if [[ "${ARCH}" == "x86_64" ]]; then
26+
# Vulkan SDK
27+
vulkan_sdk_url="https://sdk.lunarg.com/sdk/download/${vulkan_sdk_version}/linux/vulkansdk-linux-x86_64-${vulkan_sdk_version}.tar.xz"
28+
vulkan_sdk_sha256="f22a3625bd4d7a32e7a0d926ace16d5278c149e938dac63cecc00537626cbf73"
29+
30+
elif [[ "${ARCH}" == "aarch64" ]] || [[ "${ARCH}" == "arm64" ]]; then
31+
# Vulkan SDK
32+
vulkan_sdk_url="https://github.com/jakoch/vulkan-sdk-arm/releases/download/1.4.321.1/vulkansdk-ubuntu-22.04-arm-1.4.321.1.tar.xz"
33+
vulkan_sdk_sha256="c57e318d0940394d3a304034bb7ddabda788b5b0b54638e80e90f7264efe9f84"
34+
else
35+
echo "[main] Error: only x86-64 & aarch64/arm64 architecture is supported for now!"; exit 1;
36+
fi
37+
38+
function setup_vulkan_sdk() {
39+
40+
if command -v vulkaninfo > /dev/null 2>&1; then
41+
echo "[${FUNCNAME[0]}] Vulkan SDK already installed..."
42+
enable_vulkan_sdk=0
43+
return
44+
fi
45+
46+
cd "${root_dir}"
47+
48+
vulkan_sdk_tar_file="${vulkan_sdk_url##*/}"
49+
if [[ ! -e "${vulkan_sdk_tar_file}" ]]; then
50+
echo "[${FUNCNAME[0]}] Downloading Vulkan SDK - ${vulkan_sdk_url}.."
51+
curl -L --output "${vulkan_sdk_tar_file}" "${vulkan_sdk_url}"
52+
echo "${vulkan_sdk_sha256} ${vulkan_sdk_tar_file}" | sha256sum -c -
53+
rm -fr ${vulkan_sdk_base_dir}
54+
fi
55+
56+
mkdir -p ${vulkan_sdk_base_dir}
57+
tar -C ${vulkan_sdk_base_dir} -xJf "${vulkan_sdk_tar_file}"
58+
59+
vulkan_sdk_bin_path="$(cd ${vulkan_sdk_bin_dir} && pwd)"
60+
if ${vulkan_sdk_bin_path}/vulkaninfo > /dev/null 2>&1; then
61+
echo "[${FUNCNAME[0]}] Vulkan SDK OK"
62+
else
63+
echo "[${FUNCNAME[0]}] Vulkan SDK NOK - perhaps need manual install of swifthshader or mesa-vulkan driver?"
64+
exit 1
65+
fi
66+
}

backends/arm/test/TARGETS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ python_library(
3030
srcs = ["common.py"],
3131
deps = [
3232
":runner_utils",
33-
"//executorch/backends/arm:tosa_specification",
33+
"//executorch/backends/arm/tosa:tosa",
3434
"fbsource//third-party/pypi/pytest:pytest",
3535
]
3636
)
@@ -43,7 +43,7 @@ python_library(
4343
"//executorch/backends/xnnpack/test/tester:tester",
4444
"//executorch/backends/arm:ethosu_partitioner",
4545
"//executorch/backends/arm/quantizer:lib",
46-
"//executorch/backends/arm:tosa_mapping",
46+
"//executorch/backends/arm/tosa:mapping",
4747
"//executorch/devtools/backend_debug:delegation_info",
4848
"//executorch/exir/backend:operator_support",
4949
"fbsource//third-party/pypi/tabulate:tabulate",

backends/arm/tosa/TARGETS

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
2+
3+
python_library(
4+
name = "mapping",
5+
srcs = [
6+
"mapping.py",
7+
],
8+
deps = [
9+
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/serializer:serializer",
10+
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/serializer:serializer",
11+
"//caffe2:torch",
12+
":specification",
13+
],
14+
)
15+
python_library(
16+
name = "quant_utils",
17+
srcs = [
18+
"quant_utils.py",
19+
],
20+
deps = [
21+
"fbsource//third-party/pypi/numpy:numpy",
22+
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/serializer:serializer",
23+
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/serializer:serializer",
24+
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/tosa:tosa",
25+
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/tosa:tosa",
26+
"//executorch/backends/arm:constants",
27+
":mapping",
28+
"//executorch/exir/dialects:lib",
29+
],
30+
)
31+
python_library(
32+
name = "specification",
33+
srcs = [
34+
"specification.py",
35+
],
36+
deps = [
37+
"fbsource//third-party/pypi/packaging:packaging",
38+
"//executorch/exir/backend:compile_spec_schema",
39+
],
40+
)
41+
python_library(
42+
name = "utils",
43+
srcs = [
44+
"utils.py",
45+
],
46+
deps = [
47+
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/serializer:serializer",
48+
":quant_utils",
49+
"//executorch/backends/arm/operators:node_visitor",
50+
],
51+
)
52+
53+
python_library(
54+
name = "tosa",
55+
srcs = [
56+
"__init__.py",
57+
],
58+
deps = [
59+
":specification",
60+
],
61+
)

0 commit comments

Comments
 (0)