Skip to content

Commit 71c35c5

Browse files
authored
Merge pull request #989 from LinusJungemann/feature/integrateCppDriver
Add C++ driver support
2 parents 1770b5b + 52e230c commit 71c35c5

14 files changed

Lines changed: 562 additions & 330 deletions

File tree

docs/finn/command_line.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ as it goes through numerous steps:
8181
Running step: step_measure_rtlsim_performance [15/19]
8282
Running step: step_out_of_context_synthesis [16/19]
8383
Running step: step_synthesize_bitfile [17/19]
84-
Running step: step_make_pynq_driver [18/19]
84+
Running step: step_make_driver [18/19]
8585
Running step: step_deployment_package [19/19]
8686
8787

docs/finn/hw_build.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ To rapidly test the generated design on PYNQ platforms, FINN is capable of
3535
generating a Python driver for the given design. This driver packs/unpacks the
3636
input/output tensors in the expected format, then uses PYNQ APIs to initiate
3737
data movement and transfer back the results to the host CPU. The generation of
38-
the driver is done by transformation pass :py:mod:`finn.transformation.fpgadataflow.make_pynq_driver.MakePYNQDriver`.
38+
the driver is done by transformation pass :py:mod:`finn.transformation.fpgadataflow.make_driver.MakePYNQDriver`.
3939

4040
DMA and DWC Node Insertion
4141
---------------------------

docs/finn/source_code/finn.transformation.fpgadataflow.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ finn.transformation.fpgadataflow.insert\_tlastmarker
149149
finn.transformation.fpgadataflow.make\_pynq\_driver
150150
----------------------------------------------------------
151151

152-
.. automodule:: finn.transformation.fpgadataflow.make_pynq_driver
152+
.. automodule:: finn.transformation.fpgadataflow.make_driver
153153
:members:
154154
:undoc-members:
155155
:show-inheritance:

notebooks/advanced/4_advanced_builder_settings.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@
15651565
"metadata": {},
15661566
"source": [
15671567
"You can see that after the generation of the estimate reports, the code generation and the ip generation is invoked (`step_hw_codegen` and `step_hw_ipgen`). The FIFO depths are determined and the FIFOs are inserted in the network (`step_set_fifo_depths`), we can then create an IP design of our whole network by stitching the IPs from each layer together (`step_create_stitched_ip`). At this point we have an implementation of the neural network that we can integrate within a bigger FPGA design, we can run performance measurements using simulation (`step_measure_rtlsim_performance`) and out-of-context synthesis (`step_out_of_context_synthesis`) for it.\n",
1568-
"The FINN builder also provides automatic system integration for Zynq and Alveo devices, this can be invoked by running `step_synthesize_bitfile`, `step_make_pynq_driver` and `step_deployment_package`."
1568+
"The FINN builder also provides automatic system integration for Zynq and Alveo devices, this can be invoked by running `step_synthesize_bitfile`, `step_make_driver` and `step_deployment_package`."
15691569
]
15701570
},
15711571
{
@@ -1782,7 +1782,7 @@
17821782
" \"step_measure_rtlsim_performance\",\n",
17831783
" \"step_out_of_context_synthesis\",\n",
17841784
" \"step_synthesize_bitfile\",\n",
1785-
" \"step_make_pynq_driver\",\n",
1785+
" \"step_make_driver\",\n",
17861786
" \"step_deployment_package\",\n",
17871787
"]\n",
17881788
"\n",

notebooks/end2end_example/bnn-pynq/cnv_end2end_example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@
456456
"metadata": {},
457457
"outputs": [],
458458
"source": [
459-
"from finn.transformation.fpgadataflow.make_pynq_driver import MakePYNQDriver\n",
459+
"from finn.transformation.fpgadataflow.make_driver import MakePYNQDriver\n",
460460
"model = model.transform(MakePYNQDriver(\"zynq-iodma\"))"
461461
]
462462
},

notebooks/end2end_example/bnn-pynq/tfc_end2end_example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@
751751
"metadata": {},
752752
"outputs": [],
753753
"source": [
754-
"from finn.transformation.fpgadataflow.make_pynq_driver import MakePYNQDriver\n",
754+
"from finn.transformation.fpgadataflow.make_driver import MakePYNQDriver\n",
755755
"model = model.transform(MakePYNQDriver(\"zynq-iodma\"))"
756756
]
757757
},

src/finn/builder/build_dataflow_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class DataflowOutputType(str, Enum):
6262
RTLSIM_PERFORMANCE = "rtlsim_performance"
6363
BITFILE = "bitfile"
6464
PYNQ_DRIVER = "pynq_driver"
65+
CPP_DRIVER = "cpp_driver"
6566
DEPLOYMENT_PACKAGE = "deployment_package"
6667

