@@ -12,7 +12,7 @@ if(NOT CMAKE_CXX_STANDARD)
1212 set (CMAKE_CXX_STANDARD 17)
1313endif ()
1414
15- # Source root directory for executorch.
15+ # Source root directory for executorch
1616if (NOT EXECUTORCH_ROOT)
1717 set (EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR} /../..)
1818endif ()
@@ -21,70 +21,90 @@ include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2121include (${EXECUTORCH_ROOT} /tools/cmake/Codegen.cmake)
2222include (FetchContent)
2323
24- # CMSIS-NN version to download
24+ # CMSIS-NN configuration with dynamic path detection
2525set (CMSIS_NN_VERSION
26- "v4.1 .0"
26+ "v7.0 .0"
2727 CACHE STRING "CMSIS-NN version to download"
2828)
29-
30- # Declare CMSIS-NN as a FetchContent project
31- FetchContent_Declare(
32- cmsis_nn
33- GIT_REPOSITORY https://github.com/ARM-software/CMSIS-NN.git
34- GIT_TAG ${CMSIS_NN_VERSION}
29+ set (CMSIS_NN_LOCAL_PATH
30+ ""
31+ CACHE PATH "Path to existing local CMSIS-NN installation"
3532)
3633
37- # Download and make CMSIS-NN available
38- FetchContent_MakeAvailable(cmsis_nn)
34+ # Try to find existing / local CMSIS-NN installation. This is useful for
35+ # debugging and testing with local changes. This is not common, as the CMSIS-NN
36+ # library is downloaded via FetchContent in the default/regular case.
37+ if (CMSIS_NN_LOCAL_PATH AND EXISTS "${CMSIS_NN_LOCAL_PATH} " )
38+ message (STATUS "Using CMSIS-NN from specified path: ${CMSIS_NN_LOCAL_PATH} " )
39+ add_subdirectory (${CMSIS_NN_LOCAL_PATH} cmsis_nn_build)
40+ else ()
41+ # Use FetchContent with automatic fallback
42+ message (STATUS "Using CMSIS-NN via FetchContent" )
43+
44+ FetchContent_Declare(
45+ cmsis_nn
46+ GIT_REPOSITORY https://github.com/ARM-software/CMSIS-NN.git
47+ GIT_TAG ${CMSIS_NN_VERSION}
48+ GIT_SHALLOW TRUE
49+ )
50+
51+ FetchContent_GetProperties(cmsis_nn)
52+ if (NOT cmsis_nn_POPULATED)
53+ FetchContent_Populate(cmsis_nn)
54+ add_subdirectory (${cmsis_nn_SOURCE_DIR} ${cmsis_nn_BINARY_DIR} )
55+ endif ()
56+ endif ()
3957
40- # Print paths for debugging
41- message (STATUS "CMSIS-NN source dir: ${cmsis_nn_SOURCE_DIR} " )
42- message (STATUS "CMSIS-NN binary dir: ${cmsis_nn_BINARY_DIR} " )
58+ # Add MVEI define to cmsis-nn target
59+ if (TARGET cmsis-nn)
60+ target_compile_definitions (cmsis-nn PUBLIC ARM_MATH_MVEI=1)
61+ get_target_property (CMSIS_NN_INCLUDES cmsis-nn INTERFACE_INCLUDE_DIRECTORIES )
62+ message (STATUS "CMSIS-NN include dirs: ${CMSIS_NN_INCLUDES} " )
63+ else ()
64+ message (
65+ FATAL_ERROR
66+ "CMSIS-NN target not found. Check your CMSIS_NN_LOCAL_PATH or network connection."
67+ )
68+ endif ()
4369
4470# Cortex-M ops kernel sources
4571set (_cortex_m_kernels__srcs
4672 ${CMAKE_CURRENT_SOURCE_DIR} /ops/op_quantize_per_tensor.cpp
4773 ${CMAKE_CURRENT_SOURCE_DIR} /ops/op_dequantize_per_tensor.cpp
4874 ${CMAKE_CURRENT_SOURCE_DIR} /ops/op_quantized_add.cpp
75+ ${CMAKE_CURRENT_SOURCE_DIR} /ops/op_quantized_linear.cpp
4976)
5077
51- # Generate C++ bindings to register kernels into Executorch (for runtime)
78+ # Generate C++ bindings to register kernels into Executorch
5279set (_yaml_file ${CMAKE_CURRENT_LIST_DIR} /ops/operators.yaml)
5380gen_selected_ops(LIB_NAME "cortex_m_ops_lib" OPS_SCHEMA_YAML "${_yaml_file} " )
54-
5581generate_bindings_for_kernels(
5682 LIB_NAME "cortex_m_ops_lib" CUSTOM_OPS_YAML "${_yaml_file} "
5783)
58- message ("Generated files ${gen_command_sources} " )
5984
60- # Build a library for cortex_m_kernels
85+ # Build library for cortex_m_kernels
6186add_library (cortex_m_kernels ${_cortex_m_kernels__srcs} )
62- target_compile_options (cortex_m_kernels PUBLIC ${_common_compile_options} )
6387
64- # Include directories for cortex_m_kernels
65- target_include_directories (
88+ # Use PRIVATE for implementation dependencies to avoid INTERFACE pollution
89+ target_link_libraries (
6690 cortex_m_kernels
67- PRIVATE ${EXECUTORCH_ROOT} /..
68- ${EXECUTORCH_ROOT} /runtime/core/portable_type/c10
69- ${cmsis_nn_SOURCE_DIR} /Include
91+ PRIVATE cmsis-nn
92+ PRIVATE executorch
7093)
7194
72- # Link directly to the CMSIS-NN static library file
73- target_link_libraries (
74- cortex_m_kernels PUBLIC ${cmsis_nn_BINARY_DIR} /libcmsis-nn.a executorch
95+ # Include directories for cortex_m_kernels
96+ target_include_directories (
97+ cortex_m_kernels PRIVATE ${EXECUTORCH_ROOT} /..
98+ ${EXECUTORCH_ROOT} /runtime/core/portable_type/c10
7599)
76100
77- # Add dependency to ensure CMSIS-NN builds before we try to link. Use the actual
78- # CMSIS-NN target name (usually 'cmsis-nn')
79- add_dependencies (cortex_m_kernels cmsis-nn)
80-
81101# cortex_m_ops_lib: Register Cortex-M ops kernels into Executorch runtime
82102gen_operators_lib(
83103 LIB_NAME "cortex_m_ops_lib" KERNEL_LIBS cortex_m_kernels DEPS executorch
84104)
85105
86106install (
87- TARGETS cortex_m_kernels cortex_m_ops_lib
107+ TARGETS cortex_m_kernels cortex_m_ops_lib cmsis-nn
88108 EXPORT ExecuTorchTargets
89109 DESTINATION lib
90110 PUBLIC_HEADER DESTINATION include /executorch/backends/cortex_m/ops/
0 commit comments