|
| 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 | +cmake_minimum_required(VERSION 3.19) |
| 8 | + |
| 9 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 10 | +if(NOT CMAKE_CXX_STANDARD) |
| 11 | + set(CMAKE_CXX_STANDARD 17) |
| 12 | +endif() |
| 13 | +set(CMAKE_VERBOSE_MAKEFILE ON) |
| 14 | + |
| 15 | +# Source root directory for executorch. |
| 16 | +if(NOT EXECUTORCH_ROOT) |
| 17 | + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../) |
| 18 | +endif() |
| 19 | + |
| 20 | +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) |
| 21 | +include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) |
| 22 | + |
| 23 | +set(EXECUTORCH_ENABLE_LOGGING ON CACHE BOOL "Enable ExecuTorch logging") |
| 24 | +set(EXECUTORCH_LOG_LEVEL "DEBUG" CACHE STRING "ExecuTorch log level") |
| 25 | + |
| 26 | +# Path to CMSIS-NN root - adjust as needed |
| 27 | +set(CMSIS_NN_ROOT /home/sidart/working/CMSIS-NN) |
| 28 | + |
| 29 | +# Cortex-M CMSIS ops sources |
| 30 | +set(_cortex_m_kernels_cmsis__srcs |
| 31 | + "${EXECUTORCH_ROOT}/backends/cortex_m/cmsis-nn/ops/op_aten_add_tensor.cpp" |
| 32 | + "${EXECUTORCH_ROOT}/backends/cortex_m/cmsis-nn/ops/op_aten_softmax.cpp" |
| 33 | +) |
| 34 | + |
| 35 | +# Common include directories |
| 36 | +set(_common_include_directories |
| 37 | + ${EXECUTORCH_ROOT}/.. |
| 38 | + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 |
| 39 | + ${CMSIS_NN_ROOT}/Include |
| 40 | + ${CMSIS_NN_ROOT} # For any CMake or config includes |
| 41 | +) |
| 42 | + |
| 43 | +# Import CMSIS-NN static library as a target |
| 44 | +add_library(cmsis_nn STATIC IMPORTED) |
| 45 | +set_target_properties(cmsis_nn PROPERTIES |
| 46 | + IMPORTED_LOCATION "${CMSIS_NN_ROOT}/build/libcmsis-nn.a" |
| 47 | + INTERFACE_INCLUDE_DIRECTORIES "${CMSIS_NN_ROOT}/Include" |
| 48 | +) |
| 49 | + |
| 50 | +# Build cortex_m_cmsis_kernels static library |
| 51 | +add_library(cortex_m_cmsis_kernels ${_cortex_m_kernels_cmsis__srcs}) |
| 52 | + |
| 53 | +# Include directories for cortex_m_cmsis_kernels |
| 54 | +target_include_directories(cortex_m_cmsis_kernels |
| 55 | + PRIVATE |
| 56 | + ${_common_include_directories} |
| 57 | +) |
| 58 | + |
| 59 | +# Link libraries: executorch and CMSIS-NN imported target |
| 60 | +target_link_libraries(cortex_m_cmsis_kernels |
| 61 | + PRIVATE |
| 62 | + cmsis_nn |
| 63 | + executorch |
| 64 | +) |
| 65 | + |
| 66 | +# Generate C++ bindings for kernels and operators |
| 67 | +gen_selected_ops( |
| 68 | + LIB_NAME "cortex_m_cmsis_nn_ops_lib" OPS_SCHEMA_YAML |
| 69 | + "${CMAKE_CURRENT_LIST_DIR}/../cmsis.yaml" "" "" |
| 70 | +) |
| 71 | +generate_bindings_for_kernels( |
| 72 | + LIB_NAME "cortex_m_cmsis_nn_ops_lib" FUNCTIONS_YAML |
| 73 | + ${CMAKE_CURRENT_SOURCE_DIR}/../cmsis.yaml |
| 74 | +) |
| 75 | + |
| 76 | +gen_operators_lib( |
| 77 | + LIB_NAME "cortex_m_cmsis_nn_ops_lib" KERNEL_LIBS cortex_m_cmsis_kernels DEPS executorch |
| 78 | +) |
| 79 | +set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections") |
| 80 | +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections") |
| 81 | + |
| 82 | +# Install targets and headers |
| 83 | +install( |
| 84 | + TARGETS cortex_m_cmsis_kernels cortex_m_cmsis_nn_ops_lib |
| 85 | + DESTINATION lib |
| 86 | + PUBLIC_HEADER DESTINATION include/executorch/backends/cortex_m/cmsis-nn/ops/ |
| 87 | +) |
0 commit comments