Skip to content
8 changes: 4 additions & 4 deletions notebooks/advanced/2_custom_op.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@
"metadata": {},
"outputs": [],
"source": [
"from qonnx.custom_op.registry import getCustomOp\n",
"from finn.util.basic import getHWCustomOp\n",
"\n",
"# get FINN wrapper for this node, with all the functionality\n",
"op_inst = getCustomOp(mixedop_graph.model.graph.node[0])\n",
"op_inst = getHWCustomOp(mixedop_graph.model.graph.node[0])\n",
"print(\"Available functions: \" + str(dir(op_inst)))\n",
"# query some attributes\n",
"print(\"codegen_dir: \" + op_inst.get_nodeattr(\"codegen_dir\"))\n",
Expand Down Expand Up @@ -471,7 +471,7 @@
" # check node type before we do anything\n",
" if node.op_type == \"MyMixedPowerOp\":\n",
" # get FINN wrapper for this node, with all the functions\n",
" op_inst = getCustomOp(node)\n",
" op_inst = getHWCustomOp(node)\n",
" if not os.path.isdir(op_inst.get_nodeattr(\"codegen_dir\")):\n",
" # call the codegen function we defined\n",
" # this will modify the underlying node by setting attribute\n",
Expand Down Expand Up @@ -512,7 +512,7 @@
"metadata": {},
"outputs": [],
"source": [
"new_op_inst = getCustomOp(mixedop_graph_new.graph.node[0])\n",
"new_op_inst = getHWCustomOp(mixedop_graph_new.graph.node[0])\n",
"codegen_dir = new_op_inst.get_nodeattr(\"codegen_dir\")\n",
"print(codegen_dir)"
]
Expand Down
14 changes: 7 additions & 7 deletions notebooks/advanced/3_folding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
"\n",
"In the first step, we left the `PE` & `SIMD` values for all the layers on default (=1) to establish a baseline and measure the estimated clock cycles and resource utilization for each of the individual layers.\n",
"\n",
"To set `PE` & `SIMD`, we will utilize functionality from the FINN compiler. Each layer type has a Python wrapper which can be instantiated using the `getCustomOp()` function. The wrapper offers several helper functions like `get_nodeattr()` and `set_nodeattr()` to access and set the attributes of a node."
"To set `PE` & `SIMD`, we will utilize functionality from the FINN compiler. Each layer type has a Python wrapper which can be instantiated using the `getHWCustomOp()` function. The wrapper offers several helper functions like `get_nodeattr()` and `set_nodeattr()` to access and set the attributes of a node."
]
},
{
Expand All @@ -280,12 +280,12 @@
"metadata": {},
"outputs": [],
"source": [
"from qonnx.custom_op.registry import getCustomOp\n",
"from finn.util.basic import getHWCustomOp\n",
"\n",
"list_of_mvaus = model.get_nodes_by_op_type(\"MVAU_hls\")\n",
"mvau0 = list_of_mvaus[0]\n",
"\n",
"mvau0_inst = getCustomOp(mvau0)\n",
"mvau0_inst = getHWCustomOp(mvau0)\n",
"\n",
"# Get the node attributes to check the current setting\n",
"print(\"The parallelization parameters of %s were: \" % mvau0.name)\n",
Expand Down Expand Up @@ -444,7 +444,7 @@
"list_of_mvaus = model_orig.get_nodes_by_op_type(\"MVAU_hls\")\n",
"print(\"In the original model (pe=simd=1): \")\n",
"for mvau in list_of_mvaus:\n",
" mvau_inst = getCustomOp(mvau)\n",
" mvau_inst = getHWCustomOp(mvau)\n",
" print(\"Layer: \" + mvau.name)\n",
" print(\"Input shape: \" + str(mvau_inst.get_folded_input_shape()))\n",
" print(\"Output shape: \" + str(mvau_inst.get_folded_output_shape()))"
Expand All @@ -460,7 +460,7 @@
"list_of_mvaus = model_updated.get_nodes_by_op_type(\"MVAU_hls\")\n",
"print(\"In the original model (pe=simd=1): \")\n",
"for mvau in list_of_mvaus:\n",
" mvau_inst = getCustomOp(mvau)\n",
" mvau_inst = getHWCustomOp(mvau)\n",
" print(\"Layer: \" + mvau.name)\n",
" print(\"Input shape: \" + str(mvau_inst.get_folded_input_shape()))\n",
" print(\"Output shape: \" + str(mvau_inst.get_folded_output_shape()))"
Expand Down Expand Up @@ -515,7 +515,7 @@
"list_of_mvaus = model_orig.get_nodes_by_op_type(\"MVAU_hls\")\n",
"print(\"In the original model (pe=simd=1): \")\n",
"for mvau in list_of_mvaus:\n",
" mvau_inst = getCustomOp(mvau)\n",
" mvau_inst = getHWCustomOp(mvau)\n",
" print(\"Layer: \" + mvau.name)\n",
" print(\"Input stream width: \" + str(mvau_inst.get_instream_width()))\n",
" print(\"Output stream width: \" + str(mvau_inst.get_outstream_width()))"
Expand Down Expand Up @@ -545,7 +545,7 @@
"list_of_mvaus = model_updated.get_nodes_by_op_type(\"MVAU_hls\")\n",
"print(\"In the original model (pe=simd=1): \")\n",
"for mvau in list_of_mvaus:\n",
" mvau_inst = getCustomOp(mvau)\n",
" mvau_inst = getHWCustomOp(mvau)\n",
" print(\"Layer: \" + mvau.name)\n",
" print(\"Input stream width: \" + str(mvau_inst.get_instream_width()))\n",
" print(\"Output stream width: \" + str(mvau_inst.get_outstream_width()))"
Expand Down
8 changes: 4 additions & 4 deletions notebooks/end2end_example/bnn-pynq/cnv_end2end_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
")\n",
"from finn.transformation.move_reshape import RemoveCNVtoFCFlatten\n",
"from finn.transformation.fpgadataflow.specialize_layers import SpecializeLayers\n",
"from qonnx.custom_op.registry import getCustomOp\n",
"from finn.util.basic import getHWCustomOp\n",
"from qonnx.transformation.infer_data_layouts import InferDataLayouts\n",
"\n",
"model = ModelWrapper(build_dir + \"/end2end_cnv_w1a1_streamlined.onnx\")\n",
Expand All @@ -315,7 +315,7 @@
"parent_model = model.transform(CreateDataflowPartition())\n",
"parent_model.save(build_dir + \"/end2end_cnv_w1a1_dataflow_parent.onnx\")\n",
"sdp_node = parent_model.get_nodes_by_op_type(\"StreamingDataflowPartition\")[0]\n",
"sdp_node = getCustomOp(sdp_node)\n",
"sdp_node = getHWCustomOp(sdp_node)\n",
"dataflow_model_filename = sdp_node.get_nodeattr(\"model\")\n",
"# save the dataflow partition with a different name for easier access\n",
"# and specialize the layers to HLS variants\n",
Expand Down Expand Up @@ -384,15 +384,15 @@
" (5, 1, [3]),\n",
"]\n",
"for fcl, (pe, simd, ififodepth) in zip(fc_layers, folding):\n",
" fcl_inst = getCustomOp(fcl)\n",
" fcl_inst = getHWCustomOp(fcl)\n",
" fcl_inst.set_nodeattr(\"PE\", pe)\n",
" fcl_inst.set_nodeattr(\"SIMD\", simd)\n",
" fcl_inst.set_nodeattr(\"inFIFODepths\", ififodepth)\n",
"\n",
"# use same SIMD values for the sliding window operators\n",
"swg_layers = model.get_nodes_by_op_type(\"ConvolutionInputGenerator_rtl\")\n",
"for i in range(len(swg_layers)):\n",
" swg_inst = getCustomOp(swg_layers[i])\n",
" swg_inst = getHWCustomOp(swg_layers[i])\n",
" simd = folding[i][1]\n",
" swg_inst.set_nodeattr(\"SIMD\", simd)\n",
"\n",
Expand Down
14 changes: 7 additions & 7 deletions notebooks/end2end_example/bnn-pynq/tfc_end2end_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@
"metadata": {},
"outputs": [],
"source": [
"from qonnx.custom_op.registry import getCustomOp\n",
"from finn.util.basic import getHWCustomOp\n",
"sdp_node = parent_model.get_nodes_by_op_type(\"StreamingDataflowPartition\")[0]\n",
"sdp_node = getCustomOp(sdp_node)\n",
"sdp_node = getHWCustomOp(sdp_node)\n",
"dataflow_model_filename = sdp_node.get_nodeattr(\"model\")\n",
"showInNetron(dataflow_model_filename)"
]
Expand Down Expand Up @@ -543,7 +543,7 @@
"outputs": [],
"source": [
"thresh_node = model.get_nodes_by_op_type(\"Thresholding\")[0]\n",
"thresh_node_inst = getCustomOp(thresh_node)\n",
"thresh_node_inst = getHWCustomOp(thresh_node)\n",
"thresh_node_inst.set_nodeattr(\"preferred_impl_style\", \"hls\")"
]
},
Expand Down Expand Up @@ -634,7 +634,7 @@
"outputs": [],
"source": [
"fc0 = model.graph.node[1]\n",
"fc0w = getCustomOp(fc0)\n",
"fc0w = getHWCustomOp(fc0)\n",
"\n",
"print(\"CustomOp wrapper is of class \" + fc0w.__class__.__name__)\n",
"\n",
Expand Down Expand Up @@ -664,7 +664,7 @@
" (10, 8, [64], [10], \"distributed\"),\n",
"]\n",
"for fcl, (pe, simd, ififo, ofifo, ramstyle) in zip(fc_layers, config):\n",
" fcl_inst = getCustomOp(fcl)\n",
" fcl_inst = getHWCustomOp(fcl)\n",
" fcl_inst.set_nodeattr(\"PE\", pe)\n",
" fcl_inst.set_nodeattr(\"SIMD\", simd)\n",
" fcl_inst.set_nodeattr(\"inFIFODepths\", ififo)\n",
Expand All @@ -673,7 +673,7 @@
" \n",
"# set parallelism for input quantizer to be same as first layer's SIMD\n",
"inp_qnt_node = model.get_nodes_by_op_type(\"Thresholding_hls\")[0]\n",
"inp_qnt = getCustomOp(inp_qnt_node)\n",
"inp_qnt = getHWCustomOp(inp_qnt_node)\n",
"inp_qnt.set_nodeattr(\"PE\", 49)"
]
},
Expand Down Expand Up @@ -796,7 +796,7 @@
"outputs": [],
"source": [
"model = ModelWrapper(build_dir + \"/tfc_w1_a1_post_synthesis.onnx\")\n",
"sdp_node_middle = getCustomOp(model.graph.node[1])\n",
"sdp_node_middle = getHWCustomOp(model.graph.node[1])\n",
"postsynth_layers = sdp_node_middle.get_nodeattr(\"model\")\n",
"\n",
"showInNetron(postsynth_layers)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@
"metadata": {},
"outputs": [],
"source": [
"from qonnx.custom_op.registry import getCustomOp\n",
"from finn.util.basic import getHWCustomOp\n",
"\n",
"fc0 = model_for_cppsim.graph.node[1]\n",
"fc0w = getCustomOp(fc0)\n",
"fc0w = getHWCustomOp(fc0)\n",
"code_gen_dir = fc0w.get_nodeattr(\"code_gen_dir_cppsim\")\n",
"!ls {code_gen_dir}"
]
Expand Down Expand Up @@ -272,7 +272,7 @@
"parent_model = ModelWrapper(build_dir+\"/tfc_w1_a1_dataflow_parent.onnx\")\n",
"sdp_node = parent_model.graph.node[1]\n",
"child_model = build_dir + \"/tfc_w1_a1_for_cppsim.onnx\"\n",
"getCustomOp(sdp_node).set_nodeattr(\"model\", child_model)\n",
"getHWCustomOp(sdp_node).set_nodeattr(\"model\", child_model)\n",
"output_dict = oxe.execute_onnx(parent_model, input_dict)\n",
"output_cppsim = output_dict[list(output_dict.keys())[0]]\n",
"\n",
Expand Down Expand Up @@ -350,7 +350,7 @@
"# parent model\n",
"model_for_rtlsim = ModelWrapper(build_dir + \"/tfc_w1_a1_dataflow_parent.onnx\")\n",
"# reference child model\n",
"sdp_node = getCustomOp(model_for_rtlsim.graph.node[1])\n",
"sdp_node = getHWCustomOp(model_for_rtlsim.graph.node[1])\n",
"sdp_node.set_nodeattr(\"model\", build_dir + \"/tfc_w1_a1_dataflow_child.onnx\")\n",
"\n",
"model_for_rtlsim = model_for_rtlsim.transform(SetExecMode(\"rtlsim\"))"
Expand Down Expand Up @@ -416,7 +416,7 @@
"# parent model\n",
"model_for_rtlsim = ModelWrapper(build_dir + \"/tfc_w1_a1_dataflow_parent.onnx\")\n",
"# reference child model\n",
"sdp_node = getCustomOp(model_for_rtlsim.graph.node[1])\n",
"sdp_node = getHWCustomOp(model_for_rtlsim.graph.node[1])\n",
"sdp_node.set_nodeattr(\"model\", build_dir + \"/tfc_w1_a1_dataflow_child.onnx\")"
]
},
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ testing =
[options.entry_points]
console_scripts =
build_dataflow = finn.builder.build_dataflow:main

