Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to synthesize QKeras CNN model: Internal stream failed dataflow checking: it must be produced and consumed exactly once. #1105

Open
2 of 4 tasks
AnouarITI opened this issue Oct 30, 2024 · 0 comments
Labels

Comments

@AnouarITI
Copy link

AnouarITI commented Oct 30, 2024

Prerequisites

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

Quick summary

During synthesis, an Internal stream failed dataflow checking: it must be produced and consumed exactly once.

Details

I trained a QKeras CNN model containing ~35K parameters and then i converted it to an HLS model using resources strategy and a reuse factor of 32. However when I try to synthesize the model I always get errors complaining that an an Internal stream '----' failed dataflow checking: it must be produced and consumed exactly once.

Steps to Reproduce

import os
os.environ['PATH'] = "/home/user/Xilinx/Vivado/2020.1/bin:" + os.environ['PATH']

from datetime import datetime
import numpy as np
import tensorflow as tf
import tensorboard

print(tf.__version__)
print(tensorboard.__version__)
from tensorflow import keras
from keras.models import Model
from keras.optimizers import Adam
from tensorflow.keras.layers import Activation, Flatten, MaxPool2D, AveragePooling2D, InputLayer
from qkeras import QDense, QActivation, QConv2D, QBatchNormalization
from qkeras.quantizers import quantized_bits, quantized_relu

model = keras.Sequential([
    InputLayer(input_shape=(32, 32, 2), name='rf_in'),
    
    QConv2D(32, (5,5), kernel_quantizer=quantized_bits(6, 0, alpha=1),
            bias_quantizer=quantized_bits(6, 0, alpha=1),
            kernel_initializer='lecun_uniform', name='cv_1'),
    QBatchNormalization(name='BN_1'),
    QActivation(activation=quantized_relu(6), name='relu_1'),
    MaxPool2D(2, strides = (2,2),name='mp_1'),

    QConv2D(32, (5,5), kernel_quantizer=quantized_bits(6, 0, alpha=1),
            bias_quantizer=quantized_bits(6, 0, alpha=1),
            kernel_initializer='lecun_uniform', name='cv_2'),
    QBatchNormalization(name='BN_2'),
    QActivation(activation=quantized_relu(6), name='relu_2'),
    MaxPool2D(2, strides = (2,2),name='mp_2'),

    QConv2D(16, (3,3), kernel_quantizer=quantized_bits(6, 0, alpha=1),
            bias_quantizer=quantized_bits(6, 0, alpha=1),
            kernel_initializer='lecun_uniform', name='cv_3'),
    QBatchNormalization(name='BN_3'),
    QActivation(activation=quantized_relu(6), name='relu_3'),
    AveragePooling2D(2, strides = (4,4), name='ap_3'),

    Flatten(),

    QDense(64, kernel_quantizer=quantized_bits(6, 0, alpha=1), bias_quantizer=quantized_bits(6, 0, alpha=1),
           kernel_initializer='lecun_uniform', name='d1'),
    QActivation(activation=quantized_relu(6), name='relu_4'),
    QDense(32, kernel_quantizer=quantized_bits(6, 0, alpha=1), bias_quantizer=quantized_bits(6, 0, alpha=1),
           kernel_initializer='lecun_uniform', name='d2'),
    QActivation(activation=quantized_relu(6), name='relu_5'),
    QDense(7, kernel_quantizer=quantized_bits(6, 0, alpha=1), bias_quantizer=quantized_bits(6, 0, alpha=1),
           kernel_initializer='lecun_uniform', name='d3'),
    Activation(activation='softmax'),
])

from tensorflow.keras.models import load_model
from qkeras.utils import _add_supported_quantized_objects

co = {}
_add_supported_quantized_objects(co)
model = load_model('CNN_Q6_0.h5', custom_objects=co)

adam = Adam(lr=0.0001)
model.compile(optimizer=adam, loss=['categorical_crossentropy'], metrics=['accuracy'])

import hls4ml
print(hls4ml.__version__)

config = hls4ml.utils.config_from_keras_model(model, granularity='name', default_reuse_factor=32)
config['Model']['Strategy']= 'Resource'
config['LayerName']['activation']['exp_table_t'] = 'ap_fixed<18,8>'
config['LayerName']['activation']['inv_table_t'] = 'ap_fixed<18,4>'

hls_model = hls4ml.converters.convert_from_keras_model(
    model, 
    hls_config=config, 
    io_type='io_stream',
    backend='VivadoAccelerator',
    output_dir='cnn_6_0', 
    part='xczu9eg-ffvb1156-2-e')

print(config)

hls_model.compile()

hls_model.build(synth=True, csim=False, export=False)

Error

resource.h:274->firmware/nnet_utils/nnet_conv_stream.h:279->firmware/nnet_utils/nnet_conv2d_stream.h:85->firmware/nnet_utils/nnet_conv2d_stream.h:103) automatically.
INFO: [XFORM 203-721] Changing loop 'Loop_1_proc' (firmware/myproject_axi.cpp:23) to a process function for dataflow in function 'myproject_axi'.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[0].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[1].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[2].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[3].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[4].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[5].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[6].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[7].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[8].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[9].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[10].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[11].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[12].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[13].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[14].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
WARNING: [XFORM 203-731] Internal stream variable 'layer15_out.V.data[15].V' (firmware/myproject.cpp:110) is invalid: it has no data consumer.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[0].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[0].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[1].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[1].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[2].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[2].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[3].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[3].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[4].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[4].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[5].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[5].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[6].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[6].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[7].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[7].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[8].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[8].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[9].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[9].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[10].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[10].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[11].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[11].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[12].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[12].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[13].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[13].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[14].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[14].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [XFORM 203-711] Internal stream 'layer15_out.V.data[15].V' failed dataflow checking: it must be produced and consumed exactly once.
WARNING: [XFORM 203-713] Variable 'layer15_out.V.data[15].V' has write operations in process function 'nnet::relu<nnet::array<ap_fixed<16, 6, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, nnet::array<ap_ufixed<6, 0, (ap_q_mode)5, (ap_o_mode)3, 0>, 16u>, relu_config15>'.
ERROR: [HLS 200-70] Pre-synthesis failed.
command 'ap_source' returned error code
    while executing
"source build_prj.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel \#0 [list source $arg] "

INFO: [Common 17-206] Exiting vivado_hls at Wed Oct 30 15:55:39 2024...

Here is the generated hls project:
cnn_6_0.tar.gz

@AnouarITI AnouarITI added the bug label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant