Skip to content

Commit 29f8ef3

Browse files
author
pytorchbot
committed
2024-09-26 nightly release (dd8d5be)
1 parent e4919b2 commit 29f8ef3

File tree

31 files changed

+1007
-225
lines changed

31 files changed

+1007
-225
lines changed

backends/arm/test/common.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ def is_option_enabled(option: str, fail_if_not_enabled: bool = False) -> bool:
8686
return False
8787

8888

89+
def maybe_get_tosa_collate_path() -> str | None:
90+
"""
91+
Checks the environment variable TOSA_TESTCASES_BASE_PATH and returns the
92+
path to the where to store the current tests if it is set.
93+
"""
94+
tosa_test_base = os.environ.get("TOSA_TESTCASES_BASE_PATH")
95+
if tosa_test_base:
96+
current_test = os.environ.get("PYTEST_CURRENT_TEST")
97+
#'backends/arm/test/ops/test_mean_dim.py::TestMeanDim::test_meandim_tosa_BI_0_zeros (call)'
98+
test_class = current_test.split("::")[1]
99+
test_name = current_test.split("::")[-1].split(" ")[0]
100+
if "BI" in test_name:
101+
tosa_test_base = os.path.join(tosa_test_base, "tosa-bi")
102+
elif "MI" in test_name:
103+
tosa_test_base = os.path.join(tosa_test_base, "tosa-mi")
104+
else:
105+
tosa_test_base = os.path.join(tosa_test_base, "other")
106+
107+
return os.path.join(tosa_test_base, test_class, test_name)
108+
109+
return None
110+
111+
89112
def get_tosa_compile_spec(
90113
permute_memory_to_nhwc=True, custom_path=None
91114
) -> list[CompileSpec]:
@@ -101,7 +124,13 @@ def get_tosa_compile_spec_unbuilt(
101124
"""Get the ArmCompileSpecBuilder for the default TOSA tests, to modify
102125
the compile spec before calling .build() to finalize it.
103126
"""
104-
intermediate_path = custom_path or tempfile.mkdtemp(prefix="arm_tosa_")
127+
if not custom_path:
128+
intermediate_path = maybe_get_tosa_collate_path() or tempfile.mkdtemp(
129+
prefix="arm_tosa_"
130+
)
131+
else:
132+
intermediate_path = custom_path
133+
105134
if not os.path.exists(intermediate_path):
106135
os.makedirs(intermediate_path, exist_ok=True)
107136
compile_spec_builder = (

backends/arm/test/misc/test_debug_feats.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import logging
88
import os
9+
import shutil
910
import tempfile
1011
import unittest
1112

@@ -149,3 +150,39 @@ def test_dump_ops_and_dtypes(self):
149150
.dump_operator_distribution()
150151
)
151152
# Just test that there are no execeptions.
153+
154+
155+
class TestCollateTosaTests(unittest.TestCase):
156+
"""Tests the collation of TOSA tests through setting the environment variable TOSA_TESTCASE_BASE_PATH."""
157+
158+
def test_collate_tosa_BI_tests(self):
159+
# Set the environment variable to trigger the collation of TOSA tests
160+
os.environ["TOSA_TESTCASES_BASE_PATH"] = "test_collate_tosa_tests"
161+
# Clear out the directory
162+
163+
model = Linear(20, 30)
164+
(
165+
ArmTester(
166+
model,
167+
example_inputs=model.get_inputs(),
168+
compile_spec=common.get_tosa_compile_spec(),
169+
)
170+
.quantize()
171+
.export()
172+
.to_edge()
173+
.partition()
174+
.to_executorch()
175+
)
176+
# test that the output directory is created and contains the expected files
177+
assert os.path.exists(
178+
"test_collate_tosa_tests/tosa-bi/TestCollateTosaTests/test_collate_tosa_BI_tests"
179+
)
180+
assert os.path.exists(
181+
"test_collate_tosa_tests/tosa-bi/TestCollateTosaTests/test_collate_tosa_BI_tests/output_tag8.tosa"
182+
)
183+
assert os.path.exists(
184+
"test_collate_tosa_tests/tosa-bi/TestCollateTosaTests/test_collate_tosa_BI_tests/desc_tag8.json"
185+
)
186+
187+
os.environ.pop("TOSA_TESTCASES_BASE_PATH")
188+
shutil.rmtree("test_collate_tosa_tests", ignore_errors=True)

backends/cadence/CMakeLists.txt

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if(NOT EXECUTORCH_ROOT)
2020
endif()
2121

2222
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
23-
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
2423

2524
# Let files say "include <executorch/path/to/header.h>".
2625
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
@@ -30,54 +29,6 @@ if(EXECUTORCH_NNLIB_OPT)
3029
set(TARGET_DIR hifi)
3130
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/third-party/nnlib)
3231
endif()
33-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
34-
35-
# Source root directory for executorch.
36-
if(NOT EXECUTORCH_ROOT)
37-
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
38-
endif()
39-
40-
if(NOT PYTHON_EXECUTABLE)
41-
resolve_python_executable()
42-
endif()
43-
44-
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
45-
46-
# Find prebuilt libraries. executorch package should contain portable_ops_lib,
47-
# etdump, bundled_program.
48-
find_package(executorch CONFIG REQUIRED)
49-
target_link_options_shared_lib(executorch)
50-
target_link_options_shared_lib(portable_ops_lib)
51-
52-
target_include_directories(executorch INTERFACE ${_common_include_directories})
53-
54-
find_package(
55-
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party
56-
)
57-
58-
add_executable(cadence_runner cadence_runner/cadence_runner.cpp)
59-
target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED)
6032

