Custom Op - fpgadataflow

Submodules

HW Custom Op Nodes

Base Class - HWCustomOp

class finn.custom_op.fpgadataflow.hwcustomop.HWCustomOp(onnx_node, **kwargs)

Bases: CustomOp

HWCustomOp class all custom ops that can be implemented with either HLS or RTL backend are based on. Contains different functions every fpgadataflow custom node should have. Some as abstract methods, these have to be filled when writing a new fpgadataflow custom op node.

bram_efficiency_estimation()

Function for BRAM efficiency estimation: actual parameter storage needed divided by the allocated BRAM storage (from estimation)

bram_estimation()

Function for BRAM resource estimation, is member function of HWCustomOp class but has to be filled by every node

derive_characteristic_fxns(period, override_rtlsim_dict=None)

Return the unconstrained characteristic functions for this node.

dsp_estimation()

Function for DSP resource estimation, is member function of HWCustomOp class but has to be filled by every node

generate_params(model, path)

Function to generate parameters (i.e. weights and thresholds), is member function of HWCustomOp class but has to be filled by every node that needs to generate parameters.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input stream ind.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_instream_width_padded(ind=0)

Returns input stream width padded to a multiple of 8. This is required by the AXI Stream spec.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

abstract get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_op_and_param_counts()

Return a dictionary with number of ops needed per inference for this layer as well as parameter count (weights, thresholds, etc.). Entries should be in the format: {op_<optype> : <count>, param_<paramtype>: <count>}.

get_output_datatype(ind=0)

Returns FINN DataType of output stream ind.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_outstream_width_padded(ind=0)

Returns output stream width padded to a multiple of 8. This is required by the AXI Stream spec.

get_rtlsim()

Return a PyVerilator wrapper for the Verilator emulation library for this node.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

get_verilog_top_module_name()

Return the Verilog top module name for this node.

lut_estimation()

Function for LUT resource estimation, is member function of HWCustomOp class but has to be filled by every node

node_res_estimation()

Returns summarized resource estimation of BRAMs and LUTs of the node as a dictionary.

reset_rtlsim(sim)

Sets reset input in pyverilator to zero, toggles the clock and set it back to one

rtlsim(sim, inp, inp2=None)

Runs the pyverilator simulation by passing the input values to the simulation, toggle the clock and observing the execution time. Function contains also an observation loop that can abort the simulation if no output value is produced after 100 cycles.

rtlsim_multi_io(sim, io_dict)

Run rtlsim for this node, supports multiple i/o streams.

toggle_clk(sim)

Toggles the clock input in pyverilator once.

uram_efficiency_estimation()

Function for URAM efficiency estimation: actual parameter storage needed divided by the allocated URAM storage (from estimation)

uram_estimation()

Function for UltraRAM resource estimation, is member function of HWCustomOp class but has to be filled by every node

HLSBackend

class finn.custom_op.fpgadataflow.hlsbackend.HLSBackend

Bases: ABC

HLSBackend class all custom ops that correspond to a finn-hlslib function are using functionality of. Contains different functions every HLS custom node should have. Some as abstract methods, these have to be filled when writing a new HLS custom op node.

abstract blackboxfunction()

Function to generate a blackbock function in c++ from which an IP block will be generated, is member function of HLSBackend class but has to be filled by every node.

code_generation_cppsim(model)

Generates c++ code for simulation (cppsim).

code_generation_ipgen(model, fpgapart, clk)

Generates c++ code and tcl script for ip generation.

code_generation_ipi()

Constructs and returns the TCL for node instantiation in Vivado IPI.

compile_singlenode_code()

Builds the bash script for compilation using the CppBuilder from finn.util.basic and executes the script to produce the executable.

dataoutstrm()

Function to generate the commands for reading out data from c++ and convert into npy format, is member function of HLSBackend class might need to be filled by node.

abstract defines(var)

Function to set the define commands for c++ code that has to be generated for cppsim or rtlsim, is member function of HLSBackend class but has to be filled by every node.

var: makes it possible to reuse the function for different c++ code generation. I.e. if set to “ipgen” in MatrixVectorActivation additional PRAGMA defines are added.

abstract docompute()

Function to generate the commands for the computational part of the c++ code, is member function of HLSBackend class but has to be filled by every node.

