/* * SPDX-FileCopyrightText: Copyright 2023-2024 Arm Limited and/or its affiliates * * 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. */ /* ---------------------------------------------------------------------- * Project: CMSIS NN Library * Title: arm_depthwise_conv_get_buffer_sizes_s8.c * Description: Collection of get buffer size functions for the various s8 convolution layer functions. * * $Date: 17 April 2024 * $Revision: V.1.2.0 * * Target : Arm(R) M-Profile Architecture * * -------------------------------------------------------------------- */ #include "arm_nnfunctions.h" #include "arm_nnsupportfunctions.h" /** * @ingroup NNConv */ /** * @addtogroup GetBufferSizeNNConv * @{ */ int32_t arm_depthwise_conv_s8_opt_get_buffer_size_mve(const cmsis_nn_dims *input_dims, const cmsis_nn_dims *filter_dims) { (void)input_dims; return (4 * CH_IN_BLOCK_MVE * filter_dims->w * filter_dims->h) * (int32_t)sizeof(int8_t); } int32_t arm_depthwise_conv_s8_opt_get_buffer_size_dsp(const cmsis_nn_dims *input_dims, const cmsis_nn_dims *filter_dims) { return (input_dims->c * filter_dims->w * filter_dims->h) * sizeof(int16_t); } int32_t arm_depthwise_conv_s8_opt_get_buffer_size(const cmsis_nn_dims *input_dims, const cmsis_nn_dims *filter_dims) { #if defined(ARM_MATH_MVEI) return arm_depthwise_conv_s8_opt_get_buffer_size_mve(input_dims, filter_dims); #elif defined(ARM_MATH_DSP) return arm_depthwise_conv_s8_opt_get_buffer_size_dsp(input_dims, filter_dims); #else (void)input_dims; (void)filter_dims; return 0; #endif } int32_t arm_depthwise_conv_wrapper_s8_get_buffer_size(const cmsis_nn_dw_conv_params *dw_conv_params, const cmsis_nn_dims *input_dims, const cmsis_nn_dims *filter_dims, const cmsis_nn_dims *output_dims) { int32_t size = 0; if (input_dims->c == output_dims->c && input_dims->n == 1 && dw_conv_params->dilation.w == 1 && dw_conv_params->dilation.h == 1) { #if !defined(ARM_MATH_MVEI) if (filter_dims->w == 3 && filter_dims->h == 3 && dw_conv_params->padding.h <= 1 && dw_conv_params->padding.w <= 1) { return size; } #endif size = arm_depthwise_conv_s8_opt_get_buffer_size(input_dims, filter_dims); } return size; } int32_t arm_depthwise_conv_wrapper_s8_get_buffer_size_dsp(const cmsis_nn_dw_conv_params *dw_conv_params, const cmsis_nn_dims *input_dims, const cmsis_nn_dims *filter_dims, const cmsis_nn_dims *output_dims) { int32_t size = 0; if (input_dims->c == output_dims->c && input_dims->n == 1 && dw_conv_params->dilation.w == 1 && dw_conv_params->dilation.h == 1) { if (filter_dims->w == 3 && filter_dims->h == 3 && dw_conv_params->padding.h <= 1 && dw_conv_params->padding.w <= 1) { return size; } size = arm_depthwise_conv_s8_opt_get_buffer_size_dsp(input_dims, filter_dims); } return size; } int32_t arm_depthwise_conv_wrapper_s8_get_buffer_size_mve(const cmsis_nn_dw_conv_params *dw_conv_params, const cmsis_nn_dims *input_dims, const cmsis_nn_dims *filter_dims, const cmsis_nn_dims *output_dims) { int32_t size = 0; if (input_dims->c == output_dims->c && input_dims->n == 1 && dw_conv_params->dilation.w == 1 && dw_conv_params->dilation.h == 1) { size = arm_depthwise_conv_s8_opt_get_buffer_size_mve(input_dims, filter_dims); } return size; } /** * @} end of GetBufferSizeNNConv group */