6133
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/operators)
6234
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/kernels)
63-
64-
target_include_directories(
65-
etdump INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../../sdk/include
66-
${EXECUTORCH_ROOT}/third-party/flatcc/include
67-
)
68-
69-
target_include_directories(
70-
cadence_runner PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR}
71-
${_common_include_directories}
72-
)
73-
74-
target_link_libraries(
75-
cadence_runner
76-
executorch
77-
gflags
78-
etdump
79-
extension_data_loader
80-
bundled_program
81-
cadence_ops_lib
82-
flatccrt
83-
)

backends/cadence/build_cadence_xtensa.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,19 @@ else
6565
-DEXECUTORCH_BUILD_HOST_TARGETS=ON \
6666
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
6767
-DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
68-
-DEXECUTORCH_BUILD_CADENCE=OFF \
68+
-DEXECUTORCH_BUILD_CPUINFO=OFF \
69+
-DEXECUTORCH_BUILD_FLATC=OFF \
70+
-DEXECUTORCH_BUILD_CADENCE=ON \
6971
-DFLATC_EXECUTABLE="$(which flatc)" \
72+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
7073
-DEXECUTORCH_ENABLE_LOGGING=ON \
7174
-DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \
7275
-DEXECUTORCH_USE_DL=OFF \
7376
-DBUILD_EXECUTORCH_PORTABLE_OPS=ON \
7477
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=OFF \
7578
-DPYTHON_EXECUTABLE=python3 \
7679
-DEXECUTORCH_NNLIB_OPT=ON \
77-
-DEXECUTORCH_BUILD_GFLAGS=ON \
7880
-DHAVE_FNMATCH_H=OFF \
79-
-DEXECUTORCH_ENABLE_EVENT_TRACER=OFF \
80-
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
81-
-DEXECUTORCH_BUILD_CPUINFO=OFF \
8281
-Bcmake-out
8382
cmake --build cmake-out --target install --config Release -j16
8483
fi
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
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+
# Set the minimum required version of CMake for this project.
8+
cmake_minimum_required(VERSION 3.10)
9+
10+
if(NOT CMAKE_CXX_STANDARD)
11+
set(CMAKE_CXX_STANDARD 17)
12+
endif()
13+
14+
# Set the project name.
15+
project(cadence_backend)
16+
17+
# Source root directory for executorch.
18+
if(NOT EXECUTORCH_ROOT)
19+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
20+
endif()
21+
22+
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
23+
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
24+
25+
# Let files say "include <executorch/path/to/header.h>".
26+
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
27+
set(TARGET_DIR reference)
28+
29+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
30+
31+
if(NOT PYTHON_EXECUTABLE)
32+
resolve_python_executable()
33+
endif()
34+
35+
# Find prebuilt libraries. executorch package should contain portable_ops_lib,
36+
# etdump, bundled_program.
37+
find_package(executorch CONFIG REQUIRED)
38+
target_link_options_shared_lib(executorch)
39+
target_link_options_shared_lib(portable_ops_lib)
40+
41+
target_include_directories(executorch INTERFACE ${_common_include_directories})
42+
43+
find_package(
44+
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party
45+
)
46+
47+
add_executable(cadence_runner cadence_runner.cpp)
48+
target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED)
49+
50+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/operators)
51+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/kernels)
52+
53+
target_include_directories(
54+
etdump INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../../../devtools/include
55+
${EXECUTORCH_ROOT}/third-party/flatcc/include
56+
)
57+
58+
target_include_directories(
59+
cadence_runner PUBLIC ${ROOT_DIR}/../.. ${CMAKE_BINARY_DIR}
60+
${_common_include_directories}
61+
)
62+
63+
target_link_libraries(
64+
cadence_runner
65+
executorch
66+
gflags
67+
etdump
68+
extension_data_loader
69+
bundled_program
70+
cadence_ops_lib
71+
flatccrt
72+
)

backends/cadence/build_cadence_runner.sh renamed to backends/cadence/cadence_runner/build_cadence_runner.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set -euo pipefail
1212
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
1313
readonly SCRIPT_DIR
1414

