Skip to content

Commit 8f12da1

Browse files
vp-cadfacebook-github-bot
authored andcommitted
Added support for HiFi build for ISS (simulator) under EXECUTORCH_BUILD_CADENCE cmake-config switch (#3629)
Summary: …LD_CADENCE cmake-config switch. Pull Request resolved: #3629 Reviewed By: tarun292 Differential Revision: D59091758 Pulled By: mcremon-meta fbshipit-source-id: 55161bdb3d3b5c906a02da804a0e6a4f533ceae8
1 parent 3eec95a commit 8f12da1

File tree

4 files changed

+165
-119
lines changed

4 files changed

+165
-119
lines changed

CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ option(EXECUTORCH_BUILD_XNNPACK "Build the XNNPACK backend" OFF)
195195

196196
option(EXECUTORCH_BUILD_VULKAN "Build the Vulkan backend" OFF)
197197

198+
option(BUILD_EXECUTORCH_PORTABLE_OPS "Build portable_ops library" ON)
199+
200+
option(EXECUTORCH_USE_DL "Use libdl library" ON)
201+
202+
option(EXECUTORCH_BUILD_CADENCE "Build the Cadence DSP backend" OFF)
203+
198204
#
199205
# pthreadpool: build pthreadpool library. Disable on unsupported platforms
200206
#
@@ -461,11 +467,13 @@ endif()
461467

462468
add_library(executorch_no_prim_ops ${_executorch_no_prim_ops__srcs})
463469
target_link_libraries(executorch_no_prim_ops PRIVATE program_schema)
464-
# Check if dl exists for this toolchain and only then link it.
465-
find_library(DL_LIBRARY_EXISTS NAMES dl)
466-
# Check if the library was found
467-
if(DL_LIBRARY_EXISTS)
468-
target_link_libraries(executorch_no_prim_ops PRIVATE dl) # For dladdr()
470+
if(EXECUTORCH_USE_DL)
471+
# Check if dl exists for this toolchain and only then link it.
472+
find_library(DL_LIBRARY_EXISTS NAMES dl)
473+
# Check if the library was found
474+
if(DL_LIBRARY_EXISTS)
475+
target_link_libraries(executorch_no_prim_ops PRIVATE dl) # For dladdr()
476+
endif()
469477
endif()
470478
target_include_directories(
471479
executorch_no_prim_ops PUBLIC ${_common_include_directories}
@@ -517,7 +525,9 @@ target_link_options_shared_lib(executorch)
517525
# Real integrations should supply their own YAML file that only lists the
518526
# operators necessary for the models that will run.
519527
#
528+
if(BUILD_EXECUTORCH_PORTABLE_OPS)
520529
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable)
530+
endif()
521531

522532
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
523533
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/optimized)
@@ -563,6 +573,8 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
563573

564574
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
565575
list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib)
576+
elseif(EXECUTORCH_BUILD_CADENCE)
577+
list(APPEND _executor_runner_libs cadence_ops_lib)
566578
else()
567579
list(APPEND _executor_runner_libs portable_ops_lib)
568580
endif()
@@ -633,6 +645,10 @@ if(EXECUTORCH_BUILD_COREML)
633645
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml)
634646
endif()
635647

648+
if(EXECUTORCH_BUILD_CADENCE)
649+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/cadence)
650+
endif()
651+
636652
if(EXECUTORCH_BUILD_PYBIND)
637653
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/pybind11)
638654

backends/cadence/CMakeLists.txt

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if(NOT CMAKE_CXX_STANDARD)
1212
endif()
1313

1414
# Set the project name.
15-
project(cadence_executorch_example)
15+
project(cadence_backend)
1616

1717
# Source root directory for executorch.
1818
if(NOT EXECUTORCH_ROOT)
@@ -21,121 +21,10 @@ endif()
2121

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

24-
if(NOT PYTHON_EXECUTABLE)
25-
resolve_python_executable()
26-
endif()
27-
2824
# Let files say "include <executorch/path/to/header.h>".
2925
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
3026

