Generic Implementation of Global Average Pooling Fails for Integer Types
In the file: aidge_backend_cpu/include/aidge/backend/cpu/operator/GlobalAveragePoolingImpl_kernels.hpp
The current implementation of the GlobalAveragePoolingImpl_cpu_forward_kernel
function does not correctly handle integer types. The issue arises because the function uses fmaf
to compute the mean, which is not suitable for integer types. This leads to incorrect results when the input tensor contains integer values.
The function assumes that the input type I
and output type O
can be cast to and from floating-point numbers, which is not valid for integer types. Specifically, the line
mean = fmaf(filter_start[i] - mean, 1.0f/(i+1), mean);
uses fmaf
, which operates on float
values. When I
is an integer type, this results in incorrect calculations due to improper type handling.
I suggest to handle integer types separately by accumulating the sum of integer values and then performing integer division to compute the mean