Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions backends/cadence/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ if(NOT EXECUTORCH_ROOT)
endif()

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)

# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
Expand All @@ -30,54 +29,6 @@ if(EXECUTORCH_NNLIB_OPT)
set(TARGET_DIR hifi)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/third-party/nnlib)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Source root directory for executorch.
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()

if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

set(_common_compile_options -Wno-deprecated-declarations -fPIC)

# Find prebuilt libraries. executorch package should contain portable_ops_lib,
# etdump, bundled_program.
find_package(executorch CONFIG REQUIRED)
target_link_options_shared_lib(executorch)
target_link_options_shared_lib(portable_ops_lib)

target_include_directories(executorch INTERFACE ${_common_include_directories})

find_package(
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party
)

add_executable(cadence_runner cadence_runner/cadence_runner.cpp)
target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/operators)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/kernels)

target_include_directories(
etdump INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../../sdk/include
${EXECUTORCH_ROOT}/third-party/flatcc/include
)

target_include_directories(
cadence_runner PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR}
${_common_include_directories}
)

target_link_libraries(
cadence_runner
executorch
gflags
etdump
extension_data_loader
bundled_program
cadence_ops_lib
flatccrt
)
9 changes: 4 additions & 5 deletions backends/cadence/build_cadence_xtensa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,19 @@ else
-DEXECUTORCH_BUILD_HOST_TARGETS=ON \
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
-DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
-DEXECUTORCH_BUILD_CADENCE=OFF \
-DEXECUTORCH_BUILD_CPUINFO=OFF \
-DEXECUTORCH_BUILD_FLATC=OFF \
-DEXECUTORCH_BUILD_CADENCE=ON \
-DFLATC_EXECUTABLE="$(which flatc)" \
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
-DEXECUTORCH_ENABLE_LOGGING=ON \
-DEXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON \
-DEXECUTORCH_USE_DL=OFF \
-DBUILD_EXECUTORCH_PORTABLE_OPS=ON \
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=OFF \
-DPYTHON_EXECUTABLE=python3 \
-DEXECUTORCH_NNLIB_OPT=ON \
-DEXECUTORCH_BUILD_GFLAGS=ON \
-DHAVE_FNMATCH_H=OFF \
-DEXECUTORCH_ENABLE_EVENT_TRACER=OFF \
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
-DEXECUTORCH_BUILD_CPUINFO=OFF \
-Bcmake-out
cmake --build cmake-out --target install --config Release -j16
fi
Expand Down
72 changes: 72 additions & 0 deletions backends/cadence/cadence_runner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Set the minimum required version of CMake for this project.
cmake_minimum_required(VERSION 3.10)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

# Set the project name.
project(cadence_backend)

# Source root directory for executorch.
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
endif()

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)

# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
set(TARGET_DIR reference)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

# Find prebuilt libraries. executorch package should contain portable_ops_lib,
# etdump, bundled_program.
find_package(executorch CONFIG REQUIRED)
target_link_options_shared_lib(executorch)
target_link_options_shared_lib(portable_ops_lib)

target_include_directories(executorch INTERFACE ${_common_include_directories})

find_package(
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party
)

add_executable(cadence_runner cadence_runner.cpp)
target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/operators)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/kernels)

target_include_directories(
etdump INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../../../devtools/include
${EXECUTORCH_ROOT}/third-party/flatcc/include
)

target_include_directories(
cadence_runner PUBLIC ${ROOT_DIR}/../.. ${CMAKE_BINARY_DIR}
${_common_include_directories}
)

