├── .ai ├── .ldupdatedone ├── network_trained_lstm.tflite_c_graph.json └── network_trained_lstm.tflite_report.json ├── .cproject ├── .mxproject ├── .project ├── .settings ├── language.settings.xml └── stm32cubeide.project.prefs ├── Core ├── Inc │ ├── main.h │ ├── stm32g0xx_hal_conf.h │ └── stm32g0xx_it.h ├── Src │ ├── main.c │ ├── stm32g0xx_hal_msp.c │ ├── stm32g0xx_it.c │ ├── sysmem.c │ └── system_stm32g0xx.c └── Startup │ └── startup_stm32g070rbtx.s ├── Middlewares └── ST │ └── AI │ ├── Inc │ ├── ai_common_config.h │ ├── ai_datatypes.h │ ├── ai_datatypes_defines.h │ ├── ai_datatypes_format.h │ ├── ai_datatypes_internal.h │ ├── ai_layer_custom_interface.h │ ├── ai_lite.h │ ├── ai_lite_inspect.h │ ├── ai_lite_interface.h │ ├── ai_lite_math_helpers.h │ ├── ai_math_helpers.h │ ├── ai_platform.h │ ├── ai_platform_interface.h │ ├── core_common.h │ ├── core_convert.h │ ├── core_datatypes.h │ ├── core_log.h │ ├── core_net_inspect.h │ ├── core_net_inspect_interface.h │ ├── core_private.h │ ├── datatypes_network.h │ ├── formats_list.h │ ├── layers.h │ ├── layers_common.h │ ├── layers_conv2d.h │ ├── layers_conv2d_dqnn.h │ ├── layers_custom.h │ ├── layers_dense.h │ ├── layers_dense_dqnn.h │ ├── layers_formats_converters.h │ ├── layers_generic.h │ ├── layers_generic_dqnn.h │ ├── layers_list.h │ ├── layers_lite_graph.h │ ├── layers_ml.h │ ├── layers_ml_iforest.h │ ├── layers_ml_linearclassifier.h │ ├── layers_ml_svc.h │ ├── layers_ml_svmregressor.h │ ├── layers_ml_treeensembleclassifier.h │ ├── layers_ml_treeensembleregressor.h │ ├── layers_nl.h │ ├── layers_norm.h │ ├── layers_pad_dqnn.h │ ├── layers_pad_generic.h │ ├── layers_pool.h │ ├── layers_pool_dqnn.h │ ├── layers_rnn.h │ ├── layers_sm.h │ ├── layers_upsample_generic.h │ ├── lite_bn_f32.h │ ├── lite_bn_integer.h │ ├── lite_conv2d.h │ ├── lite_conv2d_dqnn.h │ ├── lite_convert_dqnn.h │ ├── lite_dense_if32.h │ ├── lite_dense_is1.h │ ├── lite_dense_is1ws1.h │ ├── lite_dense_is8os1ws1.h │ ├── lite_dense_is8os8ws8.h │ ├── lite_dense_ws1.h │ ├── lite_dw.h │ ├── lite_dw_dqnn.h │ ├── lite_generic_float.h │ ├── lite_gru_f32.h │ ├── lite_maxpool_dqnn.h │ ├── lite_nl_generic_float.h │ ├── lite_nl_generic_integer.h │ ├── lite_nl_list.h │ ├── lite_operators.h │ ├── lite_pad_dqnn.h │ ├── lite_pad_generic.h │ ├── lite_pool_f32.h │ ├── lite_pw.h │ ├── lite_pw_dqnn.h │ ├── lite_upsample.h │ └── lite_upsample_generic.h │ ├── LICENSE.txt │ └── Lib │ └── NetworkRuntime810_CM0+_GCC.a ├── README.md ├── STM32G070RBTX_FLASH.ld ├── STM32G070_AI_TEST Debug.launch ├── STM32G070_AI_TEST.ioc ├── X-CUBE-AI ├── App │ ├── network.c │ ├── network.h │ ├── network_config.h │ ├── network_data.c │ ├── network_data.h │ ├── network_data_params.c │ ├── network_data_params.h │ └── network_generate_report.txt └── LICENSE.txt └── trained_lstm.tflite /.ai/.ldupdatedone: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/colin2135/STM32G070_AI_TEST/0e71fc4834e9c1aec1badc0ecc35bb8d572008b9/.ai/.ldupdatedone -------------------------------------------------------------------------------- /.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.settings/stm32cubeide.project.prefs: -------------------------------------------------------------------------------- 1 | 66BE74F758C12D739921AEA421D593D3=1 2 | 8DF89ED150041C4CBC7CB9A9CAA90856=6A4059706C2A0D735DB38D80B7E03A36 3 | DC22A860405A8BF2F2C095E5B6529F12=86502B8B27CFCEBD9E98C02585941741 4 | eclipse.preferences.version=1 5 | -------------------------------------------------------------------------------- /Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2023 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __MAIN_H 23 | #define __MAIN_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32g0xx_hal.h" 31 | 32 | /* Private includes ----------------------------------------------------------*/ 33 | /* USER CODE BEGIN Includes */ 34 | 35 | /* USER CODE END Includes */ 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* USER CODE BEGIN ET */ 39 | 40 | /* USER CODE END ET */ 41 | 42 | /* Exported constants --------------------------------------------------------*/ 43 | /* USER CODE BEGIN EC */ 44 | 45 | /* USER CODE END EC */ 46 | 47 | /* Exported macro ------------------------------------------------------------*/ 48 | /* USER CODE BEGIN EM */ 49 | 50 | /* USER CODE END EM */ 51 | 52 | /* Exported functions prototypes ---------------------------------------------*/ 53 | void Error_Handler(void); 54 | 55 | /* USER CODE BEGIN EFP */ 56 | 57 | /* USER CODE END EFP */ 58 | 59 | /* Private defines -----------------------------------------------------------*/ 60 | 61 | /* USER CODE BEGIN Private defines */ 62 | 63 | /* USER CODE END Private defines */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __MAIN_H */ 70 | -------------------------------------------------------------------------------- /Core/Inc/stm32g0xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g0xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2023 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32G0xx_IT_H 22 | #define __STM32G0xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void SVC_Handler(void); 52 | void PendSV_Handler(void); 53 | void SysTick_Handler(void); 54 | void USART3_4_IRQHandler(void); 55 | /* USER CODE BEGIN EFP */ 56 | 57 | /* USER CODE END EFP */ 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* __STM32G0xx_IT_H */ 64 | -------------------------------------------------------------------------------- /Core/Src/stm32g0xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g0xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2023 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | /* USER CODE BEGIN Includes */ 24 | 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN TD */ 29 | 30 | /* USER CODE END TD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN Define */ 34 | 35 | /* USER CODE END Define */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN Macro */ 39 | 40 | /* USER CODE END Macro */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | /* USER CODE BEGIN PV */ 44 | 45 | /* USER CODE END PV */ 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* USER CODE BEGIN PFP */ 49 | 50 | /* USER CODE END PFP */ 51 | 52 | /* External functions --------------------------------------------------------*/ 53 | /* USER CODE BEGIN ExternalFunctions */ 54 | 55 | /* USER CODE END ExternalFunctions */ 56 | 57 | /* USER CODE BEGIN 0 */ 58 | 59 | /* USER CODE END 0 */ 60 | /** 61 | * Initializes the Global MSP. 62 | */ 63 | void HAL_MspInit(void) 64 | { 65 | /* USER CODE BEGIN MspInit 0 */ 66 | 67 | /* USER CODE END MspInit 0 */ 68 | 69 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 70 | __HAL_RCC_PWR_CLK_ENABLE(); 71 | 72 | /* System interrupt init*/ 73 | 74 | /* USER CODE BEGIN MspInit 1 */ 75 | 76 | /* USER CODE END MspInit 1 */ 77 | } 78 | 79 | /** 80 | * @brief CRC MSP Initialization 81 | * This function configures the hardware resources used in this example 82 | * @param hcrc: CRC handle pointer 83 | * @retval None 84 | */ 85 | void HAL_CRC_MspInit(CRC_HandleTypeDef* hcrc) 86 | { 87 | if(hcrc->Instance==CRC) 88 | { 89 | /* USER CODE BEGIN CRC_MspInit 0 */ 90 | 91 | /* USER CODE END CRC_MspInit 0 */ 92 | /* Peripheral clock enable */ 93 | __HAL_RCC_CRC_CLK_ENABLE(); 94 | /* USER CODE BEGIN CRC_MspInit 1 */ 95 | 96 | /* USER CODE END CRC_MspInit 1 */ 97 | } 98 | 99 | } 100 | 101 | /** 102 | * @brief CRC MSP De-Initialization 103 | * This function freeze the hardware resources used in this example 104 | * @param hcrc: CRC handle pointer 105 | * @retval None 106 | */ 107 | void HAL_CRC_MspDeInit(CRC_HandleTypeDef* hcrc) 108 | { 109 | if(hcrc->Instance==CRC) 110 | { 111 | /* USER CODE BEGIN CRC_MspDeInit 0 */ 112 | 113 | /* USER CODE END CRC_MspDeInit 0 */ 114 | /* Peripheral clock disable */ 115 | __HAL_RCC_CRC_CLK_DISABLE(); 116 | /* USER CODE BEGIN CRC_MspDeInit 1 */ 117 | 118 | /* USER CODE END CRC_MspDeInit 1 */ 119 | } 120 | 121 | } 122 | 123 | /** 124 | * @brief UART MSP Initialization 125 | * This function configures the hardware resources used in this example 126 | * @param huart: UART handle pointer 127 | * @retval None 128 | */ 129 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 130 | { 131 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 132 | if(huart->Instance==USART3) 133 | { 134 | /* USER CODE BEGIN USART3_MspInit 0 */ 135 | 136 | /* USER CODE END USART3_MspInit 0 */ 137 | /* Peripheral clock enable */ 138 | __HAL_RCC_USART3_CLK_ENABLE(); 139 | 140 | __HAL_RCC_GPIOC_CLK_ENABLE(); 141 | /**USART3 GPIO Configuration 142 | PC11 ------> USART3_RX 143 | PC10 ------> USART3_TX 144 | */ 145 | GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_10; 146 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 147 | GPIO_InitStruct.Pull = GPIO_NOPULL; 148 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 149 | GPIO_InitStruct.Alternate = GPIO_AF0_USART3; 150 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 151 | 152 | /* USART3 interrupt Init */ 153 | HAL_NVIC_SetPriority(USART3_4_IRQn, 0, 0); 154 | HAL_NVIC_EnableIRQ(USART3_4_IRQn); 155 | /* USER CODE BEGIN USART3_MspInit 1 */ 156 | 157 | /* USER CODE END USART3_MspInit 1 */ 158 | } 159 | 160 | } 161 | 162 | /** 163 | * @brief UART MSP De-Initialization 164 | * This function freeze the hardware resources used in this example 165 | * @param huart: UART handle pointer 166 | * @retval None 167 | */ 168 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 169 | { 170 | if(huart->Instance==USART3) 171 | { 172 | /* USER CODE BEGIN USART3_MspDeInit 0 */ 173 | 174 | /* USER CODE END USART3_MspDeInit 0 */ 175 | /* Peripheral clock disable */ 176 | __HAL_RCC_USART3_CLK_DISABLE(); 177 | 178 | /**USART3 GPIO Configuration 179 | PC11 ------> USART3_RX 180 | PC10 ------> USART3_TX 181 | */ 182 | HAL_GPIO_DeInit(GPIOC, GPIO_PIN_11|GPIO_PIN_10); 183 | 184 | /* USART3 interrupt DeInit */ 185 | HAL_NVIC_DisableIRQ(USART3_4_IRQn); 186 | /* USER CODE BEGIN USART3_MspDeInit 1 */ 187 | 188 | /* USER CODE END USART3_MspDeInit 1 */ 189 | } 190 | 191 | } 192 | 193 | /* USER CODE BEGIN 1 */ 194 | 195 | /* USER CODE END 1 */ 196 | -------------------------------------------------------------------------------- /Core/Src/stm32g0xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g0xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2023 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "stm32g0xx_it.h" 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN TD */ 29 | 30 | /* USER CODE END TD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN PD */ 34 | 35 | /* USER CODE END PD */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PM */ 39 | 40 | /* USER CODE END PM */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | /* USER CODE BEGIN PV */ 44 | 45 | /* USER CODE END PV */ 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* USER CODE BEGIN PFP */ 49 | 50 | /* USER CODE END PFP */ 51 | 52 | /* Private user code ---------------------------------------------------------*/ 53 | /* USER CODE BEGIN 0 */ 54 | 55 | /* USER CODE END 0 */ 56 | 57 | /* External variables --------------------------------------------------------*/ 58 | extern UART_HandleTypeDef huart3; 59 | /* USER CODE BEGIN EV */ 60 | 61 | /* USER CODE END EV */ 62 | 63 | /******************************************************************************/ 64 | /* Cortex-M0+ Processor Interruption and Exception Handlers */ 65 | /******************************************************************************/ 66 | /** 67 | * @brief This function handles Non maskable interrupt. 68 | */ 69 | void NMI_Handler(void) 70 | { 71 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 72 | 73 | /* USER CODE END NonMaskableInt_IRQn 0 */ 74 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 75 | while (1) 76 | { 77 | } 78 | /* USER CODE END NonMaskableInt_IRQn 1 */ 79 | } 80 | 81 | /** 82 | * @brief This function handles Hard fault interrupt. 83 | */ 84 | void HardFault_Handler(void) 85 | { 86 | /* USER CODE BEGIN HardFault_IRQn 0 */ 87 | 88 | /* USER CODE END HardFault_IRQn 0 */ 89 | while (1) 90 | { 91 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 92 | /* USER CODE END W1_HardFault_IRQn 0 */ 93 | } 94 | } 95 | 96 | /** 97 | * @brief This function handles System service call via SWI instruction. 98 | */ 99 | void SVC_Handler(void) 100 | { 101 | /* USER CODE BEGIN SVC_IRQn 0 */ 102 | 103 | /* USER CODE END SVC_IRQn 0 */ 104 | /* USER CODE BEGIN SVC_IRQn 1 */ 105 | 106 | /* USER CODE END SVC_IRQn 1 */ 107 | } 108 | 109 | /** 110 | * @brief This function handles Pendable request for system service. 111 | */ 112 | void PendSV_Handler(void) 113 | { 114 | /* USER CODE BEGIN PendSV_IRQn 0 */ 115 | 116 | /* USER CODE END PendSV_IRQn 0 */ 117 | /* USER CODE BEGIN PendSV_IRQn 1 */ 118 | 119 | /* USER CODE END PendSV_IRQn 1 */ 120 | } 121 | 122 | /** 123 | * @brief This function handles System tick timer. 124 | */ 125 | void SysTick_Handler(void) 126 | { 127 | /* USER CODE BEGIN SysTick_IRQn 0 */ 128 | 129 | /* USER CODE END SysTick_IRQn 0 */ 130 | HAL_IncTick(); 131 | /* USER CODE BEGIN SysTick_IRQn 1 */ 132 | 133 | /* USER CODE END SysTick_IRQn 1 */ 134 | } 135 | 136 | /******************************************************************************/ 137 | /* STM32G0xx Peripheral Interrupt Handlers */ 138 | /* Add here the Interrupt Handlers for the used peripherals. */ 139 | /* For the available peripheral interrupt handler names, */ 140 | /* please refer to the startup file (startup_stm32g0xx.s). */ 141 | /******************************************************************************/ 142 | 143 | /** 144 | * @brief This function handles USART3 and USART4 interrupts. 145 | */ 146 | void USART3_4_IRQHandler(void) 147 | { 148 | /* USER CODE BEGIN USART3_4_IRQn 0 */ 149 | 150 | /* USER CODE END USART3_4_IRQn 0 */ 151 | HAL_UART_IRQHandler(&huart3); 152 | /* USER CODE BEGIN USART3_4_IRQn 1 */ 153 | 154 | /* USER CODE END USART3_4_IRQn 1 */ 155 | } 156 | 157 | /* USER CODE BEGIN 1 */ 158 | 159 | /* USER CODE END 1 */ 160 | -------------------------------------------------------------------------------- /Core/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sysmem.c 4 | * @author Generated by STM32CubeIDE 5 | * @brief STM32CubeIDE System Memory calls file 6 | * 7 | * For more information about which C functions 8 | * need which of these lowlevel functions 9 | * please consult the newlib libc manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * Copyright (c) 2022 STMicroelectronics. 14 | * All rights reserved. 15 | * 16 | * This software is licensed under terms that can be found in the LICENSE file 17 | * in the root directory of this software component. 18 | * If no LICENSE file comes with this software, it is provided AS-IS. 19 | * 20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes */ 24 | #include 25 | #include 26 | 27 | /** 28 | * Pointer to the current high watermark of the heap usage 29 | */ 30 | static uint8_t *__sbrk_heap_end = NULL; 31 | 32 | /** 33 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc 34 | * and others from the C library 35 | * 36 | * @verbatim 37 | * ############################################################################ 38 | * # .data # .bss # newlib heap # MSP stack # 39 | * # # # # Reserved by _Min_Stack_Size # 40 | * ############################################################################ 41 | * ^-- RAM start ^-- _end _estack, RAM end --^ 42 | * @endverbatim 43 | * 44 | * This implementation starts allocating at the '_end' linker symbol 45 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack 46 | * The implementation considers '_estack' linker symbol to be RAM end 47 | * NOTE: If the MSP stack, at any point during execution, grows larger than the 48 | * reserved size, please increase the '_Min_Stack_Size'. 49 | * 50 | * @param incr Memory size 51 | * @return Pointer to allocated memory 52 | */ 53 | void *_sbrk(ptrdiff_t incr) 54 | { 55 | extern uint8_t _end; /* Symbol defined in the linker script */ 56 | extern uint8_t _estack; /* Symbol defined in the linker script */ 57 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ 58 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; 59 | const uint8_t *max_heap = (uint8_t *)stack_limit; 60 | uint8_t *prev_heap_end; 61 | 62 | /* Initialize heap end at first call */ 63 | if (NULL == __sbrk_heap_end) 64 | { 65 | __sbrk_heap_end = &_end; 66 | } 67 | 68 | /* Protect heap from growing into the reserved MSP stack */ 69 | if (__sbrk_heap_end + incr > max_heap) 70 | { 71 | errno = ENOMEM; 72 | return (void *)-1; 73 | } 74 | 75 | prev_heap_end = __sbrk_heap_end; 76 | __sbrk_heap_end += incr; 77 | 78 | return (void *)prev_heap_end; 79 | } 80 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/ai_common_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ai_common_config.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of AI platform common compile configuration defines 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef AI_COMMON_CONFIG_H 22 | #define AI_COMMON_CONFIG_H 23 | #pragma once 24 | 25 | /*! 26 | * @defgroup layers Layers Compilation Config Definitions 27 | * @brief definition 28 | * 29 | */ 30 | 31 | #define HAS_PROFILE_FLOAT 32 | #define HAS_PROFILE_FIXED 33 | 34 | 35 | #endif /*AI_COMMON_CONFIG_H*/ 36 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/ai_datatypes.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ai_datatypes.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief Definitions of AI platform private APIs types 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef AI_DATATYPES_H 23 | #define AI_DATATYPES_H 24 | #pragma once 25 | 26 | #include 27 | #include "ai_platform.h" 28 | #include "ai_platform_interface.h" 29 | 30 | /*! 31 | * @defgroup datatypes Platform Interface Datatypes 32 | * @brief Data structures used by AI platform to implement neural networks 33 | * 34 | */ 35 | 36 | /** Count Variable Number of Arguments (up to 64 elements) *******************/ 37 | #define AI_NUMARGS(...) \ 38 | PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) 39 | #define PP_NARG_(...) \ 40 | PP_ARG_N(__VA_ARGS__) 41 | #define PP_ARG_N( \ 42 | _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \ 43 | _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ 44 | _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ 45 | _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ 46 | _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ 47 | _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ 48 | _61,_62,_63,N,...) N 49 | #define PP_RSEQ_N() \ 50 | 63,62,61,60, \ 51 | 59,58,57,56,55,54,53,52,51,50, \ 52 | 49,48,47,46,45,44,43,42,41,40, \ 53 | 39,38,37,36,35,34,33,32,31,30, \ 54 | 29,28,27,26,25,24,23,22,21,20, \ 55 | 19,18,17,16,15,14,13,12,11,10, \ 56 | 9,8,7,6,5,4,3,2,1,0 57 | 58 | 59 | /*****************************************************************************/ 60 | #define AI_PTR_ALIGN(ptr, alignment) \ 61 | ((((ai_uptr)(ptr))+((ai_uptr)(alignment)-1))&(~((ai_uptr)(alignment)-1))) 62 | 63 | 64 | /*! 65 | * @typedef ai_offset 66 | * @ingroup ai_datatypes_internal 67 | * @brief Generic index offset type 68 | */ 69 | typedef int32_t ai_offset; 70 | 71 | 72 | AI_API_DECLARE_BEGIN 73 | 74 | AI_API_DECLARE_END 75 | 76 | #endif /* AI_DATATYPES_H */ 77 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/ai_lite.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ai_lite.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief Definitions and implementations of runtime-lite public APIs 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef AI_LITE_H 22 | #define AI_LITE_H 23 | #pragma once 24 | #include "ai_platform.h" 25 | #include "ai_lite_inspect.h" 26 | 27 | #define LITE_API_ENTRY \ 28 | /* LITE_API_ENTRY */ 29 | 30 | #define LITE_GRAPH_INIT(_inputs, _outputs, _activations, _weights, _cb, _cb_cookie) { \ 31 | .inputs = (_inputs), \ 32 | .outputs = (_outputs), \ 33 | .activations = (_activations), \ 34 | .weights = (const ai_handle*)(_weights), \ 35 | .cb = ((ai_lite_inspect_cb)(_cb)), \ 36 | .cb_cookie = ((ai_handle)(_cb_cookie)), \ 37 | } 38 | 39 | 40 | AI_API_DECLARE_BEGIN 41 | 42 | typedef enum { 43 | LITE_OK = 0, 44 | LITE_KO_INPUTS, 45 | LITE_KO_OUTPUTS, 46 | LITE_KO_WEIGHTS, 47 | LITE_KO_ACTIVATIONS, 48 | LITE_KO_GRAPH, 49 | } lite_result; 50 | 51 | 52 | typedef struct { 53 | ai_handle* inputs; 54 | ai_handle* outputs; 55 | ai_handle* activations; 56 | const ai_handle* weights; 57 | ai_lite_inspect_cb cb; 58 | ai_handle cb_cookie; 59 | } lite_graph; 60 | 61 | AI_API_DECLARE_END 62 | 63 | #endif /* AI_LITE_H */ 64 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/ai_lite_inspect.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ai_lite_inspect.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief Definitions and implementations of runtime-lite inspection routines 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef AI_LITE_INSPECT_H 22 | #define AI_LITE_INSPECT_H 23 | #pragma once 24 | #include "ai_platform.h" 25 | 26 | //#define HAS_LITE_INSPECT 27 | 28 | AI_API_DECLARE_BEGIN 29 | 30 | /* Types needed by inspect callback signature */ 31 | typedef ai_i32 ai_data_format; 32 | typedef ai_i32 ai_data_id; 33 | 34 | /* Lite inspect callback definition */ 35 | typedef void (*ai_lite_inspect_cb)( 36 | const ai_handle cookie, 37 | const ai_data_id node_id, 38 | const ai_handle data, const ai_size data_size, 39 | const ai_data_format data_fmt, const ai_data_id data_id); 40 | 41 | 42 | #ifdef HAS_LITE_INSPECT 43 | 44 | #define LITE_INSPECT_CB(_node_id, _data, _data_size, _data_fmt, _data_id) { \ 45 | if (graph->cb) { \ 46 | graph->cb(graph->cb_cookie, \ 47 | (ai_data_id)(_node_id), (ai_handle)(_data), (ai_size)(_data_size), \ 48 | (ai_data_format)(_data_fmt), (ai_data_id)(_data_id)); \ 49 | } \ 50 | } 51 | 52 | #else 53 | 54 | #define LITE_INSPECT_CB(_node_id, _data, _data_size, _data_fmt, _data_id) { \ 55 | do { /* LITE_INSPECT_CB() */ } while (0); \ 56 | } 57 | 58 | #endif /* HAS_LITE_INSPECT */ 59 | 60 | AI_API_DECLARE_END 61 | 62 | #endif /* AI_LITE_INSPECT_H */ 63 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/ai_lite_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ai_lite_interface.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief Definitions and implementations of runtime-lite codegen APIs 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef AI_LITE_INTERFACE_H 22 | #define AI_LITE_INTERFACE_H 23 | #pragma once 24 | #include "ai_platform.h" 25 | #include "ai_lite.h" 26 | 27 | /*****************************************************************************/ 28 | /* Generic Codegen Section */ 29 | // #ifdef HAS_LOG 30 | #if 0 31 | #include "core_log.h" 32 | 33 | #define LITE_GRAPH_START(_graph_name) \ 34 | AI_LOG_DEBUG("[LITE GRAPH START] : " _graph_name) 35 | 36 | #define LITE_GRAPH_END(_graph_name) \ 37 | AI_LOG_DEBUG("[LITE GRAPH END] : " _graph_name) 38 | 39 | #else 40 | 41 | #define LITE_GRAPH_START(_graph_name) \ 42 | /* LITE_GRAPH_START() */ 43 | 44 | #define LITE_GRAPH_END(_graph_name) \ 45 | /* LITE_GRAPH_END() */ 46 | 47 | #endif /* HAS_LOG */ 48 | 49 | #ifdef HAS_AI_ASSERT 50 | #include 51 | #define LITE_ASSERT(_cond) \ 52 | { assert(_cond); } 53 | #else 54 | #define LITE_ASSERT(_cond) \ 55 | do { /* LITE_ASSERT() */ } while (0); 56 | 57 | #endif /*HAS_AI_ASSERT*/ 58 | 59 | /*****************************************************************************/ 60 | #if defined(_MSC_VER) 61 | #define LITE_DECLARE_STATIC static __inline 62 | #define LITE_HINT_INLINE static __inline 63 | #define LITE_FORCE_INLINE static __inline 64 | #elif defined(__ICCARM__) || defined (__IAR_SYSTEMS_ICC__) 65 | #define LITE_DECLARE_STATIC static inline 66 | #define LITE_HINT_INLINE static inline 67 | #define LITE_FORCE_INLINE static inline 68 | #elif defined(__GNUC__) 69 | #define LITE_DECLARE_STATIC static __inline 70 | #define LITE_HINT_INLINE static __inline 71 | #define LITE_FORCE_INLINE static __inline 72 | #else 73 | #define LITE_DECLARE_STATIC static __inline 74 | #define LITE_HINT_INLINE static __inline 75 | #define LITE_FORCE_INLINE static __inline 76 | #endif /* _MSC_VER */ 77 | 78 | #define LITE_API_ENTRY /* LITE_API_ENTRY */ 79 | 80 | #define LITE_PACK(...) \ 81 | __VA_ARGS__ 82 | 83 | #define LITE_UNUSED(_elem) \ 84 | ((void)(_elem)); 85 | 86 | #define LITE_KERNEL_SECTION(_code_block) \ 87 | { LITE_PACK(_code_block) } 88 | 89 | 90 | /*****************************************************************************/ 91 | /* Arrays Section */ 92 | 93 | #define LITE_ARRAY_VALUES(...) \ 94 | { LITE_PACK(__VA_ARGS__) } 95 | 96 | #define LITE_ARRAY_DATA(_array, _type) \ 97 | ((_type*)(_array)->data) 98 | 99 | #define LITE_ARRAY_DATA_START(_array, _type) \ 100 | ((_type*)(_array)->data_start) 101 | 102 | /*****************************************************************************/ 103 | /* Tensors Section */ 104 | 105 | #define LITE_TENSOR_ARRAY(_tensor, _pos) \ 106 | (((_tensor)->data) + (_pos)) 107 | 108 | /*****************************************************************************/ 109 | /* Tensors List Section */ 110 | 111 | #define LITE_TENSOR_LIST(_chain, _pos) \ 112 | (&(_chain)->chain[_pos]) 113 | 114 | #define LITE_TENSOR_IN(_chain, _pos) \ 115 | (LITE_TENSOR_LIST(_chain, 0)->tensor[_pos]) 116 | 117 | #define LITE_TENSOR_OUT(_chain, _pos) \ 118 | (LITE_TENSOR_LIST(_chain, 1)->tensor[_pos]) 119 | 120 | #define LITE_TENSOR_WEIGHTS(_chain, _pos) \ 121 | (LITE_TENSOR_LIST(_chain, 2)->tensor[_pos]) 122 | 123 | #define LITE_TENSOR_SCRATCHS(_chain, _pos) \ 124 | (LITE_TENSOR_LIST(_chain, 3)->tensor[_pos]) 125 | 126 | /*****************************************************************************/ 127 | #define LITE_LAYER_ACQUIRE(name_, cast_type_, ptr_) \ 128 | LITE_ASSERT(ptr_) \ 129 | AI_CONCAT(ai_layer_, cast_type_)* name_ = \ 130 | (AI_CONCAT(ai_layer_, cast_type_)*)(ptr_); 131 | 132 | #define LITE_LAYER_RELEASE(name_, cast_type_) \ 133 | /* LITE_LAYER_RELEASE() */ 134 | 135 | 136 | /*****************************************************************************/ 137 | AI_API_DECLARE_BEGIN 138 | 139 | AI_API_DECLARE_END 140 | 141 | #endif /* AI_LITE_INTERFACE_H */ 142 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/ai_lite_math_helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef AI_LITE_MATH_HELPERS_H 2 | #define AI_LITE_MATH_HELPERS_H 3 | #include 4 | 5 | #include "ai_platform.h" 6 | #include "ai_platform_interface.h" 7 | #include "ai_datatypes_defines.h" 8 | 9 | #define AI_FLOAT_TOLERANCE (6.19209290e-5F) /* Used for small calculation 10 | noise issues */ 11 | #define AI_FLOAT_EPSILON (1.19209290e-7F) 12 | #define AI_I8_EPSILON (0.00787401F) /* 1/(2^7 - 1) */ 13 | #define AI_I16_EPSILON (3.051851e-5F) /* 1/(2^15 - 1) */ 14 | 15 | #define AI_FLT_MAX (3.40282346638528859812e+38f) 16 | 17 | #define AI_MIN(x,y) ( ((x)<(y)) ? (x) : (y) ) 18 | #define AI_MAX(x,y) ( ((x)>(y)) ? (x) : (y) ) 19 | #define AI_SIGN(x) (((x)>0) ? 1 : -1) 20 | #define AI_CLAMP(x, min, max) AI_MIN(AI_MAX(x,min), max) 21 | #define AI_ABS(x) fabsf(x) 22 | #define AI_ABS_DIFF(x, y) ( ((x)>(y)) ? ((x)-(y)) : ((y)-(x)) ) 23 | #define AI_NEG(x) ( -1 * (x) ) 24 | #define AI_NOT(x) ( ((x)==true) ? false : true) 25 | #define AI_RECIPROCAL(x) ( 1.0f / (x) ) 26 | #define AI_CEIL(x) ceilf(x) 27 | #define AI_FLOOR(x) floorf(x) 28 | #define AI_FLOOR_DIV(x, y) AI_FLOOR((x)/(y)) /* floor division: x // y */ 29 | #define AI_FLOOR_MOD(x, y) fmodf(x, y) 30 | #define AI_ROUND(x) roundf(x) 31 | #define AI_POW(x,y) powf(x, y) 32 | 33 | #define AI_SQUARED_DIFF(x, y) (((x)-(y)) * ((x)-(y))) 34 | 35 | #define AI_FLOAT_NEGATIVE_HALF (-0.5f + AI_FLOAT_EPSILON) 36 | #define AI_FLOAT_POSITIVE_HALF (0.5f) 37 | 38 | 39 | #define AI_MATH_ACOS(x) acosf(x) 40 | #define AI_MATH_ACOSH(x) acoshf(x) 41 | #define AI_MATH_ASIN(x) asinf(x) 42 | #define AI_MATH_ASINH(x) asinhf(x) 43 | #define AI_MATH_ATAN(x) atanf(x) 44 | #define AI_MATH_ATANH(x) atanhf(x) 45 | #define AI_MATH_COS(x) cosf(x) 46 | #define AI_MATH_COSH(x) coshf(x) 47 | #define AI_MATH_ERF(x) erff(x) 48 | #define AI_MATH_EXP(x) expf(x) 49 | #define AI_MATH_LOG(x) logf(x) 50 | #define AI_MATH_POW(x, e) powf((x), (e)) 51 | #define AI_MATH_RSQRT(x) (1.0f / AI_MATH_SQRT(x)) 52 | #define AI_MATH_SIN(x) sinf(x) 53 | #define AI_MATH_SINH(x) sinhf(x) 54 | #define AI_MATH_SQRT(x) ai_math_sqrt(x) 55 | #define AI_MATH_TAN(x) tanf(x) 56 | #define AI_MATH_TANH(x) tanhf(x) 57 | #define AI_MATH_SQUARE(x) AI_MATH_POW(x, 2.0f) 58 | 59 | #define AI_MATH_ACOS(x) acosf(x) 60 | #define AI_MATH_ACOSH(x) acoshf(x) 61 | #define AI_MATH_ASIN(x) asinf(x) 62 | #define AI_MATH_ASINH(x) asinhf(x) 63 | #define AI_MATH_ATAN(x) atanf(x) 64 | #define AI_MATH_ATANH(x) atanhf(x) 65 | #define AI_MATH_COS(x) cosf(x) 66 | #define AI_MATH_COSH(x) coshf(x) 67 | #define AI_MATH_ERF(x) erff(x) 68 | #define AI_MATH_EXP(x) expf(x) 69 | #define AI_MATH_LOG(x) logf(x) 70 | #define AI_MATH_POW(x, e) powf((x), (e)) 71 | #define AI_MATH_RSQRT(x) (1.0f / AI_MATH_SQRT(x)) 72 | #define AI_MATH_SIN(x) sinf(x) 73 | #define AI_MATH_SINH(x) sinhf(x) 74 | #define AI_MATH_SQRT(x) ai_math_sqrt(x) 75 | #define AI_MATH_TAN(x) tanf(x) 76 | #define AI_MATH_TANH(x) tanhf(x) 77 | #define AI_MATH_SQUARE(x) AI_MATH_POW(x, 2.0f) 78 | #define AI_MATH_RELU_TEST(x, thr, min, max) \ 79 | (((x)<=(thr)) ? (min) : (max)) 80 | 81 | #define AI_MATH_CLIP_LINEAR_REMAP(x, alpha, beta) \ 82 | (AI_MAX(0, AI_MIN(1, ((x) * (alpha) + (beta))))) 83 | 84 | #define AI_MATH_RELU_GENERIC(x, thr, alpha, max) \ 85 | AI_MATH_RELU_TEST(x, max, AI_MATH_RELU_GENERIC_NO_MAX(x, thr, alpha), max) 86 | 87 | #define AI_MATH_RELU_GENERIC_NO_MAX(x, thr, alpha) \ 88 | AI_MATH_RELU_TEST(x, thr, ((alpha)*((x)-(thr))), x) 89 | 90 | #define AI_MATH_RELU_THRESHOLDED(x, thr) \ 91 | AI_MATH_RELU_TEST(x, thr, 0, (x)) 92 | 93 | #define AI_MATH_LEAKY_RELU(x, neg_slope, pos_slope) \ 94 | AI_MATH_RELU_TEST(x, 0, (x)*(neg_slope), (x)*(pos_slope)) 95 | // ( ((x)>0) ? (x)*(pos_slope) : (x)*(neg_slope) ) 96 | 97 | #define AI_MATH_PRELU(x, slope) \ 98 | AI_MATH_RELU_TEST(x, 0, (x)*(slope), (x)) 99 | // AI_MATH_LEAKY_RELU(x, slope, 1) 100 | 101 | #define AI_MATH_RELU(x) \ 102 | AI_MATH_RELU_TEST(x, 0, 0, x) 103 | // AI_MAX(x, 0) 104 | 105 | #define AI_MATH_ELU(x, alpha) \ 106 | (AI_MAX(0.0f, (x)) + AI_MIN(0.0f, (alpha) * (AI_MATH_EXP(x)-1.0f))) 107 | 108 | #define AI_MATH_SELU(x, alpha, scale) \ 109 | ((scale)*AI_MATH_ELU(x, alpha)) 110 | 111 | #define AI_MATH_SCALED_TANH(x, alpha, beta) \ 112 | ((alpha)*AI_MATH_TANH((beta)*(x))) 113 | 114 | #define AI_MATH_SIGMOID(x) \ 115 | (1.0f / (1.0f + AI_MATH_EXP(-(x)))) 116 | 117 | #define AI_MATH_LOGISTIC(x)\ 118 | (x < 0) ? (1.0f -(1.0f / (1.0f + AI_MATH_EXP(-AI_ABS(x))))) :\ 119 | (1.0f / (1.0f + AI_MATH_EXP(-AI_ABS(x)))) 120 | 121 | #define AI_MATH_HARD_SIGMOID(x, alpha, beta) \ 122 | AI_MATH_CLIP_LINEAR_REMAP(x, alpha, beta) 123 | 124 | /* Formula with higher accuracy */ 125 | #define AI_MATH_SWISH(x) \ 126 | ((x) * AI_MATH_SIGMOID(x)) 127 | 128 | #define AI_MATH_HARD_SWISH(x) \ 129 | ((x) * AI_MATH_CLIP_LINEAR_REMAP(x, 1.0f/6, 0.5f)) 130 | 131 | #define AI_MATH_SOFT_PLUS(x) \ 132 | AI_MATH_LOG(1.0f + AI_MATH_EXP(x)) 133 | 134 | #define AI_MATH_SOFT_SIGN(x) \ 135 | ((x) / (1.0f + AI_ABS(x))) 136 | 137 | 138 | AI_API_DECLARE_BEGIN 139 | 140 | /*! 141 | * @brief platform optimized square root on a float value 142 | * @ingroup math_helpers 143 | * @param x input value 144 | * @return square root of the value 145 | */ 146 | AI_INTERFACE_ENTRY ai_float ai_math_sqrt(const ai_float x); 147 | 148 | 149 | AI_API_DECLARE_END 150 | 151 | #endif /* AI_LITE_MATH_HELPERS_H */ 152 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/core_convert.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_convert.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of core utils routines 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef CORE_CONVERT_H 23 | #define CORE_CONVERT_H 24 | #pragma once 25 | 26 | #include "ai_platform.h" 27 | #include "ai_platform_interface.h" 28 | 29 | #include "core_common.h" 30 | 31 | AI_API_DECLARE_BEGIN 32 | 33 | /*! 34 | * @defgroup core_convert Core Convert Routines 35 | * @brief Implementation of core node format convertion routines 36 | * (Q7 to float, ... etc.) 37 | */ 38 | 39 | 40 | /*! 41 | * @brief Convert tensors from float to quantized or viceversa 42 | * @ingroup core_convert 43 | * @param[in] pNode in a handler to node (layer or operator) 44 | */ 45 | AI_INTERNAL_API 46 | void node_convert(ai_node *pNode); 47 | 48 | /*! 49 | * @brief Convert integer tensors between QM.N formats (8/16 bits) 50 | * @ingroup core_convert 51 | * @param[in] pNode in a handler to node (layer or operator) 52 | */ 53 | AI_INTERNAL_API 54 | void node_convert_fixed(ai_node *pNode); 55 | 56 | /*! 57 | * @brief Convert integer tensors between signed and usigned (int8/uint8) formats 58 | * @ingroup core_convert 59 | * @param[in] pNode in a handler to node (layer or operator) 60 | */ 61 | AI_INTERNAL_API 62 | void node_convert_integer(ai_node *pNode); 63 | 64 | /*! 65 | * @brief Convert float tensor to binary 66 | * @ingroup core_convert 67 | * @param[in] pNode in a handler to node (layer or operator) 68 | */ 69 | AI_INTERNAL_API 70 | void node_convert_if32os1(ai_node *pNode); 71 | 72 | 73 | /*! 74 | * @brief Convert binary tensor to float 75 | * @ingroup core_convert 76 | * @param[in] pNode in a handler to node (layer or operator) 77 | */ 78 | AI_INTERNAL_API 79 | void node_convert_is8os1(ai_node *pNode); 80 | 81 | 82 | /*! 83 | * @brief Convert binary tensor to signed int 8 bit 84 | * @ingroup core_convert 85 | * @param[in] pNode in a handler to node (layer or operator) 86 | */ 87 | AI_INTERNAL_API 88 | void node_convert_is1os8(ai_node *pNode); 89 | 90 | 91 | /*! 92 | * @brief Convert binary tensor to signed int 16 bit 93 | * @ingroup core_convert 94 | * @param[in] pNode in a handler to node (layer or operator) 95 | */ 96 | AI_INTERNAL_API 97 | void node_convert_is1os16(ai_node *pNode); 98 | 99 | 100 | /*! 101 | * @brief Convert binary tensor to float 102 | * @ingroup core_convert 103 | * @param[in] pNode in a handler to node (layer or operator) 104 | */ 105 | AI_INTERNAL_API 106 | void node_convert_is1of32(ai_node *pNode); 107 | 108 | 109 | /*! 110 | * @brief Convert signed int 16 bit tensor to float 111 | * @ingroup core_convert 112 | * @param[in] pNode in a handler to node (layer or operator) 113 | */ 114 | AI_INTERNAL_API 115 | void node_convert_is16of32(ai_node *pNode); 116 | 117 | 118 | /*! 119 | * @brief Convert unsigned int 16 bit tensor to float 120 | * @ingroup core_convert 121 | * @param[in] pNode in a handler to node (layer or operator) 122 | */ 123 | AI_INTERNAL_API 124 | void node_convert_iu16of32(ai_node *pNode); 125 | 126 | 127 | /*! 128 | * @brief Convert float tensor to signed int 16 bit 129 | * @ingroup core_convert 130 | * @param[in] pNode in a handler to node (layer or operator) 131 | */ 132 | AI_INTERNAL_API 133 | void node_convert_if32os16(ai_node *pNode); 134 | 135 | 136 | /*! 137 | * @brief Convert float tensor to unsigned int 16 bit 138 | * @ingroup core_convert 139 | * @param[in] pNode in a handler to node (layer or operator) 140 | */ 141 | AI_INTERNAL_API 142 | void node_convert_if32ou16(ai_node *pNode); 143 | 144 | 145 | /*! 146 | * @brief Convert signed int 16 bit tensor to unsigned int 16 bit 147 | * @ingroup core_convert 148 | * @param[in] pNode in a handler to node (layer or operator) 149 | */ 150 | AI_INTERNAL_API 151 | void node_convert_is16ou16(ai_node *pNode); 152 | 153 | 154 | /*! 155 | * @brief Convert a shape struct into a stride struct 156 | * @ingroup core_convert 157 | * @param[in] in a pointer to a shape to convert 158 | * @return a condverted stride datastruct 159 | */ 160 | AI_INTERNAL_API 161 | void core_shape_to_stride(ai_stride* out, const ai_shape* in); 162 | 163 | 164 | #endif /*CORE_CONVERT_H*/ 165 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/core_datatypes.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_datatypes.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of core module private defines and datatypes 6 | * to public nor codegen tool 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | @verbatim 19 | @endverbatim 20 | ****************************************************************************** 21 | */ 22 | 23 | #ifndef AI_CORE_DATATYPES_H 24 | #define AI_CORE_DATATYPES_H 25 | #pragma once 26 | #include 27 | 28 | /*! 29 | * @defgroup Core Module Datatypes 30 | * @brief Data structures and defines used by core module 31 | */ 32 | 33 | /*! 34 | * @brief platform runtime core library version 35 | */ 36 | #define AI_PLATFORM_RUNTIME_MAJOR 8 37 | #define AI_PLATFORM_RUNTIME_MINOR 1 38 | #define AI_PLATFORM_RUNTIME_MICRO 0 39 | #define AI_PLATFORM_RUNTIME_BUILD A1-SNAPSHOT 40 | 41 | #define AI_MAGIC_CONTEXT_TOKEN (0xA1C00100) /*!< AI Cool! Magic Token */ 42 | 43 | #define AI_MAGIC_INSPECTOR_TOKEN (0xA1C00101) /*!< AI Cool! Magic Token */ 44 | 45 | 46 | #define AI_ID_OBJ(id) \ 47 | ((ai_id_obj)(id)) 48 | 49 | #define AI_C_ARRAY_COUNT(array_) \ 50 | ( sizeof(array_) / sizeof((array_)[0]) ) 51 | 52 | #define AI_C_ARRAY_BYTE_SIZE(array_) \ 53 | ( sizeof(array_) ) 54 | 55 | 56 | /*! 57 | * @typedef ai_id_obj 58 | * @ingroup core_datatypes 59 | * @brief numeric identifier for generic object instances (e.g. layers, 60 | * operators, etc.) It is used by codegen tool to keep tracks of specific 61 | * instances created 62 | */ 63 | typedef uint16_t ai_id_obj; 64 | 65 | #endif /*AI_CORE_DATATYPES_H*/ 66 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/core_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_log.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of core log interfaces 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef CORE_LOG_H 23 | #define CORE_LOG_H 24 | #pragma once 25 | 26 | #include "ai_platform.h" 27 | #include "ai_datatypes_defines.h" 28 | 29 | /*! 30 | * @defgroup core_log Logger core routines wrapper interface 31 | * @brief Common macros, datatypes and routines of ai logger module 32 | * @details This header defines the wrapping macros interfaces to handle the 33 | * global logger module. These macro are defined when the macro HAS_LOG is 34 | * defined, otherwise they are all set to NOP routines and no logger code is 35 | * compiled at all. When the macro HAS_LOG is defined, only the log messages 36 | * having an enum id >= the value of the macro are compiled. Thus to include in 37 | * compilation only log messages up to the error level the value of HAS_LOG must 38 | * be equal the the enum value of LOG_ERROR macro (i.e. 3). a value of 6 means 39 | * to include all log messages up to the lower LOG_TRACE level. 40 | */ 41 | 42 | #if defined HAS_LOG && (HAS_LOG>=0) 43 | #include "ai_log.h" 44 | #define AI_LOG_SECTION(...) \ 45 | { __VA_ARGS__ } 46 | 47 | #define AI_LOG_ACQUIRE() \ 48 | ai_log_acquire() 49 | #define AI_LOG_SET_LEVEL(level_) \ 50 | AI_WRAP_FUNC(ai_log_set_level(level_);) 51 | #define AI_LOG_SET_QUIET(onoff_) \ 52 | AI_WRAP_FUNC(ai_log_set_quiet(onoff_);) 53 | #define AI_LOG_SET_LOCK_FN(fn_, udata_) \ 54 | AI_WRAP_FUNC(ai_log_set_lock(fn_, udata_);) 55 | #define AI_LOG_CHANNEL_PUSH(level_, fn_, udata_) \ 56 | AI_WRAP_FUNC(ai_log_channel_push(level_, fn_, udata_);) 57 | #define AI_LOG_CHANNEL_POP(fn_, udata_) \ 58 | AI_WRAP_FUNC(ai_log_channel_pop(fn_, udata_);) 59 | #ifdef LOG_USE_FILE 60 | #define AI_LOG_SET_FILE_POINTER(fp_) \ 61 | AI_WRAP_FUNC(ai_log_set_fp(fp_);) 62 | #else 63 | #define AI_LOG_SET_FILE_POINTER(fp_) \ 64 | AI_WRAP_FUNC(/*AI_LOG_SET_FILE_POINTER()*/) 65 | #endif 66 | #else 67 | #define AI_LOG_SECTION(...) AI_WRAP_FUNC(/*AI_LOG_SECTION()*/) 68 | 69 | #define AI_LOG_ACQUIRE() (NULL) 70 | #define AI_LOG_SET_LEVEL(level_) AI_WRAP_FUNC(/*AI_LOG_SET_LEVEL()*/) 71 | #define AI_LOG_SET_QUIET(onoff_) AI_WRAP_FUNC(/*AI_LOG_SET_QUIET()*/) 72 | #define AI_LOG_SET_LOCK_FN(fn_, udata_) AI_WRAP_FUNC(/*AI_LOG_SET_LOCK_FN()*/) 73 | #define AI_LOG_CHANNEL_PUSH(level_, fn_, udata_) AI_WRAP_FUNC(/*AI_LOG_CHANNEL_PUSH()*/) 74 | #define AI_LOG_CHANNEL_POP(fn_, udata_) AI_WRAP_FUNC(/*AI_LOG_CHANNEL_POP()*/) 75 | #define AI_LOG_SET_FILE_POINTER(fp_) AI_WRAP_FUNC(/*AI_LOG_SET_FILE_POINTER()*/) 76 | #endif 77 | 78 | #if defined HAS_LOG 79 | #define AI_LOG_PRINT(level, fmt, ...) \ 80 | AI_WRAP_FUNC(ai_log_print(level, fmt, ##__VA_ARGS__);) 81 | #else 82 | #define AI_LOG_PRINT(level, fmt, ...) \ 83 | AI_WRAP_FUNC(/*AI_LOG_PRINT(...)*/) 84 | #endif 85 | 86 | #if defined HAS_LOG && (HAS_LOG>=LOG_SUDO) 87 | #define AI_LOG_SUDO(fmt, ...) \ 88 | AI_WRAP_FUNC(ai_log_log(LOG_SUDO, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) 89 | #else 90 | #define AI_LOG_SUDO(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_SUDO()*/) 91 | #endif 92 | 93 | #if defined HAS_LOG && (HAS_LOG>=LOG_TRACE) 94 | #define AI_LOG_TRACE(fmt, ...) \ 95 | AI_WRAP_FUNC(ai_log_log(LOG_TRACE, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) 96 | #else 97 | #define AI_LOG_TRACE(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_TRACE()*/) 98 | #endif 99 | 100 | #if defined HAS_LOG && (HAS_LOG>=LOG_DEBUG) 101 | #define AI_LOG_DEBUG(fmt, ...) \ 102 | AI_WRAP_FUNC(ai_log_log(LOG_DEBUG, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) 103 | #else 104 | #define AI_LOG_DEBUG(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_DEBUG()*/) 105 | #endif 106 | 107 | #if defined HAS_LOG && (HAS_LOG>=LOG_INFO) 108 | #define AI_LOG_INFO(fmt, ...) \ 109 | AI_WRAP_FUNC(ai_log_log(LOG_INFO, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) 110 | #else 111 | #define AI_LOG_INFO(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_INFO()*/) 112 | #endif 113 | 114 | #if defined HAS_LOG && (HAS_LOG>=LOG_WARN) 115 | #define AI_LOG_WARN(fmt, ...) \ 116 | AI_WRAP_FUNC(ai_log_log(LOG_WARN, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) 117 | #else 118 | #define AI_LOG_WARN(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_WARN()*/) 119 | #endif 120 | 121 | #if defined HAS_LOG && (HAS_LOG>=LOG_ERROR) 122 | #define AI_LOG_ERROR(fmt, ...) \ 123 | AI_WRAP_FUNC(ai_log_log(LOG_ERROR, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) 124 | #else 125 | #define AI_LOG_ERROR(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_ERROR()*/) 126 | #endif 127 | 128 | #if defined HAS_LOG && (HAS_LOG>=LOG_FATAL) 129 | #define AI_LOG_FATAL(fmt, ...) \ 130 | AI_WRAP_FUNC(ai_log_log(LOG_FATAL, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) 131 | #else 132 | #define AI_LOG_FATAL(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_FATAL()*/) 133 | #endif 134 | 135 | #endif /*CORE_LOG_H*/ 136 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/core_net_inspect.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_net_inspect.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of core network inspection APIs 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef __CORE_NET_INSPECT_H_ 23 | #define __CORE_NET_INSPECT_H_ 24 | #pragma once 25 | 26 | #include "core_net_inspect_interface.h" 27 | 28 | #include "core_common.h" 29 | #include "layers_common.h" 30 | 31 | /*! 32 | * @defgroup core_net_inspect Core Network Inspection routines 33 | * @brief Implementation of core network inspection routines that allows to 34 | * inspect on a node basis a generated network model 35 | * @details A network context @ref ai_network basically contains a chained list 36 | * of nodes @ref ai_node that have an associated forward function. 37 | * Each ai)network context and ai_node datastructs have as a required member 38 | * field an opaque handler (i.e. a void pointer) to a klass object. 39 | * This handler is intended to be used as a platform specific node context 40 | * that implements specific target platform routines. 41 | * The inspector module basically acts as a plugin that exploiting these features 42 | * by temporary creating an hidden inspection context (see 43 | * @ref ai_core_inspect_net_klass) associated to the network and 44 | * linking it by re-routing the klass field to this inspection context. The 45 | * inspection context saves as part of its state (by a stack push operation), the 46 | * internal state of the network (all node / network klass pointers and actual 47 | * forward functions). 48 | * Thus, for each node it re-routes all node's forward functions to a dedicated 49 | * inspection forward function (see @ref _forward_inspect_validate() routine) 50 | * This routine is the core of the mechanism and it allows to inspect a network 51 | * node by node. Some additional inspection could thus be done inside the 52 | * _forward_inspect_validate() routine before and after the actual node 53 | * forward function is called; 54 | * 55 | */ 56 | 57 | AI_API_DECLARE_BEGIN 58 | 59 | /*! 60 | * @defgroup core_net_inspect Network Inspection Core 61 | * @brief Implementation of the validation network routines 62 | */ 63 | 64 | /*! 65 | * @brief Initialize the network inspection context on a given network 66 | * @ingroup core net inspect 67 | * @param network opaque handler to the network instance 68 | * @param cfg a pointer to the inspector configuration we want to use 69 | * @return true if execution of the API is fine, false otherwise 70 | */ 71 | AI_API_ENTRY 72 | ai_bool ai_network_inspect_init( 73 | ai_handle network, const ai_inspect_config* cfg); 74 | 75 | /*! 76 | * @brief Get a summary report from the inspected network 77 | * @ingroup core net inspect 78 | * @param network opaque handler to the network instance 79 | * @param report a pointer to the report provided back by the inspection 80 | * @return true if execution of the API is fine, false otherwise 81 | */ 82 | AI_API_ENTRY 83 | ai_bool ai_network_inspect_get_report( 84 | ai_handle network, ai_inspect_net_report* report); 85 | 86 | /*! 87 | * @brief Destroy the network inspection context on a given network 88 | * @ingroup core net inspect 89 | * @param network opaque handler to the network instance 90 | * @return true if execution of the API is fine, false otherwise 91 | */ 92 | AI_API_ENTRY 93 | ai_bool ai_network_inspect_destroy(ai_handle network); 94 | 95 | AI_API_DECLARE_END 96 | 97 | #endif /*__CORE_NET_INSPECT_H_*/ 98 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/core_net_inspect_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_net_inspect_interface.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of core network inspection interface APIs 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef __CORE_NET_INSPECT_INTERFACE_H_ 23 | #define __CORE_NET_INSPECT_INTERFACE_H_ 24 | #pragma once 25 | 26 | #include "ai_platform.h" 27 | 28 | AI_API_DECLARE_BEGIN 29 | 30 | /*! 31 | * @defgroup core_validation Validation Core 32 | * @brief Implementation of the validation network interface headers 33 | */ 34 | 35 | 36 | /*! 37 | * @struct ai_inspect_node_info 38 | * @brief network node inspection context: there is one of this datastruct 39 | * for each node of the network 40 | */ 41 | typedef struct ai_inspect_node_info_s { 42 | ai_u16 type; /*!< node type info @see ai_node datastruct */ 43 | ai_u16 id; /*!< node id assigned by codegen tool to identify 44 | the specific node instance */ 45 | ai_u16 batch_id; /*!< current node batch processed */ 46 | ai_u16 n_batches; /*!< total number of node batches to process */ 47 | ai_float elapsed_ms; /*!< node performance analysys: time in 48 | milliseconds to execute the node forward 49 | function */ 50 | ai_u16 in_size; /*!< number of node's input activation buffers */ 51 | ai_u16 out_size; /*!< number of node's output activation buffers */ 52 | ai_buffer* in; /*!< input node activation buffer see @ref ai_buffer */ 53 | ai_buffer* out; /*!< output node activation buffer see @ref ai_buffer */ 54 | } ai_inspect_node_info; 55 | 56 | /*! 57 | * @struct ai_inspect_net_report 58 | * @brief network inspection report context 59 | */ 60 | typedef struct ai_inspect_net_report_s { 61 | ai_u32 id; /*!< id of the report */ 62 | ai_signature signature; /*!< network identification checksum */ 63 | ai_u32 num_inferences; /*!< total number of inferences processed 64 | during the inspection */ 65 | ai_u32 n_nodes; /*!< number of nodes in the network */ 66 | ai_float elapsed_ms; /*!< network total time (in ms) for processing 67 | num_inferences inferences */ 68 | ai_inspect_node_info* node; /*!< pointer to the array of size n_nodes where 69 | a single node report is reported. see @ref 70 | ai_inspect_node_info datastruct */ 71 | } ai_inspect_net_report; 72 | 73 | /*! 74 | * @enum net inspector inspection mode 75 | * @brief configuration flags to set net inspection mode 76 | */ 77 | typedef enum { 78 | VALIDATION_INSPECT = (0x1<<0), /**< Network validation inspection mode */ 79 | STORE_ALL_IO_ACTIVATIONS = (0x1<<7), /**< Store all I/O activations on snapshot datastruct */ 80 | } ai_inspect_mode; 81 | 82 | typedef enum { 83 | AI_NODE_EXEC_PRE_FORWARD_STAGE = 0x0, 84 | AI_NODE_EXEC_POST_FORWARD_STAGE = 0x1, 85 | } ai_node_exec_stage; 86 | 87 | /*! 88 | * @brief function pointer to callback report 89 | */ 90 | typedef void (*ai_inspect_report_cb_func)( 91 | const ai_handle cookie, 92 | const ai_inspect_net_report* report); 93 | 94 | /*! 95 | * @brief function pointer to node execute 96 | */ 97 | typedef void (*ai_inspect_exec_node_cb_func)( 98 | const ai_handle cookie, 99 | const ai_inspect_node_info* node_info, 100 | const ai_node_exec_stage stage); 101 | 102 | /*! 103 | * @struct ai_inspect_config 104 | * @brief inspection config datastruct 105 | */ 106 | typedef struct ai_inspect_config_s { 107 | ai_u8 validation_mode; /*!< validation mode flags 108 | see @ref ai_inspect_mode */ 109 | ai_u8 log_level; /*!< log class level see @ref LOG_SUDO */ 110 | ai_bool log_quiet; /*!< log class quiet mode */ 111 | ai_inspect_report_cb_func on_report_destroy; /*!< callback function 112 | called when a report datastruct 113 | is released from memory */ 114 | ai_inspect_exec_node_cb_func on_exec_node; /*!< callback function 115 | called when a node is executed (pre & post) */ 116 | ai_handle cookie; 117 | } ai_inspect_config; 118 | 119 | 120 | AI_API_DECLARE_END 121 | 122 | #endif /*__CORE_NET_INSPECT_INTERFACE_H_*/ 123 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/datatypes_network.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file datatypes_network.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief Definitions of code generated network types 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef DATATYPES_NETWORK_H 23 | #define DATATYPES_NETWORK_H 24 | #pragma once 25 | 26 | /* 27 | * Header to be overriden by the generated version 28 | * by including with <> the include directories are searched in the order 29 | * specified in the compiler 30 | * To enable the override, put the generated path before the API path 31 | */ 32 | 33 | #include "ai_platform.h" 34 | 35 | AI_API_DECLARE_BEGIN 36 | 37 | #ifdef AI_OVERRIDE_CUSTOM_TYPES 38 | #warning "Warning: Custom Types have been already defined!\n" 39 | #endif 40 | 41 | #define AI_CUSTOM_TYPES_COUNT (3) 42 | 43 | #define AI_CUSTOM_TYPES_SIGNATURE_DECLARE(name) \ 44 | const ai_custom_type_signature name[AI_CUSTOM_TYPES_COUNT+1] = { \ 45 | AI_CUSTOM_TYPES_COUNT, \ 46 | AI_CUSTOM_SIZE(ai_shape_dimension), \ 47 | AI_CUSTOM_SIZE(ai_stride_dimension), \ 48 | AI_CUSTOM_SIZE(ai_array_size), \ 49 | }; 50 | 51 | 52 | typedef ai_i32 ai_stride_dimension; 53 | typedef ai_u32 ai_array_size; 54 | 55 | 56 | AI_API_DECLARE_END 57 | 58 | #endif /*DATATYPES_NETWORK_H*/ 59 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/formats_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file format_list.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief Definitions of AI platform public APIs types 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2019 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | /* FMT_ENTRY( exp_(0/1 only), name_, type_id_, 23 | * sign_bit_, float_bit_, pmask_, bits_, fbits_, ldiv_bits_) 24 | * Specifications (in order of the bit fields, little endian): 25 | - name_ : it is the enum used to define both the ai_array_format and 26 | ai_buffer_format. 27 | - exp_ (1bit) : it is a boolean flag (0 or 1) indicating whether the format 28 | is available as a public APIs ai_buffer format. in this case the field 29 | exp_name_ indicates the enum name of the ai_buffer format 30 | - (7 bits): reserved for flags 31 | - sign_bit_ (1bit) : codes whether or not the format is of a signed type 32 | - float_bit_ (1bit) : codes if the format is float 33 | - ldiv_bits (2 bits) : right shift value for computing the byte size of the 34 | format 35 | - type_id_ (4bits) : it is used to define the "family" of the format: 36 | see @ref AI_FMT_Q as an example. Currently supported types are: 37 | AI_FMT_Q (fixed point types), AI_FMT_FLOAT (floating point values), 38 | AI_FMT_LUT4 or AI_FMT_LUT8 (compressed formats) 39 | - pmask_ (3bits) : padding mask bits for the format 40 | - bits_ (7bits) : size in bits of the format (NB: integer+fractional bits) 41 | - fbits_ (7bits) : number of fractional bits for the format 42 | (for AI_FMT_Q only) 43 | 44 | */ 45 | 46 | /* Format none entry */ 47 | FMT_ENTRY(1, NONE, AI_FMT_NONE, 0, 0, 0x0, 0, 0, 0) 48 | 49 | /* Floating point formats */ 50 | FMT_ENTRY(1, FLOAT, AI_FMT_FLOAT, 1, 1, 0x0, 32, 0, 0) 51 | FMT_ENTRY(0, FLOAT64, AI_FMT_FLOAT, 1, 1, 0x0, 64, 0, 0) 52 | FMT_ENTRY(0, FLOAT16, AI_FMT_FLOAT, 1, 1, 0x0, 16, 0, 0) 53 | 54 | /* Integer formats (i.e. fractional bits = 0!) */ 55 | FMT_ENTRY(1, U8, AI_FMT_Q, 0, 0, 0x0, 8, 0, 0) 56 | FMT_ENTRY(1, U16, AI_FMT_Q, 0, 0, 0x0, 16, 0, 0) 57 | FMT_ENTRY(1, U32, AI_FMT_Q, 0, 0, 0x0, 32, 0, 0) 58 | FMT_ENTRY(0, U64, AI_FMT_Q, 0, 0, 0x0, 64, 0, 0) 59 | FMT_ENTRY(1, U1, AI_FMT_Q, 0, 0, 0x0, 1, 0, 0) 60 | FMT_ENTRY(0, U4, AI_FMT_Q, 0, 0, 0x0, 4, 0, 0) 61 | 62 | FMT_ENTRY(1, S8, AI_FMT_Q, 1, 0, 0x0, 8, 0, 0) 63 | FMT_ENTRY(1, S16, AI_FMT_Q, 1, 0, 0x0, 16, 0, 0) 64 | FMT_ENTRY(1, S32, AI_FMT_Q, 1, 0, 0x0, 32, 0, 0) 65 | FMT_ENTRY(0, S64, AI_FMT_Q, 1, 0, 0x0, 64, 0, 0) 66 | FMT_ENTRY(1, S1, AI_FMT_Q, 1, 0, 0x0, 1, 0, 0) 67 | FMT_ENTRY(0, S4, AI_FMT_Q, 1, 0, 0x0, 4, 0, 0) 68 | 69 | /* Fixed-point formats including ARM CMSIS Q7, Q15, Q31 ones */ 70 | FMT_ENTRY(1, Q, AI_FMT_Q, 1, 0, 0x0, 0, 0, 0) 71 | FMT_ENTRY(1, Q7, AI_FMT_Q, 1, 0, 0x0, 8, 7, 0) 72 | FMT_ENTRY(1, Q15, AI_FMT_Q, 1, 0, 0x0, 16, 15, 0) 73 | FMT_ENTRY(0, Q31, AI_FMT_Q, 1, 0, 0x0, 32, 31, 0) 74 | 75 | FMT_ENTRY(1, UQ, AI_FMT_Q, 0, 0, 0x0, 0, 0, 0) 76 | FMT_ENTRY(1, UQ7, AI_FMT_Q, 0, 0, 0x0, 8, 7, 0) 77 | FMT_ENTRY(1, UQ15, AI_FMT_Q, 0, 0, 0x0, 16, 15, 0) 78 | FMT_ENTRY(0, UQ31, AI_FMT_Q, 0, 0, 0x0, 32, 31, 0) 79 | 80 | /* Compressed formats */ 81 | FMT_ENTRY(0, LUT4_FLOAT, AI_FMT_LUT4, 1, 1, 0x0, 32, 0, 3) 82 | FMT_ENTRY(0, LUT8_FLOAT, AI_FMT_LUT8, 1, 1, 0x0, 32, 0, 2) 83 | FMT_ENTRY(0, LUT4_Q15, AI_FMT_LUT4, 1, 0, 0x0, 16, 15, 2) 84 | FMT_ENTRY(0, LUT8_Q15, AI_FMT_LUT8, 1, 0, 0x0, 16, 15, 1) 85 | FMT_ENTRY(0, LUT4_UQ15, AI_FMT_LUT4, 0, 0, 0x0, 16, 15, 2) 86 | FMT_ENTRY(0, LUT8_UQ15, AI_FMT_LUT8, 0, 0, 0x0, 16, 15, 1) 87 | 88 | /* Boolean format */ 89 | FMT_ENTRY(1, BOOL, AI_FMT_BOOL, 0, 0, 0x0, 8, 0, 0) 90 | 91 | #undef FMT_ENTRY 92 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of AI platform layers datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_H 23 | #define LAYERS_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | #include "layers_conv2d.h" 28 | #include "layers_custom.h" 29 | #include "layers_dense.h" 30 | #include "layers_formats_converters.h" 31 | #include "layers_generic.h" 32 | #include "layers_lite_graph.h" 33 | #include "layers_nl.h" 34 | #include "layers_norm.h" 35 | #include "layers_pad_dqnn.h" 36 | #include "layers_pad_generic.h" 37 | #include "layers_pool.h" 38 | #include "layers_rnn.h" 39 | #include "layers_upsample_generic.h" 40 | #include "layers_sm.h" 41 | #include "layers_ml.h" 42 | #include "layers_ml_iforest.h" 43 | #include "layers_ml_svc.h" 44 | #include "layers_ml.h" 45 | #include "layers_ml_linearclassifier.h" 46 | #include "layers_ml_treeensembleclassifier.h" 47 | #include "layers_ml_treeensembleregressor.h" 48 | #include "layers_ml_svmregressor.h" 49 | 50 | #include "layers_conv2d_dqnn.h" 51 | #include "layers_dense_dqnn.h" 52 | #include "layers_pool_dqnn.h" 53 | #include "layers_generic_dqnn.h" 54 | #include "layers_upsample_generic.h" 55 | // #include "layers_template.h" 56 | 57 | 58 | AI_API_DECLARE_BEGIN 59 | 60 | /*! 61 | * @struct ai_any_layer_ptr 62 | * @ingroup layers 63 | * @brief Generic union for typed layers pointers 64 | */ 65 | typedef struct { 66 | ai_layer_type type; /*!< layer type id (see @ref ai_layer_type) */ 67 | union { 68 | #define LAYER_ENTRY(type_, id_, struct_, forward_func_, init_func_, destroy_func_) \ 69 | AI_CONCAT(ai_layer_, struct_)* struct_; 70 | #include "layers_list.h" 71 | }; 72 | } ai_any_layer_ptr; 73 | 74 | 75 | AI_API_DECLARE_END 76 | 77 | #endif /*LAYERS_H*/ 78 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_custom.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_custom.h 4 | * @author Marco Lattuada 5 | * @brief header file of AI platform custom layers datatype 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2020 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_CUSTOM_H 22 | #define LAYERS_CUSTOM_H 23 | #pragma once 24 | 25 | #include "layers_common.h" 26 | 27 | /*! 28 | * @defgroup layers_custom Custom layer definitions 29 | * @brief Definition of structures custom layers 30 | */ 31 | 32 | AI_API_DECLARE_BEGIN 33 | 34 | /*! 35 | * @struct ai_layer_custom 36 | * @ingroup layers_custom 37 | * @brief Custom layer wrapper 38 | * 39 | * The custom layer wrapper 40 | */ 41 | typedef ai_layer_stateful ai_layer_custom; 42 | 43 | 44 | AI_API_DECLARE_END 45 | 46 | #endif /*LAYERS_CUSTOM_H*/ 47 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_dense.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_dense.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of AI platform dense layers datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_DENSE_H 23 | #define LAYERS_DENSE_H 24 | #pragma once 25 | 26 | 27 | #include "layers_common.h" 28 | 29 | 30 | /*! 31 | * @defgroup layers Normalization Layers Definitions 32 | * @brief definition 33 | * 34 | */ 35 | 36 | AI_API_DECLARE_BEGIN 37 | 38 | /*! 39 | * @brief Computes the activations of a fixed point dense (fully connected) layer. 40 | * @ingroup layers_dense 41 | * @param layer the dense layer 42 | */ 43 | AI_INTERNAL_API 44 | void forward_dense_fixed(ai_layer *pLayer); 45 | 46 | AI_API_DECLARE_END 47 | 48 | #endif /*LAYERS_DENSE_H*/ 49 | 50 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_formats_converters.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_formats_converters.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of formats converters layers 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_FORMATS_CONVERTERS_H 22 | #define LAYERS_FORMATS_CONVERTERS_H 23 | #pragma once 24 | 25 | #include "layers_common.h" 26 | 27 | /*! 28 | * @defgroup layers_formats_converters Formats Converters Layers Definition 29 | * @brief this group implements formats converter layers (cast, etc.) 30 | * 31 | */ 32 | 33 | AI_API_DECLARE_BEGIN 34 | 35 | /*! 36 | * @struct ai_layer_cast 37 | * @ingroup layers_formats_converters 38 | * @brief C Implementation of cast layer 39 | */ 40 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_cast_ { 41 | AI_LAYER_COMMON_FIELDS_DECLARE 42 | ai_array_format to_format; /*!< cast output format */ 43 | } ai_layer_cast; 44 | 45 | 46 | /*****************************************************************************/ 47 | /* Forward Functions Section */ 48 | /*****************************************************************************/ 49 | 50 | /*! 51 | * @brief forward function for cast layer. 52 | * @ingroup layers_ 53 | * @param layer template layer as an opaque pointer 54 | */ 55 | AI_INTERNAL_API 56 | void forward_cast(ai_layer* layer); 57 | 58 | 59 | AI_API_DECLARE_END 60 | 61 | #endif /*LAYERS_FORMATS_CONVERTERS_H*/ 62 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_generic_dqnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_generic_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform DQNN generic datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_GENERIC_DQNN_H 22 | #define LAYERS_GENERIC_DQNN_H 23 | #pragma once 24 | 25 | #include "layers_common.h" 26 | #include "layers_generic.h" 27 | 28 | /*! 29 | * @defgroup layers_generic_dqnn Layers Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | 37 | 38 | /******************************************************************************/ 39 | /* Forward Functions Section */ 40 | /******************************************************************************/ 41 | 42 | /*! 43 | * @brief Handles concat with binary input, binary output and 44 | * binary weights 45 | * @ingroup layers_generic_dqnn 46 | * @param layer concat layer 47 | */ 48 | AI_INTERNAL_API 49 | void forward_concat_is1os1(ai_layer *pLayer); 50 | 51 | 52 | 53 | AI_API_DECLARE_END 54 | 55 | #endif /*LAYERS_GENERIC_DQNN_H*/ 56 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_lite_graph.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_lite_graph.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of AI platform lite graph layers wrapper interface 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_LITE_GRAPH_H 23 | #define LAYERS_LITE_GRAPH_H 24 | #pragma once 25 | 26 | #include "core_common.h" 27 | 28 | /*! 29 | * @defgroup layers_lite_graph Lite Graph Wrapper Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | /*! 37 | * @struct ai_layer_lite_graph 38 | * @ingroup layers_lite_graph 39 | * @brief Generic Lite Graph Layer Wrapper 40 | * 41 | * The type of lite graph is handled by the specific forward lite graph function. 42 | */ 43 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_lite_graph_ { 44 | AI_NODE_COMMON_FIELDS_DECLARE 45 | ai_handle* activations_map; /*!< array of pointers to shared activations memory pools */ 46 | ai_handle* weights_map; /*!< array of pointers to shared weights memory pools */ 47 | } ai_layer_lite_graph; 48 | 49 | 50 | AI_API_DECLARE_END 51 | 52 | #endif /*LAYERS_LITE_GRAPH_H*/ 53 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_ml.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_ml.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of AI platform ml layers datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_ML_H 22 | #define LAYERS_ML_H 23 | 24 | 25 | 26 | #pragma once 27 | 28 | #include "layers_common.h" 29 | 30 | /*! 31 | * @defgroup layers_generic ML Layers Definitions 32 | * @brief definition 33 | * 34 | */ 35 | 36 | AI_API_DECLARE_BEGIN 37 | 38 | /*! 39 | * @struct ai_layer_ArrayFeatureExtractor 40 | * @ingroup layers_ml 41 | * @brief ai_layer_ArrayFeatureExtractor layer definition 42 | * 43 | * This layer select elements of the input tensor based on the indices passed. It is intended to be used 44 | * by his associated forward function @ref forward_arrayfeatureextractor 45 | */ 46 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_arrayfeatureextractor_ { 47 | AI_LAYER_COMMON_FIELDS_DECLARE 48 | ai_tensor* indices; /*!< Indices of corrisponding axis in axes*/ 49 | } ai_layer_arrayfeatureextractor; 50 | 51 | 52 | /*! 53 | * @struct ai_layer_ZipMap 54 | * @ingroup layers_ml 55 | * @brief ai_layer_ZipMap layer definition 56 | * 57 | * This layer creates a map from the input and the attributes. 58 | * The values are provided by the input tensor, while the keys are specified by the attributes. 59 | * The user must provide keys in either classlabels_strings or classlabels_int64s (but not both). 60 | * The columns of the tensor correspond one-by-one to the keys specified by the attributes. 61 | * There must be as many columns as keys. 62 | * It is intended to be used by his associated forward function @ref forward_zipmap. 63 | */ 64 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_zipmap_ { 65 | AI_LAYER_COMMON_FIELDS_DECLARE 66 | ai_bool has_classlabels_int; 67 | } ai_layer_zipmap; 68 | 69 | 70 | /******************************************************************************/ 71 | /* Forward Functions Section */ 72 | /******************************************************************************/ 73 | 74 | 75 | /*! 76 | * @brief select elements of the input tensor based on the indices passed. 77 | * @ingroup layers_ml 78 | * @param layer array feture extractor 79 | */ 80 | AI_INTERNAL_API 81 | void forward_arrayfeatureextractor(ai_layer* layer); 82 | 83 | 84 | /*! 85 | * @brief creates a map from the inputs and the attributes 86 | * @ingroup layers_ml 87 | * @param layer zipmap 88 | */ 89 | AI_INTERNAL_API 90 | void forward_zipmap(ai_layer* layer); 91 | 92 | 93 | 94 | AI_API_DECLARE_END 95 | 96 | #endif /*LAYERS_ML_H*/ 97 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_ml_iforest.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_iforest.h 4 | * @author AIS 5 | * @brief header file of AI platform iForest layers datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_IFOREST_H 23 | #define LAYERS_IFOREST_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | 28 | /*! 29 | * @defgroup layers_ml Layers Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | 37 | /* Allowed tests branch in the iTrees */ 38 | typedef enum 39 | { 40 | AI_IFOREST_BRANCH_LT_IDX = 0, 41 | AI_IFOREST_BRANCH_LEQ_IDX, 42 | AI_IFOREST_BRANCH_EQ_IDX, 43 | AI_IFOREST_BRANCH_END, 44 | } ai_iforest_branch_e; 45 | 46 | 47 | /*! 48 | * @struct ai_layer_iforest 49 | * @ingroup layers_iforest 50 | * @brief iForest layer 51 | * 52 | * The type of iforest function is handled by the specific forward function 53 | * @ref forward_iforest 54 | */ 55 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_iforest_ { 56 | AI_LAYER_COMMON_FIELDS_DECLARE 57 | ai_float global_average_path_length; /*!< global average path length used to normalized average path length*/ 58 | ai_float score_threshold; /*!< score threshold used to center the score around 0 */ 59 | } ai_layer_iforest; 60 | 61 | 62 | 63 | /******************************************************************************/ 64 | /* Forward Functions Section */ 65 | /******************************************************************************/ 66 | 67 | /*! 68 | * @brief Decodes the iforest ML algorithm. 69 | * @ingroup layers_iforest 70 | * @param layer iforest layer 71 | */ 72 | AI_INTERNAL_API 73 | void forward_iforest(ai_layer *pLayer); 74 | 75 | 76 | 77 | AI_API_DECLARE_END 78 | 79 | #endif /*LAYERS_IFOREST_H*/ 80 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_ml_linearclassifier.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_ml_linearclassifier.h 4 | * @author SRA 5 | * @brief header file of AI platform LinearClassifier datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_LINEARCLASSIFIER_H 22 | #define LAYERS_LINEARCLASSIFIER_H 23 | #pragma once 24 | 25 | #include "layers_common.h" 26 | #include "layers_nl.h" 27 | 28 | /*! 29 | * @defgroup layers_linearclassifier Layers Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | 37 | /*! 38 | * @struct ai_layer_linearclassifier 39 | * @ingroup layers_linearclassifier 40 | * @brief Linearclassifier layer 41 | * 42 | * The type of svmreg function is handled by the specific forward function 43 | * @ref forward_linearclassifier 44 | */ 45 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_linearclassifier_ { 46 | AI_LAYER_COMMON_FIELDS_DECLARE 47 | func_nl nl_func; /*!< function pointer to non linear transform */ \ 48 | ai_bool multi_class; /*!< Indicates whether to do OvR or multinomial */ 49 | ai_bool has_classlabels_int; /*!< if True, LinearClassifier returns classlabels int, else classlabels string */ 50 | 51 | } ai_layer_linearclassifier; 52 | 53 | 54 | /******************************************************************************/ 55 | /* Forward Functions Section */ 56 | /******************************************************************************/ 57 | 58 | /*! 59 | * @brief Decodes the LinearClassifier ML operator. 60 | * @ingroup layers_linaerclassifier 61 | * @param layer linear classifier layer 62 | */ 63 | AI_INTERNAL_API 64 | void forward_linearclassifier(ai_layer *pLayer); 65 | 66 | 67 | 68 | AI_API_DECLARE_END 69 | 70 | #endif /*LAYERS_LINEARCLASSIFIER_H*/ 71 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_ml_svc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_svc.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of AI platform SVM Classifier (SVC) datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_SVC_H 23 | #define LAYERS_SVC_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | 28 | /*! 29 | * @defgroup layers_svc Layers Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | 37 | /* SVM classifier (SVC) kernel types */ 38 | typedef enum ai_svc_kernel_e_ { 39 | AI_SVC_KERNEL_LINEAR = 0, 40 | AI_SVC_KERNEL_POLYNOMIAL, 41 | AI_SVC_KERNEL_RBF, 42 | AI_SVC_KERNEL_SIGMOID, 43 | AI_SVC_KERNEL_UNSUPPORTED 44 | } ai_svc_kernel_e; 45 | 46 | 47 | /*! 48 | * @struct ai_layer_svc 49 | * @ingroup layers_svc 50 | * @brief SVM Classifier (SVC) layer 51 | * 52 | * The type of svc function is handled by the specific forward function 53 | * @ref forward_svc 54 | */ 55 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_svc_ { 56 | AI_LAYER_COMMON_FIELDS_DECLARE 57 | ai_float gamma; /*!< kernel coefficient for rbf, polynomial and sigmoid functions */ 58 | ai_float coef0; /*!< term in polynomial and sigmoid functions */ 59 | ai_u32 degree; /*!< polynomial function degree */ 60 | ai_svc_kernel_e kernel_type; /*!< kernel type : see ai_svm_kernel_e */ 61 | ai_bool proba_support; /*!< whether or not use the parameters learned in Platt scaling */ 62 | ai_bool has_classlabels_int; /*!< if True, SVC returns classlabels int, else classlabels string */ 63 | } ai_layer_svc; 64 | 65 | 66 | /******************************************************************************/ 67 | /* Forward Functions Section */ 68 | /******************************************************************************/ 69 | 70 | /*! 71 | * @brief Decodes the SVM Classifier ML operator. 72 | * @ingroup layers_svc 73 | * @param layer svm classifier layer 74 | */ 75 | AI_INTERNAL_API 76 | void forward_svc(ai_layer *pLayer); 77 | 78 | 79 | AI_API_DECLARE_END 80 | 81 | #endif /*LAYERS_SVC_H*/ 82 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_ml_svmregressor.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_svmregressor.h 4 | * @author AIS 5 | * @brief header file of AI platform SVM Regressor datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_SVMREGRESSOR_H 23 | #define LAYERS_SVMREGRESSOR_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | 28 | /*! 29 | * @defgroup layers_svmreg Layers Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | 37 | /* SVM regressor kernel types */ 38 | typedef enum ai_svm_kernel_e_ { 39 | AI_SVMREG_KERNEL_LINEAR = 0, 40 | AI_SVMREG_KERNEL_POLYNOMIAL, 41 | AI_SVMREG_KERNEL_RBF, 42 | AI_SVMREG_KERNEL_SIGMOID, 43 | AI_SVMREG_KERNEL_UNSUPPORTED, 44 | } ai_svm_kernel_e; 45 | 46 | 47 | /*! 48 | * @struct ai_layer_svmreg 49 | * @ingroup layers_svmreg 50 | * @brief SVM Regressor layer 51 | * 52 | * The type of svmreg function is handled by the specific forward function 53 | * @ref forward_svm_regressor 54 | */ 55 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_svmreg_ { 56 | AI_LAYER_COMMON_FIELDS_DECLARE 57 | ai_float intercept; /*!< constant used in the decision function */ 58 | ai_float gamma; /*!< kernel coefficient for rbf, polynomial and sigmoid functions */ 59 | ai_float coef0; /*!< term in polynomial and sigmoid functions */ 60 | ai_u32 degree; /*!< polynomial function degree */ 61 | ai_svm_kernel_e kernel_type; /*!< kernel type : see ai_svm_kernel_e */ 62 | } ai_layer_svmreg; 63 | 64 | 65 | 66 | /******************************************************************************/ 67 | /* Forward Functions Section */ 68 | /******************************************************************************/ 69 | 70 | /*! 71 | * @brief Decodes the SVM Regressor ML operator. 72 | * @ingroup layers_svmreg 73 | * @param layer svm regressor layer 74 | */ 75 | AI_INTERNAL_API 76 | void forward_svm_regressor(ai_layer *pLayer); 77 | 78 | 79 | 80 | AI_API_DECLARE_END 81 | 82 | #endif /*LAYERS_SVMREGRESSOR_H*/ 83 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_ml_treeensembleclassifier.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_ml_treeensembleclassifier.h 4 | * @author AIS 5 | * @brief header file of AI platform TreeEnsembleClassifier datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021-2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_TREE_ENSEMBLE_CLASSIFIER_H 23 | #define LAYERS_TREE_ENSEMBLE_CLASSIFIER_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | #include "layers_nl.h" 28 | 29 | 30 | 31 | /*! 32 | * @defgroup layers_ml_treensembleclassifier Layers Definitions 33 | * @brief definition 34 | * 35 | */ 36 | 37 | AI_API_DECLARE_BEGIN 38 | 39 | /* Error return codes */ 40 | #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_NO 0 41 | #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_WRONG_IDX_FMT -1 42 | #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_UNFOUND_LEAF -2 43 | #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_UNSUPPORTED_BRANCH -3 44 | #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_UNSUPPORTED_FEATURE -4 45 | 46 | #define AI_TREE_ENSEMBLE_CLASSIFIER_DEPTH_MAX 10000 47 | 48 | 49 | /* Type of condition in the TreeEnsembleClassifier*/ 50 | typedef enum 51 | { 52 | AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_LT_IDX = 0, 53 | AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_LEQ_IDX, 54 | AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_EQ_IDX, 55 | AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_END, 56 | } ai_tree_ensenble_classifier_branch_e; 57 | 58 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_tree_ensemble_classifier_ { 59 | AI_LAYER_COMMON_FIELDS_DECLARE 60 | func_nl nl_func; 61 | uint8_t all_weights_are_positive; 62 | ai_float nodes_values_scale; 63 | ai_float nodes_values_offset; 64 | ai_float class_weights_scale; 65 | ai_float class_weights_offset; 66 | } ai_layer_tree_ensemble_classifier; 67 | 68 | 69 | 70 | /******************************************************************************/ 71 | /* Forward Functions Section */ 72 | /******************************************************************************/ 73 | 74 | /*! 75 | * @brief Decodes the TreeEnsembleClassifier ML operator. 76 | * @ingroup layers_svmreg 77 | * @param layer tree ensemble classifier layer 78 | */ 79 | AI_INTERNAL_API 80 | void forward_tree_ensemble_classifier(ai_layer *pLayer); 81 | 82 | AI_INTERNAL_API 83 | ai_i32 decodeEstimator_LEQ_8Bits(const ai_float *pDataIn, 84 | ai_float *pOutDataScores, 85 | const ai_u8 *pFeatureIdxForEstimator, 86 | const ai_float *pValuesForEstimator, 87 | const ai_u8 *pTrueIdxForEstimator, 88 | const ai_u8 *pFalseIdxForEstimator, 89 | const ai_handle pClassWeightsForEstimator, 90 | const ai_array_format classWeightsFormat, 91 | const ai_u8 *pClassNodeIdsForEstimator, 92 | const ai_u16 nbClassWithCurrentEstimator, 93 | const ai_u8 *pClassIdsForEstimator); 94 | 95 | AI_INTERNAL_API 96 | ai_i32 decodeEstimator_LEQ_16Bits(const ai_float *pDataIn, 97 | ai_float *pOutDataScores, 98 | const ai_u8 *pFeatureIdxForEstimator, 99 | const ai_float *pValuesForEstimator, 100 | const ai_u16 *pTrueIdxForEstimator, 101 | const ai_u16 *pFalseIdxForEstimator, 102 | ai_handle pClassWeightsForEstimator, 103 | const ai_array_format classWeightsFormat, 104 | const ai_u16 *pClassNodeIdsForEstimator, 105 | const ai_u16 nbClassWithCurrentEstimator, 106 | const ai_u16 *pClassIdsForEstimator); 107 | 108 | 109 | 110 | AI_API_DECLARE_END 111 | 112 | #endif /*LAYERS_TREE_ENSEMBLE_CLASSIFIER_H*/ 113 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_ml_treeensembleregressor.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_svmregressor.h 4 | * @author AIS 5 | * @brief header file of AI platform SVM Regressor datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_TREE_ENSEMBLE_REGRESSOR_H 23 | #define LAYERS_TREE_ENSEMBLE_REGRESSOR_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | #include "layers_ml_treeensembleclassifier.h" 28 | #include "layers_nl.h" 29 | 30 | /*! 31 | * @defgroup layers_svmreg Layers Definitions 32 | * @brief definition 33 | * 34 | */ 35 | 36 | AI_API_DECLARE_BEGIN 37 | 38 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_tree_ensemble_regressor_ { 39 | AI_LAYER_COMMON_FIELDS_DECLARE 40 | func_nl nl_func; 41 | uint8_t all_weights_are_positive; 42 | ai_float nodes_values_offset; 43 | ai_float nodes_values_scale; 44 | ai_float target_weights_offset; 45 | ai_float target_weights_scale; 46 | } ai_layer_tree_ensemble_regressor; 47 | 48 | /******************************************************************************/ 49 | /* Forward Functions Section */ 50 | /******************************************************************************/ 51 | 52 | /*! 53 | * @brief Decodes the TreeEnsembleRegressor ML operator. 54 | * @ingroup layers_svmreg 55 | * @param layer tree ensemble regressor layer 56 | */ 57 | AI_INTERNAL_API 58 | void forward_tree_ensemble_regressor(ai_layer *pLayer); 59 | 60 | 61 | AI_API_DECLARE_END 62 | 63 | #endif /*LAYERS_SVMREGRESSOR_H*/ 64 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_pad_dqnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_pad_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform DQNN padding datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_PADDING_DQNN_H 22 | #define LAYERS_PADDING_DQNN_H 23 | #pragma once 24 | 25 | #include "layers_common.h" 26 | #include "layers_generic.h" 27 | 28 | /*! 29 | * @defgroup layers_generic_dqnn Layers Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | 37 | /******************************************************************************/ 38 | /* Forward Functions Section */ 39 | /******************************************************************************/ 40 | 41 | 42 | /*! 43 | * @brief Handles padding with binary input and binary output 44 | * @ingroup layers_generic_dqnn 45 | * @param layer pad layer 46 | */ 47 | AI_INTERNAL_API 48 | void forward_pad_is1os1(ai_layer *pLayer); 49 | 50 | 51 | AI_API_DECLARE_END 52 | 53 | #endif /*LAYERS_PADDING_DQNN_H*/ 54 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_pad_generic.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_pad_generic.h 4 | * @author Marco Forleo 5 | * @brief header file of AI platform padding generic datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_PADDING_DQNN_H 22 | #define LAYERS_PADDING_DQNN_H 23 | #pragma once 24 | 25 | #include "layers_generic.h" 26 | 27 | /*! 28 | * @defgroup layers_pad_generic Layers Definitions 29 | * @brief definition 30 | * 31 | */ 32 | AI_API_DECLARE_BEGIN 33 | 34 | 35 | /******************************************************************************/ 36 | /* Forward Functions Section */ 37 | /******************************************************************************/ 38 | 39 | /*! 40 | * @brief Handles generic padding in constant mode 41 | * @ingroup layers_generic_dqnn 42 | * @param layer pad layer 43 | */ 44 | AI_INTERNAL_API 45 | void forward_pad_constant(ai_layer *pLayer); 46 | 47 | /*! 48 | * @brief Handles generic padding in edge mode 49 | * @ingroup layers_generic_dqnn 50 | * @param layer pad layer 51 | */ 52 | AI_INTERNAL_API 53 | void forward_pad_edge(ai_layer *pLayer); 54 | 55 | /*! 56 | * @brief Handles generic padding in reflect mode 57 | * @ingroup layers_generic_dqnn 58 | * @param layer pad layer 59 | */ 60 | AI_INTERNAL_API 61 | void forward_pad_reflect(ai_layer *pLayer); 62 | 63 | 64 | /*! 65 | * @brief Handles generic padding in constant mode Channel 1st 8bit 66 | * @ingroup layers_generic_dqnn 67 | * @param layer pad layer 68 | */ 69 | AI_INTERNAL_API 70 | void forward_pad_8bit_ch1st_3x3_constant(ai_layer* pLayer); 71 | 72 | 73 | AI_API_DECLARE_END 74 | 75 | #endif /*LAYERS_PAD_GENERIC_H*/ 76 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_pool_dqnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_conv2d_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform DQNN pool datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_POOL_DQNN_H 23 | #define LAYERS_POOL_DQNN_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | #include "layers_pool.h" 28 | 29 | /*! 30 | * @defgroup layers_pool_dqnn Layers Definitions 31 | * @brief definition 32 | * 33 | */ 34 | 35 | AI_API_DECLARE_BEGIN 36 | 37 | 38 | 39 | /*! 40 | * @struct ai_layer_pool_dqnn 41 | * @ingroup layers_pool_dqnn 42 | * @brief pool_dqnn layer 43 | * 44 | * @ref forward_maxpool_is1os1 45 | */ 46 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_pool_dqnn_ { 47 | AI_LAYER_COMMON_FIELDS_DECLARE 48 | ai_shape_2d pool_size; /*!< pooling size */ 49 | ai_shape_2d pool_stride; /*!< pooling stride */ 50 | ai_shape pool_pad; /*!< pooling pad, y,x border sizes */ 51 | // ai_u32 pad_value; /*!< pooling pad value */ 52 | } ai_layer_pool_dqnn; 53 | 54 | 55 | 56 | /******************************************************************************/ 57 | /* Forward Functions Section */ 58 | /******************************************************************************/ 59 | 60 | /*! 61 | * @brief Handles max pooling with binary input and binary output 62 | * @ingroup layers_pool_dqnn 63 | * @param layer conv2d_pool layer 64 | */ 65 | AI_INTERNAL_API 66 | void forward_maxpool_is1os1(ai_layer *pLayer); 67 | 68 | 69 | 70 | AI_API_DECLARE_END 71 | 72 | #endif /*LAYERS_POOL_DQNN_H*/ 73 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_rnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_rnn.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of RNN layers 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_RNN_H 22 | #define LAYERS_RNN_H 23 | #pragma once 24 | 25 | #include "layers_common.h" 26 | #include "layers_nl.h" 27 | 28 | AI_API_DECLARE_BEGIN 29 | 30 | /*! 31 | * @struct ai_layer_lstm 32 | * @ingroup layers 33 | * @brief LSTM layer with generic nonlinearities and peephole connections 34 | */ 35 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_lstm_ { 36 | AI_LAYER_STATEFUL_FIELDS_DECLARE 37 | ai_size n_units; /**< size of the hidden RNN state */ 38 | func_nl activation_nl; /**< activation nonlinearity (input to cell) */ 39 | func_nl recurrent_nl; /**< recurrent nonlinearity (hidden to cell) */ 40 | func_nl out_nl; /**< output nonlinearity (cell to hidden) */ 41 | ai_bool go_backwards; /**< process reversed input */ 42 | ai_bool return_state; /**< return state */ 43 | ai_bool reverse_seq; /**< reverse output sequence */ 44 | ai_float cell_clip; /**< cell clip value */ 45 | } ai_layer_lstm; 46 | 47 | /*! 48 | * @struct ai_layer_gru 49 | * @ingroup layers 50 | * @brief Gated Recurrent Unit (GRU) layer with generic nonlinearities 51 | */ 52 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_gru_ { 53 | AI_LAYER_STATEFUL_FIELDS_DECLARE 54 | ai_size n_units; /**< size of the hidden RNN state */ 55 | func_nl activation_nl; /**< activation nonlinearity (input to cell) */ 56 | func_nl recurrent_nl; /**< recurrent nonlinearity (hidden to cell) */ 57 | ai_bool reset_after; 58 | ai_bool return_state; 59 | ai_bool go_backwards; /**< process reversed input */ 60 | ai_bool reverse_seq; /**< reverse output sequence */ 61 | } ai_layer_gru; 62 | 63 | /*! 64 | * @struct ai_layer_rnn 65 | * @ingroup layers 66 | * @brief Simple Recurrent Neural Network (RNN) layer 67 | */ 68 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_rnn_ { 69 | AI_LAYER_COMMON_FIELDS_DECLARE 70 | ai_size n_units; /**< size of the hidden RNN state */ 71 | func_nl activation_nl; /**< activation nonlinearity (input to hidden) */ 72 | ai_bool go_backwards; /**< process reversed input */ 73 | ai_bool reverse_seq; /**< reverse output sequence */ 74 | ai_bool return_state; 75 | } ai_layer_rnn; 76 | 77 | 78 | /*! 79 | * @brief Initialize a Long-Short Term Memory (LSTM) layer. 80 | * @ingroup layers 81 | * 82 | * Function used to initialize lstm internal state 83 | */ 84 | AI_INTERNAL_API 85 | void init_lstm(ai_layer * layer); 86 | 87 | 88 | /*! 89 | * @brief Destroy a Long-Short Term Memory (LSTM) layer state. 90 | * @ingroup layers 91 | * 92 | * Function used to destroy lstm internal state 93 | */ 94 | AI_INTERNAL_API 95 | void destroy_lstm(ai_layer * layer); 96 | 97 | 98 | /*! 99 | * @brief Computes the activations of a Long-Short Term Memory (LSTM) layer. 100 | * @ingroup layers 101 | * 102 | * Implements a Long-Short Term Layer with peephole connections: 103 | * \f{eqnarray*}{ 104 | * i_t &=& \sigma_a(x_t W_{xi} + h_{t-1} W_{hi} 105 | * + w_{ci} \odot c_{t-1} + b_i)\\ 106 | * f_t &=& \sigma_a(x_t W_{xf} + h_{t-1} W_{hf} 107 | * + w_{cf} \odot c_{t-1} + b_f)\\ 108 | * c_t &=& f_t \odot c_{t - 1} 109 | * + i_t \odot \sigma_r(x_t W_{xc} + h_{t-1} W_{hc} + b_c)\\ 110 | * o_t &=& \sigma_a(x_t W_{xo} + h_{t-1} W_{ho} + w_{co} \odot c_t + b_o)\\ 111 | * h_t &=& o_t \odot \sigma_o(c_t) 112 | * \f} 113 | * where \f$\sigma_a\f$ is the activation nonlinearity, \f$\sigma_r\f$ is the 114 | * recurrent nonlinearity and \f$\sigma_o\f$ is the out nonlinearity. The 115 | * \f$W_x\f$, \f$W_h\f$ and \f$W_c\f$ weights are sliced from the kernel, 116 | * recurrent and peephole weights. 117 | * 118 | * @param layer the LSTM layer 119 | */ 120 | AI_INTERNAL_API 121 | void forward_lstm(ai_layer * layer); 122 | 123 | 124 | /*! 125 | * @brief Initialize a Gated Recurrent Unit (GRU) layer. 126 | * @ingroup layers 127 | * 128 | * Function used to initialize gru internal state 129 | */ 130 | AI_INTERNAL_API 131 | void init_gru(ai_layer * layer); 132 | 133 | 134 | /*! 135 | * @brief Destroy a Gated Recurrent Unit (GRU) layer state. 136 | * @ingroup layers 137 | * 138 | * Function used to destroy gru internal state 139 | */ 140 | AI_INTERNAL_API 141 | void destroy_gru(ai_layer * layer); 142 | 143 | /*! 144 | * @brief Computes the activations of a Gated Recurrent Unit (GRU) layer. 145 | * @ingroup layers 146 | * 147 | * Implements a Gated Recurrent Unit with the formula: 148 | * \f{eqnarray*}{ 149 | * r_t &=& \sigma_a(x_t W_{xr} + h_{t - 1} W_{hr} + b_r) \\ 150 | * z_t &=& \sigma_a(x_t W_{xz} + h_{t - 1} W_{hz} + b_z) \\ 151 | * c_t &=& \sigma_r(x_t W_{xc} + r_t \odot (h_{t - 1} W_{hc} + b_{hc}) + b_c) 152 | * \qquad \textnormal{when reset after is true} \\ 153 | * c_t &=& \sigma_r(x_t W_{xc} + (r_t \odot h_{t - 1}) W_{hc} + b_{hc} + b_c) 154 | * \qquad \textnormal{when reset after is false (default)} \\ 155 | * h_t &=& (1 - z_t) \odot h_{t - 1} + z_t \odot c_t 156 | * \f} 157 | * where \f$\sigma_a\f$ is the activation nonlinearity and \f$\sigma_r\f$ is 158 | * the recurrent nonlinearity. The weights are sliced from the kernel and 159 | * recurrent weights. 160 | * 161 | * @param layer the GRU layer 162 | */ 163 | AI_INTERNAL_API 164 | void forward_gru(ai_layer * layer); 165 | 166 | /*! 167 | * @brief Computes the activations of a Recurrent Neural Network (RNN) layer. 168 | * @ingroup layers 169 | * 170 | * Implements a recurrent layer with the formula: 171 | * \f{eqnarray*}{ 172 | * h_t &=& \sigma_a(x_t W_{xr} + h_{t - 1} W_{hr} + b_r) 173 | * \f} 174 | * where \f$\sigma_a\f$ is the activation nonlinearity. The weights are sliced 175 | * from the kernel and recurrent weights. 176 | * 177 | * @param layer the RNN layer 178 | */ 179 | AI_INTERNAL_API 180 | void forward_rnn(ai_layer * layer); 181 | 182 | AI_API_DECLARE_END 183 | 184 | #endif /* LAYERS_RNN_H */ 185 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_sm.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_sm.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of AI platform non softmax layer datatype 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LAYERS_SM_H 23 | #define LAYERS_SM_H 24 | #pragma once 25 | 26 | #include "layers_common.h" 27 | 28 | /*! 29 | * @defgroup layers SoftMax Layer Definitions 30 | * @brief definition 31 | * 32 | */ 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | /*! 37 | * @brief Softmax normalization computed on an array of fixed point channels 38 | * @ingroup layers_sm 39 | * @param out opaque handler to output channel array 40 | * @param in opaque handler to input channel array 41 | * @param in_size total size (number of elements) to process on the input 42 | * @param channel_size number of elements of the input channel 43 | * @param in_channel_step number of elements to move to next input element 44 | * @param out_channel_step number of elements to move to next output element 45 | */ 46 | AI_INTERNAL_API 47 | void sm_func_sm_array_fixed(ai_handle out, const ai_handle in, 48 | const ai_size in_size, 49 | const ai_size channel_size, 50 | const ai_size in_channel_step, 51 | const ai_size out_channel_step); 52 | 53 | /*! 54 | * @brief Computes the activations of a fixed point softmax nonlinear layer. 55 | * @ingroup layers_sm 56 | * @param layer the softmax (sm) layer 57 | */ 58 | AI_INTERNAL_API 59 | void forward_sm_fixed(ai_layer *pLayer); 60 | 61 | AI_API_DECLARE_END 62 | 63 | #endif /*LAYERS_SM_H*/ 64 | 65 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/layers_upsample_generic.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_upsample_generic.h 4 | * @author Cyril Enault 5 | * @brief header file of AI platform padding generic datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LAYERS_UPSAMPLE_H 22 | #define LAYERS_UPSAMPLE_H 23 | #pragma once 24 | 25 | #include "layers_generic.h" 26 | 27 | /*! 28 | * @defgroup layers_pad_generic Layers Definitions 29 | * @brief definition 30 | * 31 | */ 32 | AI_API_DECLARE_BEGIN 33 | 34 | 35 | /******************************************************************************/ 36 | /* Forward Functions Section */ 37 | /******************************************************************************/ 38 | 39 | /*! 40 | * @brief Handles generic upsmapling in nearest mode 41 | * @ingroup layers_generic 42 | * @param layer upsample layer 43 | */ 44 | AI_INTERNAL_API 45 | void forward_upsample_nearest(ai_layer *pLayer); 46 | 47 | /*! 48 | * @brief Handles generic upsmapling in zeros mode 49 | * @ingroup layers_generic 50 | * @param layer upsample layer 51 | */ 52 | AI_INTERNAL_API 53 | void forward_upsample_zeros(ai_layer *pLayer); 54 | 55 | /*! 56 | * @brief Handles generic upsmapling in bilinear mode 57 | * @ingroup layers_generic 58 | * @param layer upsample layer 59 | */ 60 | AI_INTERNAL_API 61 | void forward_upsample_bilinear(ai_layer *pLayer); 62 | 63 | 64 | AI_API_DECLARE_END 65 | 66 | #endif /*LAYERS_PAD_GENERIC_H*/ 67 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_bn_f32.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_BN_F32_H 2 | #define LITE_BN_F32_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | /*! 8 | * @brief Forward function for a batch normalization (BN) layer with 9 | * signed float input, signed float output, and float parameters. 10 | * @ingroup lite_bn_f32 11 | * @param output The pointer to output buffer. 12 | * @param input The pointer to input buffer. 13 | * @param scale The pointer to BN scale param. 14 | * @param bias The pointer to bias. 15 | * @param n_elements The number of elements in the input tensor. 16 | * @param n_channel_in The number of channel in the input tensor. 17 | */ 18 | LITE_API_ENTRY 19 | void forward_lite_bn_if32of32wf32( 20 | ai_float* output, const ai_float* input, 21 | const ai_float* scale, const ai_float* bias, 22 | const ai_u32 n_elements, const ai_u32 n_channel_in); 23 | 24 | 25 | #endif /* LITE_BN_F32_H */ 26 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_bn_integer.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_BN_INTEGER_H 2 | #define LITE_BN_INTEGER_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | /** 8 | * @brief Batch Normalization with 16-bit input, 16-bit threshold and binary output. 9 | * It is implemented using a threshold, and this is possible because the output is binary. 10 | * 11 | * @param[in] pIn Input data pointer 12 | * @param[out] pOut_32 Output data pointer 13 | * @param[in] pThreshold Thresholds pointer (one per channel) 14 | * @param[in] dim_x X dimension 15 | * @param[in] dim_y Y dimension 16 | * @param[in] channels_num Channels number 17 | */ 18 | LITE_API_ENTRY 19 | void forward_lite_bn_is16os1ws16(const ai_i16 *pIn, 20 | ai_u32 *pOut_32, 21 | const ai_i16 *pThreshold, 22 | const ai_i16 dim_x, 23 | const ai_i16 dim_y, 24 | const ai_i16 channels_num); 25 | #endif /* LITE_BN_INTEGER_H */ 26 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_convert_dqnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_convert_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform lite convert kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_CONVERT_DQNN_H 22 | #define LITE_CONVERT_DQNN_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | /******************************************************************************/ 28 | /* Forward Functions Section */ 29 | /******************************************************************************/ 30 | 31 | LITE_API_ENTRY 32 | void forward_lite_node_convert_is1os8( 33 | const ai_pbits *p_in, 34 | ai_i8 *p_out, 35 | const ai_i32 n_channels, 36 | const ai_i32 n_pixels, 37 | const ai_i8 *n_values); 38 | 39 | 40 | LITE_API_ENTRY 41 | void forward_lite_node_convert_is1os16( 42 | const ai_pbits *p_in, 43 | ai_i16 *p_out, 44 | const ai_i32 n_channels, 45 | const ai_i32 n_pixels, 46 | const ai_i16 *n_values); 47 | 48 | 49 | LITE_API_ENTRY 50 | void forward_lite_node_convert_is1of32( 51 | const ai_pbits *p_in, 52 | ai_float *p_out, 53 | const ai_i32 n_channels, 54 | const ai_i32 n_pixels, 55 | const ai_float *n_values); 56 | 57 | 58 | /*! 59 | * @brief Handles data conversion from 8-bits signed input to signed binary 60 | * outputs - Lite API version 61 | * @ingroup lite_pw_dqnn 62 | */ 63 | LITE_API_ENTRY 64 | void forward_lite_node_convert_is8os1( 65 | const ai_i8 *p_in, 66 | ai_pbits *p_out, 67 | const ai_i32 n_channels, 68 | const ai_i32 n_pixels, 69 | const ai_i8 zp, 70 | const ai_i8 pad); 71 | 72 | 73 | LITE_API_ENTRY 74 | void forward_lite_node_convert_is16os1( 75 | const ai_i16 *p_in, 76 | ai_pbits *p_out, 77 | const ai_i32 n_channels, 78 | const ai_i32 n_pixels, 79 | const ai_i8 zp, 80 | const ai_i8 pad); 81 | 82 | 83 | LITE_API_ENTRY 84 | void forward_lite_node_convert_if32os1( 85 | const ai_float *p_in, 86 | ai_pbits *p_out, 87 | const ai_i32 n_channels, 88 | const ai_i32 n_pixels, 89 | const ai_i8 zp, 90 | const ai_i8 pad); 91 | 92 | 93 | LITE_API_ENTRY 94 | void forward_lite_node_convert_integer_if32os8( 95 | const ai_float *p_in, 96 | ai_i8 *p_out, 97 | const ai_u32 size, 98 | const ai_float out_scale, 99 | const ai_i8 out_zeropoint); 100 | 101 | 102 | LITE_API_ENTRY 103 | void forward_lite_node_convert_integer_if32ou8( 104 | const ai_float *p_in, 105 | ai_u8 *p_out, 106 | const ai_u32 size, 107 | const ai_float out_scale, 108 | const ai_u8 out_zeropoint); 109 | 110 | 111 | LITE_API_ENTRY 112 | void forward_lite_node_convert_integer_is8of32( 113 | const ai_i8 *p_in, 114 | ai_float *p_out, 115 | const ai_u32 size, 116 | const ai_float in_scale, 117 | const ai_i8 in_zeropoint); 118 | 119 | 120 | LITE_API_ENTRY 121 | void forward_lite_node_convert_integer_iu8of32( 122 | const ai_u8 *p_in, 123 | ai_float *p_out, 124 | const ai_u32 size, 125 | const ai_float in_scale, 126 | const ai_u8 in_zeropoint); 127 | 128 | 129 | LITE_API_ENTRY 130 | void forward_lite_node_convert_if32os16( 131 | const ai_float *p_in, 132 | ai_i16 *p_out, 133 | const ai_u32 size, 134 | const ai_float out_scale, 135 | const ai_i16 out_zeropoint); 136 | 137 | 138 | LITE_API_ENTRY 139 | void forward_lite_node_convert_if32ou16( 140 | const ai_float *p_in, 141 | ai_u16 *p_out, 142 | const ai_u32 size, 143 | const ai_float out_scale, 144 | const ai_u16 out_zeropoint); 145 | 146 | 147 | LITE_API_ENTRY 148 | void forward_lite_node_convert_is16of32( 149 | const ai_i16 *p_in, 150 | ai_float *p_out, 151 | const ai_u32 size, 152 | const ai_float in_scale, 153 | const ai_i16 in_zeropoint); 154 | 155 | 156 | LITE_API_ENTRY 157 | void forward_lite_node_convert_iu16of32( 158 | const ai_u16 *p_in, 159 | ai_float *p_out, 160 | const ai_u32 size, 161 | const ai_float in_scale, 162 | const ai_u16 in_zeropoint); 163 | 164 | 165 | LITE_API_ENTRY 166 | void forward_lite_node_convert_integer_iu8ou8( 167 | const ai_u8 *p_in, 168 | ai_u8 *p_out, 169 | const ai_i32 n_elems, 170 | const ai_float scale_ratio, 171 | const ai_u8 in_zp, 172 | const ai_u8 out_zp); 173 | 174 | 175 | LITE_API_ENTRY 176 | void forward_lite_node_convert_integer_iu8os8( 177 | const ai_u8 *p_in, 178 | ai_i8 *p_out, 179 | const ai_i32 n_elems, 180 | const ai_float scale_ratio, 181 | const ai_u8 in_zp, 182 | const ai_i8 out_zp); 183 | 184 | 185 | LITE_API_ENTRY 186 | void forward_lite_node_convert_integer_iu8os8_fast( 187 | const ai_u8 *p_in, 188 | ai_i8 *p_out, 189 | const ai_i32 n_elems, 190 | const ai_float scale_ratio, 191 | const ai_u8 in_zp, 192 | const ai_i8 out_zp); 193 | 194 | 195 | LITE_API_ENTRY 196 | void forward_lite_node_convert_integer_is8ou8( 197 | const ai_i8 *p_in, 198 | ai_u8 *p_out, 199 | const ai_i32 n_elems, 200 | const ai_float scale_ratio, 201 | const ai_i8 in_zp, 202 | const ai_u8 out_zp); 203 | 204 | 205 | LITE_API_ENTRY 206 | void forward_lite_node_convert_integer_is8ou8_fast( 207 | const ai_i8 *p_in, 208 | ai_u8 *p_out, 209 | const ai_i32 n_elems, 210 | const ai_float scale_ratio, 211 | const ai_i8 in_zp, 212 | const ai_u8 out_zp); 213 | 214 | 215 | LITE_API_ENTRY 216 | void forward_lite_node_convert_is16ou16( 217 | const ai_i16 *p_in, 218 | ai_u16 *p_out, 219 | const ai_i32 n_elems, 220 | const ai_float scale_ratio, 221 | const ai_i16 in_zp, 222 | const ai_u16 out_zp); 223 | 224 | #endif /*LITE_CONVERT_DQNN_H*/ 225 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_dense_if32.h: -------------------------------------------------------------------------------- 1 | #ifndef _LITE_DENSE_IF32_H 2 | #define _LITE_DENSE_IF32_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | /*! 8 | * @brief Forward function for a dense layer with signed float input, 9 | * signed float output, and float weights. 10 | * @ingroup lite_dense_if32 11 | * @param output The pointer to output buffer. 12 | * @param input The pointer to input buffer. 13 | * @param weights The pointer to weights. 14 | * @param bias The pointer to bias (NULL if not available). 15 | * @param n_channel_in The number of channels of the input. 16 | * @param n_channel_out The number of channels of the output, i.e., 17 | * the number of dense hidden neurons. 18 | */ 19 | LITE_API_ENTRY 20 | void forward_lite_dense_if32of32wf32( 21 | ai_float* output, const ai_float* input, 22 | const ai_float* weights, const ai_float* bias, 23 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 24 | 25 | 26 | #endif /*_LITE_DENSE_IF32_H*/ 27 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_dense_is1.h: -------------------------------------------------------------------------------- 1 | #ifndef _LITE_DENSE_IS1_H 2 | #define _LITE_DENSE_IS1_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | 8 | /*! 9 | * @brief Forward function for a dense layer with signed binary input, 10 | * signed float output, and float weights. 11 | * @ingroup lite_dense_is1 12 | * @param output The pointer to output buffer. 13 | * @param input The pointer to input buffer. 14 | * @param weights The pointer to weights. 15 | * @param bias The pointer to bias (NULL if not available). 16 | * @param scratch The pointer to the scratch buffer (unused). 17 | * @param n_channel_in The number of channels of the input. 18 | * @param n_channel_ouy The number of channels of the output, i.e., 19 | * the number of dense hidden neurons. 20 | */ 21 | LITE_API_ENTRY 22 | void forward_lite_dense_is1of32wf32( 23 | ai_float *output, const ai_pbits *input, const ai_float *weights, 24 | const ai_float *bias, ai_float *scratch, 25 | const ai_u32 n_channel_in, const ai_u32 n_channel_out 26 | ); 27 | 28 | 29 | /*! 30 | * @brief Forward function for a dense layer with signed binary input, 31 | * signed float output, and float weights. 32 | * The BN is fused, i.e., the layer requires weights, scale, and offset, where 33 | * weights are those of the dense layer, scale is that of the BN, and the offset 34 | * corresponds to dense bias * bn scale + bn offset. If the parameters do not 35 | * agree with such convention, the behavior is undefined. 36 | * @ingroup lite_dense_is1 37 | * @param output The pointer to output buffer. 38 | * @param input The pointer to input buffer. 39 | * @param weights The pointer to weights. 40 | * @param scale The pointer to scale. 41 | * @param offset The pointer to offset. 42 | * @param scratch The pointer to the scratch buffer (unused). 43 | * @param n_channel_in The number of channels of the input. 44 | * @param n_channel_ouy The number of channels of the output, i.e., 45 | * the number of dense hidden neurons. 46 | */ 47 | LITE_API_ENTRY 48 | void forward_lite_dense_is1of32wf32_bn( 49 | ai_float *output, const ai_pbits *input, const ai_float *weights, 50 | const ai_float *scale, const ai_float *offset, ai_float *scratch, 51 | const ai_u32 n_channel_in, const ai_u32 n_channel_out 52 | ); 53 | 54 | #endif /*_LITE_DENSE_IS1_H*/ 55 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_dense_is1ws1.h: -------------------------------------------------------------------------------- 1 | #ifndef _LITE_DENSE_IS1WS1_H 2 | #define _LITE_DENSE_IS1WS1_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | /*! 8 | * @brief Forward function for a dense layer with signed binary input, 9 | * signed binary output, and signed binary weights. 10 | * @ingroup lite_dense_is1ws1 11 | * @param output The pointer to output buffer. 12 | * @param input The pointer to input buffer. 13 | * @param weights The pointer to weights. 14 | * @param bias The pointer to bias (NULL if not available). 15 | * @param scratch The pointer to the scratch buffer. 16 | * @param n_channel_in The number of channels of the input. 17 | * @param n_channel_ouy The number of channels of the output, i.e., 18 | * the number of dense hidden neurons. 19 | */ 20 | LITE_API_ENTRY 21 | void forward_lite_dense_is1os1ws1( 22 | ai_pbits *output, const ai_pbits *input, const ai_pbits *weights, 23 | const ai_pbits *bias, ai_i32 *scratch, 24 | const ai_u32 n_channel_in, const ai_u32 n_channel_out 25 | ); 26 | 27 | /*! 28 | * @brief Forward function for a dense layer with signed binary input, 29 | * signed binary output, and signed binary weights. 30 | * The BN is fused, i.e., the layer requires weights, scale, and offset, where 31 | * weights are those of the dense layer, scale is that of the BN, and the offset 32 | * corresponds to dense bias * bn scale + bn offset. If the parameters do not 33 | * agree with such convention, the behavior is undefined. 34 | * @ingroup lite_dense_is1ws1 35 | * @param output The pointer to output buffer. 36 | * @param input The pointer to input buffer. 37 | * @param weights The pointer to weights. 38 | * @param scale The pointer to scale. 39 | * @param offset The pointer to offset. 40 | * @param scratch The pointer to the scratch buffer. 41 | * @param n_channel_in The number of channels of the input. 42 | * @param n_channel_ouy The number of channels of the output, i.e., 43 | * the number of dense hidden neurons. 44 | */ 45 | LITE_API_ENTRY 46 | void forward_lite_dense_is1os1ws1_bn( 47 | ai_pbits *output, const ai_pbits *input, const ai_pbits *weights, 48 | const ai_float *scale, const ai_float *offset, ai_i32 *scratch, 49 | const ai_u32 n_channel_in, const ai_u32 n_channel_out 50 | ); 51 | 52 | 53 | /*! 54 | * @brief Forward function for a dense layer with signed binary input, 55 | * signed binary output, and signed 16bit weights. 56 | * @ingroup lite_dense_is1ws1 57 | * @param output The pointer to output buffer. 58 | * @param input The pointer to input buffer. 59 | * @param weights The pointer to weights. 60 | * @param bias The pointer to bias (NULL if not available). 61 | * @param scratch The pointer to the scratch buffer (signed 32bit). 62 | * @param n_channel_in The number of channels of the input. 63 | * @param n_channel_ouy The number of channels of the output, i.e., 64 | * the number of dense hidden neurons. 65 | */ 66 | LITE_API_ENTRY 67 | void forward_lite_dense_is1os16ws1( 68 | ai_i16 *output, const ai_pbits *input, const ai_pbits *weights, 69 | const ai_pbits *bias, ai_i32 *scratch, 70 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 71 | 72 | 73 | /*! 74 | * @brief Forward function for a dense layer with signed binary input, 75 | * signed binary output, and signed 16bit weights. 76 | * The BN is fused, i.e., the layer requires weights, scale, and offset, where 77 | * weights are those of the dense layer, scale is that of the BN, and the offset 78 | * corresponds to dense bias * bn scale + bn offset. If the parameters do not 79 | * agree with such convention, the behavior is undefined. 80 | * @ingroup lite_dense_is1ws1 81 | * @param output The pointer to output buffer. 82 | * @param input The pointer to input buffer. 83 | * @param weights The pointer to weights. 84 | * @param bias The pointer to bias (NULL if not available). 85 | * @param scratch The pointer to the scratch buffer (signed 32bit). 86 | * @param n_channel_in The number of channels of the input. 87 | * @param n_channel_ouy The number of channels of the output, i.e., 88 | * the number of dense hidden neurons. 89 | */ 90 | LITE_API_ENTRY 91 | void forward_lite_dense_is1os16ws1_bn( 92 | ai_i16 *output, const ai_pbits *input, const ai_pbits *weights, 93 | const ai_float *scale, const ai_float *offset, ai_i32 *scratch, 94 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 95 | 96 | 97 | /*! 98 | * @brief Forward function for a dense layer with signed binary input, 99 | * signed float output, and signed binary weights. 100 | * @ingroup lite_dense_is1ws1 101 | * @param output The pointer to output buffer. 102 | * @param input The pointer to input buffer. 103 | * @param weights The pointer to weights. 104 | * @param bias The pointer to bias (NULL if not available). 105 | * @param scratch The pointer to the scratch buffer (unused). 106 | * @param n_channel_in The number of channels of the input. 107 | * @param n_channel_ouy The number of channels of the output, i.e., 108 | * the number of dense hidden neurons. 109 | */ 110 | LITE_API_ENTRY 111 | void forward_lite_dense_is1of32ws1( 112 | ai_float *output, const ai_pbits *input, const ai_pbits *weights, 113 | const ai_pbits *bias, ai_i32 *scratch, 114 | const ai_u32 n_channel_in, const ai_u32 n_channel_out 115 | ); 116 | 117 | 118 | /*! 119 | * @brief Forward function for a dense layer with signed binary input, 120 | * signed float output, and signed binary weights. 121 | * The BN is fused, i.e., the layer requires weights, scale, and offset, where 122 | * weights are those of the dense layer, scale is that of the BN, and the offset 123 | * corresponds to dense bias * bn scale + bn offset. If the parameters do not 124 | * agree with such convention, the behavior is undefined. 125 | * @ingroup lite_dense_is1ws1 126 | * @param output The pointer to output buffer. 127 | * @param input The pointer to input buffer. 128 | * @param weights The pointer to weights. 129 | * @param scale The pointer to scale. 130 | * @param offset The pointer to offset. 131 | * @param scratch The pointer to the scratch buffer (unused). 132 | * @param n_channel_in The number of channels of the input. 133 | * @param n_channel_out The number of channels of the output, i.e., 134 | * the number of dense hidden neurons. 135 | */ 136 | LITE_API_ENTRY 137 | void forward_lite_dense_is1of32ws1_bn( 138 | ai_float *output, const ai_pbits *input, const ai_pbits *weights, 139 | const ai_float *scale, const ai_float *offset, ai_i32 *scratch, 140 | const ai_u32 n_channel_in, const ai_u32 n_channel_out 141 | ); 142 | 143 | #endif /*_LITE_DENSE_IS1WS1_H*/ 144 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_dense_is8os1ws1.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_dense_is8os1ws1.h 4 | * @author Marco Forleo 5 | * @brief header file of AI platform lite dense kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2023 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef LITE_DENSE_IS8OS1WS1_H 23 | #define LITE_DENSE_IS8OS1WS1_H 24 | #pragma once 25 | 26 | #include "ai_lite_interface.h" 27 | 28 | /******************************************************************************/ 29 | /* Forward Functions Section */ 30 | /******************************************************************************/ 31 | 32 | /*! 33 | * @brief Forward function for a dense layer with signed 8 bits input, 34 | * binary weights and binary output. 35 | * @ingroup lite_dense_is8os1ws1 36 | * @param out_ptr The pointer to output buffer. 37 | *@param data_in_init_ptr The pointer to input buffer. 38 | * @param weights_ptr The pointer to weights. 39 | * @param scratch_ptr The pointer to scratch buffer. 40 | * @param scratch_size The value of scratch tensor size. 41 | * @param n_channel_out The number of channels of the output, i.e., 42 | * the number of dense hidden neurons. 43 | * @param n_channel_in The number of channels of the input. 44 | * @param scale_ptr The pointer to scale buffer of BN. 45 | * @param offset_ptr The pointer to offset buffer of BN. 46 | */ 47 | LITE_API_ENTRY 48 | void forward_lite_dense_is8os1ws1_bn_fxp(ai_pbits *out_ptr, 49 | const ai_i8 *data_in_init_ptr, 50 | const ai_pbits *weights_ptr, 51 | ai_i32 *scratch_ptr, 52 | const ai_u32 scratch_size, 53 | const ai_u32 n_channel_out, 54 | const ai_u32 n_channel_in, 55 | const ai_i32 *threshold_ptr); 56 | 57 | #endif /*LITE_DENSE_IS8OS1WS1_H*/ 58 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_dense_is8os8ws8.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_dense_is8os8ws8.h 4 | * @author Marco Forleo 5 | * @brief header file of AI platform lite dense kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_DENSE_IS8OS8WS8_H 22 | #define LITE_DENSE_IS8OS8WS8_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | /******************************************************************************/ 28 | /* Forward Functions Section */ 29 | /******************************************************************************/ 30 | 31 | /*! 32 | * @brief Forward function for a dense layer with signed input, 33 | * signed output and signed weights all at 8 bits. 34 | * @ingroup lite_dense_is8os8ws8 35 | * @param input The pointer to input buffer. 36 | * @param output The pointer to output buffer. 37 | * @param weights The pointer to weights. 38 | * @param bias The pointer to bias (NULL if not available). 39 | * @param in_zeropoint The value of the zero point of the input. 40 | * @param out_zeropoint TThe value of the zero point of the output. 41 | * @param n_channel_in The number of channels of the input. 42 | * @param n_channel_out The number of channels of the output, i.e., 43 | * the number of dense hidden neurons. 44 | * @param n_pixels Total number of pixels. 45 | */ 46 | LITE_API_ENTRY 47 | void forward_lite_dense_is8os8ws8(ai_i8 * pDataOut, 48 | const ai_i8 *pDataIn, 49 | const ai_i8 *pWeights, 50 | const ai_i32 *pBias, 51 | const ai_i8 in_zeropoint, 52 | const ai_i8 out_zeropoint, 53 | const ai_u16 n_channel_in, 54 | const ai_u16 n_channel_out, 55 | const ai_size n_pixels, 56 | const ai_float in_scale, 57 | const ai_float out_scale, 58 | const ai_float Wt_scale, 59 | ai_i16 *pBuffer_a); 60 | 61 | void forward_lite_dense_is8os8ws8_ch(ai_i8 * pDataOut, 62 | const ai_i8 *pDataIn, 63 | const ai_i8 *pWeights, 64 | const ai_i32 *pBias, 65 | const ai_i8 in_zeropoint, 66 | const ai_i8 out_zeropoint, 67 | const ai_u16 n_channel_in, 68 | const ai_u16 n_channel_out, 69 | const ai_size n_pixels, 70 | const ai_float in_scale, 71 | const ai_float out_scale, 72 | const ai_float *pWt_scale, 73 | ai_i16 *pBuffer_a); 74 | 75 | #endif /*LITE_DENSE_IS8OS8WS8_H*/ 76 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_dense_ws1.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_DENSE_WS1_H 2 | #define LITE_DENSE_WS1_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | 8 | /*! 9 | * @brief Forward function for a dense layer with signed 16bit input, 10 | * signed 16bit output, binary weights and binary bias. 11 | * @ingroup lite_dense_ws1 12 | * @param output The pointer to output buffer. 13 | * @param input The pointer to input buffer. 14 | * @param weights The pointer to weights. 15 | * @param bias The pointer to bias. 16 | * @param scratch The pointer to the scratch buffer (unused). 17 | * @param n_channel_in The number of channels of the input. 18 | * @param n_channel_out The number of channels of the output, i.e., 19 | * the number of dense hidden neurons. 20 | */ 21 | LITE_API_ENTRY 22 | void forward_lite_dense_is16os16ws1( 23 | ai_i16* output, const ai_i16* input, 24 | const ai_pbits* weights, 25 | const ai_pbits* bias, ai_i32* scratch, 26 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 27 | 28 | 29 | /*! 30 | * @brief Forward function for a dense layer with signed 16bit input, 31 | * signed 16bit output, binary weights and binary bias. 32 | * The BN is fused, i.e., the layer requires weights, scale, and offset, where 33 | * weights are those of the dense layer, scale is that of the BN, and the offset 34 | * corresponds to dense bias * bn scale + bn offset. If the parameters do not 35 | * agree with such convention, the behavior is undefined. 36 | * @ingroup lite_dense_ws1 37 | * @param output The pointer to output buffer. 38 | * @param input The pointer to input buffer. 39 | * @param weights The pointer to weights. 40 | * @param scale The pointer to scale. 41 | * @param offset The pointer to offset. 42 | * @param scratch The pointer to the scratch buffer (unused). 43 | * @param n_channel_in The number of channels of the input. 44 | * @param n_channel_out The number of channels of the output, i.e., 45 | * the number of dense hidden neurons. 46 | */ 47 | LITE_API_ENTRY 48 | void forward_lite_dense_is16os16ws1_bn( 49 | ai_i16* output, const ai_i16* input, 50 | const ai_pbits* weights, 51 | const ai_float *scale, const ai_float *offset, ai_i32* scratch, 52 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 53 | 54 | 55 | /*! 56 | * @brief Forward function for a dense layer with signed f32 input, 57 | * f32 output, binary weights and binary bias. 58 | * @ingroup lite_dense_ws1 59 | * @param output The pointer to output buffer. 60 | * @param input The pointer to input buffer. 61 | * @param weights The pointer to weights. 62 | * @param bias The pointer to bias. 63 | * @param scratch The pointer to the scratch buffer (unused). 64 | * @param n_channel_in The number of channels of the input. 65 | * @param n_channel_out The number of channels of the output, i.e., 66 | * the number of dense hidden neurons. 67 | */ 68 | LITE_API_ENTRY 69 | void forward_lite_dense_if32os1ws1( 70 | ai_pbits *output, const ai_float *input, const ai_pbits *weights, 71 | const ai_float *bias, ai_float *scratch, 72 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 73 | 74 | 75 | /*! 76 | * @brief Forward function for a dense layer with signed f32 input, 77 | * f32 output, binary weights. 78 | * The BN is fused, i.e., the layer requires weights, scale, and offset, where 79 | * weights are those of the dense layer, scale is that of the BN, and the offset 80 | * corresponds to dense bias * bn scale + bn offset. If the parameters do not 81 | * agree with such convention, the behavior is undefined. 82 | * @ingroup lite_dense_ws1 83 | * @param output The pointer to output buffer. 84 | * @param input The pointer to input buffer. 85 | * @param weights The pointer to weights. 86 | * @param scale The pointer to scale. 87 | * @param offset The pointer to offset. 88 | * @param scratch The pointer to the scratch buffer (unused). 89 | * @param n_channel_in The number of channels of the input. 90 | * @param n_channel_out The number of channels of the output, i.e., 91 | * the number of dense hidden neurons. 92 | */ 93 | LITE_API_ENTRY 94 | void forward_lite_dense_if32os1ws1_bn( 95 | ai_pbits *output, const ai_float *input, const ai_pbits *weights, 96 | const ai_float *scale, const ai_float *offset, ai_float *scratch, 97 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 98 | 99 | 100 | /*! 101 | * @brief Forward function for a dense layer with signed f32 input, 102 | * f32 output, and binary weights. 103 | * @ingroup lite_dense_ws1 104 | * @param output The pointer to output buffer. 105 | * @param input The pointer to input buffer. 106 | * @param weights The pointer to weights. 107 | * @param bias The pointer to binary bias. 108 | * @param scratch The pointer to the scratch buffer (unused). 109 | * @param n_channel_in The number of channels of the input. 110 | * @param n_channel_out The number of channels of the output, i.e., 111 | * the number of dense hidden neurons. 112 | */ 113 | LITE_API_ENTRY 114 | void forward_lite_dense_if32of32ws1( 115 | ai_float* output, const ai_float* input, 116 | const ai_pbits* weights, 117 | const ai_pbits* bias, ai_float* scratch, 118 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 119 | 120 | /*! 121 | * @brief Forward function for a dense layer with signed f32 input, 122 | * f32 output, and binary weights. 123 | * The BN is fused, i.e., the layer requires weights, scale, and offset, where 124 | * weights are those of the dense layer, scale is that of the BN, and the offset 125 | * corresponds to dense bias * bn scale + bn offset. If the parameters do not 126 | * agree with such convention, the behavior is undefined. 127 | * @ingroup lite_dense_ws1 128 | * @param output The pointer to output buffer. 129 | * @param input The pointer to input buffer. 130 | * @param weights The pointer to weights. 131 | * @param scale The pointer to scale. 132 | * @param offset The pointer to offset. 133 | * @param scratch The pointer to the scratch buffer (unused). 134 | * @param n_channel_in The number of channels of the input. 135 | * @param n_channel_out The number of channels of the output, i.e., 136 | * the number of dense hidden neurons. 137 | */ 138 | LITE_API_ENTRY 139 | void forward_lite_dense_if32of32ws1_bn( 140 | ai_float *output, const ai_float *input, const ai_pbits *weights, 141 | const ai_float *scale, const ai_float *offset, ai_float *scratch, 142 | const ai_u32 n_channel_in, const ai_u32 n_channel_out); 143 | 144 | #endif /* LITE_DENSE_IS1WS1_H */ 145 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_dw.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_dw.h 4 | * @author AIS 5 | * @brief header file of AI platform lite dw kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_DW_H 22 | #define LITE_DW_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | 28 | 29 | /******************************************************************************/ 30 | /* Forward Functions Section */ 31 | /******************************************************************************/ 32 | 33 | /*! 34 | * @brief Handles dw convolutions generic case (supports depth multiplier >= 1) 35 | * @ingroup lite_dw 36 | */ 37 | LITE_API_ENTRY 38 | void 39 | forward_lite_dw_dm_sssa8_ch(const ai_i8 *Im_in, 40 | const ai_u16 dim_im_in_x, 41 | const ai_u16 dim_im_in_y, 42 | const ai_u16 ch_im_in, 43 | const ai_i8 *wt, 44 | const ai_u16 ch_im_out, 45 | const ai_u16 dim_kernel_x, 46 | const ai_u16 dim_kernel_y, 47 | const ai_u16 padding_x, 48 | const ai_u16 padding_y, 49 | const ai_u16 stride_x, 50 | const ai_u16 stride_y, 51 | const ai_i32 *bias, 52 | const ai_i8 In_ZeroPoint, 53 | const ai_i8 Out_ZeroPoint, 54 | ai_i8 *Im_out, 55 | const ai_u16 dim_im_out_x, 56 | const ai_u16 dim_im_out_y, 57 | const ai_i32 nl_pool_fused, 58 | ai_i16 *bufferA); 59 | 60 | /*! 61 | * @brief Handles dw convolutions with depth multiplier = 1 only 62 | * @ingroup lite_dw 63 | */ 64 | LITE_API_ENTRY 65 | void 66 | forward_lite_dw_sssa8_ch(const ai_i8 *Im_in, 67 | const ai_u16 dim_im_in_x, 68 | const ai_u16 dim_im_in_y, 69 | const ai_u16 ch_im_in, 70 | const ai_i8 *wt, 71 | const ai_u16 dim_kernel_x, 72 | const ai_u16 dim_kernel_y, 73 | const ai_u16 padding_x, 74 | const ai_u16 padding_y, 75 | const ai_u16 stride_x, 76 | const ai_u16 stride_y, 77 | const ai_i32 *bias, 78 | const ai_i8 In_ZeroPoint, 79 | const ai_i8 Out_ZeroPoint, 80 | ai_i8 *Im_out, 81 | const ai_u16 dim_im_out_x, 82 | const ai_u16 dim_im_out_y, 83 | const ai_i32 nl_pool_fused, 84 | ai_i16 *bufferA); 85 | 86 | /*! 87 | * @brief Handles dw convolutions with depth multiplier = 1, valid padding 88 | * and 3*3 kernel size 89 | * @ingroup lite_dw 90 | */ 91 | LITE_API_ENTRY 92 | void 93 | forward_lite_dw_3x3_sssa8_ch(const ai_i8 *Im_in, 94 | const ai_u16 dim_im_in_x, 95 | const ai_u16 dim_im_in_y, 96 | const ai_u16 ch_im_in, 97 | const ai_i8 *wt, 98 | const ai_u16 stride_x, 99 | const ai_u16 stride_y, 100 | const ai_i32 *bias, 101 | const ai_i8 In_ZeroPoint, 102 | const ai_i8 Out_ZeroPoint, 103 | ai_i8 *Im_out, 104 | const ai_u16 dim_im_out_x, 105 | const ai_u16 dim_im_out_y, 106 | const ai_i32 nl_pool_fused, 107 | ai_i16 *bufferA); 108 | 109 | /*! 110 | * @brief Handles dw convolutions with depth multiplier = 1, valid padding, 111 | * 3*3 kernel size, stride_x = 1 and weights/input are channel first 112 | * @ingroup lite_dw 113 | */ 114 | LITE_API_ENTRY 115 | void 116 | forward_lite_dw_3x3_ch1st_sssa8_ch(const ai_i8 *Im_in, 117 | const ai_u16 dim_im_in_x, 118 | const ai_u16 dim_im_in_y, 119 | const ai_u16 ch_im_in, 120 | const ai_i8 *wt, 121 | const ai_u16 stride_x, 122 | const ai_u16 stride_y, 123 | const ai_i32 *bias, 124 | const ai_i8 In_ZeroPoint, 125 | const ai_i8 Out_ZeroPoint, 126 | ai_i8 *Im_out, 127 | const ai_u16 dim_im_out_x, 128 | const ai_u16 dim_im_out_y, 129 | const ai_i32 nl_pool_fused, 130 | ai_i16 *bufferA); 131 | 132 | #endif /*LITE_DW_H*/ 133 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_generic_float.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_conv2d_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform lite conv kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_GENERIC_FLOAT_H 22 | #define LITE_GENERIC_FLOAT_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | 28 | 29 | /******************************************************************************/ 30 | /* Forward Functions Section */ 31 | /******************************************************************************/ 32 | 33 | /*! 34 | * @brief Handles 2D convolution with binary input, binary output and 35 | * binary weights - with 0 padding (QKeras like) - Lite I/F 36 | * @ingroup lite_conv2d_dqnn 37 | */ 38 | LITE_API_ENTRY 39 | void forward_lite_topK_axis_0_if32of32(const ai_float *pDataIn_init, 40 | ai_float *pDataOut_values_init, 41 | ai_i32 *pDataOut_index_init, 42 | const ai_size height_in, 43 | const ai_size width_in, 44 | const ai_size n_channel_in, 45 | const ai_size k, ai_i16 largest, 46 | void (*f)(const ai_float* inputs, ai_float* values, ai_i32* indices, ai_size k, ai_size n_elements, ai_i32 stride, ai_i16 largest) 47 | ); 48 | 49 | 50 | /*! 51 | * @brief Handles 2D convolution with binary input, binary output and 52 | * binary weights - with 0 padding (QKeras like) - Lite I/F 53 | * - Optimized thanks to Optim0 assumptions 54 | * @ingroup lite_conv2d_dqnn 55 | */ 56 | 57 | LITE_API_ENTRY 58 | void forward_lite_topK_axis_1_if32of32(const ai_float *pDataIn_init, 59 | ai_float *pDataOut_values_init, 60 | ai_i32 *pDataOut_index_init, 61 | const ai_size height_in, 62 | const ai_size width_in, 63 | const ai_size n_channel_in, 64 | const ai_size k, ai_i16 largest, 65 | void (*f)(const ai_float* inputs, ai_float* values, ai_i32* indices, ai_size k, ai_size n_elements, ai_i32 stride, ai_i16 largest) 66 | ); 67 | 68 | /*! 69 | * @brief Handles 2D convolution with binary input, 8-bits output and 70 | * binary weights - with 0 padding (QKeras like) - Lite I/F 71 | * @ingroup lite_conv2d_dqnn 72 | */ 73 | LITE_API_ENTRY 74 | void forward_lite_topK_axis_2_if32of32(const ai_float *pDataIn_init, 75 | ai_float *pDataOut_values_init, 76 | ai_i32 *pDataOut_index_init, 77 | const ai_size height_in, 78 | const ai_size width_in, 79 | const ai_size n_channel_in, 80 | const ai_size k, ai_i16 largest, 81 | void (*f)(const ai_float* inputs, ai_float* values, ai_i32* indices, ai_size k, ai_size n_elements, ai_i32 stride, ai_i16 largest) 82 | ); 83 | 84 | LITE_API_ENTRY 85 | void forward_lite_func_reduce_l1_if32of32( 86 | ai_float* out_ptr, const ai_float* in_ptr, 87 | const ai_size out_size, const ai_size in_step, 88 | const ai_size axis_size, const ai_size axis_step); 89 | 90 | LITE_API_ENTRY 91 | void forward_lite_func_reduce_l2_if32of32( 92 | ai_float* out_ptr, const ai_float* in_ptr, 93 | const ai_size out_size, const ai_size in_step, 94 | const ai_size axis_size, const ai_size axis_step); 95 | 96 | 97 | #endif /*LITE_GENERIC_FLOAT_H*/ 98 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_gru_f32.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_GRU_F32_H 2 | #define LITE_GRU_F32_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | /*! 8 | * @brief Forward function for a stateless GRU (gate recurrent unit) layer with 9 | * signed float input, signed float output, and float parameters. 10 | * @ingroup lite_gru_f32 11 | * @param output The pointer to output buffer. 12 | * @param input The pointer to input buffer. 13 | * @param gru_kernel The pointer to gru kernel param. 14 | * @param gru_recurrent The pointer to gru recurrent param. 15 | * @param gru_bias The pointer to bias. 16 | * @param gru_scratch The pointer to GRU scratch. 17 | * @param n_units The number of GRU cells (dimensionality of output space). 18 | * @param n_timesteps The number of timesteps of the input sequence. 19 | * @param n_features The number of features of the input sequence. 20 | * @param activation_nl The activation function used to update memory state. 21 | * @param recurrent_nl The activation function to use for the recurrent step. 22 | * @param return_seq If True, returns the full output sequence, else only the last output. 23 | * @param go_backwards If True, process the input sequence backwards. 24 | * @param reverse_seq If True, reverse the input sequence 25 | * @param reset_after Whether to apply reset gate after (True) or before (False) matmul. 26 | * @param activation_param The parameters for activation_nl (can be NULL) 27 | * @param recurrent_param The parameters for recurrent_nl (can be NULL) 28 | */ 29 | LITE_API_ENTRY 30 | void forward_lite_gru_if32of32wf32( 31 | ai_float* output, const ai_float* input, const ai_float* gru_kernel, 32 | const ai_float* gru_recurrent, const ai_float* gru_bias, ai_float* gru_scratch, 33 | const ai_u32 n_units, const ai_size n_timesteps, const ai_size n_features, 34 | ai_handle activation_nl, ai_handle recurrent_nl, ai_bool return_seq, 35 | ai_bool go_backwards, ai_bool reverse_seq, ai_bool reset_after, 36 | const ai_float* activation_param, const ai_float* recurrent_param); 37 | 38 | 39 | #endif /* LITE_GRU_F32_H */ 40 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_nl_generic_float.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_NL_GENERIC_FLOAT_H 2 | #define LITE_NL_GENERIC_FLOAT_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | 8 | #define LITE_NL_ENTRY(nl_id_, nl_name_, nl_op_, nl_op_args_) \ 9 | /** \ 10 | * @brief lite function for a templated non-linearity nl_op_. \ 11 | * @ingroup lite_nl_generic_float \ 12 | * @param out_ptr The pointer to output buffer. \ 13 | * @param in_ptr The pointer to input buffer. \ 14 | * @param in_size. The size of the input. \ 15 | * @param params opaque handler to optional NL params (not used). \ 16 | */ \ 17 | LITE_API_ENTRY \ 18 | void forward_lite_nl_ ## nl_name_ ## _if32of32( \ 19 | ai_handle out_ptr, const ai_handle in_ptr, const ai_i32 in_size, const ai_handle params); 20 | 21 | #include "lite_nl_list.h" 22 | 23 | /** 24 | * @brief lite function for a float softmax non-linearity where the softmax is applied per channel. 25 | * @ingroup lite_nl_generic_float 26 | * @param output The pointer to output buffer. 27 | * @param input The pointer to input buffer. 28 | * @param in_size. The size of the input. 29 | * @param channel_size The nsize of each channel. 30 | * @param in_channel_step 31 | * @param out_channel_step 32 | */ 33 | LITE_API_ENTRY 34 | void forward_lite_nl_softmax_if32of32( 35 | ai_handle out_ptr, const ai_handle in_ptr, const ai_i32 in_size, const ai_size ch_size, 36 | const ai_i32 in_ch_step, const ai_i32 out_ch_step); 37 | 38 | 39 | /** 40 | * @brief lite function for a float softmax zero channel non-linearity where the softmax is applied per channel. 41 | * @ingroup lite_nl_generic_float 42 | * @param output The pointer to output buffer. 43 | * @param input The pointer to input buffer. 44 | * @param in_size. The size of the input. 45 | * @param channel_size The nsize of each channel. 46 | * @param in_channel_step 47 | * @param out_channel_step 48 | */ 49 | LITE_API_ENTRY 50 | void forward_lite_nl_softmax_zero_channel_if32of32( 51 | ai_handle out_ptr, const ai_handle in_ptr, const ai_i32 in_size, const ai_size ch_size, 52 | const ai_i32 in_ch_step, const ai_i32 out_ch_step); 53 | 54 | 55 | #endif /* LITE_NL_GENERIC_FLOAT_H */ 56 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_nl_generic_integer.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_NL_GENERIC_INTEGER_H 2 | #define LITE_NL_GENERIC_INTEGER_H 3 | #pragma once 4 | 5 | #include "ai_lite_interface.h" 6 | 7 | /** 8 | * @brief forward lite function for a s8 softmax non-linearity where the softmax is applied per channel. 9 | * @ingroup lite_nl_generic_integer 10 | * @param output The pointer to output buffer (s8). 11 | * @param input The pointer to input buffer (s8). 12 | * @param in_size. The size of the input (including channels). 13 | * @param ch_size The nsize of each channel. 14 | * @param in_ch_step The step between consecutive elements (inputs) 15 | * @param out_ch_step The step between consecutive elements (outputs) 16 | * @param mult 17 | * @param shift 18 | * @param min_diff 19 | */ 20 | LITE_API_ENTRY 21 | void forward_lite_nl_softmax_is8os8( 22 | ai_i8* out_ptr, const ai_i8* in_ptr, 23 | const ai_size in_size, const ai_size ch_size, 24 | const ai_i32 in_ch_step, const ai_i32 out_ch_step, 25 | const ai_i32 mult, const ai_i32 shift, const ai_i32 min_diff, 26 | ai_i32* scratch); 27 | 28 | 29 | /** 30 | * @brief forward lite function for a u8 softmax non-linearity where the softmax is applied per channel. 31 | * @ingroup lite_nl_generic_integer 32 | * @param output The pointer to output buffer (s8). 33 | * @param input The pointer to input buffer (s8). 34 | * @param in_size. The size of the input (including channels). 35 | * @param ch_size The nsize of each channel. 36 | * @param in_ch_step The step between consecutive elements (inputs) 37 | * @param out_ch_step The step between consecutive elements (outputs) 38 | * @param mult 39 | * @param shift 40 | * @param min_diff 41 | */ 42 | LITE_API_ENTRY 43 | void forward_lite_nl_softmax_iu8ou8( 44 | ai_u8* out_ptr, const ai_u8* in_ptr, 45 | const ai_size in_size, const ai_size ch_size, 46 | const ai_i32 in_ch_step, const ai_i32 out_ch_step, 47 | const ai_i32 mult, const ai_i32 shift, const ai_i32 min_diff, 48 | ai_i32* scratch); 49 | 50 | #endif /* LITE_NL_GENERIC_INTEGER_H */ 51 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_nl_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_nl_list.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @brief header file of lite supported non-linearities routines 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | 22 | // #define LITE_NL_ENTRY(nl_id_, nl_name_, nl_op_, nl_op_args_) 23 | 24 | /* No sentry. This is deliberate!! */ 25 | 26 | LITE_NL_ENTRY(1, abs, AI_ABS, 1) 27 | LITE_NL_ENTRY(2, acos, AI_MATH_ACOS, 1) 28 | LITE_NL_ENTRY(3, acosh, AI_MATH_ACOSH, 1) 29 | LITE_NL_ENTRY(4, asin, AI_MATH_ASIN, 1) 30 | LITE_NL_ENTRY(5, asinh, AI_MATH_ASINH, 1) 31 | LITE_NL_ENTRY(6, atan, AI_MATH_ATAN, 1) 32 | LITE_NL_ENTRY(7, atanh, AI_MATH_ATANH, 1) 33 | LITE_NL_ENTRY(8, ceil, AI_CEIL, 1) 34 | LITE_NL_ENTRY(9, cos, AI_MATH_COS, 1) 35 | LITE_NL_ENTRY(10, cosh, AI_MATH_COSH, 1) 36 | LITE_NL_ENTRY(11, erf, AI_MATH_ERF, 1) 37 | LITE_NL_ENTRY(12, exp, AI_MATH_EXP, 1) 38 | LITE_NL_ENTRY(13, floor, AI_FLOOR, 1) 39 | LITE_NL_ENTRY(14, hardmax, /**/, 0) 40 | LITE_NL_ENTRY(15, log, AI_MATH_LOG, 1) 41 | LITE_NL_ENTRY(16, logistic, AI_MATH_LOGISTIC, 1) 42 | LITE_NL_ENTRY(17, neg, AI_NEG, 1) 43 | LITE_NL_ENTRY(18, rsqrt, AI_MATH_RSQRT, 1) 44 | LITE_NL_ENTRY(19, sin, AI_MATH_SIN, 1) 45 | LITE_NL_ENTRY(20, sinh, AI_MATH_SINH, 1) 46 | LITE_NL_ENTRY(21, tan, AI_MATH_TAN, 1) 47 | LITE_NL_ENTRY(22, square, AI_MATH_SQUARE, 1) 48 | LITE_NL_ENTRY(23, reciprocal, AI_RECIPROCAL, 1) 49 | LITE_NL_ENTRY(24, round, AI_ROUND, 1) 50 | LITE_NL_ENTRY(25, sigmoid, AI_MATH_SIGMOID, 1) 51 | LITE_NL_ENTRY(26, swish, AI_MATH_SWISH, 1) 52 | LITE_NL_ENTRY(27, hard_swish, AI_MATH_HARD_SWISH, 1) 53 | LITE_NL_ENTRY(28, sign, AI_SIGN, 1) 54 | LITE_NL_ENTRY(29, sqrt, AI_MATH_SQRT, 1) 55 | // LITE_NL_ENTRY(30, softmax, /**/, 0) // for future changes 56 | // LITE_NL_ENTRY(31, softmax_zero_channel, /**/, 0) // for future changes 57 | LITE_NL_ENTRY(32, soft_plus, AI_MATH_SOFT_PLUS, 1) 58 | LITE_NL_ENTRY(33, soft_sign, AI_MATH_SOFT_SIGN, 1) 59 | LITE_NL_ENTRY(34, tanh, AI_MATH_TANH, 1) 60 | LITE_NL_ENTRY(35, prelu, /**/, 0) 61 | LITE_NL_ENTRY(36, relu, AI_MATH_RELU, 1) 62 | LITE_NL_ENTRY(37, relu_generic, /**/, 0) 63 | 64 | LITE_NL_ENTRY(101, elu, AI_MATH_ELU, 2) 65 | LITE_NL_ENTRY(102, relu_thresholded, AI_MATH_RELU_THRESHOLDED, 2) 66 | 67 | 68 | LITE_NL_ENTRY(201, clip, AI_CLAMP, 3) 69 | LITE_NL_ENTRY(202, hard_sigmoid, AI_MATH_HARD_SIGMOID, 3) 70 | LITE_NL_ENTRY(203, selu, AI_MATH_SELU, 3) 71 | 72 | 73 | #undef LITE_NL_ENTRY 74 | #undef LITE_NL_IIF_0 75 | #undef LITE_NL_IIF_1 76 | #undef LITE_NL_IIF_2 77 | #undef LITE_NL_IIF_3 78 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_operators.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_OPERATORS_H 2 | #define LITE_OPERATORS_H 3 | #pragma once 4 | 5 | #include "lite_bn_f32.h" 6 | #include "lite_bn_integer.h" 7 | #include "lite_conv2d.h" 8 | #include "lite_conv2d_dqnn.h" 9 | #include "lite_convert_dqnn.h" 10 | #include "lite_dense_if32.h" 11 | #include "lite_dense_is1.h" 12 | #include "lite_dense_is1ws1.h" 13 | #include "lite_dense_ws1.h" 14 | #include "lite_gru_f32.h" 15 | #include "lite_dw_dqnn.h" 16 | #include "lite_pw_dqnn.h" 17 | 18 | #include "lite_dense_is8os8ws8.h" 19 | #include "lite_generic_float.h" 20 | #include "lite_pool_f32.h" 21 | #include "lite_maxpool_dqnn.h" 22 | #include "lite_nl_generic_float.h" 23 | #include "lite_nl_generic_integer.h" 24 | #include "lite_pad_generic.h" 25 | #include "lite_pad_dqnn.h" 26 | #include "lite_upsample_generic.h" 27 | 28 | #endif /* LITE_OPERATORS_H */ 29 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_pad_dqnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_pad_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform lite padding kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_PADDING_DQNN_H 22 | #define LITE_PADDING_DQNN_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | /******************************************************************************/ 28 | /* Forward Functions Section */ 29 | /******************************************************************************/ 30 | 31 | /*! 32 | * @brief Handles padding with binary input and binary output - Lite I/F 33 | * @ingroup lite_padding_dqnn 34 | */ 35 | LITE_API_ENTRY 36 | void forward_lite_pad_is1os1(const ai_u32 *pDataIn_init, 37 | ai_u32 *pDataOut_init, 38 | const ai_i32 width_in, 39 | const ai_i32 width_out, 40 | const ai_i32 height_in, 41 | const ai_i32 height_out, 42 | const ai_u32 n_channel_out, 43 | const ai_i32 mode, 44 | const ai_u16 pads_x, 45 | const ai_u16 pads_y, 46 | const ai_u16 pads_x_r, 47 | const ai_u16 pads_y_b, 48 | const ai_u32 pad_value); 49 | 50 | 51 | #endif /*LITE_PADDING_DQNN_H*/ 52 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_pad_generic.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_pad_generic.h 4 | * @author AIS 5 | * @brief header file of AI platform lite padding kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_PADDING_DQNN_H 22 | #define LITE_PADDING_DQNN_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | /******************************************************************************/ 28 | /* Forward Functions Section */ 29 | /******************************************************************************/ 30 | 31 | /*! 32 | * @brief Handles padding with 8 bits input/output in constant mode - Lite I/F 33 | * Channel 1st Format Input and Output 34 | * @ingroup lite_padding_dqnn 35 | */ 36 | LITE_API_ENTRY 37 | 38 | void forward_lite_pad_8bit_ch1st_3x3_constant(ai_ptr_const in_data_tensor, 39 | ai_ptr out_data_tensor, 40 | const ai_handle fill_value, 41 | const ai_i32 height_in, 42 | const ai_i32 channel_in, 43 | const ai_ptr_offset ch_stride_in, 44 | const ai_ptr_offset h_stride_in, 45 | const ai_ptr_offset h_stride_pad); 46 | 47 | /*! 48 | * @brief Handles padding with 8 bits input/output in constant mode - Lite I/F 49 | * @ingroup lite_padding_dqnn 50 | */ 51 | LITE_API_ENTRY 52 | void forward_lite_pad_constant(ai_ptr_const in_data, 53 | ai_ptr out_data, 54 | const ai_handle fill_value, 55 | const ai_i16 in_bits, 56 | const ai_i32 height_in, 57 | const ai_ptr_offset ch_stride_in, 58 | const ai_ptr_offset h_stride_in, 59 | const ai_ptr_offset h_stride_pad, 60 | const ai_ptr_offset h_stride_pad_b, 61 | const ai_ptr_offset w_stride_pad, 62 | const ai_ptr_offset w_stride_pad_r); 63 | 64 | /*! 65 | * @brief Handles padding with 8 bits input/output in edge mode - Lite I/F 66 | * @ingroup lite_padding_dqnn 67 | */ 68 | void forward_lite_pad_edge(ai_ptr_const in_data_tensor, 69 | ai_ptr out_data, 70 | const ai_i32 height_in, 71 | const ai_i16 pads_y, 72 | const ai_i16 pads_x_r, 73 | const ai_ptr_offset h_stride_in, 74 | const ai_ptr_offset w_stride_in, 75 | const ai_ptr_offset h_stride_out, 76 | const ai_ptr_offset h_stride_pad, 77 | const ai_ptr_offset w_stride_pad, 78 | const ai_ptr_offset h_stride_pad_b); 79 | 80 | /*! 81 | * @brief Handles padding with 8 bits input/output in reflect mode - Lite I/F 82 | * @ingroup lite_padding_dqnn 83 | */ 84 | void forward_lite_pad_reflect(ai_ptr_const in_data, 85 | ai_ptr out_data, 86 | const ai_i32 depth, 87 | const ai_i32 height_in, 88 | const ai_i32 width_in, 89 | const ai_i32 height_out, 90 | const ai_i32 width_out, 91 | const ai_ptr_offset h_stride_in, 92 | const ai_ptr_offset w_stride_in, 93 | const ai_ptr_offset h_stride_out, 94 | const ai_ptr_offset w_stride_out, 95 | const ai_i16 pads_x, 96 | const ai_i16 pads_y, 97 | const ai_i16 pads_y_b, 98 | const ai_ptr_offset h_stride_pad, 99 | const ai_ptr_offset w_stride_pad, 100 | const ai_ptr_offset w_stride_pad_r); 101 | 102 | #endif /*LITE_PADDING_GENERIC_H*/ 103 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_pool_f32.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_maxpool_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform lite maxpool kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_POOL_F32_H 22 | #define LITE_POOL_F32_H 23 | 24 | #include "ai_lite_interface.h" 25 | 26 | 27 | #define FUNC_POOL(handle) \ 28 | ((func_pool)(handle)) 29 | 30 | 31 | /*! 32 | * @typedef (*func_pool) 33 | * @ingroup layers_pool 34 | * @brief Fuction pointer for generic pooling transform 35 | * this function pointer abstracts a generic pooling layer. 36 | * see @ref pool_func_ap_array_f32 as examples 37 | */ 38 | typedef void (*func_pool)(ai_float* in, 39 | const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, 40 | const ai_u16 ch_im_in, 41 | const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, 42 | const ai_u16 padding_x, const ai_u16 padding_y, 43 | const ai_u16 stride_x, const ai_u16 stride_y, 44 | const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, 45 | ai_float* out); 46 | 47 | 48 | /******************************************************************************/ 49 | /** Conv2d Functions Section **/ 50 | /******************************************************************************/ 51 | 52 | AI_INTERNAL_API 53 | void pool_func_mp_array_f32(ai_float* pData_in, 54 | const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, 55 | const ai_u16 ch_im_in, 56 | const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, 57 | const ai_u16 padding_x, const ai_u16 padding_y, 58 | const ai_u16 stride_x, const ai_u16 stride_y, 59 | const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, 60 | ai_float* pData_out); 61 | 62 | AI_INTERNAL_API 63 | void pool_func_ap_array_f32(ai_float *pData_in, 64 | const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, 65 | const ai_u16 ch_im_in, 66 | const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, 67 | const ai_u16 padding_x, const ai_u16 padding_y, 68 | const ai_u16 stride_x, const ai_u16 stride_y, 69 | const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, 70 | ai_float *pData_out); 71 | 72 | #endif // LITE_POOL_F32_H_ 73 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_pw.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_pw.h 4 | * @author AIS 5 | * @brief header file of AI platform lite pw kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_PW_H 22 | #define LITE_PW_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | 28 | 29 | /******************************************************************************/ 30 | /* Forward Functions Section */ 31 | /******************************************************************************/ 32 | 33 | /*! 34 | * @brief Handles pw convolutions generic case 35 | * @ingroup lite_pw 36 | */ 37 | LITE_API_ENTRY 38 | void 39 | forward_lite_pw_sssa8_ch(const ai_i8 *pData_in, 40 | const ai_u16 width_in, 41 | const ai_u16 height_in, 42 | const ai_u16 n_channel_in, 43 | const ai_i8 *pWeights, 44 | const ai_u16 n_channel_out, 45 | const ai_i32 *pBias, 46 | const ai_i8 in_zeropoint, 47 | const ai_i8 out_zeropoint, 48 | const ai_layer_format_type out_ch_format, 49 | ai_i8 *pData_out, 50 | ai_u32 height_loop_cnt, 51 | ai_u16 weights_prefetch_enabled, 52 | ai_i32 scratch_size, 53 | ai_i16 *pBuffer_a); 54 | 55 | #endif /*LITE_PW_H*/ 56 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_pw_dqnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_pw_dqnn.h 4 | * @author AIS 5 | * @brief header file of AI platform lite pw kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_PW_DQNN_H 22 | #define LITE_PW_DQNN_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | 28 | /******************************************************************************/ 29 | /* Forward Functions Section */ 30 | /******************************************************************************/ 31 | 32 | /*! 33 | * @brief Handles point wise convolution with binary input, binary output and 34 | * binary weights - Lite API version 35 | * @ingroup lite_pw_dqnn 36 | */ 37 | LITE_API_ENTRY 38 | void forward_lite_pw_is1os1ws1_bn(const ai_u32 *pDataIn_init, 39 | ai_u32 *pDataOut_init, 40 | const ai_u32 *pWeights_init, 41 | const ai_u32 n_channel_in, 42 | const ai_u32 n_channel_out, 43 | const ai_i32 width_out, 44 | const ai_i32 height_out, 45 | const ai_i32 *pThreshold); 46 | 47 | /*! 48 | * @brief Handles point wise convolution with binary input, binary output and 49 | * binary weights - Lite API version - Optimized thanks to Optim2 50 | * assumptions 51 | * @ingroup lite_pw_dqnn 52 | */ 53 | LITE_API_ENTRY 54 | void forward_lite_pw_is1os1ws1_bn_optim2(const ai_u32 *pDataIn_init, 55 | ai_u32 *pDataOut_init, 56 | const ai_u32 *pWeights_init, 57 | const ai_u32 n_channel_in, 58 | const ai_u32 n_channel_out, 59 | const ai_i32 width_out, 60 | const ai_i32 height_out, 61 | const ai_i32 *pThreshold); 62 | 63 | /*! 64 | * @brief Handles point wise convolution with binary input, 8-bits output and 65 | * binary weights - Lite API version 66 | * @ingroup lite_pw_dqnn 67 | */ 68 | LITE_API_ENTRY 69 | void forward_lite_pw_is1os8ws1_bn(const ai_u32 *pDataIn_init, 70 | ai_i8 *pDataOut_init, 71 | const ai_u32 *pWeights_init, 72 | const ai_u32 n_channel_in, 73 | const ai_u32 n_channel_out, 74 | const ai_i32 width_out, 75 | const ai_i32 height_out, 76 | const ai_float *pScale, 77 | const ai_float *pOffset); 78 | 79 | /*! 80 | * @brief Handles point wise convolution with binary input, 8-bits output and 81 | * binary weights - Lite API version - Optimized thanks to Optim1 82 | * assumptions 83 | * @ingroup lite_pw_dqnn 84 | */ 85 | LITE_API_ENTRY 86 | void forward_lite_pw_is1os8ws1_bn_optim1(const ai_u32 *pDataIn_init, 87 | ai_i8 *pDataOut_init, 88 | const ai_u32 *pWeights_init, 89 | const ai_u32 n_channel_in, 90 | const ai_u32 n_channel_out, 91 | const ai_i32 width_out, 92 | const ai_i32 height_out, 93 | const ai_float *pScale, 94 | const ai_float *pOffset); 95 | 96 | /*! 97 | * @brief Handles point-wise convolution with binary input, float32 output 98 | * and binary weights - Lite API version 99 | * @ingroup lite_pw_dqnn 100 | */ 101 | LITE_API_ENTRY 102 | void forward_lite_pw_is1of32ws1_bn(const ai_u32 *pDataIn_init, 103 | ai_float *pDataOut_init, 104 | const ai_u32 *pWeights_init, 105 | const ai_u32 n_channel_in, 106 | const ai_u32 n_channel_out, 107 | const ai_i32 width_out, 108 | const ai_i32 height_out, 109 | const ai_float *pScale, 110 | const ai_float *pOffset); 111 | 112 | /*! 113 | * @brief Handles point-wise convolution with binary input, float32 output 114 | * and binary weights - Lite API version - Optimized thanks to Optim1 115 | * assumptions 116 | * @ingroup lite_pw_dqnn 117 | */ 118 | LITE_API_ENTRY 119 | void forward_lite_pw_is1of32ws1_bn_optim1(const ai_u32 *pDataIn_init, 120 | ai_float *pDataOut_init, 121 | const ai_u32 *pWeights_init, 122 | const ai_u32 n_channel_in, 123 | const ai_u32 n_channel_out, 124 | const ai_i32 width_out, 125 | const ai_i32 height_out, 126 | const ai_float *pScale, 127 | const ai_float *pOffset); 128 | 129 | 130 | #endif /*LITE_PW_DQNN_H*/ 131 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_upsample.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_upsample.h 4 | * @author AIS 5 | * @brief header file of AI platform lite pw kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_UPSAMPLE_H 22 | #define LITE_UPSAMPLE_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | 28 | void forward_lite_upsample_bilinear_if32of32(const ai_float* in_data, 29 | ai_float* out_data, 30 | const ai_size width_in, 31 | const ai_size height_in, 32 | const ai_float width_scale, 33 | const ai_float height_scale, 34 | const ai_size width_out, 35 | const ai_size height_out, 36 | const ai_bool center, 37 | const ai_size n_channel); 38 | void forward_lite_upsample_bilinear_is8os8(const ai_i8* in_data, 39 | ai_i8* out_data, 40 | const ai_size width_in, 41 | const ai_size height_in, 42 | const ai_float width_scale, 43 | const ai_float height_scale, 44 | const ai_size width_out, 45 | const ai_size height_out, 46 | const ai_bool center, 47 | const ai_size n_channel); 48 | void forward_lite_upsample_bilinear_iu8ou8(const ai_u8* in_data, 49 | ai_u8* out_data, 50 | const ai_size width_in, 51 | const ai_size height_in, 52 | const ai_float width_scale, 53 | const ai_float height_scale, 54 | const ai_size width_out, 55 | const ai_size height_out, 56 | const ai_bool center, 57 | const ai_size n_channel); 58 | void forward_lite_upsample_bilinear_is16os16(const ai_i16* in_data, 59 | ai_i16* out_data, 60 | const ai_size width_in, 61 | const ai_size height_in, 62 | const ai_float width_scale, 63 | const ai_float height_scale, 64 | const ai_size width_out, 65 | const ai_size height_out, 66 | const ai_bool center, 67 | const ai_size n_channel); 68 | void forward_lite_upsample_bilinear_iu16ou16(const ai_u16* in_data, 69 | ai_u16* out_data, 70 | const ai_size width_in, 71 | const ai_size height_in, 72 | const ai_float width_scale, 73 | const ai_float height_scale, 74 | const ai_size width_out, 75 | const ai_size height_out, 76 | const ai_bool center, 77 | const ai_size n_channel); 78 | 79 | 80 | #endif /*LITE_UPSAMPLE__H*/ 81 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Inc/lite_upsample_generic.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lite_upsample.h 4 | * @author AIS 5 | * @brief header file of AI platform lite pw kernel datatypes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | @verbatim 18 | @endverbatim 19 | ****************************************************************************** 20 | */ 21 | #ifndef LITE_UPSAMPLE_GENERIC_H 22 | #define LITE_UPSAMPLE_GENERIC_H 23 | #pragma once 24 | 25 | #include "ai_lite_interface.h" 26 | 27 | 28 | void forward_lite_upsample_generic_nearest(const ai_u8* in_data, 29 | ai_u8* out_data, 30 | const ai_size width_in, 31 | const ai_size width_out, 32 | const ai_float width_scale, 33 | const ai_size height_out, 34 | const ai_float height_scale, 35 | const ai_u32 output_tensor_w_stride, 36 | const ai_float offset_round_coeff); 37 | 38 | void forward_lite_upsample_nearest(ai_ptr in_data, 39 | ai_ptr out_data, 40 | const ai_size width_in, 41 | const ai_float width_scale, 42 | const ai_float height_scale, 43 | const ai_size width_out, 44 | const ai_size height_out, 45 | const ai_ptr_offset stride_w, 46 | const ai_float offset_round_coeff); 47 | 48 | void forward_lite_upsample_zeros( ai_ptr in_data, 49 | ai_ptr out_data, 50 | const ai_size width_in, 51 | const ai_size height_in, 52 | const ai_float width_scale, 53 | const ai_float height_scale, 54 | const ai_size width_out, 55 | const ai_size height_out, 56 | const ai_ptr_offset stride_ch, 57 | const ai_ptr_offset stride_w, 58 | const ai_handle p_zero_value); 59 | 60 | #endif /*LITE_UPSAMPLE_GENERIC_H*/ 61 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software component is provided to you as part of a software package and 2 | applicable license terms are in the Package_license file. If you received this 3 | software component outside of a package or without applicable license terms, 4 | the terms of the SLA0044 license shall apply and are fully reproduced below: 5 | 6 | SLA0044 Rev5/February 2018 7 | 8 | Software license agreement 9 | 10 | ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT 11 | 12 | BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE 13 | OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS 14 | INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES 15 | (STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON 16 | BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES 17 | TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. 18 | 19 | Under STMicroelectronics’ intellectual property rights, the redistribution, 20 | reproduction and use in source and binary forms of the software or any part 21 | thereof, with or without modification, are permitted provided that the following 22 | conditions are met: 23 | 24 | 1. Redistribution of source code (modified or not) must retain any copyright 25 | notice, this list of conditions and the disclaimer set forth below as items 10 26 | and 11. 27 | 28 | 2. Redistributions in binary form, except as embedded into microcontroller or 29 | microprocessor device manufactured by or for STMicroelectronics or a software 30 | update for such device, must reproduce any copyright notice provided with the 31 | binary code, this list of conditions, and the disclaimer set forth below as 32 | items 10 and 11, in documentation and/or other materials provided with the 33 | distribution. 34 | 35 | 3. Neither the name of STMicroelectronics nor the names of other contributors to 36 | this software may be used to endorse or promote products derived from this 37 | software or part thereof without specific written permission. 38 | 39 | 4. This software or any part thereof, including modifications and/or derivative 40 | works of this software, must be used and execute solely and exclusively on or in 41 | combination with a microcontroller or microprocessor device manufactured by or 42 | for STMicroelectronics. 43 | 44 | 5. No use, reproduction or redistribution of this software partially or totally 45 | may be done in any manner that would subject this software to any Open Source 46 | Terms. “Open Source Terms” shall mean any open source license which requires as 47 | part of distribution of software that the source code of such software is 48 | distributed therewith or otherwise made available, or open source license that 49 | substantially complies with the Open Source definition specified at 50 | www.opensource.org and any other comparable open source license such as for 51 | example GNU General Public License (GPL), Eclipse Public License (EPL), Apache 52 | Software License, BSD license or MIT license. 53 | 54 | 6. STMicroelectronics has no obligation to provide any maintenance, support or 55 | updates for the software. 56 | 57 | 7. The software is and will remain the exclusive property of STMicroelectronics 58 | and its licensors. The recipient will not take any action that jeopardizes 59 | STMicroelectronics and its licensors' proprietary rights or acquire any rights 60 | in the software, except the limited rights specified hereunder. 61 | 62 | 8. The recipient shall comply with all applicable laws and regulations affecting 63 | the use of the software or any part thereof including any applicable export 64 | control law or regulation. 65 | 66 | 9. Redistribution and use of this software or any part thereof other than as 67 | permitted under this license is void and will automatically terminate your 68 | rights under this license. 69 | 70 | 10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND 71 | ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 72 | IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 73 | NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE 74 | DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL 75 | STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 76 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 77 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 78 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 79 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 80 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 81 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 82 | 83 | 11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER 84 | EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY 85 | RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. 86 | 87 | -------------------------------------------------------------------------------- /Middlewares/ST/AI/Lib/NetworkRuntime810_CM0+_GCC.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/colin2135/STM32G070_AI_TEST/0e71fc4834e9c1aec1badc0ecc35bb8d572008b9/Middlewares/ST/AI/Lib/NetworkRuntime810_CM0+_GCC.a -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Copy the Drivers Files from STM32Cube_FW_G0_V1.6.2 and compile. 2 | 3 | 把STM32Cube_FW_G0_V1.6.2里的Drivers目录考到这个文件夹编译就可以了。 -------------------------------------------------------------------------------- /STM32G070RBTX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32G070RBTx Device from STM32G0 series 9 | ** 128Kbytes FLASH 10 | ** 36Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is, without any warranty 20 | ** of any kind. 21 | ** 22 | ****************************************************************************** 23 | ** @attention 24 | ** 25 | ** Copyright (c) 2023 STMicroelectronics. 26 | ** All rights reserved. 27 | ** 28 | ** This software is licensed under terms that can be found in the LICENSE file 29 | ** in the root directory of this software component. 30 | ** If no LICENSE file comes with this software, it is provided AS-IS. 31 | ** 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Entry Point */ 36 | ENTRY(Reset_Handler) 37 | 38 | /* Highest address of the user mode stack */ 39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 40 | 41 | _Min_Heap_Size = 0x800 ; /* required amount of heap */ 42 | _Min_Stack_Size = 0x800 ; /* required amount of stack */ 43 | 44 | /* Memories definition */ 45 | MEMORY 46 | { 47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 36K 48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K 49 | } 50 | 51 | /* Sections */ 52 | SECTIONS 53 | { 54 | /* The startup code into "FLASH" Rom type memory */ 55 | .isr_vector : 56 | { 57 | . = ALIGN(4); 58 | KEEP(*(.isr_vector)) /* Startup code */ 59 | . = ALIGN(4); 60 | } >FLASH 61 | 62 | /* The program code and other data into "FLASH" Rom type memory */ 63 | .text : 64 | { 65 | . = ALIGN(4); 66 | *(.text) /* .text sections (code) */ 67 | *(.text*) /* .text* sections (code) */ 68 | *(.glue_7) /* glue arm to thumb code */ 69 | *(.glue_7t) /* glue thumb to arm code */ 70 | *(.eh_frame) 71 | 72 | KEEP (*(.init)) 73 | KEEP (*(.fini)) 74 | 75 | . = ALIGN(4); 76 | _etext = .; /* define a global symbols at end of code */ 77 | } >FLASH 78 | 79 | /* Constant data into "FLASH" Rom type memory */ 80 | .rodata : 81 | { 82 | . = ALIGN(4); 83 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 84 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 85 | . = ALIGN(4); 86 | } >FLASH 87 | 88 | .ARM.extab : { 89 | . = ALIGN(4); 90 | *(.ARM.extab* .gnu.linkonce.armextab.*) 91 | . = ALIGN(4); 92 | } >FLASH 93 | 94 | .ARM : { 95 | . = ALIGN(4); 96 | __exidx_start = .; 97 | *(.ARM.exidx*) 98 | __exidx_end = .; 99 | . = ALIGN(4); 100 | } >FLASH 101 | 102 | .preinit_array : 103 | { 104 | . = ALIGN(4); 105 | PROVIDE_HIDDEN (__preinit_array_start = .); 106 | KEEP (*(.preinit_array*)) 107 | PROVIDE_HIDDEN (__preinit_array_end = .); 108 | . = ALIGN(4); 109 | } >FLASH 110 | 111 | .init_array : 112 | { 113 | . = ALIGN(4); 114 | PROVIDE_HIDDEN (__init_array_start = .); 115 | KEEP (*(SORT(.init_array.*))) 116 | KEEP (*(.init_array*)) 117 | PROVIDE_HIDDEN (__init_array_end = .); 118 | . = ALIGN(4); 119 | } >FLASH 120 | 121 | .fini_array : 122 | { 123 | . = ALIGN(4); 124 | PROVIDE_HIDDEN (__fini_array_start = .); 125 | KEEP (*(SORT(.fini_array.*))) 126 | KEEP (*(.fini_array*)) 127 | PROVIDE_HIDDEN (__fini_array_end = .); 128 | . = ALIGN(4); 129 | } >FLASH 130 | 131 | /* Used by the startup to initialize data */ 132 | _sidata = LOADADDR(.data); 133 | 134 | /* Initialized data sections into "RAM" Ram type memory */ 135 | .data : 136 | { 137 | . = ALIGN(4); 138 | _sdata = .; /* create a global symbol at data start */ 139 | *(.data) /* .data sections */ 140 | *(.data*) /* .data* sections */ 141 | *(.RamFunc) /* .RamFunc sections */ 142 | *(.RamFunc*) /* .RamFunc* sections */ 143 | 144 | . = ALIGN(4); 145 | _edata = .; /* define a global symbol at data end */ 146 | 147 | } >RAM AT> FLASH 148 | 149 | /* Uninitialized data section into "RAM" Ram type memory */ 150 | . = ALIGN(4); 151 | .bss : 152 | { 153 | /* This is used by the startup in order to initialize the .bss section */ 154 | _sbss = .; /* define a global symbol at bss start */ 155 | __bss_start__ = _sbss; 156 | *(.bss) 157 | *(.bss*) 158 | *(COMMON) 159 | 160 | . = ALIGN(4); 161 | _ebss = .; /* define a global symbol at bss end */ 162 | __bss_end__ = _ebss; 163 | } >RAM 164 | 165 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 166 | ._user_heap_stack : 167 | { 168 | . = ALIGN(8); 169 | PROVIDE ( end = . ); 170 | PROVIDE ( _end = . ); 171 | . = . + _Min_Heap_Size; 172 | . = . + _Min_Stack_Size; 173 | . = ALIGN(8); 174 | } >RAM 175 | 176 | /* Remove information from the compiler libraries */ 177 | /DISCARD/ : 178 | { 179 | libc.a ( * ) 180 | libm.a ( * ) 181 | libgcc.a ( * ) 182 | } 183 | 184 | .ARM.attributes 0 : { *(.ARM.attributes) } 185 | } 186 | -------------------------------------------------------------------------------- /X-CUBE-AI/App/network_config.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | * @file network_config.h 5 | * @author AST Embedded Analytics Research Platform 6 | * @date Wed Dec 27 14:47:37 2023 7 | * @brief AI Tool Automatic Code Generator for Custom Layers Implementation 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * Copyright (c) 2023 STMicroelectronics. 12 | * All rights reserved. 13 | * 14 | * This software is licensed under terms that can be found in the LICENSE file 15 | * in the root directory of this software component. 16 | * If no LICENSE file comes with this software, it is provided AS-IS. 17 | ****************************************************************************** 18 | */ 19 | 20 | #ifndef AI_NETWORK_CONFIG_H 21 | #define AI_NETWORK_CONFIG_H 22 | #pragma once 23 | 24 | #undef AI_TOOLS_VERSION_MAJOR 25 | #undef AI_TOOLS_VERSION_MINOR 26 | #undef AI_TOOLS_VERSION_MICRO 27 | #define AI_TOOLS_VERSION_MAJOR 8 28 | #define AI_TOOLS_VERSION_MINOR 1 29 | #define AI_TOOLS_VERSION_MICRO 0 30 | #define AI_TOOLS_VERSION_EXTRA "19520" 31 | 32 | 33 | #undef AI_PLATFORM_API_MAJOR 34 | #undef AI_PLATFORM_API_MINOR 35 | #undef AI_PLATFORM_API_MICRO 36 | #define AI_PLATFORM_API_MAJOR (1) 37 | #define AI_PLATFORM_API_MINOR (1) 38 | #define AI_PLATFORM_API_MICRO (0) 39 | 40 | #undef AI_TOOLS_API_VERSION_MAJOR 41 | #undef AI_TOOLS_API_VERSION_MINOR 42 | #undef AI_TOOLS_API_VERSION_MICRO 43 | #define AI_TOOLS_API_VERSION_MAJOR (1) 44 | #define AI_TOOLS_API_VERSION_MINOR (5) 45 | #define AI_TOOLS_API_VERSION_MICRO (0) 46 | 47 | #endif /*AI_NETWORK_CONFIG_H*/ 48 | -------------------------------------------------------------------------------- /X-CUBE-AI/App/network_data.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file network_data.c 4 | * @author AST Embedded Analytics Research Platform 5 | * @date Wed Dec 27 14:47:37 2023 6 | * @brief AI Tool Automatic Code Generator for Embedded NN computing 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2023 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | ****************************************************************************** 17 | */ 18 | #include "network_data.h" 19 | #include "ai_platform_interface.h" 20 | 21 | AI_API_DECLARE_BEGIN 22 | ai_buffer g_network_data_map_activations[AI_NETWORK_DATA_ACTIVATIONS_COUNT] = { 23 | AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8, 24 | AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 5936, 1, 1), 25 | 5936, NULL, NULL), /* heap_overlay_pool */ 26 | }; 27 | ai_buffer g_network_data_map_weights[AI_NETWORK_DATA_WEIGHTS_COUNT] = { 28 | AI_BUFFER_INIT(AI_FLAG_NONE, AI_BUFFER_FORMAT_U8, 29 | AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, 38360, 1, 1), 30 | 38360, NULL, s_network_weights_array_u64), /* weights_array */ 31 | }; 32 | 33 | 34 | /*! 35 | * @brief Get network activations buffer initialized struct. 36 | * @ingroup network_data 37 | * @param[in] ptr a pointer to the activations array storage area 38 | * @return an ai_buffer initialized struct 39 | */ 40 | AI_DEPRECATED 41 | AI_API_ENTRY 42 | ai_buffer ai_network_data_activations_buffer_get(const ai_handle ptr) 43 | { 44 | ai_buffer buf = AI_BUFFER_INIT( 45 | AI_FLAG_NONE, AI_BUFFER_FORMAT_U8, 46 | AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, AI_NETWORK_DATA_ACTIVATIONS_SIZE, 1, AI_NETWORK_DATA_ACTIVATIONS_COUNT), 47 | AI_NETWORK_DATA_ACTIVATIONS_SIZE, 48 | NULL, ptr); 49 | return buf; 50 | } 51 | 52 | /*! 53 | * @brief Get network weights buffer initialized struct. 54 | * @ingroup network_data 55 | * @param[in] ptr a pointer to the weights array storage area 56 | * @return an ai_buffer initialized struct 57 | */ 58 | AI_DEPRECATED 59 | AI_API_ENTRY 60 | ai_buffer ai_network_data_weights_buffer_get(const ai_handle ptr) 61 | { 62 | ai_buffer buf = AI_BUFFER_INIT( 63 | AI_FLAG_NONE, AI_BUFFER_FORMAT_U8|AI_BUFFER_FMT_FLAG_CONST, 64 | AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, 1, AI_NETWORK_DATA_WEIGHTS_SIZE, 1, AI_NETWORK_DATA_WEIGHTS_COUNT), 65 | AI_NETWORK_DATA_WEIGHTS_SIZE, 66 | NULL, ptr); 67 | return buf; 68 | } 69 | 70 | 71 | /*! 72 | * @brief Get network weights array pointer as a handle ptr. 73 | * @ingroup network_data 74 | * @return a ai_handle pointer to the weights array 75 | */ 76 | AI_DEPRECATED 77 | AI_API_ENTRY 78 | ai_handle ai_network_data_weights_get(void) 79 | { 80 | return AI_HANDLE_PTR(g_network_weights_table); 81 | 82 | } 83 | 84 | 85 | /*! 86 | * @brief Get network params configuration data structure. 87 | * @ingroup network_data 88 | * @return true if a valid configuration is present, false otherwise 89 | */ 90 | AI_API_ENTRY 91 | ai_bool ai_network_data_params_get(ai_network_params* params) 92 | { 93 | if (!params) return false; 94 | 95 | const ai_buffer_array map_activations = 96 | AI_BUFFER_ARRAY_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_DATA_ACTIVATIONS_COUNT, g_network_data_map_activations); 97 | 98 | const ai_buffer_array map_weights = 99 | AI_BUFFER_ARRAY_OBJ_INIT(AI_FLAG_NONE, AI_NETWORK_DATA_WEIGHTS_COUNT, g_network_data_map_weights); 100 | 101 | return ai_platform_bind_network_params(params, &map_weights, &map_activations); 102 | } 103 | 104 | 105 | AI_API_DECLARE_END 106 | -------------------------------------------------------------------------------- /X-CUBE-AI/App/network_data.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file network_data.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date Wed Dec 27 14:47:37 2023 6 | * @brief AI Tool Automatic Code Generator for Embedded NN computing 7 | ****************************************************************************** 8 | * Copyright (c) 2023 STMicroelectronics. 9 | * All rights reserved. 10 | * 11 | * This software is licensed under terms that can be found in the LICENSE file 12 | * in the root directory of this software component. 13 | * If no LICENSE file comes with this software, it is provided AS-IS. 14 | ****************************************************************************** 15 | */ 16 | 17 | #ifndef NETWORK_DATA_H 18 | #define NETWORK_DATA_H 19 | #pragma once 20 | 21 | #include "network_config.h" 22 | #include "network_data_params.h" 23 | 24 | AI_DEPRECATED 25 | #define AI_NETWORK_DATA_ACTIVATIONS(ptr_) \ 26 | ai_network_data_activations_buffer_get(AI_HANDLE_PTR(ptr_)) 27 | 28 | AI_DEPRECATED 29 | #define AI_NETWORK_DATA_WEIGHTS(ptr_) \ 30 | ai_network_data_weights_buffer_get(AI_HANDLE_PTR(ptr_)) 31 | 32 | 33 | AI_API_DECLARE_BEGIN 34 | 35 | 36 | extern const ai_u64 s_network_weights_array_u64[4795]; 37 | 38 | 39 | 40 | /*! 41 | * @brief Get network activations buffer initialized struct. 42 | * @ingroup network_data 43 | * @param[in] ptr a pointer to the activations array storage area 44 | * @return an ai_buffer initialized struct 45 | */ 46 | AI_DEPRECATED 47 | AI_API_ENTRY 48 | ai_buffer ai_network_data_activations_buffer_get(const ai_handle ptr); 49 | 50 | /*! 51 | * @brief Get network weights buffer initialized struct. 52 | * @ingroup network_data 53 | * @param[in] ptr a pointer to the weights array storage area 54 | * @return an ai_buffer initialized struct 55 | */ 56 | AI_DEPRECATED 57 | AI_API_ENTRY 58 | ai_buffer ai_network_data_weights_buffer_get(const ai_handle ptr); 59 | 60 | /*! 61 | * @brief Get network weights array pointer as a handle ptr. 62 | * @ingroup network_data 63 | * @return a ai_handle pointer to the weights array 64 | */ 65 | AI_DEPRECATED 66 | AI_API_ENTRY 67 | ai_handle ai_network_data_weights_get(void); 68 | 69 | 70 | /*! 71 | * @brief Get network params configuration data structure. 72 | * @ingroup network_data 73 | * @return true if a valid configuration is present, false otherwise 74 | */ 75 | AI_API_ENTRY 76 | ai_bool ai_network_data_params_get(ai_network_params* params); 77 | 78 | 79 | AI_API_DECLARE_END 80 | 81 | #endif /* NETWORK_DATA_H */ 82 | 83 | -------------------------------------------------------------------------------- /X-CUBE-AI/App/network_data_params.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file network_data_params.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date Wed Dec 27 14:47:37 2023 6 | * @brief AI Tool Automatic Code Generator for Embedded NN computing 7 | ****************************************************************************** 8 | * Copyright (c) 2023 STMicroelectronics. 9 | * All rights reserved. 10 | * 11 | * This software is licensed under terms that can be found in the LICENSE file 12 | * in the root directory of this software component. 13 | * If no LICENSE file comes with this software, it is provided AS-IS. 14 | ****************************************************************************** 15 | */ 16 | 17 | #ifndef NETWORK_DATA_PARAMS_H 18 | #define NETWORK_DATA_PARAMS_H 19 | #pragma once 20 | 21 | #include "ai_platform.h" 22 | 23 | /* 24 | #define AI_NETWORK_DATA_WEIGHTS_PARAMS \ 25 | (AI_HANDLE_PTR(&ai_network_data_weights_params[1])) 26 | */ 27 | 28 | #define AI_NETWORK_DATA_CONFIG (NULL) 29 | 30 | 31 | #define AI_NETWORK_DATA_ACTIVATIONS_SIZES \ 32 | { 5936, } 33 | #define AI_NETWORK_DATA_ACTIVATIONS_SIZE (5936) 34 | #define AI_NETWORK_DATA_ACTIVATIONS_COUNT (1) 35 | #define AI_NETWORK_DATA_ACTIVATION_1_SIZE (5936) 36 | 37 | 38 | 39 | #define AI_NETWORK_DATA_WEIGHTS_SIZES \ 40 | { 38360, } 41 | #define AI_NETWORK_DATA_WEIGHTS_SIZE (38360) 42 | #define AI_NETWORK_DATA_WEIGHTS_COUNT (1) 43 | #define AI_NETWORK_DATA_WEIGHT_1_SIZE (38360) 44 | 45 | 46 | 47 | #define AI_NETWORK_DATA_ACTIVATIONS_TABLE_GET() \ 48 | (&g_network_activations_table[1]) 49 | 50 | extern ai_handle g_network_activations_table[1 + 2]; 51 | 52 | 53 | 54 | #define AI_NETWORK_DATA_WEIGHTS_TABLE_GET() \ 55 | (&g_network_weights_table[1]) 56 | 57 | extern ai_handle g_network_weights_table[1 + 2]; 58 | 59 | 60 | #endif /* NETWORK_DATA_PARAMS_H */ 61 | -------------------------------------------------------------------------------- /X-CUBE-AI/LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software component is provided to you as part of a software package and 2 | applicable license terms are in the Package_license file. If you received this 3 | software component outside of a package or without applicable license terms, 4 | the terms of the SLA0044 license shall apply and are fully reproduced below: 5 | 6 | SLA0044 Rev5/February 2018 7 | 8 | Software license agreement 9 | 10 | ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT 11 | 12 | BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE 13 | OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS 14 | INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES 15 | (STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON 16 | BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES 17 | TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. 18 | 19 | Under STMicroelectronics’ intellectual property rights, the redistribution, 20 | reproduction and use in source and binary forms of the software or any part 21 | thereof, with or without modification, are permitted provided that the following 22 | conditions are met: 23 | 24 | 1. Redistribution of source code (modified or not) must retain any copyright 25 | notice, this list of conditions and the disclaimer set forth below as items 10 26 | and 11. 27 | 28 | 2. Redistributions in binary form, except as embedded into microcontroller or 29 | microprocessor device manufactured by or for STMicroelectronics or a software 30 | update for such device, must reproduce any copyright notice provided with the 31 | binary code, this list of conditions, and the disclaimer set forth below as 32 | items 10 and 11, in documentation and/or other materials provided with the 33 | distribution. 34 | 35 | 3. Neither the name of STMicroelectronics nor the names of other contributors to 36 | this software may be used to endorse or promote products derived from this 37 | software or part thereof without specific written permission. 38 | 39 | 4. This software or any part thereof, including modifications and/or derivative 40 | works of this software, must be used and execute solely and exclusively on or in 41 | combination with a microcontroller or microprocessor device manufactured by or 42 | for STMicroelectronics. 43 | 44 | 5. No use, reproduction or redistribution of this software partially or totally 45 | may be done in any manner that would subject this software to any Open Source 46 | Terms. “Open Source Terms” shall mean any open source license which requires as 47 | part of distribution of software that the source code of such software is 48 | distributed therewith or otherwise made available, or open source license that 49 | substantially complies with the Open Source definition specified at 50 | www.opensource.org and any other comparable open source license such as for 51 | example GNU General Public License (GPL), Eclipse Public License (EPL), Apache 52 | Software License, BSD license or MIT license. 53 | 54 | 6. STMicroelectronics has no obligation to provide any maintenance, support or 55 | updates for the software. 56 | 57 | 7. The software is and will remain the exclusive property of STMicroelectronics 58 | and its licensors. The recipient will not take any action that jeopardizes 59 | STMicroelectronics and its licensors' proprietary rights or acquire any rights 60 | in the software, except the limited rights specified hereunder. 61 | 62 | 8. The recipient shall comply with all applicable laws and regulations affecting 63 | the use of the software or any part thereof including any applicable export 64 | control law or regulation. 65 | 66 | 9. Redistribution and use of this software or any part thereof other than as 67 | permitted under this license is void and will automatically terminate your 68 | rights under this license. 69 | 70 | 10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND 71 | ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 72 | IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 73 | NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE 74 | DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL 75 | STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 76 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 77 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 78 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 79 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 80 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 81 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 82 | 83 | 11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER 84 | EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY 85 | RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. 86 | 87 | -------------------------------------------------------------------------------- /trained_lstm.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/colin2135/STM32G070_AI_TEST/0e71fc4834e9c1aec1badc0ecc35bb8d572008b9/trained_lstm.tflite --------------------------------------------------------------------------------