dynamic_input_to_npy(context, count, target_dir='')

Saves input (given context) into .npy files.

Count indicates the number of inputs that have to be saved.

exec_precompiled_singlenode_model()

Executes precompiled executable.

execute_node(context, graph)

Executes single node using cppsim or rtlsim.

get_all_verilog_filenames(abspath=False)

Return list of all Verilog files used for this node.

get_all_verilog_paths()

Return list of all folders containing Verilog code for this node.

get_ap_int_max_w()

Return the maximum width of any ap_int used in this module. Used to set the AP_INT_MAX_W definition for HLS.

get_nodeattr_types()
abstract global_includes()

Function to set the global includes for c++ code that has to be generated for cppsim or rtlsim, is member function of HLSBackend class but has to be filled by every node.

hls_sname()

Get the naming convention used by Vitis HLS for stream signals Example: the TDATA for a stream called “out” would be out_V_TDATA.

ipgen_default_directives()

Return list of default HLS synthesis directives

ipgen_extra_directives()

Return a list of extra tcl directives for HLS synthesis.

ipgen_singlenode_code()

Builds the bash script for IP generation using the CallHLS utility.

npy_to_dynamic_output(context)

Reads the output from an output.npy file generated from cppsim and places its content into the context dictionary.

npy_to_dynamic_outputs(context, npy_list)

Reads the output from .npy files generated from cppsim and places their content into the context dictionary. npy_list is a list specifying which files to read, and its order must match the order of node outputs.

pragmas()

Function to generate the pragma commands in c++, might need to be overwritten depending on custom op.

prepare_rtlsim()

Creates a Verilator emulation library for the RTL code generated for this node, sets the rtlsim_so attribute to its path and returns a PyVerilator wrapper around it.

read_npy_data()

Function to generate the commands for reading data from .npy file in c++, might need to be overwritten depending on custom op.

save_as_npy()

Function to generate the commands for saving data in .npy file in c++

strm_decl()

Function to generate the commands for the stream declaration in c++, is member function of HLSBackend class but might need to be filled by node.

RTLBackend

class finn.custom_op.fpgadataflow.rtlbackend.RTLBackend

Bases: ABC

RTLBackend class all custom ops that correspond to a module in finn-rtllib are using functionality of. Contains different functions every RTL custom node should have. Some as abstract methods, these have to be filled when writing a new RTL custom op node.

code_generation_ipgen(model, fpgapart, clk)
abstract code_generation_ipi()
abstract generate_hdl(model, fpgapart, clk)
get_nodeattr_types()
hls_sname()

Get the naming convention used by Vitis HLS for stream signals Example: the TDATA for a stream called “out” would be out_V_TDATA.

abstract prepare_rtlsim()

finn.custom_op.fpgadataflow.addstreams

