From 9444564e20ca7757bb89dd7f0895b73464697d19 Mon Sep 17 00:00:00 2001
From: cmoineau <cyril.moineau@cea.fr>
Date: Fri, 19 Jul 2024 11:33:37 +0000
Subject: [PATCH] Update _def_io template and reflect changes in operator
 templates.

---
 .../templates/configuration/_def_io.jinja        | 16 ++++++++++------
 .../configuration/activation_config.jinja        |  1 +
 .../configuration/elemwise_config.jinja          |  1 +
 .../configuration/leakyrelu_config.jinja         |  1 +
 .../templates/kernel_forward/_save_outputs.jinja | 11 ++++++-----
 .../kernel_forward/batchnorm_forward.jinja       |  6 +++---
 .../kernel_forward/convolution_forward.jinja     | 12 ++++++------
 .../kernel_forward/fullyconnected_forward.jinja  | 12 ++++++------
 .../kernel_forward/pooling_forward.jinja         | 12 ++++++------
 .../templates/network/network_forward.jinja      |  2 +-
 10 files changed, 41 insertions(+), 33 deletions(-)

diff --git a/aidge_export_cpp/templates/configuration/_def_io.jinja b/aidge_export_cpp/templates/configuration/_def_io.jinja
index 9770465..e8330d9 100644
--- a/aidge_export_cpp/templates/configuration/_def_io.jinja
+++ b/aidge_export_cpp/templates/configuration/_def_io.jinja
@@ -1,8 +1,12 @@
 {# NOTE: Suppose input is first #}
-#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 }}_NB_OUTPUTS {{ out_chan[0] }}
-#define {{ name|upper }}_OUTPUTS_HEIGHT {{ out_height[0] }}
-#define {{ name|upper }}_OUTPUTS_WIDTH {{ out_width[0] }}
 
+{% for inidx in range(nb_in) -%}
+#define {{ in_name[inidx]|upper }}_NB_CHANNELS {{ in_chan[inidx] }}
+#define {{ in_name[inidx]|upper }}_IN_HEIGHT {{ in_height[inidx] }}
+#define {{ in_name[inidx]|upper }}_IN_WIDTH {{ in_width[inidx] }}
+{% endfor %}
+{% for outidx in range(nb_out) -%}
+#define {{ out_name[outidx]|upper }}_NB_OUTPUTS {{ out_chan[outidx] }}
+#define {{ out_name[outidx]|upper }}_OUT_HEIGHT {{ out_height[outidx] }}
+#define {{ out_name[outidx]|upper }}_OUT_WIDTH {{ out_width[outidx] }}
+{% endfor %}
diff --git a/aidge_export_cpp/templates/configuration/activation_config.jinja b/aidge_export_cpp/templates/configuration/activation_config.jinja
index 240e86b..f9535e7 100644
--- a/aidge_export_cpp/templates/configuration/activation_config.jinja
+++ b/aidge_export_cpp/templates/configuration/activation_config.jinja
@@ -6,6 +6,7 @@
 {%- set nb_data = in_chan[0] * in_height[0] * in_width[0] %}
 #define {{ name|upper }}_NB_DATA {{ nb_data }}
 #define {{ name|upper }}_ACTIVATION {{ activation }}
+{% include "./_def_io.jinja" %}
 {% include "./_meminfo.jinja" %}
 static const {{ rescaling }} {{ name|upper }}_RESCALING = {};
 
diff --git a/aidge_export_cpp/templates/configuration/elemwise_config.jinja b/aidge_export_cpp/templates/configuration/elemwise_config.jinja
index 2c5c436..fc801f1 100644
--- a/aidge_export_cpp/templates/configuration/elemwise_config.jinja
+++ b/aidge_export_cpp/templates/configuration/elemwise_config.jinja
@@ -2,6 +2,7 @@
 #ifndef {{ name|upper }}_LAYER_H
 #define {{ name|upper }}_LAYER_H
 
+{% include "./_def_io.jinja" %}
 {% include "./_meminfo.jinja" %}
 {# For layer configuration -#}
 #define {{ name|upper }}_NB_ELTS {{ in_dims[0]|join('*') }}
diff --git a/aidge_export_cpp/templates/configuration/leakyrelu_config.jinja b/aidge_export_cpp/templates/configuration/leakyrelu_config.jinja
index d8377de..8090362 100644
--- a/aidge_export_cpp/templates/configuration/leakyrelu_config.jinja
+++ b/aidge_export_cpp/templates/configuration/leakyrelu_config.jinja
@@ -3,6 +3,7 @@
 #define {{ name|upper }}_LAYER_H
 
 {# For layer configuration -#}
+{% include "./_def_io.jinja" %}
 {% include "./_meminfo.jinja" %}
 #define {{ name|upper }}_NB_DATA {{ nb_data }}
 #define {{ name|upper }}_ALPHA {{ alpha }}
diff --git a/aidge_export_cpp/templates/kernel_forward/_save_outputs.jinja b/aidge_export_cpp/templates/kernel_forward/_save_outputs.jinja
index 1b2a698..ddefc0c 100644
--- a/aidge_export_cpp/templates/kernel_forward/_save_outputs.jinja
+++ b/aidge_export_cpp/templates/kernel_forward/_save_outputs.jinja
@@ -1,18 +1,19 @@
-/* COMMENTED FOR THE MOMENT
+/*
 #ifdef SAVE_OUTPUTS
 {% for outidx in range(nb_out) -%}
     FILE* {{out_name[outidx]|upper}}_STREAM = fopen("outputs/{{out_name[outidx]}}.txt", "w");
-    saveOutputs(
+    saveOutputs<{{out_cdtype[outidx]}}>(
         {{out_name[outidx]|upper}}_NB_OUTPUTS,
-        {{out_name[outidx]|upper}}_OUTPUTS_HEIGHT,
-        {{out_name[outidx]|upper}}_OUTPUTS_WIDTH,
+        {{out_name[outidx]|upper}}_OUT_HEIGHT,
+        {{out_name[outidx]|upper}}_OUT_WIDTH,
         {{out_name[outidx]|upper}}_CONT_OFFSET,
         {{out_name[outidx]|upper}}_CONT_SIZE,
         {{out_name[outidx]|upper}}_WRAP_OFFSET,
         {{out_name[outidx]|upper}}_WRAP_SIZE,
         {{out_name[outidx]|upper}}_STRIDE,
         {{out_name[outidx]}},
-        {{out_name[outidx]|upper}}_STREAM, Network::Format::CHW);
+        {{out_name[outidx]|upper}}_STREAM,
+        Format::{{out_format[outidx]}});
     fclose({{out_name[outidx]|upper}}_STREAM);
 {% endfor %}
 #endif
diff --git a/aidge_export_cpp/templates/kernel_forward/batchnorm_forward.jinja b/aidge_export_cpp/templates/kernel_forward/batchnorm_forward.jinja
index 4bf5191..86dfb9b 100644
--- a/aidge_export_cpp/templates/kernel_forward/batchnorm_forward.jinja
+++ b/aidge_export_cpp/templates/kernel_forward/batchnorm_forward.jinja
@@ -1,6 +1,6 @@
-batchnorm_forward<{{name|upper}}_NB_OUTPUTS,
-                  {{name|upper}}_OUTPUTS_HEIGHT,
-                  {{name|upper}}_OUTPUTS_WIDTH,
+batchnorm_forward<{{ out_name[0]|upper }}_NB_OUTPUTS,
+                  {{ out_name[0]|upper }}_OUT_HEIGHT,
+                  {{ out_name[0]|upper }}_OUT_WIDTH,
                   {{name|upper}}_ACTIVATION>
                   ({{input_name}}, {{output_name}}, {{biases_name}}, {{variances_name}}, {{means_name}}, {{scales_name}}, {{name|upper}}_EPSILON);
 {% include "./_save_outputs.jinja" %}
diff --git a/aidge_export_cpp/templates/kernel_forward/convolution_forward.jinja b/aidge_export_cpp/templates/kernel_forward/convolution_forward.jinja
index e51fa3b..59f2187 100644
--- a/aidge_export_cpp/templates/kernel_forward/convolution_forward.jinja
+++ b/aidge_export_cpp/templates/kernel_forward/convolution_forward.jinja
@@ -1,12 +1,12 @@
 {% if not is_output %}
 {{out_cdtype[0]}}* {{out_name[0]}} = ({{out_cdtype[0]}}*) mem + {{out_name[0]|upper}}_OFFSET;
 {% endif %}
-convolution_forward<{{name|upper}}_NB_CHANNELS,
-                    {{name|upper}}_CHANNELS_HEIGHT,
-                    {{name|upper}}_CHANNELS_WIDTH,
-                    {{name|upper}}_NB_OUTPUTS,
-                    {{name|upper}}_OUTPUTS_HEIGHT,
-                    {{name|upper}}_OUTPUTS_WIDTH,
+convolution_forward<{{ 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,
diff --git a/aidge_export_cpp/templates/kernel_forward/fullyconnected_forward.jinja b/aidge_export_cpp/templates/kernel_forward/fullyconnected_forward.jinja
index e0043ed..bb1e5f4 100644
--- a/aidge_export_cpp/templates/kernel_forward/fullyconnected_forward.jinja
+++ b/aidge_export_cpp/templates/kernel_forward/fullyconnected_forward.jinja
@@ -1,12 +1,12 @@
 {% if not is_output %}
 {{out_cdtype[0]}}* {{out_name[0]}} = ({{out_cdtype[0]}}*) mem + {{out_name[0]|upper}}_OFFSET;
 {% endif %}
-fullyconnected_forward<{{name|upper}}_NB_CHANNELS,
-                       {{name|upper}}_CHANNELS_HEIGHT,
-                       {{name|upper}}_CHANNELS_WIDTH,
-                       {{name|upper}}_NB_OUTPUTS,
-                       {{name|upper}}_OUTPUTS_HEIGHT,
-                       {{name|upper}}_OUTPUTS_WIDTH,
+fullyconnected_forward<{{ 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}}_ACTIVATION>
                        ({{in_name[0]}}, {{out_name[0]}}, {{in_name[1]}}, {{in_name[2]}}, {{name|upper}}_RESCALING);
 {% include "./_save_outputs.jinja" %}
diff --git a/aidge_export_cpp/templates/kernel_forward/pooling_forward.jinja b/aidge_export_cpp/templates/kernel_forward/pooling_forward.jinja
index c70bba6..4797308 100644
--- a/aidge_export_cpp/templates/kernel_forward/pooling_forward.jinja
+++ b/aidge_export_cpp/templates/kernel_forward/pooling_forward.jinja
@@ -1,12 +1,12 @@
 {% if not is_output %}
 {{out_cdtype[0]}}* {{out_name[0]}} = ({{out_cdtype[0]}}*) mem + {{out_name[0]|upper}}_OFFSET;
 {% endif %}
-pooling_forward<{{name|upper}}_NB_CHANNELS,
-                {{name|upper}}_CHANNELS_HEIGHT,
-                {{name|upper}}_CHANNELS_WIDTH,
-                {{name|upper}}_NB_OUTPUTS,
-                {{name|upper}}_OUTPUTS_HEIGHT,
-                {{name|upper}}_OUTPUTS_WIDTH,
+pooling_forward<{{ 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,
diff --git a/aidge_export_cpp/templates/network/network_forward.jinja b/aidge_export_cpp/templates/network/network_forward.jinja
index 863fefd..592e8c9 100644
--- a/aidge_export_cpp/templates/network/network_forward.jinja
+++ b/aidge_export_cpp/templates/network/network_forward.jinja
@@ -25,7 +25,7 @@ void model_forward({% for inp in inputs %}const {{inp[0]}}* {{inp[1]}}, {% endfo
 
     #ifdef SAVE_OUTPUTS
     // Creation of the outputs directory
-    struct stat st = {0};
+    struct stat st {};
     if (stat("outputs", &st) == -1) {
         mkdir("outputs", 0700);
     }
-- 
GitLab