1# Copyright (c) 2023 Meta Platforms
2# SPDX-License-Identifier: Apache-2.0
3
4if(CONFIG_CMSIS_NN)
5
6  set(CMSIS_NN_DIR ${ZEPHYR_CURRENT_MODULE_DIR})
7  set(cmsis_glue_path ${ZEPHYR_CMSIS_MODULE_DIR})
8
9  zephyr_library()
10
11  zephyr_library_compile_options(-Ofast)
12
13  zephyr_include_directories(${CMSIS_NN_DIR}/Include)
14
15  zephyr_library_include_directories(${cmsis_glue_path}/CMSIS/Core/Include)
16
17  if(CONFIG_CMSIS_NN_ACTIVATION)
18    file(GLOB SRC "${CMSIS_NN_DIR}/Source/ActivationFunctions/*_s8*.c")
19    file(GLOB SRC_S16 "${CMSIS_NN_DIR}/Source/ActivationFunctions/*_s16*.c")
20    zephyr_library_sources(${SRC} ${SRC_S16}
21      ${CMSIS_NN_DIR}/Source/ActivationFunctions/arm_relu_q7.c
22      ${CMSIS_NN_DIR}/Source/ActivationFunctions/arm_relu_q15.c)
23  endif()
24
25  if(CONFIG_CMSIS_NN_BASICMATH)
26    file(GLOB SRC "${CMSIS_NN_DIR}/Source/BasicMathFunctions/*_*.c")
27    zephyr_library_sources(${SRC})
28  endif()
29
30  if(CONFIG_CMSIS_NN_CONCATENATION)
31    file(GLOB SRC "${CMSIS_NN_DIR}/Source/ConcatenationFunctions/*_*.c")
32    zephyr_library_sources(${SRC})
33  endif()
34
35  if(CONFIG_CMSIS_NN_CONVOLUTION)
36    file(GLOB SRC_S4 "${CMSIS_NN_DIR}/Source/ConvolutionFunctions/*_s4*.c")
37    file(GLOB SRC_S8 "${CMSIS_NN_DIR}/Source/ConvolutionFunctions/*_s8*.c")
38    file(GLOB SRC_S16 "${CMSIS_NN_DIR}/Source/ConvolutionFunctions/*_s16*.c")
39    zephyr_library_sources(${SRC_S4} ${SRC_S8} ${SRC_S16})
40  endif()
41
42  if(CONFIG_CMSIS_NN_FULLYCONNECTED)
43    file(GLOB SRC_S4 "${CMSIS_NN_DIR}/Source/FullyConnectedFunctions/*_s4.c")
44    file(GLOB SRC_S8 "${CMSIS_NN_DIR}/Source/FullyConnectedFunctions/*_s8.c")
45    file(GLOB SRC_S16 "${CMSIS_NN_DIR}/Source/FullyConnectedFunctions/*_s16*.c")
46    zephyr_library_sources(${SRC_S4} ${SRC_S8} ${SRC_S16})
47  endif()
48
49  if(CONFIG_CMSIS_NN_NNSUPPORT)
50    file(GLOB SRC_S4 "${CMSIS_NN_DIR}/Source/NNSupportFunctions/*_s4*.c")
51    file(GLOB SRC_S8 "${CMSIS_NN_DIR}/Source/NNSupportFunctions/*_s8*.c")
52    file(GLOB SRC_S16 "${CMSIS_NN_DIR}/Source/NNSupportFunctions/*_s16*.c")
53    zephyr_library_sources(${SRC_S4} ${SRC_S8} ${SRC_S16}
54      ${CMSIS_NN_DIR}/Source/NNSupportFunctions/arm_nntables.c
55      ${CMSIS_NN_DIR}/Source/NNSupportFunctions/arm_q7_to_q15_with_offset.c
56      ${CMSIS_NN_DIR}/Source/NNSupportFunctions/arm_s8_to_s16_unordered_with_offset.c)
57  endif()
58
59  if(CONFIG_CMSIS_NN_POOLING)
60    file(GLOB SRC "${CMSIS_NN_DIR}/Source/PoolingFunctions/*_s8.c")
61    file(GLOB SRC_S16 "${CMSIS_NN_DIR}/Source/PoolingFunctions/*_s16.c")
62    zephyr_library_sources(${SRC} ${SRC_S16})
63  endif()
64
65  if(CONFIG_CMSIS_NN_RESHAPE)
66    file(GLOB SRC "${CMSIS_NN_DIR}/Source/ReshapeFunctions/*_*.c")
67    zephyr_library_sources(${SRC})
68  endif()
69
70  if(CONFIG_CMSIS_NN_SOFTMAX)
71    file(GLOB SRC "${CMSIS_NN_DIR}/Source/SoftmaxFunctions/*_s8.c")
72    zephyr_library_sources(${SRC}
73      ${CMSIS_NN_DIR}/Source/SoftmaxFunctions/arm_softmax_s8_s16.c
74      ${CMSIS_NN_DIR}/Source/SoftmaxFunctions/arm_softmax_s16.c
75      ${CMSIS_NN_DIR}/Source/SoftmaxFunctions/arm_nn_softmax_common_s8.c)
76  endif()
77
78  if(CONFIG_CMSIS_NN_SVD)
79    file(GLOB SRC "${CMSIS_NN_DIR}/Source/SVDFunctions/*_s8.c")
80    zephyr_library_sources(${SRC})
81  endif()
82
83  if(CONFIG_CMSIS_NN_LSTM)
84    file(GLOB SRC "${CMSIS_NN_DIR}/Source/LSTMFunctions/*_s16.c")
85    zephyr_library_sources(${SRC})
86  endif()
87
88endif()
89