class finn.custom_op.fpgadataflow.addstreams.AddStreams(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of AddStreams.

derive_characteristic_fxns(period)

Return the unconstrained characteristic functions for this node.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.channelwise_op

class finn.custom_op.fpgadataflow.channelwise_op.ChannelwiseOp(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of ChannelwiseOp.

calc_tmem()

Calculates and returns TMEM, the depth of the memory used to store the channelwise op parameters.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.channelwise_op.get_smallest_possible(vals)

Returns smallest (fewest bits) possible DataType that can represent value. Prefers unsigned integers where possible.

finn.custom_op.fpgadataflow.concat

class finn.custom_op.fpgadataflow.concat.StreamingConcat(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of Concat. Only supports concatenating along the last axis.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input stream ind.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_instream_width_padded(ind=0)

Returns input stream width padded to a multiple of 8. This is required by the AXI Stream spec.

get_n_inputs()
get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output stream ind.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_total_elems()
get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.convolutioninputgenerator

class finn.custom_op.fpgadataflow.convolutioninputgenerator.ConvolutionInputGenerator(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of ConvolutionInputGenerator

bram_estimation()

Function for BRAM resource estimation, is member function of HWCustomOp class but has to be filled by every node

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_1d_conv_attrs_normalized()
get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns stream width, input and output stream width are equal for the sliding window function

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

lut_estimation()

Function for LUT resource estimation, is member function of HWCustomOp class but has to be filled by every node

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

uram_estimation()

Function for UltraRAM resource estimation, is member function of HWCustomOp class but has to be filled by every node

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.downsampler

class finn.custom_op.fpgadataflow.downsampler.DownSampler(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of DownSampling Basically performs a down sampling of the image removing rows and columns.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_downsampled_odim()

Return the down sampled spatial size of the output.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output. (Same as input datatype)

get_outstream_width(ind=0)

Returns output stream width, if implemented.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.duplicatestreams

class finn.custom_op.fpgadataflow.duplicatestreams.DuplicateStreams(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of DuplicateStreams

derive_characteristic_fxns(period)

Return the unconstrained characteristic functions for this node.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_num_output_streams()
get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.fmpadding

class finn.custom_op.fpgadataflow.fmpadding.FMPadding(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW impplementation of FMPadding. Pads input image by given amount.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output. (Same as input datatype)

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_padded_odim()

Return the padded spatial size of the output.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.fmpadding_pixel

class finn.custom_op.fpgadataflow.fmpadding_pixel.FMPadding_Pixel(onnx_node, **kwargs)

Bases: HWCustomOp

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output. (Same as input datatype)

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_padded_odim()

Return the padded spatial size of the output.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.globalaccpool

class finn.custom_op.fpgadataflow.globalaccpool.GlobalAccPool(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of GlobalAccPool

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.labelselect

class finn.custom_op.fpgadataflow.labelselect.LabelSelect(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of LabelSelect

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.lookup

class finn.custom_op.fpgadataflow.lookup.Lookup(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of streaming elementwise lookup, mapping indices to values.

bram_efficiency_estimation()

Function for BRAM efficiency estimation: actual parameter storage needed divided by the allocated BRAM storage (from estimation)

bram_estimation()

Function for BRAM resource estimation, is member function of HWCustomOp class but has to be filled by every node

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input stream ind.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output stream ind.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.matrixvectoractivation

class finn.custom_op.fpgadataflow.matrixvectoractivation.MVAU(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of MatrixVectorActivation layers.

bram_efficiency_estimation()

Function for BRAM efficiency estimation: actual parameter storage needed divided by the allocated BRAM storage (from estimation)

bram_estimation()

Calculates resource estimation for BRAM based on: - FINN-R: An End-to-End Deep-Learning Framework for Fast Exploration of Quantized Neural Networks - M. Blott, T. B. Preusser, N. J. Fraser, G. Gambardella, K. O’Brien, Y. Umuroglu, M. Leeser and K. Vissers - 12. Sep 2018

calc_tmem()

Calculates and returns TMEM.

calc_wmem()

Calculates and returns WMEM.

code_generation_ipi()
derive_characteristic_fxns(period)

Return the unconstrained characteristic functions for this node.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

generate_params(model, path)

Function to generate parameters (i.e. weights and thresholds), is member function of HWCustomOp class but has to be filled by every node that needs to generate parameters.

get_accumulator_datatype()

Returns FINN DataType of accumulator

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_hw_compatible_threshold_tensor(orig_thres_matrix)

Convert the original numpy weight matrix orig_weight_matrix into a form suitable for passing to the hlslib call: * ensure MH % PE == 0 * for bipolar weights&inputs, ensure thresholds are positive * interleave rows between PEs * reshape into (PE, TMEM, n_thres_steps) and return

get_hw_compatible_weight_tensor(orig_weight_matrix)

Convert the original numpy weight matrix orig_weight_matrix into a form suitable for passing to the hlslib call: * ensure MH % PE == 0 and MW % SIMD == 0 * for bipolar {-1,+1} weights, convert to binary {0, 1} * interleave rows between PEs * reshape into (1, PE, WMEM, SIMD) and return

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_op_and_param_counts()

Return a dictionary with number of ops needed per inference for this layer as well as parameter count (weights, thresholds, etc.). Entries should be in the format: {op_<optype> : <count>, param_<paramtype>: <count>}.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

get_weight_datatype()

Returns FINN DataType of weights.

get_weightstream_width()

Returns weight stream width. Used only in internal_decoupled and external mode.

get_weightstream_width_padded()

Returns weight stream width padded to a multiple of 8. This is required by the AXI Stream spec. Used in internal_decoupled mode.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

make_weight_file(weights, weight_file_mode, weight_file_name)

Produce a file containing given weights in appropriate format for this layer. This file can be used for either synthesis or run-time reconfig of weights.

Arguments:

  • weights : numpy array with weights to be put into the file

  • weight_file_mode : one of {hls_header, decoupled_verilog_dat, decoupled_runtime}

  • weight_file_name : filename for the weight file to be generated

minimize_accumulator_width(model)

Minimize the accumulator bit width according to the weight values, input data types, and size of dot product

minimize_weight_bit_width(model)

Minimize the bit width based on the values of the weights

uram_efficiency_estimation()

Function for URAM efficiency estimation: actual parameter storage needed divided by the allocated URAM storage (from estimation)

uram_estimation()

Function for UltraRAM resource estimation, is member function of HWCustomOp class but has to be filled by every node

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.pool

class finn.custom_op.fpgadataflow.pool.Pool(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of Pool. Requires ConvolutionInputGenerator(depthwise == 1) to format its input

Input shape (BatchSize,OutImgDim,OutImgDim,TotalKernelSize*Channels) Output shape (BatchSize,OutImgDim,OutImgDim,Channels)

Notes:

  • The input shape was chosen to be compatible with im2col (only true when there is not folding).

  • The actual data layout produced by the hlslib kernels is different for depthwise ops.

    • depthwise SWG: (1, OFMDim, OFMDim, IFMChannels/PE, K, K, PE)

Channels can be folded using PE (SIMD from the input perspective)

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.streamingdataflowpartition

class finn.custom_op.fpgadataflow.streamingdataflowpartition.StreamingDataflowPartition(onnx_node, onnx_opset_version=11)

Bases: CustomOp

Class that corresponds to the meta/container node StreamingDataflowPartition which is a placeholder for a group of fpgadataflow nodes that have been separated out into a FINN-ONNX model of its own. Note that is does not produce any HLS or bitfile by itself.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.streamingdatawidthconverter

class finn.custom_op.fpgadataflow.streamingdatawidthconverter.StreamingDataWidthConverter(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of StreamingDataWidthConverter

check_divisible_iowidths()
execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_iowidth_lcm()
get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

lut_estimation()

Calculates resource estimations for LUTs

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

needs_lcm()
verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.streamingeltwise

class finn.custom_op.fpgadataflow.streamingeltwise.StreamingEltwise(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of StreamingEltwise

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_eltwise_op_lambda()
get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.streamingfifo

class finn.custom_op.fpgadataflow.streamingfifo.StreamingFIFO(onnx_node, **kwargs)

Bases: HWCustomOp

bram_efficiency_estimation()

Function for BRAM efficiency estimation: actual parameter storage needed divided by the allocated BRAM storage (from estimation)

bram_estimation()

Calculates resource estimation for BRAM

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input stream ind.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output stream ind.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

lut_estimation()

Calculates resource estimations for LUTs

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

uram_estimation()

Calculates resource estimation for URAM

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.streamingmaxpool

class finn.custom_op.fpgadataflow.streamingmaxpool.StreamingMaxPool(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of StreamingMaxPool

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_1d_attrs_normalized()
get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

For streaming maxpool out stream width is the same as in stream width

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

is_1d()
make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.templates

finn.custom_op.fpgadataflow.thresholding

class finn.custom_op.fpgadataflow.thresholding.Thresholding(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of Thresholding.

calc_tmem()

Calculates and returns TMEM.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_hw_compatible_threshold_tensor(orig_thres_matrix)

Convert the original numpy weight matrix orig_weight_matrix into a form suitable for passing to the hlslib call: * ensure MH % PE == 0 * for unsigned inputs, ensure thresholds are positive * interleave rows between PEs * reshape into (PE, TMEM, n_thres_steps) and return

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_weight_datatype()

Returns FINN DataType of thresholds, here called weights.

get_weightstream_width()

Returns weight stream width

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

minimize_accumulator_width(model)

Minimize threshold width (‘accumulator width’ here due to convention)

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.upsampler

class finn.custom_op.fpgadataflow.upsampler.UpsampleNearestNeighbour(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of UpsampleNearestNeighbour.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_output_datatype(ind=0)

Returns FINN DataType of output. (Same as input datatype)

get_outstream_width(ind=0)

Returns output stream width, if implemented.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.

finn.custom_op.fpgadataflow.vectorvectoractivation

class finn.custom_op.fpgadataflow.vectorvectoractivation.VVAU(onnx_node, **kwargs)

Bases: HWCustomOp

Abstraction layer for HW implementation of VectorVectorActivation layers.

bram_efficiency_estimation()

Function for BRAM efficiency estimation: actual parameter storage needed divided by the allocated BRAM storage (from estimation)

bram_estimation()

Calculates resource estimation for BRAM

calc_tmem()

Calculates and returns TMEM.

calc_wmem()

Calculates and returns WMEM.

code_generation_ipi()
derive_characteristic_fxns(period)

Return the unconstrained characteristic functions for this node.

execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

generate_params(model, path)

Function to generate parameters (i.e. weights and thresholds), is member function of HWCustomOp class but has to be filled by every node that needs to generate parameters.

get_accumulator_datatype()

Returns FINN DataType of accumulator

get_exp_cycles()

Function for estimation of expected cycles for set folding, is member function of HWCustomOp class but has to be filled by every node

get_folded_input_shape(ind=0)

Returns folded input shape (according to synapse folding), if implemented.

get_folded_output_shape(ind=0)

Returns folded output shape (according to neuron folding), if implemented.

get_hw_compatible_threshold_tensor(orig_thres_matrix)

Convert the original numpy weight matrix orig_weight_matrix into a form suitable for passing to the hlslib call: * ensure MH % PE == 0 * for bipolar weights&inputs, ensure thresholds are positive * interleave rows between PEs * reshape into (PE, TMEM, n_thres_steps) and return

get_hw_compatible_weight_tensor(orig_weight_matrix)
get_input_datatype(ind=0)

Returns FINN DataType of input.

get_instream_width(ind=0)

Returns input stream width, if implemented.

get_nodeattr_types()

Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.

get_normal_input_shape(ind=0)

Returns normal input shape if implemented.

get_normal_output_shape(ind=0)

Returns folded output shape if implemented.

get_number_output_values()

Function to get the number of expected output values, is member function of HWCustomOp class but has to be filled by every node.

get_op_and_param_counts()

Return a dictionary with number of ops needed per inference for this layer as well as parameter count (weights, thresholds, etc.). Entries should be in the format: {op_<optype> : <count>, param_<paramtype>: <count>}.

get_output_datatype(ind=0)

Returns FINN DataType of output.

get_outstream_width(ind=0)

Returns output stream width, if implemented.

get_verilog_top_module_intf_names()

Return a dict of names of input and output interfaces. The keys reflect the protocols each interface implements: ‘clk’, ‘rst’, ‘m_axis’, ‘s_axis’, ‘aximm’, ‘axilite’. Values are lists of tuples (axis, aximm) or names (axilite): ‘axis’ tuples correspond to the list of node inputs in order, each tuple is (interface_name, interface_width_bits). axilite always assumed to be 32 bits and is not tuple (name only). Each block must have at most one aximm and one axilite.

get_weight_datatype()

Returns FINN DataType of weights.

get_weightstream_width()

Returns weight stream width. Used only in internal_decoupled mode.

get_weightstream_width_padded()

Returns weight stream width padded to a multiple of 8. This is required by the AXI Stream spec. Used in internal_decoupled mode.

infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

make_weight_file(weights, weight_file_mode, weight_file_name)

Produce a file containing given weights in appropriate format for this layer. This file can be used for either synthesis or run-time reconfig of weights.

Arguments:

  • weights : numpy array with weights to be put into the file

  • weight_file_mode : one of {hls_header, decoupled_verilog_dat, decoupled_runtime}

  • weight_file_name : filename for the weight file to be generated

minimize_accumulator_width(model)

Minimize the accumulator bit width according to the weight values, input data types, and size of dot product

minimize_weight_bit_width(model)

Minimize the bit width based on the values of the weights

uram_efficiency_estimation()

Function for URAM efficiency estimation: actual parameter storage needed divided by the allocated URAM storage (from estimation)

uram_estimation()

Function for UltraRAM resource estimation, is member function of HWCustomOp class but has to be filled by every node

verify_node()

Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.