# Brainsmith plugin integration
brainsmith.plugins =
finn = finn.util.brainsmith_integration:register_all

# Add here console scripts like:
# console_scripts =
# script_name = finn.module:function
Expand Down
5 changes: 2 additions & 3 deletions src/finn/analysis/fpgadataflow/dataflow_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from qonnx.custom_op.registry import getCustomOp

from finn.util.basic import getHWCustomOp
from finn.util.fpgadataflow import is_hls_node, is_rtl_node


Expand All @@ -54,7 +53,7 @@ def dataflow_performance(model):

for node in model.graph.node:
if is_hls_node(node) or is_rtl_node(node):
inst = getCustomOp(node)
inst = getHWCustomOp(node, model)
node_cycles = int(inst.get_nodeattr("cycles_estimate"))
if node_cycles > max_cycles:
max_cycles = node_cycles
Expand Down
5 changes: 2 additions & 3 deletions src/finn/analysis/fpgadataflow/exp_cycles_per_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import qonnx.custom_op.registry as registry

from finn.util.basic import getHWCustomOp
from finn.util.fpgadataflow import is_hls_node, is_rtl_node


Expand All @@ -43,7 +42,7 @@ def exp_cycles_per_layer(model):
cycle_dict = {}
for node in model.graph.node:
if is_hls_node(node) or is_rtl_node(node):
inst = registry.getCustomOp(node)
inst = getHWCustomOp(node, model)
cycle_dict[node.name] = int(inst.get_exp_cycles())