31-
# Find prebuilt executorch lib
32-
find_package(executorch CONFIG REQUIRED)
33-
34-
add_compile_options(
35-
-DSDK_DEBUGCONSOLE=1
36-
-DSERIAL_PORT_TYPE_UART=1
37-
-DDEBUG_CONSOLE_RX_ENABLE=0
38-
-DDEBUG
39-
-DCPU_MIMXRT685SFVKB_dsp
40-
-DMCUXPRESSO_SDK
41-
-g
42-
-O0
43-
-Wall
44-
-fsigned-char
45-
-Wno-missing-braces
46-
-fmessage-length=0
47-
-DPRINTF_FLOAT_ENABLE=1
48-
)
49-
50-
if(NOT DEFINED NXP_SDK_ROOT_DIR)
51-
message(FATAL_ERROR "NXP_SDK_ROOT_DIR is not set")
52-
endif()
53-
54-
# lint_cmake: -linelength
55-
set(SOURCES
56-
${NXP_SDK_ROOT_DIR}/components/lists/fsl_component_generic_list.c
57-
${NXP_SDK_ROOT_DIR}/components/uart/fsl_adapter_usart.c
58-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_clock.c
59-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common.c
60-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common_dsp.c
61-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_flexcomm.c
62-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_gpio.c
63-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_mu.c
64-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_reset.c
65-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_usart.c
66-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/system_MIMXRT685S_dsp.c
67-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_assert.c
68-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_debug_console.c
69-
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/board_hifi4.c
70-
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/pin_mux.c
71-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str/fsl_str.c
72-
)
73-
74-
add_library(dsp_mu_polling_libs STATIC ${SOURCES})
75-
76-
target_include_directories(
77-
dsp_mu_polling_libs
78-
PUBLIC ${NXP_SDK_ROOT_DIR}
79-
${NXP_SDK_ROOT_DIR}/components/uart
80-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers
81-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite
82-
${NXP_SDK_ROOT_DIR}/components/lists
83-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S
84-
${NXP_SDK_ROOT_DIR}/CMSIS/Core/Include
85-
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str
86-
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp
87-
)
88-
89-
add_library(extension_runner_util STATIC IMPORTED)
90-
set_property(
91-
TARGET extension_runner_util
92-
PROPERTY
93-
IMPORTED_LOCATION
94-
"${CMAKE_CURRENT_LIST_DIR}/../../cmake-out/extension/runner_util/libextension_runner_util.a"
95-
)
9627

9728
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hifi/operators)
9829
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hifi/kernels)
9930

100-
# Generate the model header file
101-
add_custom_command(
102-
OUTPUT ${CMAKE_BINARY_DIR}/model_pte.h
103-
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
104-
--model_path ${MODEL_PATH} --header_output_path ${CMAKE_BINARY_DIR}
105-
COMMENT "Converting .pte model to header file..."
106-
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
107-
)
108-
109-
add_custom_target(gen_model_header DEPENDS ${CMAKE_BINARY_DIR}/model_pte.h)
110-
111-
add_executable(cadence_executorch_example executor_runner.cpp)
112-
add_dependencies(cadence_executorch_example gen_model_header)
113-
114-
# lint_cmake: -linelength
115-
target_include_directories(
116-
cadence_executorch_example PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR}
117-
${_common_include_directories}
118-
)
119-
120-
target_link_options(
121-
cadence_executorch_example PRIVATE
122-
-mlsp=${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/xtensa/min-rt
123-
)
124-
target_link_libraries(
125-
cadence_executorch_example dsp_mu_polling_libs cadence_ops_lib
126-
extension_runner_util executorch
127-
)
128-
129-
add_custom_command(
130-
TARGET cadence_executorch_example
131-
POST_BUILD
132-
COMMAND
133-
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
134-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}
135-
COMMENT
136-
"Generating .bin files that can be used to flash the DSP with. Copy over
137-
the dsp_text_release.bin and dsp_data_release.bin that are generated into
138-
your NXP MCUXpresso IDE workspace and flash the DSP with these binaries."
139-
DEPENDS
140-
${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
141-
)

backends/cadence/cadence.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ set(CMAKE_CROSSCOMPILING TRUE)
4141
set(CMAKE_C_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang)
4242
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang++)
4343

