forked from Xilinx/finn
-
Notifications
You must be signed in to change notification settings - Fork 9
Integrate C++ driver #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
ef412d9
Add Singularity support to existing run script
fpjentzsch 8adee81
Add GHA to build & test singularity container
fpjentzsch 39e88cd
[Singularity] Add documentation
fpjentzsch 7d7d061
[Singularity] Fixes for GHA
fpjentzsch ed1a325
[Singularity] Fixes for GHA
fpjentzsch 5aa85d0
[Singularity] Increase build space for GHA
fpjentzsch 71259c5
[Singularity] Adjust build space for GHA
fpjentzsch 3ed04b8
[Singularity] GHA fixes
fpjentzsch 8f263bc
[Singularity] Adjust GHA
fpjentzsch be61c31
[Singularity] Adjust GHA
fpjentzsch a61ac9b
[Singularity] Adjust GHA
fpjentzsch c80c03c
Merge remote-tracking branch 'upstream/dev' into feature/apptainer
fpjentzsch cbf9f48
Skeleton for C driver generation
bwintermann f0bdea2
Creating templates for C and C++ drivers
bwintermann 634ef9f
C++ kernel wip
bwintermann 24a8066
Fixes for C++ driver
bwintermann 201011a
Fixes for driver creation
bwintermann 60640dd
C++ driver buffers and memory initialization
bwintermann c0b390c
Compilation fix
bwintermann 89e3ff3
Inclusion of cpp drivers per submodule. Fixes for MakeCPPDriver
bwintermann 820e8f8
Fixes for c++ driver generation
bwintermann ea554b5
Fixed driver export
bwintermann c5225e1
Temporary debugging print statements
bwintermann 50b04d2
Updated to write out header and config files for updated cpp driver
bwintermann 2145749
Updated finn-cpp-driver submodule to track dev branch
bwintermann b5aaa2d
Some path fixing
bwintermann cacbd55
Transfer run-docker update for singularity from PR
bwintermann 7c39ad5
Fixed path errors during cpp driver step
bwintermann 9b521f5
Fixed pathing issues and type name conversion
bwintermann 1e2aea6
Datatype parser fix
bwintermann da51f97
Add support for U55C to FINN
LinusJungemann dcc0f14
Update gitignore
LinusJungemann b179136
Merge branch 'singularity_support' into dev
LinusJungemann 40f9495
Periodic merge of Xilinx FINN into Eki FINN
LinusJungemann f4552e8
Change HBM bank allocation to use different banks for input and output
LinusJungemann e1303d2
Merge dev into c_driver to get c_driver up to newest version
LinusJungemann 9e65299
Update finn integration of C++ driver
LinusJungemann 1428ca9
Add C++ driver integration to FINN
LinusJungemann cd2e82f
Remove some merge artifacts#
LinusJungemann 8bf469e
Update documentation
LinusJungemann fa7cef9
Remove debug printing
LinusJungemann 7c5b3fd
Merge branch 'dev' into feature/integrateCppDriver
LinusJungemann 6dbe116
Move high performance driver version to v1.1
LinusJungemann 46cceaa
Merge remote-tracking branch 'upstream/dev' into feature/integrateCpp…
auphelia faba00a
Unify Python and C++ driver generation
LinusJungemann ac6e2ed
Update repo checkout and dependency building
LinusJungemann 8b4c26d
Remove C++ driver as a submodule, because it is now cloned during run…
LinusJungemann 113b8ea
Remove finn-plus code that is unneccesary for finn
LinusJungemann 9c9b195
Fix small issues
LinusJungemann 8ed6263
Fix output to shell
LinusJungemann 7e1d6ce
Fix linting
LinusJungemann c709777
Fix linting
LinusJungemann 75d5b77
Merge branch 'feature/integrateCppDriver' of github.com:LinusJungeman…
LinusJungemann 5b63111
Revert changes to notebooks
LinusJungemann e2a217f
Merge remote-tracking branch 'origin/dev' into feature/integrateCppDr…
LinusJungemann 2c2a33a
Remove replicated code
LinusJungemann aec60db
Add missing import
LinusJungemann 808798a
Add license
LinusJungemann c1415b4
Merge C++ driver
LinusJungemann fbc8dfc
Change output format
LinusJungemann cb43305
Replace warnings package and fix linting
LinusJungemann 19d94b7
Add warnings for untested features
LinusJungemann 092ca58
Update notebooks
LinusJungemann 60acc6a
Merge branch 'dev' into feature/integrateCPPDriver
fpjentzsch e6ac73a
Adjust make_driver to refactoring of FINN_ROOT
fpjentzsch dcefe27
Delete empty file
fpjentzsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ __pycache__/* | |
| .cache/* | ||
| .*.swp | ||
| *.ipynb_checkpoints* | ||
| *.sif | ||
|
|
||
| # Project files | ||
| .vscode | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/finn/transformation/fpgadataflow/get_driver_shapes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # Copyright (C) 2025, Advanced Micro Devices, Inc. | ||
| # All rights reserved. | ||
|
|
||
| # Redistribution and use in source and binary forms, with or without | ||
| # modification, are permitted provided that the following conditions are met: | ||
|
|
||
| # * Redistributions of source code must retain the above copyright notice, this | ||
| # list of conditions and the following disclaimer. | ||
|
|
||
| # * Redistributions in binary form must reproduce the above copyright notice, | ||
| # this list of conditions and the following disclaimer in the documentation | ||
| # and/or other materials provided with the distribution. | ||
|
|
||
| # * Neither the name of FINN nor the names of its | ||
| # contributors may be used to endorse or promote products derived from | ||
| # this software without specific prior written permission. | ||
|
|
||
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| # 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 numpy as np | ||
| from qonnx.core.modelwrapper import ModelWrapper | ||
| from qonnx.custom_op.registry import getCustomOp | ||
| from qonnx.util.basic import gen_finn_dt_tensor, roundup_to_integer_multiple | ||
| from typing import Dict | ||
|
|
||
| import finn.util.data_packing as dpk | ||
| from finn.util.data_packing import hexstring2npbytearray, pack_innermost_dim_as_hex_string | ||
|
|
||
|
|
||
| def to_external_tensor(init, w_dtype): | ||
| """Return an appropriately formatted and packed numpy byte array for given | ||
| external parameter tensor.""" | ||
|
|
||
| weight_width = init.shape[1] * w_dtype.bitwidth() | ||
| weight_width_padded = roundup_to_integer_multiple(weight_width, 4) | ||
| hex_init = pack_innermost_dim_as_hex_string(init, w_dtype, weight_width_padded, prefix="0x") | ||
| ext_weight = np.array([], dtype=np.uint8) | ||
| for line in hex_init: | ||
| array_line = [x for x in reversed(hexstring2npbytearray(line, remove_prefix="0x"))] | ||
| ext_weight = np.append(ext_weight, array_line) | ||
|
|
||
| return ext_weight | ||
|
|
||
|
|
||
| def get_driver_shapes(model: ModelWrapper) -> Dict: | ||
| idt = [] | ||
| idma_names = [] | ||
| ishape_normal = [] | ||
| ishape_folded = [] | ||
| ishape_packed = [] | ||
| for idma_ind, graph_in in enumerate(model.graph.input): | ||
| i_tensor_name = graph_in.name | ||
| # get inp tensor properties | ||
| i_tensor_dt = model.get_tensor_datatype(i_tensor_name) | ||
| i_tensor_shape_normal = tuple(model.get_tensor_shape(i_tensor_name)) | ||
| # go down into dataflow partition to get folded shape info etc | ||
| # TODO consider setting these as attributes during dataflow partitioning | ||
| i_consumer = model.find_consumer(i_tensor_name) | ||
| assert ( | ||
| i_consumer.op_type == "StreamingDataflowPartition" | ||
| ), """ | ||
| Ensure CreateDataflowPartition called before driver creation.""" | ||
| first_df_model = ModelWrapper(getCustomOp(i_consumer).get_nodeattr("model")) | ||
| assert ( | ||
| first_df_model.graph.node[0].op_type == "IODMA_hls" | ||
| ), "First partition must hold input IODMA" | ||
| successors = model.find_direct_successors(i_consumer) | ||
| successor_input_num = list(successors[0].input).index(i_consumer.output[0]) | ||
| successor_sdp = getCustomOp(successors[0]) | ||
| successor_df_model = ModelWrapper(successor_sdp.get_nodeattr("model")) | ||
| first_node = successor_df_model.find_consumer( | ||
| successor_df_model.graph.input[successor_input_num].name | ||
| ) | ||
| i_tensor_shape_folded = tuple(getCustomOp(first_node).get_folded_input_shape()) | ||
| # generate dummy folded i/o tensors and their packed versions | ||
| i_tensor_dummy_folded = gen_finn_dt_tensor(i_tensor_dt, i_tensor_shape_folded) | ||
| i_tensor_dummy_packed = dpk.finnpy_to_packed_bytearray(i_tensor_dummy_folded, i_tensor_dt) | ||
| i_tensor_shape_packed = i_tensor_dummy_packed.shape | ||
| # append all input tensor info to relevant lists | ||
| idt.append("DataType['%s']" % i_tensor_dt.name) | ||
| ishape_normal.append(i_tensor_shape_normal) | ||
| ishape_folded.append(i_tensor_shape_folded) | ||
| ishape_packed.append(i_tensor_shape_packed) | ||
| idma_names.append(getCustomOp(i_consumer).get_nodeattr("instance_name")) | ||
|
|
||
| odt = [] | ||
| odma_names = [] | ||
| oshape_normal = [] | ||
| oshape_folded = [] | ||
| oshape_packed = [] | ||
| for odma_ind, graph_out in enumerate(model.graph.output): | ||
| o_tensor_name = graph_out.name | ||
| # get inp tensor properties | ||
| o_tensor_dt = model.get_tensor_datatype(o_tensor_name) | ||
| o_tensor_shape_normal = tuple(model.get_tensor_shape(o_tensor_name)) | ||
| # go down into IODMA partition to get folded shape info etc | ||
| # TODO consider setting these as attributes during dataflow partitioning | ||
| o_producer = model.find_producer(o_tensor_name) | ||
| assert ( | ||
| o_producer.op_type == "StreamingDataflowPartition" | ||
| ), """ | ||
| Ensure CreateDataflowPartition called before driver creation.""" | ||
| df_model = ModelWrapper(getCustomOp(o_producer).get_nodeattr("model")) | ||
| assert df_model.graph.node[-1].op_type == "IODMA_hls", "Partition must hold output IODMA" | ||
| predecessors = model.find_direct_predecessors(o_producer) | ||
| predecessor_output_num = list(predecessors[0].output).index(o_producer.input[0]) | ||
| predecessor_sdp = getCustomOp(predecessors[0]) | ||
| predecessor_df_model = ModelWrapper(predecessor_sdp.get_nodeattr("model")) | ||
| last_node = predecessor_df_model.find_producer( | ||
| predecessor_df_model.graph.output[predecessor_output_num].name | ||
| ) | ||
| o_tensor_shape_folded = tuple(getCustomOp(last_node).get_folded_output_shape()) | ||
| o_tensor_dummy_folded = gen_finn_dt_tensor(o_tensor_dt, o_tensor_shape_folded) | ||
| o_tensor_dummy_packed = dpk.finnpy_to_packed_bytearray(o_tensor_dummy_folded, o_tensor_dt) | ||
| o_tensor_shape_packed = o_tensor_dummy_packed.shape | ||
| # append all output tensor info to relevant lists | ||
| odt.append("DataType['%s']" % o_tensor_dt.name) | ||
| oshape_normal.append(o_tensor_shape_normal) | ||
| oshape_folded.append(o_tensor_shape_folded) | ||
| oshape_packed.append(o_tensor_shape_packed) | ||
| odma_names.append(getCustomOp(o_producer).get_nodeattr("instance_name")) | ||
|
|
||
| return { | ||
| "idt": idt, | ||
| "idma_names": idma_names, | ||
| "ishape_normal": ishape_normal, | ||
| "ishape_folded": ishape_folded, | ||
| "ishape_packed": ishape_packed, | ||
| "odt": odt, | ||
| "odma_names": odma_names, | ||
| "oshape_normal": oshape_normal, | ||
| "oshape_folded": oshape_folded, | ||
| "oshape_packed": oshape_packed, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.