Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
316
csky/csi_dsp/include/csi_common_tables.h
Normal file
316
csky/csi_dsp/include/csi_common_tables.h
Normal file
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csi_common_tables.h
|
||||
* @brief This file has extern declaration for common tables like
|
||||
* Bitreverse, reciprocal etc which are used across different functions.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSI_COMMON_TABLES_H
|
||||
#define _CSI_COMMON_TABLES_H
|
||||
|
||||
#include "csi_math.h"
|
||||
|
||||
extern const uint16_t csiBitRevTable[1024];
|
||||
extern const q15_t csiRecipTableQ15[64];
|
||||
extern const q31_t csiRecipTableQ31[64];
|
||||
extern const uint32_t twiddleCoef_16[32];
|
||||
extern const uint32_t twiddleCoef_32[64];
|
||||
extern const uint32_t twiddleCoef_64[128];
|
||||
extern const uint32_t twiddleCoef_128[256];
|
||||
extern const uint32_t twiddleCoef_256[512];
|
||||
extern const uint32_t twiddleCoef_512[1024];
|
||||
extern const uint32_t twiddleCoef_1024[2048];
|
||||
extern const uint32_t twiddleCoef_2048[4096];
|
||||
extern const uint32_t twiddleCoef_4096[8192];
|
||||
extern const q31_t twiddleCoef_16_q31[24];
|
||||
extern const q31_t twiddleCoef_32_q31[48];
|
||||
extern const q31_t twiddleCoef_64_q31[96];
|
||||
extern const q31_t twiddleCoef_128_q31[192];
|
||||
extern const q31_t twiddleCoef_256_q31[384];
|
||||
extern const q31_t twiddleCoef_512_q31[768];
|
||||
extern const q31_t twiddleCoef_1024_q31[1536];
|
||||
extern const q31_t twiddleCoef_2048_q31[3072];
|
||||
extern const q31_t twiddleCoef_4096_q31[6144];
|
||||
extern const q15_t twiddleCoef_16_q15[24];
|
||||
extern const q15_t twiddleCoef_32_q15[48];
|
||||
extern const q15_t twiddleCoef_64_q15[96];
|
||||
extern const q15_t twiddleCoef_128_q15[192];
|
||||
extern const q15_t twiddleCoef_256_q15[384];
|
||||
extern const q15_t twiddleCoef_512_q15[768];
|
||||
extern const q15_t twiddleCoef_1024_q15[1536];
|
||||
extern const q15_t twiddleCoef_2048_q15[3072];
|
||||
extern const q15_t twiddleCoef_4096_q15[6144];
|
||||
extern const float32_t twiddleCoef_rfft_32[32];
|
||||
extern const float32_t twiddleCoef_rfft_64[64];
|
||||
extern const float32_t twiddleCoef_rfft_128[128];
|
||||
extern const float32_t twiddleCoef_rfft_256[256];
|
||||
extern const float32_t twiddleCoef_rfft_512[512];
|
||||
extern const float32_t twiddleCoef_rfft_1024[1024];
|
||||
extern const float32_t twiddleCoef_rfft_2048[2048];
|
||||
extern const float32_t twiddleCoef_rfft_4096[4096];
|
||||
extern const float32_t twiddleCoef_rfft_8192[8192];
|
||||
|
||||
extern const q15_t twiddleCoef_fast_16_q15[24];
|
||||
extern const q15_t twiddleCoef_fast_32_q15[56];
|
||||
extern const q15_t twiddleCoef_fast_64_q15[120];
|
||||
extern const q15_t twiddleCoef_fast_128_q15[248];
|
||||
extern const q15_t twiddleCoef_fast_256_q15[504];
|
||||
extern const q15_t twiddleCoef_fast_512_q15[1016];
|
||||
extern const q15_t twiddleCoef_fast_1024_q15[2040];
|
||||
extern const q15_t twiddleCoef_fast_2048_q15[4088];
|
||||
extern const q15_t twiddleCoef_fast_4096_q15[8184];
|
||||
|
||||
extern const q31_t twiddleCoef_fast_16_q31[24];
|
||||
extern const q31_t twiddleCoef_fast_32_q31[56];
|
||||
extern const q31_t twiddleCoef_fast_64_q31[120];
|
||||
extern const q31_t twiddleCoef_fast_128_q31[248];
|
||||
extern const q31_t twiddleCoef_fast_256_q31[504];
|
||||
extern const q31_t twiddleCoef_fast_512_q31[1016];
|
||||
extern const q31_t twiddleCoef_fast_1024_q31[2040];
|
||||
extern const q31_t twiddleCoef_fast_2048_q31[4088];
|
||||
extern const q31_t twiddleCoef_fast_4096_q31[8184];
|
||||
|
||||
extern const uint32_t twiddleCoef_fast_16[24];
|
||||
extern const uint32_t twiddleCoef_fast_32[56];
|
||||
extern const uint32_t twiddleCoef_fast_64[120];
|
||||
extern const uint32_t twiddleCoef_fast_128[248];
|
||||
extern const uint32_t twiddleCoef_fast_256[504];
|
||||
extern const uint32_t twiddleCoef_fast_512[1016];
|
||||
extern const uint32_t twiddleCoef_fast_1024[2040];
|
||||
extern const uint32_t twiddleCoef_fast_2048[4088];
|
||||
extern const uint32_t twiddleCoef_fast_4096[8184];
|
||||
|
||||
extern const q15_t realCoefAQ15_8192[8192];
|
||||
extern const q31_t realCoefAQ31_8192[8192];
|
||||
extern const q15_t realCoefBQ15_8192[8192];
|
||||
extern const q31_t realCoefBQ31_8192[8192];
|
||||
|
||||
/*Tables for RFFT.*/
|
||||
extern const q15_t ALIGN4 realCoefAQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_4096[4096];
|
||||
|
||||
extern const q15_t ALIGN4 realCoefBQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_4096[4096];
|
||||
|
||||
extern const q31_t realCoefAQ31_32[32];
|
||||
extern const q31_t realCoefAQ31_64[64];
|
||||
extern const q31_t realCoefAQ31_128[128];
|
||||
extern const q31_t realCoefAQ31_256[256];
|
||||
extern const q31_t realCoefAQ31_512[512];
|
||||
extern const q31_t realCoefAQ31_1024[1024];
|
||||
extern const q31_t realCoefAQ31_2048[2048];
|
||||
extern const q31_t realCoefAQ31_4096[4096];
|
||||
|
||||
extern const q31_t realCoefBQ31_32[32];
|
||||
extern const q31_t realCoefBQ31_64[64];
|
||||
extern const q31_t realCoefBQ31_128[128];
|
||||
extern const q31_t realCoefBQ31_256[256];
|
||||
extern const q31_t realCoefBQ31_512[512];
|
||||
extern const q31_t realCoefBQ31_1024[1024];
|
||||
extern const q31_t realCoefBQ31_2048[2048];
|
||||
extern const q31_t realCoefBQ31_4096[4096];
|
||||
|
||||
|
||||
extern const float32_t realCoefA[8192];
|
||||
extern const float32_t realCoefB[8192];
|
||||
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len16;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len32;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len64;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len128;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len256;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len512;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len1024;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len2048;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len4096;
|
||||
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len16;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len32;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len64;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len128;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len256;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len512;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len1024;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len2048;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len4096;
|
||||
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len32;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len64;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len128;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len256;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len512;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len1024;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len2048;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len4096;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len8192;
|
||||
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len32;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len64;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len128;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len256;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len512;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len1024;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len2048;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len4096;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len8192;
|
||||
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len32;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len64;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len128;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len256;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len512;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len1024;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len2048;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len4096;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len8192;
|
||||
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len32;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len64;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len128;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len256;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len512;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len1024;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len2048;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len4096;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len8192;
|
||||
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len128;
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len512;
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len2048;
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len8192;
|
||||
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len128;
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len512;
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len2048;
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len8192;
|
||||
|
||||
/*Tables for DCT4*/
|
||||
#ifndef CSI_OPT_WEIGHT
|
||||
extern const q15_t ALIGN4 WeightsQ15_128[256];
|
||||
extern const q15_t ALIGN4 WeightsQ15_512[1024];
|
||||
extern const q15_t ALIGN4 WeightsQ15_2048[4096];
|
||||
extern const q15_t ALIGN4 WeightsQ15_8192[16384];
|
||||
#else
|
||||
extern const q15_t ALIGN4 WeightsQ15_128[128+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_512[512+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_2048[2048+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_8192[8192+2];
|
||||
#endif
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_128[128];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_512[512];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_8192[8192];
|
||||
|
||||
#ifndef CSI_OPT_WEIGHT
|
||||
extern const q31_t WeightsQ31_128[256];
|
||||
extern const q31_t WeightsQ31_512[1024];
|
||||
extern const q31_t WeightsQ31_2048[4096];
|
||||
extern const q31_t WeightsQ31_8192[16384];
|
||||
#else
|
||||
extern const q31_t WeightsQ31_128[128+2];
|
||||
extern const q31_t WeightsQ31_512[512+2];
|
||||
extern const q31_t WeightsQ31_2048[2048+2];
|
||||
extern const q31_t WeightsQ31_8192[8192+2];
|
||||
#endif
|
||||
|
||||
extern const q31_t cos_factorsQ31_128[128];
|
||||
extern const q31_t cos_factorsQ31_512[512];
|
||||
extern const q31_t cos_factorsQ31_2048[2048];
|
||||
extern const q31_t cos_factorsQ31_8192[8192];
|
||||
|
||||
#ifndef CSI_OPT_WEIGHT
|
||||
extern const float32_t Weights_128[256];
|
||||
extern const float32_t Weights_512[1024];
|
||||
extern const float32_t Weights_2048[4096];
|
||||
extern const float32_t Weights_8192[16384];
|
||||
|
||||
#else
|
||||
extern const float32_t Weights_128[128+2];
|
||||
extern const float32_t Weights_512[512+2];
|
||||
extern const float32_t Weights_2048[2048+2];
|
||||
extern const float32_t Weights_8192[8192+2];
|
||||
#endif
|
||||
extern const float32_t cos_factors_128[128];
|
||||
extern const float32_t cos_factors_512[512];
|
||||
extern const float32_t cos_factors_2048[2048];
|
||||
extern const float32_t cos_factors_8192[8192];
|
||||
|
||||
/* floating-point bit reversal tables */
|
||||
#define CSIBITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20 )
|
||||
#define CSIBITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48 )
|
||||
#define CSIBITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSIBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
|
||||
#define CSIBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
|
||||
#define CSIBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
|
||||
#define CSIBITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800)
|
||||
#define CSIBITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808)
|
||||
#define CSIBITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t csiBitRevIndexTable16[CSIBITREVINDEXTABLE_16_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable32[CSIBITREVINDEXTABLE_32_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable64[CSIBITREVINDEXTABLE_64_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable128[CSIBITREVINDEXTABLE_128_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable256[CSIBITREVINDEXTABLE_256_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable512[CSIBITREVINDEXTABLE_512_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable1024[CSIBITREVINDEXTABLE_1024_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable2048[CSIBITREVINDEXTABLE_2048_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable4096[CSIBITREVINDEXTABLE_4096_TABLE_LENGTH];
|
||||
|
||||
/* fixed-point bit reversal tables */
|
||||
#define CSIBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
|
||||
#define CSIBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_16[CSIBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_32[CSIBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_64[CSIBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_128[CSIBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_256[CSIBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_512[CSIBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_1024[CSIBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_2048[CSIBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_4096[CSIBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
|
||||
|
||||
/* Tables for Fast Math Sine and Cosine */
|
||||
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
|
||||
|
||||
#endif /* CSI_COMMON_TABLES_H */
|
||||
157
csky/csi_dsp/include/csi_const_structs.h
Normal file
157
csky/csi_dsp/include/csi_const_structs.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 T-head Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csi_const_structs.h
|
||||
* @brief Constant structs that are initialized for user convenience.
|
||||
* @version V1.0
|
||||
* @date Feb. 2020
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#ifndef _RISCV_CONST_STRUCTS_H
|
||||
#define _RISCV_CONST_STRUCTS_H
|
||||
|
||||
#include "csi_math.h"
|
||||
#include "csi_common_tables.h"
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len16;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len32;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len64;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len128;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len256;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len512;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len1024;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len2048;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len4096;
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len16;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len32;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len64;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len128;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len256;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len512;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len1024;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len2048;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len4096;
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len16;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len32;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len64;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len128;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len256;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len512;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len1024;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len2048;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len4096;
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len16 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len32 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len64 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len128 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len256 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len512 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len1024 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len2048 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len4096 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len16 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len32 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len64 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len128 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len256 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len512 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len1024 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len2048 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len4096 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len16 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len32 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len64 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len128 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len256 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len512 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len1024 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len2048 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len4096 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len32 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len64 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len128 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len256 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len512 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len1024 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len2048 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len4096 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len8192 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len32 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len64 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len128 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len256 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len512 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len1024 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len2048 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len4096 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len8192 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len32 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len64 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len128 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len256 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len512 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len1024 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len2048 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len4096 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len8192 ;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len32;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len64;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len128;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len256;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len512;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len1024;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len2048;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len4096;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len8192;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len32;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len64;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len128;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len256;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len512;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len1024;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len2048;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len4096;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len8192;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len32;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len64;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len128;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len256;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len512;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len1024;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len2048;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len4096;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len8192;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len128;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len512;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len2048;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len8192;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len128;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len512;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len2048;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len8192;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len128;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len512;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len2048;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len8192;
|
||||
|
||||
#endif
|
||||
1879
csky/csi_dsp/include/csi_instance.h
Normal file
1879
csky/csi_dsp/include/csi_instance.h
Normal file
File diff suppressed because it is too large
Load Diff
5739
csky/csi_dsp/include/csi_math.h
Normal file
5739
csky/csi_dsp/include/csi_math.h
Normal file
File diff suppressed because it is too large
Load Diff
54
csky/csi_dsp/include/csi_nn_tables.h
Normal file
54
csky/csi_dsp/include/csi_nn_tables.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_nn_tables.h
|
||||
* Description: Extern declaration for NN tables
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSI_NN_TABLES_H
|
||||
#define _CSI_NN_TABLES_H
|
||||
|
||||
#include "csi_instance.h"
|
||||
|
||||
/**
|
||||
* @brief tables for various activation functions
|
||||
*
|
||||
*/
|
||||
|
||||
extern const q15_t sigmoidTable_q15[256];
|
||||
extern const q7_t sigmoidTable_q7[256];
|
||||
|
||||
extern const q7_t tanhTable_q7[256];
|
||||
extern const q15_t tanhTable_q15[256];
|
||||
|
||||
/**
|
||||
* @brief 2-way tables for various activation functions
|
||||
*
|
||||
* 2-way table, H table for value larger than 1/4
|
||||
* L table for value smaller than 1/4, H table for remaining
|
||||
* We have this only for the q15_t version. It does not make
|
||||
* sense to have it for q7_t type
|
||||
*/
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
|
||||
#endif /* CSI_NN_TABLES_H */
|
||||
552
csky/csi_dsp/include/csi_nnfunctions.h
Normal file
552
csky/csi_dsp/include/csi_nnfunctions.h
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csi_nnfunctions.h
|
||||
* Description: Public header file for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSI_NNFUNCTIONS_H
|
||||
#define _CSI_NNFUNCTIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef CSI_MATH_DSP
|
||||
#include "csi_instance.h"
|
||||
#include "csi_nnsupportfunctions.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Struct for specifying activation function types
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CSKY_SIGMOID = 0, /**< Sigmoid activation function */
|
||||
CSKY_TANH = 1, /**< Tanh activation function */
|
||||
} csi_nn_activation_type;
|
||||
|
||||
/**
|
||||
* @brief Basic Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q7_basic(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Basic Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q15_basic(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q7_fast_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 version of 1x1 convolution (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function implement convolution with 1x1 kernel size (i.e., dim_kernel_x=1
|
||||
* and dim_kernel_y=1). It can be used for
|
||||
* second half of MobileNets after depthwise separable convolution.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csi_convolve_1x1_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 version of convolution for RGB image
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This kernel is written exclusively for convolution with ch_im_in
|
||||
* equals 3. This applies on the first layer of CNNs which has input
|
||||
* image with RGB format.
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q7_RGB(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csi_depthwise_separable_conv_HWC_q7(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function (non-square shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding sizes x
|
||||
* @param[in] padding_y padding sizes y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csi_depthwise_separable_conv_HWC_q7_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_fully_connected_q7(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q15 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_fully_connected_q15(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_fully_connected_mat_q7_vec_q15(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_relu_q7(q7_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q15 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_relu_q15(q15_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q7 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_nn_activations_direct_q7(q7_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csi_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q15 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_nn_activations_direct_q15(q15_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csi_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q7 max pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_maxpool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
/**
|
||||
* @brief Q7 average pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_avepool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
|
||||
void csi_avepool_q7_HWC_nonsquare(
|
||||
q7_t *Im_in, // input image
|
||||
const uint16_t dim_im_in_x, // input image dimension
|
||||
const uint16_t dim_im_in_y, // input image dimension
|
||||
const uint16_t ch_im_in, // number of input image channels
|
||||
const uint16_t dim_kernel_x, // window kernel size
|
||||
const uint16_t dim_kernel_y, // window kernel size
|
||||
const uint16_t padding_x, // padding sizes
|
||||
const uint16_t padding_y, // padding sizes
|
||||
const uint16_t stride_x, // stride
|
||||
const uint16_t stride_y, // stride
|
||||
const uint16_t dim_im_out_x, // output image dimension
|
||||
const uint16_t dim_im_out_y, // output image dimension
|
||||
q7_t *bufferA, // a buffer for local storage
|
||||
q7_t *Im_out, // output feature
|
||||
const uint16_t out_lshift); // output left shift (scaling)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out);
|
||||
|
||||
/**
|
||||
* @brief Q15 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec,
|
||||
q15_t *p_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
162
csky/csi_dsp/include/csi_nnsupportfunctions.h
Normal file
162
csky/csi_dsp/include/csi_nnsupportfunctions.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csi_nnsupportfunctions.h
|
||||
* Description: Public header file of support functions for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
#define _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
|
||||
#include "csi_instance.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Union for SIMD access of Q31/Q15/Q7 types
|
||||
*/
|
||||
union csi_nnword
|
||||
{
|
||||
q31_t word; /**< Q31 type */
|
||||
q15_t half_words[2]; /**< Q15 type */
|
||||
q7_t bytes[4]; /**< Q7 type */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup nndata_convert Neural Network Data Conversion Functions
|
||||
*
|
||||
* Perform data type conversion in-between neural network operations
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_q7_to_q15_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to reordered Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_q7_to_q15_reordered_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
#if defined (CSI_MATH_DSP)
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad(void *source, q31_t *out1,
|
||||
q31_t *out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
q31_t inAbuf1 = __SXTB16(__ROR(inA, 8));
|
||||
q31_t inAbuf2 = __SXTB16(inA);
|
||||
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out1 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#else
|
||||
*out1 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out2 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words with reordering
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad_reordered(void *source, q31_t * out1,
|
||||
q31_t * out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __SXTB16(__ROR(inA, 8));
|
||||
*out1 = __SXTB16(inA);
|
||||
#else
|
||||
*out1 = __SXTB16(__ROR(inA, 8));
|
||||
*out2 = __SXTB16(inA);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
#endif
|
||||
|
||||
q7_t *csi_nn_mat_mult_kernel_q7_q15_reordered(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
q7_t *csi_nn_mat_mult_kernel_q7_q15(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief A few utility functions used by pooling functions
|
||||
*
|
||||
*/
|
||||
|
||||
void buffer_scale_back_q15_to_q7(q15_t * buffer, q7_t * target,
|
||||
uint16_t length, uint16_t scale);
|
||||
|
||||
void accumulate_q7_to_q15(q15_t * base, q7_t * target,
|
||||
const uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief defition to adding rouding offset
|
||||
*/
|
||||
#ifndef CSKY_NN_TRUNCATE
|
||||
#define NN_ROUND(out_shift) ( 0x1 << (out_shift - 1) )
|
||||
#else
|
||||
#define NN_ROUND(out_shift) 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
229
csky/csi_dsp/include/csky_common_tables.h
Normal file
229
csky/csi_dsp/include/csky_common_tables.h
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csky_common_tables.h
|
||||
* @brief This file has extern declaration for common tables like
|
||||
* Bitreverse, reciprocal etc which are used across different functions.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSKY_COMMON_TABLES_H
|
||||
#define _CSKY_COMMON_TABLES_H
|
||||
|
||||
#include "csky_math.h"
|
||||
|
||||
extern const uint16_t cskyBitRevTable[1024];
|
||||
extern const q15_t cskyRecipTableQ15[64];
|
||||
extern const q31_t cskyRecipTableQ31[64];
|
||||
extern const uint32_t twiddleCoef_16[32];
|
||||
extern const uint32_t twiddleCoef_32[64];
|
||||
extern const uint32_t twiddleCoef_64[128];
|
||||
extern const uint32_t twiddleCoef_128[256];
|
||||
extern const uint32_t twiddleCoef_256[512];
|
||||
extern const uint32_t twiddleCoef_512[1024];
|
||||
extern const uint32_t twiddleCoef_1024[2048];
|
||||
extern const uint32_t twiddleCoef_2048[4096];
|
||||
extern const uint32_t twiddleCoef_4096[8192];
|
||||
extern const q31_t twiddleCoef_16_q31[24];
|
||||
extern const q31_t twiddleCoef_32_q31[48];
|
||||
extern const q31_t twiddleCoef_64_q31[96];
|
||||
extern const q31_t twiddleCoef_128_q31[192];
|
||||
extern const q31_t twiddleCoef_256_q31[384];
|
||||
extern const q31_t twiddleCoef_512_q31[768];
|
||||
extern const q31_t twiddleCoef_1024_q31[1536];
|
||||
extern const q31_t twiddleCoef_2048_q31[3072];
|
||||
extern const q31_t twiddleCoef_4096_q31[6144];
|
||||
extern const q15_t twiddleCoef_16_q15[24];
|
||||
extern const q15_t twiddleCoef_32_q15[48];
|
||||
extern const q15_t twiddleCoef_64_q15[96];
|
||||
extern const q15_t twiddleCoef_128_q15[192];
|
||||
extern const q15_t twiddleCoef_256_q15[384];
|
||||
extern const q15_t twiddleCoef_512_q15[768];
|
||||
extern const q15_t twiddleCoef_1024_q15[1536];
|
||||
extern const q15_t twiddleCoef_2048_q15[3072];
|
||||
extern const q15_t twiddleCoef_4096_q15[6144];
|
||||
extern const float32_t twiddleCoef_rfft_32[32];
|
||||
extern const float32_t twiddleCoef_rfft_64[64];
|
||||
extern const float32_t twiddleCoef_rfft_128[128];
|
||||
extern const float32_t twiddleCoef_rfft_256[256];
|
||||
extern const float32_t twiddleCoef_rfft_512[512];
|
||||
extern const float32_t twiddleCoef_rfft_1024[1024];
|
||||
extern const float32_t twiddleCoef_rfft_2048[2048];
|
||||
extern const float32_t twiddleCoef_rfft_4096[4096];
|
||||
extern const float32_t twiddleCoef_rfft_8192[8192];
|
||||
|
||||
extern const q15_t twiddleCoef_fast_16_q15[24];
|
||||
extern const q15_t twiddleCoef_fast_32_q15[56];
|
||||
extern const q15_t twiddleCoef_fast_64_q15[120];
|
||||
extern const q15_t twiddleCoef_fast_128_q15[248];
|
||||
extern const q15_t twiddleCoef_fast_256_q15[504];
|
||||
extern const q15_t twiddleCoef_fast_512_q15[1016];
|
||||
extern const q15_t twiddleCoef_fast_1024_q15[2040];
|
||||
extern const q15_t twiddleCoef_fast_2048_q15[4088];
|
||||
extern const q15_t twiddleCoef_fast_4096_q15[8184];
|
||||
|
||||
extern const q31_t twiddleCoef_fast_16_q31[24];
|
||||
extern const q31_t twiddleCoef_fast_32_q31[56];
|
||||
extern const q31_t twiddleCoef_fast_64_q31[120];
|
||||
extern const q31_t twiddleCoef_fast_128_q31[248];
|
||||
extern const q31_t twiddleCoef_fast_256_q31[504];
|
||||
extern const q31_t twiddleCoef_fast_512_q31[1016];
|
||||
extern const q31_t twiddleCoef_fast_1024_q31[2040];
|
||||
extern const q31_t twiddleCoef_fast_2048_q31[4088];
|
||||
extern const q31_t twiddleCoef_fast_4096_q31[8184];
|
||||
|
||||
extern const uint32_t twiddleCoef_fast_16[24];
|
||||
extern const uint32_t twiddleCoef_fast_32[56];
|
||||
extern const uint32_t twiddleCoef_fast_64[120];
|
||||
extern const uint32_t twiddleCoef_fast_128[248];
|
||||
extern const uint32_t twiddleCoef_fast_256[504];
|
||||
extern const uint32_t twiddleCoef_fast_512[1016];
|
||||
extern const uint32_t twiddleCoef_fast_1024[2040];
|
||||
extern const uint32_t twiddleCoef_fast_2048[4088];
|
||||
extern const uint32_t twiddleCoef_fast_4096[8184];
|
||||
|
||||
extern const q15_t realCoefAQ15_8192[8192];
|
||||
extern const q31_t realCoefAQ31_8192[8192];
|
||||
extern const q15_t realCoefBQ15_8192[8192];
|
||||
extern const q31_t realCoefBQ31_8192[8192];
|
||||
|
||||
/*Tables for RFFT.*/
|
||||
extern const q15_t ALIGN4 realCoefAQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_4096[4096];
|
||||
|
||||
extern const q15_t ALIGN4 realCoefBQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_4096[4096];
|
||||
|
||||
extern const q31_t realCoefAQ31_32[32];
|
||||
extern const q31_t realCoefAQ31_64[64];
|
||||
extern const q31_t realCoefAQ31_128[128];
|
||||
extern const q31_t realCoefAQ31_256[256];
|
||||
extern const q31_t realCoefAQ31_512[512];
|
||||
extern const q31_t realCoefAQ31_1024[1024];
|
||||
extern const q31_t realCoefAQ31_2048[2048];
|
||||
extern const q31_t realCoefAQ31_4096[4096];
|
||||
|
||||
extern const q31_t realCoefBQ31_32[32];
|
||||
extern const q31_t realCoefBQ31_64[64];
|
||||
extern const q31_t realCoefBQ31_128[128];
|
||||
extern const q31_t realCoefBQ31_256[256];
|
||||
extern const q31_t realCoefBQ31_512[512];
|
||||
extern const q31_t realCoefBQ31_1024[1024];
|
||||
extern const q31_t realCoefBQ31_2048[2048];
|
||||
extern const q31_t realCoefBQ31_4096[4096];
|
||||
|
||||
|
||||
extern const float32_t realCoefA[8192];
|
||||
extern const float32_t realCoefB[8192];
|
||||
|
||||
|
||||
/*Tables for DCT4*/
|
||||
extern const q15_t ALIGN4 WeightsQ15_128[128+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_512[512+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_2048[2048+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_8192[8192+2];
|
||||
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_128[128];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_512[512];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_8192[8192];
|
||||
|
||||
|
||||
extern const q31_t WeightsQ31_128[128+2];
|
||||
extern const q31_t WeightsQ31_512[512+2];
|
||||
extern const q31_t WeightsQ31_2048[2048+2];
|
||||
extern const q31_t WeightsQ31_8192[8192+2];
|
||||
|
||||
extern const q31_t cos_factorsQ31_128[128];
|
||||
extern const q31_t cos_factorsQ31_512[512];
|
||||
extern const q31_t cos_factorsQ31_2048[2048];
|
||||
extern const q31_t cos_factorsQ31_8192[8192];
|
||||
|
||||
|
||||
extern const float32_t Weights_128[128+2];
|
||||
extern const float32_t Weights_512[512+2];
|
||||
extern const float32_t Weights_2048[2048+2];
|
||||
extern const float32_t Weights_8192[8192+2];
|
||||
|
||||
extern const float32_t cos_factors_128[128];
|
||||
extern const float32_t cos_factors_512[512];
|
||||
extern const float32_t cos_factors_2048[2048];
|
||||
extern const float32_t cos_factors_8192[8192];
|
||||
|
||||
/* floating-point bit reversal tables */
|
||||
#define CSKYBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
|
||||
#define CSKYBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
|
||||
#define CSKYBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSKYBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
|
||||
#define CSKYBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
|
||||
#define CSKYBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
|
||||
#define CSKYBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
|
||||
#define CSKYBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
|
||||
#define CSKYBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t cskyBitRevIndexTable16[CSKYBITREVINDEXTABLE__16_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable32[CSKYBITREVINDEXTABLE__32_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable64[CSKYBITREVINDEXTABLE__64_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable128[CSKYBITREVINDEXTABLE_128_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable256[CSKYBITREVINDEXTABLE_256_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable512[CSKYBITREVINDEXTABLE_512_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable1024[CSKYBITREVINDEXTABLE1024_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable2048[CSKYBITREVINDEXTABLE2048_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable4096[CSKYBITREVINDEXTABLE4096_TABLE_LENGTH];
|
||||
|
||||
/* fixed-point bit reversal tables */
|
||||
#define CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
|
||||
#define CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_16[CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_32[CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_64[CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_128[CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_256[CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_512[CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_1024[CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_2048[CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_4096[CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
|
||||
|
||||
/* Tables for Fast Math Sine and Cosine */
|
||||
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
|
||||
|
||||
#endif /* CSKY_COMMON_TABLES_H */
|
||||
131
csky/csi_dsp/include/csky_const_structs.h
Normal file
131
csky/csi_dsp/include/csky_const_structs.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csky_const_structs.h
|
||||
* @brief This file has constant structs that are initialized for
|
||||
* user convenience. For example, some can be given as
|
||||
* arguments to the csky_cfft_f32() function.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSKY_CONST_STRUCTS_H
|
||||
#define _CSKY_CONST_STRUCTS_H
|
||||
|
||||
#include "csky_math.h"
|
||||
#include "csky_common_tables.h"
|
||||
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len16;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len32;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len64;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len128;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len256;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len512;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len1024;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len2048;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len4096;
|
||||
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len16;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len32;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len64;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len128;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len256;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len512;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len1024;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len2048;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len4096;
|
||||
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len16;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len32;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len64;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len128;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len256;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len512;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len1024;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len2048;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len4096;
|
||||
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len32;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len64;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len128;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len256;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len512;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len1024;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len2048;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len4096;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len32;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len64;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len128;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len256;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len512;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len1024;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len2048;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len4096;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len32;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len64;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len128;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len256;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len512;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len1024;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len2048;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len4096;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len8192;
|
||||
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len32;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len64;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len128;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len256;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len512;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len1024;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len2048;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len4096;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len8192;
|
||||
|
||||
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len32;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len64;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len128;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len256;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len512;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len1024;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len2048;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len4096;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len8192;
|
||||
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len128;
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len512;
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len2048;
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len8192;
|
||||
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len128;
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len512;
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len2048;
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len8192;
|
||||
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len128;
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len512;
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len2048;
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len8192;
|
||||
#endif
|
||||
745
csky/csi_dsp/include/csky_dsp2_nnfunctions.h
Normal file
745
csky/csi_dsp/include/csky_dsp2_nnfunctions.h
Normal file
@@ -0,0 +1,745 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_dsp2_nnfunctions.h
|
||||
* Description: Public header file for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNFUNCTIONS_H
|
||||
#define _CSKY_DSP2_NNFUNCTIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include"csky_math.h"
|
||||
/**
|
||||
* @brief Struct for specifying activation function types
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CSKY_SIGMOID = 0, /**< Sigmoid activation function */
|
||||
CSKY_TANH = 1, /**< Tanh activation function */
|
||||
} csky_dsp2_nn_activation_type;
|
||||
|
||||
/**
|
||||
* @brief Basic Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_basic(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Basic Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q15_basic(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_fast_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 version of 1x1 convolution (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function implement convolution with 1x1 kernel size (i.e., dim_kernel_x=1
|
||||
* and dim_kernel_y=1). It can be used for
|
||||
* second half of MobileNets after depthwise separable convolution.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_dsp2_convolve_1x1_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 version of convolution for RGB image
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This kernel is written exclusively for convolution with ch_im_in
|
||||
* equals 3. This applies on the first layer of CNNs which has input
|
||||
* image with RGB format.
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_RGB(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q15_fast(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_depthwise_separable_conv_HWC_q7(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function (non-square shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding sizes x
|
||||
* @param[in] padding_y padding sizes y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_dsp2_depthwise_separable_conv_HWC_q7_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q7(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Q7 opt fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @param[in,out] vec_buffer pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q7_opt(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut,
|
||||
q15_t * vec_buffer);
|
||||
|
||||
/**
|
||||
* @brief Q15 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q15(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Q15 opt fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q15_opt(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_mat_q7_vec_q15(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 opt fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_mat_q7_vec_q15_opt(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Matrix-Multiplication Kernels for Convolution
|
||||
*
|
||||
* These functions are used within convolution layer functions for
|
||||
* matrix multiplication.
|
||||
*
|
||||
* The implementation is similar to CSI-DSP csky_dsp2_mat_mult functions
|
||||
* with one Q7 and one Q15 operands. The Q15 operand is the im2col
|
||||
* output which is always with 2 columns.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Matrix-multiplication function for convolution
|
||||
* @param[in] pA pointer to operand A
|
||||
* @param[in] pInBuffer pointer to operand B, always conssists of 2 vectors
|
||||
* @param[in] ch_im_out numRow of A
|
||||
* @param[in] numCol_A numCol of A
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias the bias
|
||||
* @param[in,out] pOut pointer to output
|
||||
* @return The function returns the incremented output pointer
|
||||
*/
|
||||
|
||||
q7_t *csky_dsp2_nn_mat_mult_kernel_q7_q15(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Matrix-multiplication function for convolution with reordered columns
|
||||
* @param[in] pA pointer to operand A
|
||||
* @param[in] pInBuffer pointer to operand B, always conssists of 2 vectors
|
||||
* @param[in] ch_im_out numRow of A
|
||||
* @param[in] numCol_A numCol of A
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias the bias
|
||||
* @param[in,out] pOut pointer to output
|
||||
* @return The function returns the incremented output pointer
|
||||
*/
|
||||
|
||||
q7_t *csky_dsp2_nn_mat_mult_kernel_q7_q15_reordered(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Other functions
|
||||
* These layers are typically not timing critical
|
||||
* Basic implementation is supported here
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_relu_q7(q7_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q15 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_relu_q15(q15_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q7 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_nn_activations_direct_q7(q7_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_dsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q15 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_nn_activations_direct_q15(q15_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_dsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q7 max pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_maxpool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
/**
|
||||
* @brief Q7 average pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_avepool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out);
|
||||
|
||||
/**
|
||||
* @brief Q15 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec,
|
||||
q15_t *p_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
132
csky/csi_dsp/include/csky_dsp2_nnsupportfunctions.h
Normal file
132
csky/csi_dsp/include/csky_dsp2_nnsupportfunctions.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_dsp2_nnsupportfunctions.h
|
||||
* Description: Public header file of support functions for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
#define _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
|
||||
#include "csky_math.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Union for SIMD access of Q31/Q15/Q7 types
|
||||
*/
|
||||
union csky_dsp2_nnword
|
||||
{
|
||||
q31_t word; /**< Q31 type */
|
||||
q15_t half_words[2]; /**< Q15 type */
|
||||
q7_t bytes[4]; /**< Q7 type */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup nndata_convert Neural Network Data Conversion Functions
|
||||
*
|
||||
* Perform data type conversion in-between neural network operations
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_q7_to_q15_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to reordered Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_q7_to_q15_reordered_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
#if defined (CSKY_MATH_DSP)
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words
|
||||
*/
|
||||
|
||||
__ALWAYS_INLINE void *read_and_pad(void *source, q31_t *out1, q31_t *out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
q31_t inAbuf1 = __SXTB16(__ROR(inA, 8));
|
||||
q31_t inAbuf2 = __SXTB16(inA);
|
||||
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out1 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#else
|
||||
*out1 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out2 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words with reordering
|
||||
*/
|
||||
|
||||
__ALWAYS_INLINE void *read_and_pad_reordered(void *source, q31_t * out1,
|
||||
q31_t * out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __SXTB16(__ROR(inA, 8));
|
||||
*out1 = __SXTB16(inA);
|
||||
#else
|
||||
*out1 = __SXTB16(__ROR(inA, 8));
|
||||
*out2 = __SXTB16(inA);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief defition to adding rouding offset
|
||||
*/
|
||||
#ifndef CSKY_NN_TRUNCATE
|
||||
#define NN_ROUND(out_shift) ( 0x1 << (out_shift - 1) )
|
||||
#else
|
||||
#define NN_ROUND(out_shift) 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
4637
csky/csi_dsp/include/csky_math.h
Normal file
4637
csky/csi_dsp/include/csky_math.h
Normal file
File diff suppressed because it is too large
Load Diff
54
csky/csi_dsp/include/csky_nn_tables.h
Normal file
54
csky/csi_dsp/include/csky_nn_tables.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_nn_tables.h
|
||||
* Description: Extern declaration for NN tables
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_NN_TABLES_H
|
||||
#define _CSKY_NN_TABLES_H
|
||||
|
||||
#include "csky_vdsp2_math.h"
|
||||
|
||||
/**
|
||||
* @brief tables for various activation functions
|
||||
*
|
||||
*/
|
||||
|
||||
extern const q15_t sigmoidTable_q15[256];
|
||||
extern const q7_t sigmoidTable_q7[256];
|
||||
|
||||
extern const q7_t tanhTable_q7[256];
|
||||
extern const q15_t tanhTable_q15[256];
|
||||
|
||||
/**
|
||||
* @brief 2-way tables for various activation functions
|
||||
*
|
||||
* 2-way table, H table for value larger than 1/4
|
||||
* L table for value smaller than 1/4, H table for remaining
|
||||
* We have this only for the q15_t version. It does not make
|
||||
* sense to have it for q7_t type
|
||||
*/
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
|
||||
#endif /* CSKY_NN_TABLES_H */
|
||||
232
csky/csi_dsp/include/csky_vdsp2_const_structs.h
Normal file
232
csky/csi_dsp/include/csky_vdsp2_const_structs.h
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csky_vdsp2_const_structs.h
|
||||
* @brief This file has constant structs that are initialized for
|
||||
* user convenience. For example, some can be given as
|
||||
* arguments to the csky_vdsp2_cfft_f32() function.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSKY_CONST_STRUCTS_H
|
||||
#define _CSKY_CONST_STRUCTS_H
|
||||
|
||||
#include "csky_vdsp2_math.h"
|
||||
#include "csky_common_tables.h"
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len4096;
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len128;
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len512;
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len2048;
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len128;
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len512;
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len2048;
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len128;
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len512;
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len2048;
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len128;
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len512;
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len2048;
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len128;
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len512;
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len2048;
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len8192;
|
||||
#endif
|
||||
2378
csky/csi_dsp/include/csky_vdsp2_math.h
Normal file
2378
csky/csi_dsp/include/csky_vdsp2_math.h
Normal file
File diff suppressed because it is too large
Load Diff
552
csky/csi_dsp/include/csky_vdsp2_nnfunctions.h
Normal file
552
csky/csi_dsp/include/csky_vdsp2_nnfunctions.h
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_vdsp2_nnfunctions.h
|
||||
* Description: Public header file for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_VDSP2_NNFUNCTIONS_H
|
||||
#define _CSKY_VDSP2_NNFUNCTIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef CSKY_VDSP2_MATH_DSP
|
||||
#include "csky_vdsp2_math.h"
|
||||
#include "csky_vdsp2_nnsupportfunctions.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Struct for specifying activation function types
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CSKY_SIGMOID = 0, /**< Sigmoid activation function */
|
||||
CSKY_TANH = 1, /**< Tanh activation function */
|
||||
} csky_vdsp2_nn_activation_type;
|
||||
|
||||
/**
|
||||
* @brief Basic Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q7_basic(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Basic Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q15_basic(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q7_fast_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 version of 1x1 convolution (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function implement convolution with 1x1 kernel size (i.e., dim_kernel_x=1
|
||||
* and dim_kernel_y=1). It can be used for
|
||||
* second half of MobileNets after depthwise separable convolution.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_vdsp2_convolve_1x1_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 version of convolution for RGB image
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This kernel is written exclusively for convolution with ch_im_in
|
||||
* equals 3. This applies on the first layer of CNNs which has input
|
||||
* image with RGB format.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q7_RGB(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_vdsp2_depthwise_separable_conv_HWC_q7(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function (non-square shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding sizes x
|
||||
* @param[in] padding_y padding sizes y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_vdsp2_depthwise_separable_conv_HWC_q7_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_fully_connected_q7(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q15 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_fully_connected_q15(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_fully_connected_mat_q7_vec_q15(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_relu_q7(q7_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q15 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_relu_q15(q15_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q7 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_nn_activations_direct_q7(q7_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_vdsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q15 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_nn_activations_direct_q15(q15_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_vdsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q7 max pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_maxpool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
/**
|
||||
* @brief Q7 average pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_avepool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
|
||||
void csky_vdsp2_avepool_q7_HWC_nonsquare(
|
||||
q7_t *Im_in, // input image
|
||||
const uint16_t dim_im_in_x, // input image dimension
|
||||
const uint16_t dim_im_in_y, // input image dimension
|
||||
const uint16_t ch_im_in, // number of input image channels
|
||||
const uint16_t dim_kernel_x, // window kernel size
|
||||
const uint16_t dim_kernel_y, // window kernel size
|
||||
const uint16_t padding_x, // padding sizes
|
||||
const uint16_t padding_y, // padding sizes
|
||||
const uint16_t stride_x, // stride
|
||||
const uint16_t stride_y, // stride
|
||||
const uint16_t dim_im_out_x, // output image dimension
|
||||
const uint16_t dim_im_out_y, // output image dimension
|
||||
q7_t *bufferA, // a buffer for local storage
|
||||
q7_t *Im_out, // output feature
|
||||
const uint16_t out_lshift); // output left shift (scaling)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out);
|
||||
|
||||
/**
|
||||
* @brief Q15 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec,
|
||||
q15_t *p_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
162
csky/csi_dsp/include/csky_vdsp2_nnsupportfunctions.h
Normal file
162
csky/csi_dsp/include/csky_vdsp2_nnsupportfunctions.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_vdsp2_nnsupportfunctions.h
|
||||
* Description: Public header file of support functions for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
#define _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
|
||||
#include "csky_math.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Union for SIMD access of Q31/Q15/Q7 types
|
||||
*/
|
||||
union csky_vdsp2_nnword
|
||||
{
|
||||
q31_t word; /**< Q31 type */
|
||||
q15_t half_words[2]; /**< Q15 type */
|
||||
q7_t bytes[4]; /**< Q7 type */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup nndata_convert Neural Network Data Conversion Functions
|
||||
*
|
||||
* Perform data type conversion in-between neural network operations
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_q7_to_q15_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to reordered Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_q7_to_q15_reordered_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
#if defined (CSKY_VDSP2_MATH_DSP)
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad(void *source, q31_t *out1,
|
||||
q31_t *out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
q31_t inAbuf1 = __SXTB16(__ROR(inA, 8));
|
||||
q31_t inAbuf2 = __SXTB16(inA);
|
||||
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out1 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#else
|
||||
*out1 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out2 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words with reordering
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad_reordered(void *source, q31_t * out1,
|
||||
q31_t * out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __SXTB16(__ROR(inA, 8));
|
||||
*out1 = __SXTB16(inA);
|
||||
#else
|
||||
*out1 = __SXTB16(__ROR(inA, 8));
|
||||
*out2 = __SXTB16(inA);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
#endif
|
||||
|
||||
q7_t *csky_vdsp2_nn_mat_mult_kernel_q7_q15_reordered(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
q7_t *csky_vdsp2_nn_mat_mult_kernel_q7_q15(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief A few utility functions used by pooling functions
|
||||
*
|
||||
*/
|
||||
|
||||
void buffer_scale_back_q15_to_q7(q15_t * buffer, q7_t * target,
|
||||
uint16_t length, uint16_t scale);
|
||||
|
||||
void accumulate_q7_to_q15(q15_t * base, q7_t * target,
|
||||
const uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief defition to adding rouding offset
|
||||
*/
|
||||
#ifndef CSKY_NN_TRUNCATE
|
||||
#define NN_ROUND(out_shift) ( 0x1 << (out_shift - 1) )
|
||||
#else
|
||||
#define NN_ROUND(out_shift) 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user