hls4ml icon indicating copy to clipboard operation
hls4ml copied to clipboard

Activation function tables with low precision

Open SerenaC94 opened this issue 3 years ago • 1 comments

Hi, I noticed a potential bug/corner case when using ap_fixed types with low precision.

The default table_size for activation functions is 1024, so in this line N will be 10, and x.width - N can be negative if the data type of x has less than 10 bits.

When I generated a model with ap_fixed<8,6> as default type, I got a lot of these warnings from vivado during csim: WARNING: Higher bound(7) and lower(-2) bound cannot be negative. And then C/RTL cosimulation failed.

I imagine this could be a problem also for other activation functions, not only softmax.

Was this intended, meaning that when the user goes below 10 bits they should also change table_size accordingly? If yes, is it written somewhere in the documentation?

@nicologhielmetti for visibility

SerenaC94 avatar Jul 02 '21 13:07 SerenaC94

Thanks for flagging this. @vloncar I think you encountered it at some point too, right? Or at least I remember you describing that warning too.

In terms of correcting it... maybe we could implement an optimizer pass to modify the table size if it's too large given the input data width.

thesps avatar Jul 06 '21 07:07 thesps