44-
set(CMAKE_C_FLAGS_INIT "-stdlib=libc++")
45-
set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++")
44+
set(CMAKE_C_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
45+
set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
4646
set(CMAKE_SYSROOT ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
4747
set(CMAKE_LINKER ${TOOLCHAIN_HOME}/bin/xt-ld)
4848
add_link_options(-lm -stdlib=libc++ -Wl,--no-as-needed -static)

examples/cadence/CMakeLists.txt

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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_executorch_example)
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+
24+
if(NOT PYTHON_EXECUTABLE)
25+
resolve_python_executable()
26+
endif()
27+
28+
# Let files say "include <executorch/path/to/header.h>".
29+
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
30+
31+
# Find prebuilt executorch lib
32+
find_package(executorch CONFIG REQUIRED)
33+
34+
add_compile_options(
35+
-DSDK_DEBUGCONSOLE=1
36+
-DSERIAL_PORT_TYPE_UART=1
37+
-DDEBUG_CONSOLE_RX_ENABLE=0
38+
-DDEBUG
39+
-DCPU_MIMXRT685SFVKB_dsp
40+
-DMCUXPRESSO_SDK
41+
-g
42+
-O0
43+
-Wall
44+
-fsigned-char
45+
-Wno-missing-braces
46+
-fmessage-length=0
47+
-DPRINTF_FLOAT_ENABLE=1
48+
)
49+
50+
if(NOT DEFINED NXP_SDK_ROOT_DIR)
51+
message(FATAL_ERROR "NXP_SDK_ROOT_DIR is not set")
52+
endif()
53+
54+
# lint_cmake: -linelength
55+
set(SOURCES
56+
${NXP_SDK_ROOT_DIR}/components/lists/fsl_component_generic_list.c
57+
${NXP_SDK_ROOT_DIR}/components/uart/fsl_adapter_usart.c
58+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_clock.c
59+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common.c
60+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common_dsp.c
61+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_flexcomm.c
62+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_gpio.c
63+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_mu.c
64+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_reset.c
65+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_usart.c
66+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/system_MIMXRT685S_dsp.c
67+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_assert.c
68+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_debug_console.c
69+
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/board_hifi4.c
70+
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/pin_mux.c
71+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str/fsl_str.c
72+
)
73+
74+
add_library(dsp_mu_polling_libs STATIC ${SOURCES})
75+
76+
target_include_directories(
77+
dsp_mu_polling_libs
78+
PUBLIC ${NXP_SDK_ROOT_DIR}
79+
${NXP_SDK_ROOT_DIR}/components/uart
80+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers
81+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite
82+
${NXP_SDK_ROOT_DIR}/components/lists
83+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S
84+
${NXP_SDK_ROOT_DIR}/CMSIS/Core/Include
85+
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str
86+
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp
87+
)
88+
89+
add_library(extension_runner_util STATIC IMPORTED)
90+
set_property(
91+
TARGET extension_runner_util
92+
PROPERTY
93+
IMPORTED_LOCATION
94+
"${CMAKE_CURRENT_LIST_DIR}/../../cmake-out/extension/runner_util/libextension_runner_util.a"
95+
)
96+
97+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hifi/operators)
98+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hifi/kernels)
99+
100+
# Generate the model header file
101+
add_custom_command(
102+
OUTPUT ${CMAKE_BINARY_DIR}/model_pte.h
103+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
104+
--model_path ${MODEL_PATH} --header_output_path ${CMAKE_BINARY_DIR}
105+
COMMENT "Converting .pte model to header file..."
106+
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
107+
)
108+
109+
add_custom_target(gen_model_header DEPENDS ${CMAKE_BINARY_DIR}/model_pte.h)
110+
111+
add_executable(cadence_executorch_example executor_runner.cpp)
112+
add_dependencies(cadence_executorch_example gen_model_header)
113+
114+
# lint_cmake: -linelength
115+
target_include_directories(
116+
cadence_executorch_example PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR}
117+
${_common_include_directories}
118+
)
119+
120+
target_link_options(
121+
cadence_executorch_example PRIVATE
122+
-mlsp=${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/xtensa/min-rt
123+
)
124+
target_link_libraries(
125+
cadence_executorch_example dsp_mu_polling_libs cadence_ops_lib
126+
extension_runner_util executorch
127+
)
128+
129+
add_custom_command(
130+
TARGET cadence_executorch_example
131+
POST_BUILD
132+
COMMAND
133+
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
134+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}
135+
COMMENT
136+
"Generating .bin files that can be used to flash the DSP with. Copy over
137+
the dsp_text_release.bin and dsp_data_release.bin that are generated into
138+
your NXP MCUXpresso IDE workspace and flash the DSP with these binaries."
139+
DEPENDS
140+
${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
141+
)

0 commit comments

Comments
 (0)