Skip to content

Added support for HiFi build for ISS (simulator) under EXECUTORCH_BUILD_CADENCE cmake-config switch #3629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
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
26 changes: 21 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ option(EXECUTORCH_BUILD_XNNPACK "Build the XNNPACK backend" OFF)

option(EXECUTORCH_BUILD_VULKAN "Build the Vulkan backend" OFF)

option(BUILD_EXECUTORCH_PORTABLE_OPS "Build portable_ops library" ON)

option(EXECUTORCH_USE_DL "Use libdl library" ON)

option(EXECUTORCH_BUILD_CADENCE "Build the Cadence DSP backend" OFF)

#
# pthreadpool: build pthreadpool library. Disable on unsupported platforms
#
Expand Down Expand Up @@ -461,11 +467,13 @@ endif()

add_library(executorch_no_prim_ops ${_executorch_no_prim_ops__srcs})
target_link_libraries(executorch_no_prim_ops PRIVATE program_schema)
# Check if dl exists for this toolchain and only then link it.
find_library(DL_LIBRARY_EXISTS NAMES dl)
# Check if the library was found
if(DL_LIBRARY_EXISTS)
target_link_libraries(executorch_no_prim_ops PRIVATE dl) # For dladdr()
if(EXECUTORCH_USE_DL)
# Check if dl exists for this toolchain and only then link it.
find_library(DL_LIBRARY_EXISTS NAMES dl)
# Check if the library was found
if(DL_LIBRARY_EXISTS)
target_link_libraries(executorch_no_prim_ops PRIVATE dl) # For dladdr()
endif()
endif()
target_include_directories(
executorch_no_prim_ops PUBLIC ${_common_include_directories}
Expand Down Expand Up @@ -517,7 +525,9 @@ target_link_options_shared_lib(executorch)
# Real integrations should supply their own YAML file that only lists the
# operators necessary for the models that will run.
#
if(BUILD_EXECUTORCH_PORTABLE_OPS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable)
endif()

if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/optimized)
Expand Down Expand Up @@ -563,6 +573,8 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)

if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib)
elseif(EXECUTORCH_BUILD_CADENCE)
list(APPEND _executor_runner_libs cadence_ops_lib)
else()
list(APPEND _executor_runner_libs portable_ops_lib)
endif()
Expand Down Expand Up @@ -633,6 +645,10 @@ if(EXECUTORCH_BUILD_COREML)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml)
endif()

if(EXECUTORCH_BUILD_CADENCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/cadence)
endif()

if(EXECUTORCH_BUILD_PYBIND)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/pybind11)

Expand Down
113 changes: 1 addition & 112 deletions backends/cadence/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(NOT CMAKE_CXX_STANDARD)
endif()

# Set the project name.
project(cadence_executorch_example)
project(cadence_backend)

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

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

if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

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

# Find prebuilt executorch lib
find_package(executorch CONFIG REQUIRED)

add_compile_options(
-DSDK_DEBUGCONSOLE=1
-DSERIAL_PORT_TYPE_UART=1
-DDEBUG_CONSOLE_RX_ENABLE=0
-DDEBUG
-DCPU_MIMXRT685SFVKB_dsp
-DMCUXPRESSO_SDK
-g
-O0
-Wall
-fsigned-char
-Wno-missing-braces
-fmessage-length=0
-DPRINTF_FLOAT_ENABLE=1
)

if(NOT DEFINED NXP_SDK_ROOT_DIR)
message(FATAL_ERROR "NXP_SDK_ROOT_DIR is not set")
endif()

# lint_cmake: -linelength
set(SOURCES
${NXP_SDK_ROOT_DIR}/components/lists/fsl_component_generic_list.c
${NXP_SDK_ROOT_DIR}/components/uart/fsl_adapter_usart.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_clock.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common_dsp.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_flexcomm.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_gpio.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_mu.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_reset.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_usart.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/system_MIMXRT685S_dsp.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_assert.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_debug_console.c
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/board_hifi4.c
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/pin_mux.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str/fsl_str.c
)

add_library(dsp_mu_polling_libs STATIC ${SOURCES})

target_include_directories(
dsp_mu_polling_libs
PUBLIC ${NXP_SDK_ROOT_DIR}
${NXP_SDK_ROOT_DIR}/components/uart
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite
${NXP_SDK_ROOT_DIR}/components/lists
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S
${NXP_SDK_ROOT_DIR}/CMSIS/Core/Include
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp
)

add_library(extension_runner_util STATIC IMPORTED)
set_property(
TARGET extension_runner_util
PROPERTY
IMPORTED_LOCATION
"${CMAKE_CURRENT_LIST_DIR}/../../cmake-out/extension/runner_util/libextension_runner_util.a"
)

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

# Generate the model header file
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/model_pte.h
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
--model_path ${MODEL_PATH} --header_output_path ${CMAKE_BINARY_DIR}
COMMENT "Converting .pte model to header file..."
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
)

