diff --git a/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Convolution/ConvDW.hpp b/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Convolution/ConvDW.hpp index cefe933057f0e858e54dbf45e6f0b548407bd593..e1cca080058740c046e9124f935c22c31dd282c6 100644 --- a/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Convolution/ConvDW.hpp +++ b/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Convolution/ConvDW.hpp @@ -95,8 +95,8 @@ __attribute__((always_inline)) inline void convcellDWPropagate( for (int output = 0; output < NB_OUTPUTS; ++output) { const int channel = (output * NB_CHANNELS) / NB_OUTPUTS; - - SUM_T weightedSum = biasses[output]; + using Sum_T = typename std::conditional<std::is_floating_point<Input_T>::value, float, int32_t>::type; + Sum_T weightedSum = biasses[output]; for (int sy = 0; sy < KERNEL_HEIGHT; ++sy) { if ((PADDING_Y != 0 diff --git a/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Softmax/aidge_softmax_chw_float32.h b/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Softmax/aidge_softmax_chw_float32.h index 93d710e5955f478e11ead1c7f848dc5d716b28f0..6ec9122729fcd0436784cc64c573c2a2fe7c85ce 100644 --- a/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Softmax/aidge_softmax_chw_float32.h +++ b/aidge_export_arm_cortexm/_Aidge_Arm/kernels/Softmax/aidge_softmax_chw_float32.h @@ -2,16 +2,16 @@ void aidge_softmax_chw_float32 (float* inputs, float* outputs, - int inputDims[], + const int inputDims[], int axis, - unsigned int size_inputDim, - unsigned int size) + const unsigned int size_inputDim, + const unsigned int size) { axis += (axis >= 0 ) ? 0 : size_inputDim; int postAxisElems = 1; - for (int i = axis+1; i < size_inputDim; ++i) { + for (unsigned int i = axis+1; i < size_inputDim; ++i) { postAxisElems *= inputDims[i]; } int preAxisElems = 1; diff --git a/aidge_export_arm_cortexm/_Aidge_Arm/templates/configuration/conv_dw_cinfig.jinja b/aidge_export_arm_cortexm/_Aidge_Arm/templates/configuration/conv_dw_cinfig.jinja new file mode 100644 index 0000000000000000000000000000000000000000..71c8b59ba2fa58f7db1e8d08c02e7078eb667a9f --- /dev/null +++ b/aidge_export_arm_cortexm/_Aidge_Arm/templates/configuration/conv_dw_cinfig.jinja @@ -0,0 +1,40 @@ +#define {{ name|upper }}_LAYER_H + +#include "typedefs.h" +#include "nn_scaling_functions.hpp" + +{% include "./_def_io.jinja" %} +{% include "./_meminfo.jinja" %} + +// Attributes +#define {{ name|upper }}_KERNEL_HEIGHT {{ kernel_dims[1] }} +#define {{ name|upper }}_KERNEL_WIDTH {{ kernel_dims[0] }} +#define {{ name|upper }}_PADDING_Y {{ padding[1] }} +#define {{ name|upper }}_PADDING_X {{ padding[0] }} +#define {{ name|upper }}_STRIDE_Y {{ stride_dims[1] }} +#define {{ name|upper }}_STRIDE_X {{ stride_dims[0] }} +#define {{ name|upper }}_DILATION_Y {{ dilation_dims[1] }} +#define {{ name|upper }}_DILATION_X {{ dilation_dims[0] }} +{# #define {{ name|upper }}_GROUP {{ group }} #} + +// Activation/Scaling +#define {{ name|upper }}_ACTIVATION {{ activation }} + +{%- if scaling_type == "floating_point" %} +static const N2D2_Export::FloatingPointScaling {{ name|upper }}_SCALING = { {{scaling_value}} }; +{%- elif scaling_type == "fixed_point" %} +static const N2D2_Export::FixedPointScaling<{{scaling_value}}, {{fractional_bits}}> {{ name|upper }}_SCALING; +{%- elif scaling_type == "single_shift" %} +static const N2D2_Export::SingleShiftScaling<{{shift_value}}> {{ name|upper }}_SCALING; +{%- else %} +static const N2D2_Export::NoScaling {{ name|upper }}_SCALING; +{%- endif %} + +// Sizes +#define {{ name|upper }}_WEIGHTS_SIZE {{ out_chan[0] * in_chan[0] * kernel_dims[1] * kernel_dims[0] }} +#define {{ name|upper }}_BIASES_SIZE {{ out_chan[0] }} +#define {{ name|upper }}_OUTPUTS_SIZE {{ out_chan[0] * out_height[0] * out_width[0] }} +#define {{ name|upper }}_CHANNELS_SIZE {{ in_chan[0] * in_height[0] * in_width[0] }} + + +#endif /* {{ name|upper }}_LAYER_H */ diff --git a/aidge_export_arm_cortexm/_Aidge_Arm/templates/configuration/softmax.jinja b/aidge_export_arm_cortexm/_Aidge_Arm/templates/configuration/softmax.jinja index 9f1eb503251117c70c07e81e478bdd84d6beb566..b48a02cb3f1c102b46aaa6c50488e1f8a75eae4a 100644 --- a/aidge_export_arm_cortexm/_Aidge_Arm/templates/configuration/softmax.jinja +++ b/aidge_export_arm_cortexm/_Aidge_Arm/templates/configuration/softmax.jinja @@ -1,3 +1,7 @@ + +{% include "./_def_io.jinja" %} +{% include "./_meminfo.jinja" %} + {#- For name header -#} #ifndef {{ name|upper }}_LAYER_H #define {{ name|upper }}_LAYER_H @@ -5,9 +9,8 @@ {# For layer configuration -#} #define {{ name|upper }}_INPUTS_SIZE {{ in_size[0] }} #define {{ name|upper }}_OUTPUTS_SIZE {{ out_size[0] }} -#define {{ name|upper }}_DIMS {{ in_dims[0] }} #define {{ name|upper }}_AXIS {{ axis }} #define {{ name|upper }}_INPUT_DIMS_SIZE {{ in_dims[0]|length}} - +static const int {{ name|upper }}_DIMS[] = { {{ in_dims[0] | join(', ') }} }; #endif /* {{ name|upper }}_LAYER_H */ diff --git a/aidge_export_arm_cortexm/_Aidge_Arm/templates/forward_call/conv_dw_kernel.jinja b/aidge_export_arm_cortexm/_Aidge_Arm/templates/forward_call/conv_dw_kernel.jinja new file mode 100644 index 0000000000000000000000000000000000000000..af00c262f6e9ce38614cc29e09b2112a078a41f6 --- /dev/null +++ b/aidge_export_arm_cortexm/_Aidge_Arm/templates/forward_call/conv_dw_kernel.jinja @@ -0,0 +1,28 @@ +{% filter indent(width=4, first=False) %} +{% include "./_mem_offset.jinja" %} +N2D2_Export::convcellDWPropagate<{{ in_name[0]|upper }}_NB_CHANNELS, + {{ in_name[0]|upper }}_IN_HEIGHT, + {{ in_name[0]|upper }}_IN_WIDTH, + {{ out_name[0]|upper }}_NB_OUTPUTS, + {{ out_name[0]|upper }}_OUT_HEIGHT, + {{ out_name[0]|upper }}_OUT_WIDTH, + {{ name|upper }}_PADDING_Y, + {{ name|upper }}_PADDING_X, + {{ name|upper }}_STRIDE_Y, + {{ name|upper }}_STRIDE_X, + {{ name|upper }}_KERNEL_HEIGHT, + {{ name|upper }}_KERNEL_WIDTH, + {{ name|upper }}_ACTIVATION, + {{ in_name[0]|upper }}_CONT_OFFSET, + {{ in_name[0]|upper }}_CONT_SIZE, + {{ in_name[0]|upper }}_WRAP_OFFSET, + {{ in_name[0]|upper }}_WRAP_SIZE, + {{ in_name[0]|upper }}_STRIDE, + {{ out_name[0]|upper }}_CONT_OFFSET, + {{ out_name[0]|upper }}_CONT_SIZE, + {{ out_name[0]|upper }}_WRAP_OFFSET, + {{ out_name[0]|upper }}_WRAP_SIZE, + {{ out_name[0]|upper }}_STRIDE> + ({{in_name[0]}}, {{out_name[0]}}, {{in_name[2]}}, {{in_name[1]}}, {{ name|upper }}_SCALING); +{% endfilter %} + diff --git a/aidge_export_arm_cortexm/operators.py b/aidge_export_arm_cortexm/operators.py index 9f006329d46c27b5a6b8952c4c91eab1e08f27a8..b27efa7d0eb0ab2e8bf0965291722ce1452a7c06 100644 --- a/aidge_export_arm_cortexm/operators.py +++ b/aidge_export_arm_cortexm/operators.py @@ -250,8 +250,8 @@ class ConvDW_ARMCortexM(ExportNodeCpp): # Use PaddedConv to add padding attribute self.attributes["padding"] = [0, 0] - self.config_template = str(ROOT / "_Aidge_Arm" / "templates" / "configuration" / "conv_config.jinja") - self.forward_template = str(ROOT / "_Aidge_Arm" / "templates" / "forward_call" / "conv_kernel.jinja") + self.config_template = str(ROOT / "_Aidge_Arm" / "templates" / "configuration" / "conv_dw_config.jinja") + self.forward_template = str(ROOT / "_Aidge_Arm" / "templates" / "forward_call" / "conv_dw_kernel.jinja") self.include_list = [] self.kernels_to_copy = [ str(ROOT / "_Aidge_Arm" / "kernels" / "Convolution" / "ConvDW.hpp") @@ -275,8 +275,8 @@ class PaddedConvDW_ARMCortexM(ExportNodeCpp): self.attributes["dilation_dims"] = n.get_operator( ).attr.dilation_dims - self.config_template = str(ROOT / "_Aidge_Arm" / "templates" / "configuration" / "conv_config.jinja") - self.forward_template = str(ROOT / "_Aidge_Arm" / "templates" / "forward_call" / "conv_kernel.jinja") + self.config_template = str(ROOT / "_Aidge_Arm" / "templates" / "configuration" / "conv_dw_config.jinja") + self.forward_template = str(ROOT / "_Aidge_Arm" / "templates" / "forward_call" / "conv_dw_kernel.jinja") self.include_list = [] self.kernels_to_copy = [ str(ROOT / "_Aidge_Arm" / "kernels" / "Convolution" / "ConvDW.hpp")