Skip to content
Snippets Groups Projects
Commit 1ccec6ee authored by Axel Farrugia's avatar Axel Farrugia
Browse files

[Feat] Add float support for aidge_cmp feature

parent b478eed8
No related branches found
No related tags found
2 merge requests!710.4.0,!58Fix the aidge_cmp feature
...@@ -160,7 +160,10 @@ int get_ofst_from_fmt(int out, int h, int w) { ...@@ -160,7 +160,10 @@ int get_ofst_from_fmt(int out, int h, int w) {
template<int NB_OUTPUTS, int OUT_WIDTH, int OUT_HEIGHT, Format AIDGE_FMT, Format DEV_FMT, typename AidgeOutput_T, typename DevOutput_T> template<int NB_OUTPUTS, int OUT_WIDTH, int OUT_HEIGHT, Format AIDGE_FMT, Format DEV_FMT, typename AidgeOutput_T, typename DevOutput_T>
void aidge_cmp(std::string layer_name, AidgeOutput_T* aidge_output, DevOutput_T* dev_output) { void aidge_cmp(std::string layer_name, AidgeOutput_T* aidge_output, DevOutput_T* dev_output) {
printf("[AIDGE COMPARE] - %s\n", layer_name.c_str()); printf("[NOTICE] - Comparing with Aidge ref for node : %s -> ", layer_name.c_str());
const float atol = 1e-5f; // Absolute
const float rtol = 1e-3f; // Relative
for (auto out = 0; out < NB_OUTPUTS; ++out) { for (auto out = 0; out < NB_OUTPUTS; ++out) {
for (auto h = 0; h < OUT_HEIGHT; ++h) { for (auto h = 0; h < OUT_HEIGHT; ++h) {
...@@ -170,20 +173,34 @@ void aidge_cmp(std::string layer_name, AidgeOutput_T* aidge_output, DevOutput_T* ...@@ -170,20 +173,34 @@ void aidge_cmp(std::string layer_name, AidgeOutput_T* aidge_output, DevOutput_T*
const int dev_ofst = get_ofst_from_fmt<NB_OUTPUTS, OUT_WIDTH, OUT_HEIGHT, DEV_FMT>(out, h, w); const int dev_ofst = get_ofst_from_fmt<NB_OUTPUTS, OUT_WIDTH, OUT_HEIGHT, DEV_FMT>(out, h, w);
if (aidge_ofst == -1 || dev_ofst == -1) { if (aidge_ofst == -1 || dev_ofst == -1) {
printf("[FAILURE]\n");
printf("[ERROR] - Aborting this layer comparison...\n"); printf("[ERROR] - Aborting this layer comparison...\n");
return; return;
} }
if (aidge_output[aidge_ofst] != dev_output[dev_ofst]) { // Float Comparison
if (std::is_floating_point<DevOutput_T>::value) { if (std::is_floating_point<DevOutput_T>::value) {
printf("[ERROR] - First error detected at %dx%dx%d (out x h x w) : aidge_out = %f vs dev_out = %f\n",
out, h, w, static_cast<double>(aidge_output[aidge_ofst]), static_cast<double>(dev_output[dev_ofst])); const float diff = std::abs(aidge_output[aidge_ofst] - dev_output[dev_ofst]);
} else { const float tolerance = atol + rtol * std::abs(dev_output[dev_ofst]);
if (diff > tolerance) {
printf("[FAILURE]\n");
printf("[ERROR] - First error detected at %dx%dx%d (out x h x w) : aidge_out = %f vs dev_out = %f\n",
out, h, w, static_cast<double>(aidge_output[aidge_ofst]), static_cast<double>(dev_output[dev_ofst]));
printf("Abort program.\n");
exit(1);
}
// Int Comparison
} else {
if (aidge_output[aidge_ofst] != dev_output[dev_ofst]) {
printf("[FAILURE]\n");
printf("[ERROR] - First error detected at %dx%dx%d (out x h x w) : aidge_out = %d vs dev_out = %d\n", printf("[ERROR] - First error detected at %dx%dx%d (out x h x w) : aidge_out = %d vs dev_out = %d\n",
out, h, w, static_cast<int>(aidge_output[aidge_ofst]), static_cast<int>(dev_output[dev_ofst])); out, h, w, static_cast<int>(aidge_output[aidge_ofst]), static_cast<int>(dev_output[dev_ofst]));
printf("[ERROR] - Abort program.\n");
exit(1);
} }
printf("Abort program.\n");
exit(1);
} }
} }
} }
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
#define {{name|upper}}_FMT Format::{{ dformat | upper }} #define {{name|upper}}_FMT Format::{{ dformat | upper }}
{%- set format_map = {
"int8_t": "%4d",
"int32_t": "%6d",
"float": "%.9f"
} %}
static const {{ dtype }} {{ name }} static const {{ dtype }} {{ name }}
{%- for dim in dims -%} {%- for dim in dims -%}
[{{ dim }}] [{{ dim }}]
...@@ -13,7 +19,7 @@ static const {{ dtype }} {{ name }} ...@@ -13,7 +19,7 @@ static const {{ dtype }} {{ name }}
{%- if dims | length == 1 -%} {%- if dims | length == 1 -%}
{{ '{' }} {{ '{' }}
{%- for x in range(dims[0]) -%} {%- for x in range(dims[0]) -%}
{{ "%4d" | format(values[x]) }}, {{ format_map[dtype] | format(values[x]) }},
{%- endfor -%} {%- endfor -%}
{{ '}' }}; {{ '}' }};
{%- endif -%} {%- endif -%}
...@@ -23,7 +29,7 @@ static const {{ dtype }} {{ name }} ...@@ -23,7 +29,7 @@ static const {{ dtype }} {{ name }}
{%- for y in range(dims[0]) -%} {%- for y in range(dims[0]) -%}
{{ '{' }} {{ '{' }}
{%- for x in range(dims[1]) -%} {%- for x in range(dims[1]) -%}
{{ "%4d" | format(values[y][x]) }}, {{ format_map[dtype] | format(values[y][x]) }},
{%- endfor -%} {%- endfor -%}
{{ '}' }}, {{ '}' }},
{%- endfor -%} {%- endfor -%}
...@@ -36,7 +42,7 @@ static const {{ dtype }} {{ name }} ...@@ -36,7 +42,7 @@ static const {{ dtype }} {{ name }}
{%- for y in range(dims[1]) %} {%- for y in range(dims[1]) %}
{{ '{' }} {{ '{' }}
{%- for x in range(dims[2]) -%} {%- for x in range(dims[2]) -%}
{{ "%4d" | format(values[z][y][x]) }}, {{ format_map[dtype] | format(values[z][y][x]) }},
{%- endfor -%} {%- endfor -%}
{{ '}' }}, {{ '}' }},
{%- endfor %} {%- endfor %}
...@@ -53,7 +59,7 @@ static const {{ dtype }} {{ name }} ...@@ -53,7 +59,7 @@ static const {{ dtype }} {{ name }}
{%- for y in range(dims[2]) %} {%- for y in range(dims[2]) %}
{{ '{' }} {{ '{' }}
{%- for x in range(dims[3]) -%} {%- for x in range(dims[3]) -%}
{{ "%4d" | format(values[n][z][y][x]) }}, {{ format_map[dtype] | format(values[n][z][y][x]) }},
{%- endfor -%} {%- endfor -%}
{{ '}' }}, {{ '}' }},
{%- endfor %} {%- endfor %}
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{%- set format_map = { {%- set format_map = {
"int8_t": "%4d", "int8_t": "%4d",
"int32_t": "%6d", "int32_t": "%6d",
"float": "%8.3f" "float": "%.9f"
} %} } %}
{# Design header of the array -#} {# Design header of the array -#}
......
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