hls4ml icon indicating copy to clipboard operation
hls4ml copied to clipboard

Error while building hls_model. Cannot partition array 'tmp.data.V': array access out of bound.

Open B-Willems opened this issue 3 years ago • 0 comments

Quick summary

When trying to put a custom model through the hls4ml toolchain, I encountered an error when building the model using Vivado HLS. The error reads: ERROR: [XFORM 203-103] Cannot partition array 'tmp.data.V': array access out of bound (firmware/nnet_utils/nnet_merge_stream.h:392:16).

Details

Im on the latest master branch of the code (installed through setup.py). This bug only occurs on my custom model, not on the tutorials.

Steps to Reproduce

  1. load the model model = load_model('../import_models/model_compact_easy.h5')
  2. convert model
`import hls4ml
import plotting

hls4ml.model.optimizer.passes.qkeras.OutputRoundingSaturationMode.layers = ['Activation']
hls4ml.model.optimizer.passes.qkeras.OutputRoundingSaturationMode.rounding_mode = 'AP_RND'
hls4ml.model.optimizer.passes.qkeras.OutputRoundingSaturationMode.saturation_mode = 'AP_SAT'

#First, the baseline model
hls_config = hls4ml.utils.config_from_keras_model(model, granularity='name')

# Set the precision and reuse factor for the full model
hls_config['Model']['Precision'] = 'ap_fixed<16,6>'
hls_config['Model']['ReuseFactor'] = 64
hls_config['Model']['Strategy'] = 'resource'

# Create an entry for each layer, here you can for instance change the strategy for a layer to 'resource' 
# or increase the reuse factor individually for large layers.
# In this case, we designed the model to be small enough for a fully parallel implementation 
# so we use the latency strategy and reuse factor of 1 for all layers.
for Layer in hls_config['LayerName'].keys():
    hls_config['LayerName'][Layer]['Strategy'] = 'resource'
    hls_config['LayerName'][Layer]['ReuseFactor'] = 64
#If you want best numerical performance for high-accuray models, while the default latency strategy is faster but numerically more unstable
hls_config['LayerName']['inference']['Strategy'] = 'Stable'
hls_config['LayerName']['power']['Strategy'] = 'Stable'
hls_config['LayerName']['modcod']['Strategy'] = 'Stable'
hls_config['LayerName']['snr']['Strategy'] = 'Stable'
#plotting.print_dict(hls_config)

cfg = hls4ml.converters.create_config(backend='Vivado')
cfg['IOType']     = 'io_stream' # Must set this if using CNNs!
cfg['HLSConfig']  = hls_config
cfg['KerasModel'] = model
cfg['OutputDir']  = 'pruned_cnn/'
cfg['XilinxPart'] = 'xcu250-figd2104-2L-e'
  
hls_model = hls4ml.converters.keras_to_hls(cfg)`
  1. compile model hls_model.compile()

  2. build model hls_model.build(csim=False, synth=True, vsynth=True)

Expected behavior

Expected the model to build.

Actual behavior

Building the model throws an error.

Additional context

I use vivado HLS 2020.1 model attached. Vivado log attached vivado_hls.log . model_compact_easy.zip

Update

After some digging in the .log files i think the problem has to do with the concatenate layers used in the model. I have no clue on how to fix the problem though...

B-Willems avatar Jul 07 '22 11:07 B-Willems