add_custom_target(gen_model_header DEPENDS ${CMAKE_BINARY_DIR}/model_pte.h)

add_executable(cadence_executorch_example executor_runner.cpp)
add_dependencies(cadence_executorch_example gen_model_header)

# lint_cmake: -linelength
target_include_directories(
cadence_executorch_example PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR}
${_common_include_directories}
)

target_link_options(
cadence_executorch_example PRIVATE
-mlsp=${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/xtensa/min-rt
)
target_link_libraries(
cadence_executorch_example dsp_mu_polling_libs cadence_ops_lib
extension_runner_util executorch
)

add_custom_command(
TARGET cadence_executorch_example
POST_BUILD
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}
COMMENT
"Generating .bin files that can be used to flash the DSP with. Copy over
the dsp_text_release.bin and dsp_data_release.bin that are generated into
your NXP MCUXpresso IDE workspace and flash the DSP with these binaries."
DEPENDS
${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
)
4 changes: 2 additions & 2 deletions backends/cadence/cadence.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_C_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang++)

set(CMAKE_C_FLAGS_INIT "-stdlib=libc++")
set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++")
set(CMAKE_C_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
set(CMAKE_SYSROOT ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
set(CMAKE_LINKER ${TOOLCHAIN_HOME}/bin/xt-ld)
add_link_options(-lm -stdlib=libc++ -Wl,--no-as-needed -static)
Expand Down
141 changes: 141 additions & 0 deletions examples/cadence/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# 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_executorch_example)

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

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

if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

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

# Find prebuilt executorch lib
find_package(executorch CONFIG REQUIRED)

add_compile_options(
-DSDK_DEBUGCONSOLE=1
-DSERIAL_PORT_TYPE_UART=1
-DDEBUG_CONSOLE_RX_ENABLE=0
-DDEBUG
-DCPU_MIMXRT685SFVKB_dsp
-DMCUXPRESSO_SDK
-g
-O0
-Wall
-fsigned-char
-Wno-missing-braces
-fmessage-length=0
-DPRINTF_FLOAT_ENABLE=1
)

if(NOT DEFINED NXP_SDK_ROOT_DIR)
message(FATAL_ERROR "NXP_SDK_ROOT_DIR is not set")
endif()

# lint_cmake: -linelength
set(SOURCES
${NXP_SDK_ROOT_DIR}/components/lists/fsl_component_generic_list.c
${NXP_SDK_ROOT_DIR}/components/uart/fsl_adapter_usart.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_clock.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_common_dsp.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_flexcomm.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_gpio.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_mu.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_reset.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers/fsl_usart.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/system_MIMXRT685S_dsp.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_assert.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite/fsl_debug_console.c
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/board_hifi4.c
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp/pin_mux.c
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str/fsl_str.c
)

add_library(dsp_mu_polling_libs STATIC ${SOURCES})

target_include_directories(
dsp_mu_polling_libs
PUBLIC ${NXP_SDK_ROOT_DIR}
${NXP_SDK_ROOT_DIR}/components/uart
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/drivers
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/debug_console_lite
${NXP_SDK_ROOT_DIR}/components/lists
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S
${NXP_SDK_ROOT_DIR}/CMSIS/Core/Include
${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/utilities/str
${NXP_SDK_ROOT_DIR}/boards/evkmimxrt685/dsp_examples/mu_polling/dsp
)

add_library(extension_runner_util STATIC IMPORTED)
set_property(
TARGET extension_runner_util
PROPERTY
IMPORTED_LOCATION
"${CMAKE_CURRENT_LIST_DIR}/../../cmake-out/extension/runner_util/libextension_runner_util.a"
)

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

# Generate the model header file
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/model_pte.h
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
--model_path ${MODEL_PATH} --header_output_path ${CMAKE_BINARY_DIR}
COMMENT "Converting .pte model to header file..."
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/utils/gen_header.py
)

add_custom_target(gen_model_header DEPENDS ${CMAKE_BINARY_DIR}/model_pte.h)

add_executable(cadence_executorch_example executor_runner.cpp)
add_dependencies(cadence_executorch_example gen_model_header)

# lint_cmake: -linelength
target_include_directories(
cadence_executorch_example PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR}
${_common_include_directories}
)

target_link_options(
cadence_executorch_example PRIVATE
-mlsp=${NXP_SDK_ROOT_DIR}/devices/MIMXRT685S/xtensa/min-rt
)
target_link_libraries(
cadence_executorch_example dsp_mu_polling_libs cadence_ops_lib
extension_runner_util executorch
)

add_custom_command(
TARGET cadence_executorch_example
POST_BUILD
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_BINARY_DIR}
COMMENT
"Generating .bin files that can be used to flash the DSP with. Copy over
the dsp_text_release.bin and dsp_data_release.bin that are generated into
your NXP MCUXpresso IDE workspace and flash the DSP with these binaries."
DEPENDS
${CMAKE_CURRENT_LIST_DIR}/utils/post_compilation.py
)