Skip to content
Snippets Groups Projects
Commit 4c08399c authored by Olivier Antoni's avatar Olivier Antoni
Browse files

Fix some operators

parent f774822c
No related branches found
No related tags found
1 merge request!31Fix some operators
Showing
with 110 additions and 138 deletions
#include <math.h>
void aidge_batchnorm2d_chw_float32 (float* inputs,
float* outputs,
float* input_mean,
float* input_var,
float* scale,
float* bias,
float epsilon,
const int nb_channels,
const int channel_width, const int channel_height)
{
int featureMapSize = channel_width * channel_height;
for (int ch = 0; ch < nb_channels; ++ch)
{
int ioIndex = ch * featureMapSize;
for (int i = ioIndex; i < ioIndex + featureMapSize; i++){
outputs[i] = bias[ch];
}
float var =sqrt(input_var[ch] + epsilon);
for (int feature = 0; feature<featureMapSize; ++feature) {
outputs[ioIndex + feature] += scale[ch] * (inputs[ioIndex + feature]-input_mean[ch]) / var;
}
}
}
\ No newline at end of file
#include <math.h>
void aidge_batchnorm2d_chw_float32 (float* inputs,
float* outputs,
float* input_mean,
float* input_var,
float* scale,
float* bias,
float epsilon,
const int nb_channels,
const int channel_width, const int channel_height)
void aidge_batchnorm2d_chw_float32 (const float* inputs,
float* outputs,
const float* input_mean,
const float* input_var,
const float* scale,
const float* bias,
float epsilon,
int nb_channels,
int channel_width,
int channel_height)
{
int featureMapSize = channel_width * channel_height;
for (int ch = 0; ch < nb_channels; ++ch)
......
void aidge_gather_chw_float32 (float* inputs,
float* outputs,
int axis,
int indices[],
int input_dims[],
int size_inputDim,
int indices_size,
unsigned int size)
void aidge_gather_chw_float32 (const float* inputs,
float* outputs,
int axis,
const int indices[],
const int input_dims[],
int size_inputDim,
int indices_size,
int output_size)
{
axis += (axis >= 0 ) ? 0 : size_inputDim;
......
#include <cstring>
template <unsigned int SIZE, typename Input_T, typename Output_T>
template <unsigned int SIZE, typename T>
__attribute__((always_inline)) inline static
void aidge_reshape(Input_T* __restrict input, Output_T* __restrict output, unsigned int size) {
void aidge_reshape(T* __restrict input, T* __restrict output) {
// Copy the input data to the output data
std::memcpy(output, input, size * sizeof(float));
std::memcpy(output, input, SIZE * sizeof(T));
}
\ No newline at end of file
void aidge_reshape_chw_float32(float* inputs,
float* outputs,
unsigned int size)
{
for (int i = 0; i < size; i++){
outputs[i] = inputs[i];
}
}
\ No newline at end of file
#include <math.h>
void aidge_sigmoid_float32 (float* inputs,
float* outputs,
unsigned int size)
{
for (unsigned int i = 0; i < size; ++i) {
outputs[i] = 1 / ( 1 + exp(-inputs[i]) );
}
}
\ No newline at end of file
#include <math.h>
void aidge_softmax_chw_float32(const float* inputs,
float* outputs,
const int inputDims[],
int axis,
const unsigned int size_inputDim,
const unsigned int size)
void aidge_softmax_chw_float32(const float* inputs,
float* outputs,
const int inputDims[],
int axis,
const unsigned int size_inputDim,
const unsigned int output_size)
{
axis += (axis >= 0 ) ? 0 : size_inputDim;
......
void aidge_transpose_chw_float32 (float* inputs,
float* outputs,
int input_dims[],
int perm[],
int output_dims[],
unsigned int size_outputDims,
unsigned int size)
void aidge_transpose_chw_float32 (const float* inputs,
float* outputs,
const int input_dims[],
const int perm[],
const int output_dims[],
unsigned int size_outputDims,
unsigned int output_size)
{
int newStrides[size_outputDims];
for (int i = 0; i<size_outputDims;++i){newStrides[i] = 1;}
......
......@@ -3,12 +3,11 @@
#define {{ name|upper }}_LAYER_H
{# For layer configuration -#}
#define {{ name|upper }}_NB_BATCH {{ in_dims[0] }}
#define {{ name|upper }}_NB_CHANNELS {{ in_dims[1] }}
#define {{ name|upper }}_CHANNELS_HEIGHT {{ in_dims[2] }}
#define {{ name|upper }}_CHANNELS_WIDTH {{ in_dims[3] }}
#define {{ name|upper }}_NB_BATCH {{ in_batch[0] }}
#define {{ name|upper }}_NB_CHANNELS {{ in_chan[0] }}
#define {{ name|upper }}_CHANNELS_HEIGHT {{ in_height[0] }}
#define {{ name|upper }}_CHANNELS_WIDTH {{ in_width[0] }}
#define {{ name|upper }}_EPSILON {{ epsilon }}
#endif /* {{ name|upper }}_LAYER_H */
\ No newline at end of file
......@@ -6,10 +6,11 @@
#define {{name|upper}}_AXIS {{ axis }}
#define {{name|upper}}_INDEXES_DIMS_SIZE {{ indices|length}}
#define {{name|upper}}_INPUT_DIMS_SIZE {{ input_dims|length}}
#define {{name|upper}}_OUTPUT_SIZE {{ nb_outputs}}
static const int {{ name|upper }}_INDEXES[] = { {{ indices|join(", ") }} };
static const int {{ name|upper }}_DIMS[] = { {{ in_dims[0]|join(", ") }} };
#define {{name|upper}}_INDEXES_DIMS_SIZE {{ indices|length }}
#define {{name|upper}}_INPUT_DIMS_SIZE {{ in_dims[0]|length }}
#define {{name|upper}}_OUTPUT_SIZE {{ out_size[0] }}
#endif /* {{ name|upper }}_LAYER_H */
......@@ -7,9 +7,9 @@
{# For layer configuration -#}
static const int {{ in_name[0]|upper }}_DIMS[] = { {{ in_dims[0]|join(", ") }} };
static const int {{ in_name[1]|upper}}_DIMS[] = { {{ in_dims[0]|join(", ") }} };
static const int {{ out_name[0]|upper }}_DIMS[] = { {{ out_dims[0]|join(", ") }} };
static const int {{name|upper}}_INPUT_A_DIMS[] = { {{ in_dims[0]|join(", ") }} };
static const int {{name|upper}}_INPUT_B_DIMS[] = { {{ in_dims[1]|join(", ") }} };
static const int {{name|upper}}_OUTPUT_DIMS[] = { {{ out_dims[0]|join(", ") }} };
#define {{name|upper}}_INPUT_A_DIMS_SIZE {{ in_dims[0]|length}}
#define {{name|upper}}_INPUT_B_DIMS_SIZE {{ in_dims[1]|length}}
......
{#- For name header -#}
#ifndef {{ name|upper }}_LAYER_H
#define {{ name|upper }}_LAYER_H
{% include "./_def_io.jinja" %}
{% include "./_meminfo.jinja" %}
{# For layer configuration -#}
#define {{ name|upper }}_INPUTS_SIZE {{ nb_inputs }}
#define {{ name|upper }}_OUTPUTS_SIZE {{ nb_outputs }}
#define {{ name|upper }}_OUTPUTS_SIZE {{ out_size[0] }}
#endif /* {{ name|upper }}_LAYER_H */
\ No newline at end of file
......@@ -7,14 +7,6 @@
{% include "./_meminfo.jinja" %}
{# For layer configuration -#}
#define {{ name|upper }}_INPUTS_SIZE {{ in_size[0] }}
#define {{ name|upper }}_OUTPUTS_SIZE {{ out_size[0] }}
#define {{in_name[0]|upper}}_NB_DIM {{ in_dims[0]|length}}
#define {{out_name[0]|upper}}_NB_DIM {{ out_dims[0]|length}}
static const int {{ in_name[0]|upper }}_DIMS[] = { {{ in_dims[0]|join(", ") }} };
static const int {{ out_name[0]|upper }}_DIMS[] = { {{ out_dims[0]|join(", ") }} };
#endif /* {{ name|upper }}_LAYER_H */
{% include "./_def_io.jinja" %}
{% include "./_meminfo.jinja" %}
{#- For name header -#}
#ifndef {{ name|upper }}_LAYER_H
#define {{ name|upper }}_LAYER_H
{% include "./_def_io.jinja" %}
{% include "./_meminfo.jinja" %}
{# For layer configuration -#}
#define {{ name|upper }}_AXIS {{ axis }}
#define {{ name|upper }}_INPUTS_SIZE {{ in_size[0] }}
#define {{ name|upper }}_OUTPUTS_SIZE {{ out_size[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(', ') }} };
#define {{ name|upper }}_INPUT_DIMS_SIZE {{ in_dims[0]|length }}
static const int {{ name|upper }}_INPUT_DIMS[] = { {{ in_dims[0] | join(', ') }} };
#endif /* {{ name|upper }}_LAYER_H */
......@@ -3,10 +3,14 @@
#define {{ name|upper }}_LAYER_H
{# For layer configuration -#}
static const int {{ name|upper }}_PERMUTATIONS[] = { {{ output_dims_order|join(", ") }} };
#define {{name|upper}}_OUTPUT_DIMS_SIZE {{ output_dims|length}}
static const int {{ name|upper }}_INPUT_DIMS[] = { {{ in_dims[0]|join(", ") }} };
static const int {{ name|upper }}_OUTPUT_DIMS[] = { {{ out_dims[0]|join(", ") }} };
#define {{name|upper}}_OUTPUT_SIZE {{ nb_outputs}}
#define {{name|upper}}_INPUT_DIMS_SIZE {{ in_dims[0]|length }}
#define {{name|upper}}_OUTPUT_DIMS_SIZE {{ out_dims[0]|length }}
#define {{name|upper}}_OUTPUT_SIZE {{ out_size[0]}}
#endif /* {{ name|upper }}_LAYER_H */
aidge_batchnorm2d_chw_{{dataformat|default("float32") }}
({{in_name}},
{{out_name}},
{{running_mean_name}},
{{running_var_name}},
{{weight_name}},
{{bias_name}},
{{ name|upper }}_EPSILON,
{{ name|upper }}_NB_CHANNELS,
{{ name|upper }}_CHANNELS_WIDTH,
{{ name|upper }}_CHANNELS_HEIGHT);
{% filter indent(width=4, first=False) %}
{% include "./_mem_offset.jinja" %}
aidge_batchnorm2d_chw_float32(
{{in_name[0]}},
{{out_name[0]}},
{{in_name[3]}},
{{in_name[4]}},
{{in_name[1]}},
{{in_name[2]}},
{{name|upper}}_EPSILON,
{{name|upper}}_NB_CHANNELS,
{{name|upper}}_CHANNELS_WIDTH,
{{name|upper}}_CHANNELS_HEIGHT);
{% endfilter %}
aidge_gather_chw_{{dataformat}} ({{input_name}}, {{output_name}}, {{name|upper}}_AXIS, {{name}}_INDEXES , {{input_name}}_DIMS, {{name|upper}}_INPUT_DIMS_SIZE,{{name|upper}}_INDEXES_DIMS_SIZE,{{name|upper}}_OUTPUT_SIZE);
\ No newline at end of file
{% filter indent(width=4, first=False) %}
{% include "./_mem_offset.jinja" %}
aidge_gather_chw_float32(
{{in_name[0]}},
{{out_name[0]}},
{{name|upper}}_AXIS,
{{name|upper}}_INDEXES,
{{name|upper}}_DIMS,
{{name|upper}}_INPUT_DIMS_SIZE,
{{name|upper}}_INDEXES_DIMS_SIZE,
{{name|upper}}_OUTPUT_SIZE);
{% endfilter %}
{% filter indent(width=4, first=False) %}
{% include "./_mem_offset.jinja" %}
aidge_matmul_chw_{{dataformat| default("float32") }}
({{in_name[0]}},
{{in_name[1]}},
{{out_name[0]}},
{{in_name[0]|upper}}_DIMS,
{{in_name[1]|upper}}_DIMS,
{{out_name[0]|upper}}_DIMS,
{{name|upper}}_INPUT_A_DIMS_SIZE,
{{name|upper}}_INPUT_B_DIMS_SIZE,
{{name|upper}}_OUTPUT_DIMS_SIZE);
aidge_matmul_chw_float32(
{{in_name[0]}},
{{in_name[1]}},
{{out_name[0]}},
{{name|upper}}_INPUT_A_DIMS,
{{name|upper}}_INPUT_B_DIMS,
{{name|upper}}_OUTPUT_DIMS,
{{name|upper}}_INPUT_A_DIMS_SIZE,
{{name|upper}}_INPUT_B_DIMS_SIZE,
{{name|upper}}_OUTPUT_DIMS_SIZE);
{% endfilter %}
\ No newline at end of file
{% filter indent(width=4, first=False) %}
{% include "./_mem_offset.jinja" %}
aidge_reshape<{{name|upper}}_OUTPUTS_SIZE>
({{input_name}}, {{output_name}}, {{name|upper}}_OUTPUTS_SIZE);
({{in_name[0]}},
{{out_name[0]}});
{% endfilter %}
\ No newline at end of file
{% filter indent(width=4, first=False) %}
{% include "./_mem_offset.jinja" %}
aidge_softmax_chw_float32({{in_name[0]}}, {{out_name[0]}}, {{name|upper}}_DIMS, {{name|upper}}_AXIS, {{name|upper}}_INPUT_DIMS_SIZE, {{name|upper}}_OUTPUTS_SIZE);
aidge_softmax_chw_float32(
{{in_name[0]}},
{{out_name[0]}},
{{name|upper}}_INPUT_DIMS,
{{name|upper}}_AXIS,
{{name|upper}}_INPUT_DIMS_SIZE,
{{name|upper}}_OUTPUTS_SIZE);
{% endfilter %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment