Custom Op

Custom Op Nodes

Base Class

class finn.custom_op.CustomOp(onnx_node)

Bases: abc.ABC

CustomOp class all custom op nodes are based on. Contains different functions every custom node should have. Some as abstract methods, these have to be filled when writing a new custom op node.

abstract execute_node(context, graph)

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

get_nodeattr(name)

Get a node attribute by name. Data is stored inside the ONNX node’s AttributeProto container. Attribute must be part of get_nodeattr_types. Default value is returned if attribute is not set.

abstract 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 infer_node_datatype(model)

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

abstract make_shape_compatible_op()

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

set_nodeattr(name, value)

Set a node attribute by name. Data is stored inside the ONNX node’s AttributeProto container. Attribute must be part of get_nodeattr_types.

abstract 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.multithreshold

class finn.custom_op.multithreshold.MultiThreshold(onnx_node)

Bases: finn.custom_op.CustomOp

Class that corresponds to a multithresholding node.

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: 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

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.

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.multithreshold.compare(x, y)

Comparison helper function for multithresholding.

Gets two values and returns 1.0 if x>=y otherwise 0.0.

finn.custom_op.multithreshold.multithreshold(v, thresholds, out_scale=None, out_bias=None)

Given a set of threshold values t={t_0, t_1 … t_n} the successive thresholding maps any real number x to an integer in the interval [0, n], where the returned integer is the number of thresholds x is greater than or equal to.

The output tensor will be scaled by out_scale and biased by out_bias.

finn.custom_op.registry

finn.custom_op.registry.getCustomOp(node)

Return a FINN CustomOp instance for the given ONNX node, if it exists.

finn.custom_op.streamingdataflowpartition

class finn.custom_op.streamingdataflowpartition.StreamingDataflowPartition(onnx_node)

Bases: finn.custom_op.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: 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

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.

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.xnorpopcount

class finn.custom_op.xnorpopcount.XnorPopcountMatMul(onnx_node)

Bases: finn.custom_op.CustomOp

Class that corresponds to a XNOR-popcount matrix multiplication node.

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: 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

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.

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.xnorpopcount.xnorpopcountmatmul(inp0, inp1)

Simulates XNOR-popcount matrix multiplication as a regular bipolar matrix multiplication followed by some post processing.