return cycle_dict
5 changes: 2 additions & 3 deletions src/finn/analysis/fpgadataflow/floorplan_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from qonnx.custom_op.registry import getCustomOp

from finn.util.basic import getHWCustomOp
from finn.util.fpgadataflow import is_fpgadataflow_node


Expand All @@ -47,7 +46,7 @@ def floorplan_params(model):
}
for node in model.graph.node:
if is_fpgadataflow_node(node):
node_inst = getCustomOp(node)
node_inst = getHWCustomOp(node, model)
node_slr = node_inst.get_nodeattr("slr")
node_pid = node_inst.get_nodeattr("partition_id")
node_mport = node_inst.get_nodeattr("mem_port")
Expand Down
4 changes: 2 additions & 2 deletions src/finn/analysis/fpgadataflow/hls_synth_res_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import qonnx.custom_op.registry as registry
import warnings
import xml.etree.ElementTree as ET

from finn.util.basic import getHWCustomOp
from finn.util.fpgadataflow import is_hls_node


Expand All @@ -52,7 +52,7 @@ def hls_synth_res_estimation(model):
res_dict[node.name]["LUT"] = 0
res_dict[node.name]["DSP48E"] = 0
res_dict[node.name]["URAM"] = 0
inst = registry.getCustomOp(node)
inst = getHWCustomOp(node, model)
code_gen_dir = inst.get_nodeattr("code_gen_dir_ipgen")
if code_gen_dir == "":
warnings.warn(
Expand Down
5 changes: 3 additions & 2 deletions src/finn/analysis/fpgadataflow/op_and_param_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import qonnx.custom_op.registry as registry
from qonnx.util.basic import is_finn_op

from finn.util.basic import getHWCustomOp


def aggregate_dict_keys(res_dict):
total_dict = {}
Expand All @@ -52,7 +53,7 @@ def op_and_param_counts(model):
ret_dict = {}
for node in model.graph.node:
if is_finn_op(node.domain):
inst = registry.getCustomOp(node)
inst = getHWCustomOp(node, model)
if hasattr(inst, "get_op_and_param_counts"):
node_op_and_param_counts = inst.get_op_and_param_counts()
ret_dict[node.name] = node_op_and_param_counts
Expand Down
4 changes: 2 additions & 2 deletions src/finn/analysis/fpgadataflow/post_synth_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import os
import xml.etree.ElementTree as ET
from qonnx.core.modelwrapper import ModelWrapper
from qonnx.custom_op.registry import getCustomOp

from finn.util.basic import getHWCustomOp
from finn.util.fpgadataflow import is_hls_node, is_rtl_node


Expand Down Expand Up @@ -122,7 +122,7 @@ def get_instance_stats(inst_name):

for node in model.graph.node:
if node.op_type == "StreamingDataflowPartition":
sdp_model = ModelWrapper(getCustomOp(node).get_nodeattr("model"))
sdp_model = ModelWrapper(getHWCustomOp(node, model).get_nodeattr("model"))
sdp_res_dict = post_synth_res(sdp_model, synth_report_filename)
res_dict.update(sdp_res_dict)
elif is_hls_node(node) or is_rtl_node(node):
Expand Down
7 changes: 3 additions & 4 deletions src/finn/analysis/fpgadataflow/res_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import qonnx.custom_op.registry as registry

from finn.util.basic import getHWCustomOp
from finn.util.fpgadataflow import is_hls_node, is_rtl_node


Expand All @@ -42,7 +41,7 @@ def res_estimation(model, fpgapart):
res_dict = {}
for node in model.graph.node:
if is_hls_node(node) or is_rtl_node(node):
inst = registry.getCustomOp(node)
inst = getHWCustomOp(node, model)
res_dict[node.name] = inst.node_res_estimation(fpgapart)

return res_dict
Expand All @@ -60,7 +59,7 @@ def res_estimation_complete(model, fpgapart):
res_dict = {}
for node in model.graph.node:
if is_hls_node(node) or is_rtl_node(node):
inst = registry.getCustomOp(node)
inst = getHWCustomOp(node, model)
op_type = node.op_type
if op_type.startswith("MVAU") or op_type.startswith("VVAU"):
orig_restype = inst.get_nodeattr("resType")
Expand Down
Loading