6768

@@ -123,7 +124,7 @@ class VerificationStepType(str, Enum):
123124
"step_measure_rtlsim_performance",
124125
"step_out_of_context_synthesis",
125126
"step_synthesize_bitfile",
126-
"step_make_pynq_driver",
127+
"step_make_driver",
127128
"step_deployment_package",
128129
]
129130

@@ -356,6 +357,11 @@ class DataflowBuildConfig:
356357
#: rtlsim, otherwise they will be replaced by RTL implementations.
357358
rtlsim_use_vivado_comps: Optional[bool] = True
358359

360+
#: Determine if the C++ driver should be generated instead of the PYNQ driver
361+
#: If set to latest newest version will be used
362+
#: If set to commit hash specified version will be used
363+
cpp_driver_version: Optional[str] = "latest"
364+
359365
def _resolve_hls_clk_period(self):
360366
if self.hls_clk_period_ns is None:
361367
# use same clk for synth and hls if not explicitly specified

src/finn/builder/build_dataflow_steps.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import numpy as np
3232
import os
3333
import shutil
34+
import warnings
3435
from copy import deepcopy
3536
from functools import partial
3637
from qonnx.core.modelwrapper import ModelWrapper
@@ -87,7 +88,7 @@
8788
from finn.transformation.fpgadataflow.hlssynth_ip import HLSSynthIP
8889
from finn.transformation.fpgadataflow.insert_dwc import InsertDWC
8990
from finn.transformation.fpgadataflow.insert_fifo import InsertFIFO
90-
from finn.transformation.fpgadataflow.make_pynq_driver import MakePYNQDriver
91+
from finn.transformation.fpgadataflow.make_driver import MakeCPPDriver, MakePYNQDriver
9192
from finn.transformation.fpgadataflow.make_zynq_proj import ZynqBuild
9293
from finn.transformation.fpgadataflow.minimize_accumulator_width import (
9394
MinimizeAccumulatorWidth,
@@ -732,15 +733,31 @@ def step_measure_rtlsim_performance(model: ModelWrapper, cfg: DataflowBuildConfi
732733
return model
733734

734735

735-
def step_make_pynq_driver(model: ModelWrapper, cfg: DataflowBuildConfig):
736-
"""Create a PYNQ Python driver that can be used to interface the generated
737-
accelerator."""
736+
def step_make_driver(model: ModelWrapper, cfg: DataflowBuildConfig):
737+
"""Create a driver that can be used to interface the generated accelerator.
738+
Use DataflowBuildConfig to select PYNQ Python or C++ driver."""
738739

740+
driver_dir = os.path.join(cfg.output_dir, "driver")
739741
if DataflowOutputType.PYNQ_DRIVER in cfg.generate_outputs:
740-
driver_dir = cfg.output_dir + "/driver"
742+
# generate PYNQ driver
741743
model = model.transform(MakePYNQDriver(cfg._resolve_driver_platform()))
742744
shutil.copytree(model.get_metadata_prop("pynq_driver_dir"), driver_dir, dirs_exist_ok=True)
743745
print("PYNQ Python driver written into " + driver_dir)
746+
elif DataflowOutputType.CPP_DRIVER in cfg.generate_outputs:
747+
# generate C++ Driver
748+
model = model.transform(
749+
MakeCPPDriver(
750+
cfg._resolve_driver_platform(),
751+
version=cfg.cpp_driver_version,
752+
)
753+
)
754+
shutil.copytree(model.get_metadata_prop("cpp_driver_dir"), driver_dir, dirs_exist_ok=True)
755+
print("C++ driver written into " + driver_dir)
756+
else:
757+
warnings.warn(
758+
"The step step_make_driver is in the build list but will not be executed"
759+
+ " since no driver is selected in generate_outputs in your build.py file!"
760+
)
744761
return model
745762

746763

@@ -862,7 +879,7 @@ def step_deployment_package(model: ModelWrapper, cfg: DataflowBuildConfig):
862879
"step_set_fifo_depths": step_set_fifo_depths,
863880
"step_create_stitched_ip": step_create_stitched_ip,
864881
"step_measure_rtlsim_performance": step_measure_rtlsim_performance,
865-
"step_make_pynq_driver": step_make_pynq_driver,
882+
"step_make_driver": step_make_driver,
866883
"step_out_of_context_synthesis": step_out_of_context_synthesis,
867884
"step_synthesize_bitfile": step_synthesize_bitfile,
868885
"step_deployment_package": step_deployment_package,

0 commit comments

Comments
 (0)