Custom Op - FPGADataFlow¶
HLS Custom Op Nodes¶
Base Class¶
-
class
finn.custom_op.fpgadataflow.
HLSCustomOp
(onnx_node)¶ Bases:
finn.custom_op.CustomOp
HLSCustomOp class all custom ops that correspond to a finn-hlslib function 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.
-
abstract
blackboxfunction
()¶ Function to generate a blackbock function in c++ from which an IP block will be generated, is member function of HLSCustomOp class but has to be filled by every node.
-
bram_estimation
()¶ Function for BRAM resource estimation, is member function of HLSCustomOp class but has to be filled by every node
-
code_generation_ipgen
(model, fpgapart, clk)¶ Generates c++ code and tcl script for ip generation.
-
code_generation_npysim
(model)¶ Generates c++ code for simulation (npysim).
-
compile_singlenode_code
()¶ Builds the bash script for compilation using the CppBuilder from finn.util.basic and executes the script to produce the executable.
-
abstract
dataoutstrm
()¶ Function to generate the commands for reading out data from c++ and convert into npy format, is member function of HLSCustomOp class but has to be filled by every node.
-
abstract
defines
(var)¶ Function to set the define commands for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp 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 StreamingFCLayer_Batch additional PRAGMA defines are added.
-
abstract
docompute
()¶ Function to generate the commands for the computational part of the c++ code, is member function of HLSCustomOp class but has to be filled by every node.
-
dynamic_input_to_npy
(context, count)¶ 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 npysim or rtlsim.
-
generate_params
(model, path)¶ Function to generate parameters (i.e. weights and thresholds), is member function of HLSCustomOp class but has to be filled by every node.
-
get_folded_input_shape
()¶ Returns folded input shape (according to synapse folding), if implemented.
-
get_folded_output_shape
()¶ Returns folded output shape (according to neuron folding), if implemented.
-
get_instream_width
()¶ Returns input stream width, if implemented.
-
get_nodeattr_types
()¶ Returns a dict of permitted attributes for node, where: returned_dict[attribute_name] = (dtype, require, default_value) - 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
-
abstract
get_number_output_values
()¶ Function to get the number of expected output values, is member function of HLSCustomOp class but has to be filled by every node.
-
get_outstream_width
()¶ Returns output stream width, if implemented.
-
abstract
global_includes
()¶ Function to set the global includes for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp class but has to be filled by every node.
-
ipgen_singlenode_code
()¶ Builds the bash script for ip generation using the IPGenBuilder from finn.util.fpgadataflow.
-
lut_estimation
()¶ Function for LUT resource estimation, is member function of HLSCustomOp class but has to be filled by every node
-
node_res_estimation
()¶ Returns summarized resource estimation of BRAMs and LUTs of the node.
-
npy_to_dynamic_output
(context)¶ Reads the output from a .npy file and saves it at the right place in the context dictionary.
-
abstract
pragmas
()¶ Function to generate the pragma commands in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
abstract
read_npy_data
()¶ Function to generate the commands for reading data from .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
reset_rtlsim
(sim)¶ Sets reset input in pyverilator to zero, toggles the clock and set it back to one
-
rtlsim
(sim, inp)¶ 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.
-
abstract
save_as_npy
()¶ Function to generate the commands for saving data in .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
abstract
strm_decl
()¶ Function to generate the commands for the stream declaration in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
toggle_clk
(sim)¶ Toggles the clock input in pyverilator once.
-
abstract
finn.custom_op.fpgadataflow.convolutioninputgenerator¶
-
class
finn.custom_op.fpgadataflow.convolutioninputgenerator.
ConvolutionInputGenerator
(onnx_node)¶ Bases:
finn.custom_op.fpgadataflow.HLSCustomOp
Class that corresponds to finn-hlslib ConvolutionInputGenerator (sliding window) function.
-
blackboxfunction
()¶ Function to generate a blackbock function in c++ from which an IP block will be generated, is member function of HLSCustomOp class but has to be filled by every node.
-
bram_estimation
()¶ Function for BRAM resource estimation, is member function of HLSCustomOp class but has to be filled by every node
-
dataoutstrm
()¶ Function to generate the commands for reading out data from c++ and convert into npy format, is member function of HLSCustomOp class but has to be filled by every node.
-
defines
(var)¶ Function to set the define commands for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp 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 StreamingFCLayer_Batch additional PRAGMA defines are added.
-
docompute
()¶ Function to generate the commands for the computational part of the c++ code, is member function of HLSCustomOp class but has to be filled by every node.
-
execute_node
(context, graph)¶ Executes single node using npysim or rtlsim.
-
get_input_datatype
()¶ Returns FINN DataType of input.
-
get_nodeattr_types
()¶ Returns a dict of permitted attributes for node, where: returned_dict[attribute_name] = (dtype, require, default_value) - 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
-
get_number_output_values
()¶ Function to get the number of expected output values, is member function of HLSCustomOp class but has to be filled by every node.
-
get_output_datatype
()¶ Returns FINN DataType of output.
-
get_stream_width
()¶ Returns stream width, input and output stream width are equal for the sliding window function
-
global_includes
()¶ Function to set the global includes for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp class but has to be filled by every node.
-
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 HLSCustomOp class but has to be filled by every node
-
make_shape_compatible_op
()¶ Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.
-
pragmas
()¶ Function to generate the pragma commands in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
read_npy_data
()¶ Function to generate the commands for reading data from .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
save_as_npy
()¶ Function to generate the commands for saving data in .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
strm_decl
()¶ Function to generate the commands for the stream declaration in c++, is member function of HLSCustomOp 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.streamingfclayer_batch¶
-
class
finn.custom_op.fpgadataflow.streamingfclayer_batch.
StreamingFCLayer_Batch
(onnx_node)¶ Bases:
finn.custom_op.fpgadataflow.HLSCustomOp
Class that corresponds to finn-hls StreamingFCLayer_Batch function.
-
blackboxfunction
()¶ Function to generate a blackbock function in c++ from which an IP block will be generated, is member function of HLSCustomOp class but has to be filled by every node.
-
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.
-
dataoutstrm
()¶ Function to generate the commands for reading out data from c++ and convert into npy format, is member function of HLSCustomOp class but has to be filled by every node.
-
defines
(var)¶ Function to set the define commands for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp 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 StreamingFCLayer_Batch additional PRAGMA defines are added.
-
docompute
()¶ Function to generate the commands for the computational part of the c++ code, is member function of HLSCustomOp class but has to be filled by every node.
-
execute_node
(context, graph)¶ Executes single node using npysim or rtlsim.
-
generate_params
(model, path)¶ Saves weights into params.h and if existing thresholds into thresh.h.
-
get_folded_input_shape
()¶ Returns folded input shape (according to synapse folding), if implemented.
-
get_folded_output_shape
()¶ Returns folded output shape (according to neuron folding), if implemented.
-
get_hls_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_hls_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
()¶ Returns FINN DataType of input.
-
get_instream_width
()¶ Returns input stream width, if implemented.
-
get_nodeattr_types
()¶ Returns a dict of permitted attributes for node, where: returned_dict[attribute_name] = (dtype, require, default_value) - 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
-
get_number_output_values
()¶ Function to get the number of expected output values, is member function of HLSCustomOp class but has to be filled by every node.
-
get_output_datatype
()¶ Returns FINN DataType of output.
-
get_outstream_width
()¶ Returns output stream width, if implemented.
-
get_template_param_values
()¶ Returns the template parameter values according to input, output and weight data types.
-
get_weight_datatype
()¶ Returns FINN DataType of weights.
-
global_includes
()¶ Function to set the global includes for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp class but has to be filled by every node.
-
infer_node_datatype
(model)¶ Set the DataType annotations corresponding to the outputs of this node.
-
lut_estimation
()¶ Calculates resource estimations for LUTs 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
-
make_shape_compatible_op
()¶ Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.
-
pragmas
()¶ Function to generate the pragma commands in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
read_npy_data
()¶ Function to generate the commands for reading data from .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
save_as_npy
()¶ Function to generate the commands for saving data in .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
strm_decl
()¶ Function to generate the commands for the stream declaration in c++, is member function of HLSCustomOp 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.streamingmaxpool_batch¶
-
class
finn.custom_op.fpgadataflow.streamingmaxpool_batch.
StreamingMaxPool_Batch
(onnx_node)¶ Bases:
finn.custom_op.fpgadataflow.HLSCustomOp
Class that corresponds to finn-hlslib StreamingMaxPool_batch function.
-
blackboxfunction
()¶ Function to generate a blackbock function in c++ from which an IP block will be generated, is member function of HLSCustomOp class but has to be filled by every node.
-
bram_estimation
()¶ Function for BRAM resource estimation, is member function of HLSCustomOp class but has to be filled by every node
-
dataoutstrm
()¶ Function to generate the commands for reading out data from c++ and convert into npy format, is member function of HLSCustomOp class but has to be filled by every node.
-
defines
(var)¶ Function to set the define commands for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp 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 StreamingFCLayer_Batch additional PRAGMA defines are added.
-
docompute
()¶ Function to generate the commands for the computational part of the c++ code, is member function of HLSCustomOp class but has to be filled by every node.
-
get_nodeattr_types
()¶ Returns a dict of permitted attributes for node, where: returned_dict[attribute_name] = (dtype, require, default_value) - 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
-
get_number_output_values
()¶ Function to get the number of expected output values, is member function of HLSCustomOp class but has to be filled by every node.
-
global_includes
()¶ Function to set the global includes for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp class but has to be filled by every node.
-
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 HLSCustomOp class but has to be filled by every node
-
make_shape_compatible_op
()¶ Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.
-
pragmas
()¶ Function to generate the pragma commands in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
read_npy_data
()¶ Function to generate the commands for reading data from .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
save_as_npy
()¶ Function to generate the commands for saving data in .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
strm_decl
()¶ Function to generate the commands for the stream declaration in c++, is member function of HLSCustomOp 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.templates¶
finn.custom_op.fpgadataflow.tlastmarker¶
-
class
finn.custom_op.fpgadataflow.tlastmarker.
TLastMarker
(onnx_node)¶ Bases:
finn.custom_op.fpgadataflow.HLSCustomOp
Class that corresponds to the TLastMarker node that needs to be inserted at the end of the model for rtlsim with stitched IP. It marks the end of the current image/input sample.
-
blackboxfunction
()¶ Function to generate a blackbock function in c++ from which an IP block will be generated, is member function of HLSCustomOp class but has to be filled by every node.
-
dataoutstrm
()¶ Function to generate the commands for reading out data from c++ and convert into npy format, is member function of HLSCustomOp class but has to be filled by every node.
-
defines
(var)¶ Function to set the define commands for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp 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 StreamingFCLayer_Batch additional PRAGMA defines are added.
-
docompute
()¶ Function to generate the commands for the computational part of the c++ code, is member function of HLSCustomOp class but has to be filled by every node.
-
execute_node
(context, graph)¶ Executes single node using npysim or rtlsim.
-
get_folded_input_shape
()¶ Returns folded input shape (according to synapse folding), if implemented.
-
get_folded_output_shape
()¶ Returns folded output shape (according to neuron folding), if implemented.
-
get_instream_width
()¶ Returns input stream width, if implemented.
-
get_nodeattr_types
()¶ Returns a dict of permitted attributes for node, where: returned_dict[attribute_name] = (dtype, require, default_value) - 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
-
get_number_output_values
()¶ Function to get the number of expected output values, is member function of HLSCustomOp class but has to be filled by every node.
-
get_outstream_width
()¶ Returns output stream width, if implemented.
-
global_includes
()¶ Function to set the global includes for c++ code that has to be generated for npysim or rtlsim, is member function of HLSCustomOp class but has to be filled by every node.
-
infer_node_datatype
(model)¶ Set the DataType annotations corresponding to the outputs of this node.
-
make_shape_compatible_op
()¶ Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.
-
pragmas
()¶ Function to generate the pragma commands in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
read_npy_data
()¶ Function to generate the commands for reading data from .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
save_as_npy
()¶ Function to generate the commands for saving data in .npy file in c++, is member function of HLSCustomOp class but has to be filled by every node.
-
strm_decl
()¶ Function to generate the commands for the stream declaration in c++, is member function of HLSCustomOp 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.
-