target_link_libraries(
cadence_runner
executorch
gflags
etdump
extension_data_loader
bundled_program
cadence_ops_lib
flatccrt
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -euo pipefail
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR

readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../.."
readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../../.."

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

local example_dir=backends/cadence
local build_dir="cmake-out/${example_dir}"
Expand All @@ -43,7 +44,7 @@ main() {
-DCMAKE_BUILD_TYPE=Release \
-B"${build_dir}" \
"${example_dir}"
cmake --build "${build_dir}" --config Release
cmake --build "${build_dir}" --config Release -j16

local runner="${PWD}/${build_dir}/cadence_runner"
if [[ ! -f "${runner}" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions backends/cadence/hifi/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ add_library(
kernels.cpp
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/matmul_asym8uxasym8u_asym8u.cpp
)
# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)

target_include_directories(
cadence_kernels
Expand All @@ -19,6 +21,7 @@ target_include_directories(
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/include/nnlib
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/include
${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4/xa_nnlib/algo/ndsp/hifi4/include/
${_common_include_directories}
)

target_link_libraries(cadence_kernels PRIVATE xa_nnlib)
1 change: 1 addition & 0 deletions backends/cadence/hifi/kernels/kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <executorch/backends/cadence/hifi/kernels/kernels.h>

#include <xa_nnlib_common.h>
#include <xa_nnlib_common_macros.h>

Expand Down
1 change: 1 addition & 0 deletions backends/cadence/hifi/operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(_aten_ops__srcs
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/matmul_ops_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/reduce_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/repeat_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/slice_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_add.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_bmm.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_cat.cpp"
Expand Down
7 changes: 6 additions & 1 deletion backends/cadence/reference/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
# lint_cmake: -linelength
add_library(cadence_kernels kernels.cpp)

target_include_directories(cadence_kernels PUBLIC .)
# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)

target_include_directories(cadence_kernels PUBLIC .
${_common_include_directories}
)
19 changes: 9 additions & 10 deletions backends/cadence/reference/kernels/kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
* LICENSE file in the root directory of this source tree.
*/

#include <executorch/backends/cadence/reference/kernels/kernels.h>

#include <math.h>
#include <algorithm>
#include <cstring>
#include <limits>
#include <numeric>

namespace impl {
Expand All @@ -17,8 +20,7 @@ namespace kernels {

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

// Dequantize an int8_t/uint8_t value to an fp32 value
template <typename T>
__attribute__((always_inline)) float
dequantize(const T x, float scale, int32_t zero_point) {
float dequantize(const T x, float scale, int32_t zero_point) {
return scale * (x - zero_point);
}

Expand All @@ -60,9 +61,8 @@ void dequantize(

// explicit template instantiation

#define typed_quantize_val(dtype) \
template __attribute__((always_inline)) dtype quantize( \
const float x, float inv_scale, int32_t zero_point);
#define typed_quantize_val(dtype) \
template dtype quantize(const float x, float inv_scale, int32_t zero_point);
typed_quantize_val(int8_t);
typed_quantize_val(uint8_t);
typed_quantize_val(int16_t);
Expand All @@ -82,9 +82,8 @@ typed_quantize_vec(int16_t);
typed_quantize_vec(int32_t);
#undef typed_quantize_vec

#define typed_dequantize_val(dtype) \
template __attribute__((always_inline)) float dequantize( \
const dtype x, float scale, int32_t zero_point);
#define typed_dequantize_val(dtype) \
template float dequantize(const dtype x, float scale, int32_t zero_point);
typed_dequantize_val(int8_t);
typed_dequantize_val(uint8_t);
typed_dequantize_val(int16_t);
Expand Down
1 change: 1 addition & 0 deletions backends/cadence/reference/operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(_aten_ops__srcs
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/matmul_ops_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/reduce_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/repeat_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/slice_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/pattern/unary_ufunc_realhb_to_floath.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_bmm.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_cat.cpp"
Expand Down
4 changes: 3 additions & 1 deletion backends/cadence/runtime/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def __init__(
working_dir: str = "",
):
self.working_dir = working_dir
self.executor_builder = "./backends/cadence/build_cadence_runner.sh"
self.executor_builder = (
"./backends/cadence/cadence_runner/build_cadence_runner.sh"
)
self.execute_runner = "./cmake-out/backends/cadence/cadence_runner"
self.bundled_program_path: str = "CadenceDemoModel.bpte"

Expand Down
Loading