15-
readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../.."
15+
readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../../.."
1616

1717
# Allow overriding the number of build jobs. Default to 9.
1818
export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-9}"
@@ -32,8 +32,9 @@ main() {
3232
-DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
3333
-DEXECUTORCH_BUILD_CPUINFO=OFF \
3434
-DEXECUTORCH_ENABLE_LOGGING=ON \
35-
-Bcmake-out .
36-
cmake --build cmake-out --target install --config Release
35+
-DEXECUTORCH_NNLIB_OPT=OFF \
36+
-Bcmake-out
37+
cmake --build cmake-out --target install --config Release -j16
3738

3839
local example_dir=backends/cadence
3940
local build_dir="cmake-out/${example_dir}"
@@ -43,7 +44,7 @@ main() {
4344
-DCMAKE_BUILD_TYPE=Release \
4445
-B"${build_dir}" \
4546
"${example_dir}"
46-
cmake --build "${build_dir}" --config Release
47+
cmake --build "${build_dir}" --config Release -j16
4748

4849
local runner="${PWD}/${build_dir}/cadence_runner"
4950
if [[ ! -f "${runner}" ]]; then

backends/cadence/hifi/kernels/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ add_library(
1010
kernels.cpp
1111
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/matmul_asym8uxasym8u_asym8u.cpp
1212
)
13+
# Let files say "include <executorch/path/to/header.h>".
14+
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
1315

1416
target_include_directories(
1517
cadence_kernels
@@ -19,6 +21,7 @@ target_include_directories(
1921
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/include/nnlib
2022
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/include
2123
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/algo/ndsp/hifi4/include/
24+
${_common_include_directories}
2225
)
2326

2427
target_link_libraries(cadence_kernels PRIVATE xa_nnlib)

backends/cadence/hifi/operators/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(_aten_ops__srcs
2828
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/matmul_ops_util.cpp"
2929
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/reduce_util.cpp"
3030
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/repeat_util.cpp"
31+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/slice_util.cpp"
3132
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_add.cpp"
3233
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_bmm.cpp"
3334
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_cat.cpp"

backends/cadence/reference/kernels/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
# lint_cmake: -linelength
88
add_library(cadence_kernels kernels.cpp)
99

10-
target_include_directories(cadence_kernels PUBLIC .)
10+
# Let files say "include <executorch/path/to/header.h>".
11+
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
12+
13+
target_include_directories(cadence_kernels PUBLIC .
14+
${_common_include_directories}
15+
)

backends/cadence/reference/kernels/kernels.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <math.h>
1010
#include <algorithm>
1111
#include <cstring>
12+
#include <limits>
1213
#include <numeric>
1314

1415
namespace impl {
@@ -17,8 +18,7 @@ namespace kernels {
1718

1819
// Quantize a fp32 value to an int8_t/uint8_t value
1920
template <typename T>
20-
__attribute__((always_inline)) T
21-
quantize(const float x, float scale, int32_t zero_point) {
21+
T quantize(const float x, float scale, int32_t zero_point) {
2222
constexpr float min_val = std::numeric_limits<T>::min();
2323
constexpr float max_val = std::numeric_limits<T>::max();
2424
float tmp = roundf(x * scale + zero_point);
@@ -40,8 +40,7 @@ void quantize(
4040

4141
// Dequantize an int8_t/uint8_t value to an fp32 value
4242
template <typename T>
43-
__attribute__((always_inline)) float
44-
dequantize(const T x, float scale, int32_t zero_point) {
43+
float dequantize(const T x, float scale, int32_t zero_point) {
4544
return scale * (x - zero_point);
4645
}
4746

@@ -60,9 +59,8 @@ void dequantize(
6059

6160
// explicit template instantiation
6261

63-
#define typed_quantize_val(dtype) \
64-
template __attribute__((always_inline)) dtype quantize( \
65-
const float x, float inv_scale, int32_t zero_point);
62+
#define typed_quantize_val(dtype) \
63+
template dtype quantize(const float x, float inv_scale, int32_t zero_point);
6664
typed_quantize_val(int8_t);
6765
typed_quantize_val(uint8_t);
6866
typed_quantize_val(int16_t);
@@ -82,9 +80,8 @@ typed_quantize_vec(int16_t);
8280
typed_quantize_vec(int32_t);
8381
#undef typed_quantize_vec
8482

85-
#define typed_dequantize_val(dtype) \
86-
template __attribute__((always_inline)) float dequantize( \
87-
const dtype x, float scale, int32_t zero_point);
83+
#define typed_dequantize_val(dtype) \
84+
template float dequantize(const dtype x, float scale, int32_t zero_point);
8885
typed_dequantize_val(int8_t);
8986
typed_dequantize_val(uint8_t);
9087
typed_dequantize_val(int16_t);

0 commit comments

Comments
 (0)