fastmachinelearning / hls4ml

Machine learning on FPGAs using HLS
https://fastmachinelearning.org/hls4ml
Apache License 2.0
1.16k stars 386 forks source link

"warning: integer constant is so large that it is unsigned" causes hls_model.compile() to fail #1011

Open RikPi opened 1 month ago

RikPi commented 1 month ago

Prerequisites

Please make sure to check off these prerequisites before submitting a bug report.

Quick summary

Since I added a LSTM/GRU layer after my CNN, it won't compile, reporting multiple overflow errors. I am running hls4ml 0.8.1 on a Ubuntu 22.04 (with CUDA) Docker, Vivado is 2019.1. I have deleted Vivado's own ld executable and linked the system one to make it work with Ubuntu 22.04. The compilation works when I have just a CNN.

The first warning messages I get are:

In file included from firmware/myproject.cpp:4:
firmware/parameters.h:96:764: warning: integer constant is so large that it is unsigned
   96 | const ap_uint<config2::filt_height * config2::filt_width> config2::pixels[] = [OMITTED]

And the error log terminates with:

/usr/bin/ld: cannot find myproject.o: No such file or directory
collect2: error: ld returned 1 exit status

A full log is available as attachment below.

Please let me know if I can provide more useful context and thank you, keep up the good work!

Details

Steps to Reproduce

This is my config code:

import hls4ml
import plotting

# Import model
hls_config = hls4ml.utils.config_from_keras_model(model_loaded, granularity='name')

# Set model config
hls_config['Model']['Precision'] = 'ap_fixed<24,6>'
hls_config['Model']['ReuseFactor'] = 1
hls_config['Model']['Strategy'] = 'Latency'

# Set layer config
for Layer in hls_config['LayerName'].keys():
    hls_config['LayerName'][Layer]['Strategy'] = 'Latency'
    hls_config['LayerName'][Layer]['ReuseFactor'] = 1
    hls_config['LayerName'][Layer]['Precision'] = 'ap_fixed<24,6>'

# Last layer stable
hls_config['LayerName']['output_dense']['Strategy'] = 'Stable'
plotting.print_dict(hls_config)

# Generate config for Vivado
cfg = hls4ml.converters.create_config(backend='VivadoAccelerator', part= 'XCZU7EV-FFVC1156-2-E')
cfg['IOType'] = 'io_stream'
cfg['HLSConfig'] = hls_config
cfg['KerasModel'] = model_loaded
cfg['OutputDir'] = 'COSMIC_CRNN_LSTM_98/'
cfg['Board'] = 'zcu106'
cfg['Part'] = 'XCZU7EV-FFVC1156-2-E'
cfg['XilinxPart'] = 'XCZU7EV-FFVC1156-2-E'
cfg['Interface'] = 'axi_stream'
cfg['InputData'] = 'X_test.npy'
cfg['OutputPredictions'] = 'Y_test.npy'

hls_model = hls4ml.converters.keras_to_hls(cfg)
hls_model.compile()

After I run it, I get the following error: hls4ml_error.txt

Expected behavior

The model should compile.

Actual behavior

The model does not compile.

Optional

Possible fix

I am not very familiar with C++ or the inner workings of Tensorflow/hls4ml but there could be something wrong in the way the LSTM/GRU layer is generated in HLS.

Additional context