hls4ml icon indicating copy to clipboard operation
hls4ml copied to clipboard

BatchNormalization scale and bias array size

Open jmitrevs opened this issue 3 years ago • 2 comments

The normalize function call in both nnet_batchnorm.h and nnet_batchnorm_stream.h has an interface of:

template<class data_T, class res_T, typename CONFIG_T>
void normalize(
    data_T    data[CONFIG_T::n_in],
    res_T     res[CONFIG_T::n_in],
    typename CONFIG_T::scale_t  scale[CONFIG_T::n_in],
    typename CONFIG_T::bias_t   bias[CONFIG_T::n_in]
)

However, in the case when CONFIG_T::n_filt == -1, only the first CONFIG_T::n_filt of the arrays is used. This value is usually much smaller. The code should be updated to reflect this (potentially by me).

Two options that I can think of are to either introduce another constant, say CONFIG::n_scale_bias, that is set appropriately to the size of the scale and bias, or to have separate normailze variants depending on the value of CONFIG_T::n_filt.

jmitrevs avatar Feb 17 '22 16:02 jmitrevs

CONFIG::n_scale_bias approach seems far simpler, but are we sure we won't have to split the functions anyway for optimal QoR?

vloncar avatar Feb 17 '22 16:02 vloncar

This was merged on the Vivado side but not on the Quartus side. Leaving it open till it's fixed there.

jmitrevs avatar Jul 25 '22 16:07 jmitrevs

This was fixed in #749 for Quartus, so closing.

jmitrevs avatar May 12 '23 21:05 jmitrevs