Skip to content

Commit 09c3a5a

Browse files
committed
Merge remote-tracking branch 'origin/feature/AddCLSToken' into feature/SelectToken
2 parents 598b572 + 6581499 commit 09c3a5a

9 files changed

Lines changed: 28 additions & 16 deletions

File tree

docs/finn/components/rtl-swg.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Dynamic Mode
9696
The "default" style also supports a dynamic mode, which provides an interface to change feature map dimensions, stride, or dilation at run-time. See `this pull request <https://github.com/Xilinx/finn/pull/688>`_ for more information.
9797

9898
Folding
99-
-------
99+
=======
100100

101101
The RTL SWG is supported by the basic automatic folding algorithm in FINN (:py:mod:`finn.transformation.fpgadataflow.set_folding.SetFolding`). Consider the following implications:
102102

docs/finn/developers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ computer, and you should be able to launch the various .tcl scripts or .xpr proj
9999
Docker container as well.
100100

101101
Linting
102-
-------
102+
=======
103103

104104
We use a pre-commit hook to auto-format Python code and check for issues.
105105
See https://pre-commit.com/ for installation. Once you have pre-commit, you can install

docs/finn/source_code/finn.builder.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Builder
33
*******
44

55
Modules
6-
~~~~~~~
6+
=======
77

88
finn.builder.build\_dataflow
99
----------------------------

docs/finn/source_code/finn.core.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Core
33
****
44

55
Modules
6-
~~~~~~~
6+
=======
77

88
qonnx.core.data\_layout
99
-------------------------

docs/finn/source_code/finn.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The FINN sources are divided into different modules. They are listed below.
66
.. note:: **Some of these functions and modules are located in the `qonnx` repository.**
77

88
Modules
9-
~~~~~~~
9+
=======
1010

1111
.. toctree::
1212
:maxdepth: 1

src/finn/custom_op/fpgadataflow/rtl/addclstoken_rtl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def get_rtl_file_list(self, abspath=False):
135135
]
136136
return verilog_files
137137

138+
def get_rtlsim_input_indices(self):
139+
"""Only patch tokens are streamed; CLS token data is embedded in generated RTL."""
140+
return [0]
141+
138142
def code_generation_ipi(self):
139143
code_gen_dir = self.get_nodeattr("code_gen_dir_ipgen")
140144
sourcefiles = self.get_rtl_file_list()

src/finn/custom_op/fpgadataflow/rtlbackend.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,21 @@ def code_generation_ipi(self):
8585
def code_generation_ipgen(self, model, fpgapart, clk):
8686
self.generate_hdl(model, fpgapart, clk)
8787

88+
def get_rtlsim_input_indices(self):
89+
"""Return ONNX input indices that are driven as RTLSim input streams."""
90+
return range(len(self.onnx_node.input))
91+
8892
def execute_node(self, context, graph):
8993
mode = self.get_nodeattr("exec_mode")
9094
code_gen_dir = self.get_nodeattr("code_gen_dir_ipgen")
9195

9296
if mode == "rtlsim":
9397
node = self.onnx_node
9498
inputs = {}
95-
for i, inp in enumerate(node.input):
99+
for i in self.get_rtlsim_input_indices():
100+
inp = node.input[i]
96101
nbits = self.get_instream_width(i)
97-
if nbits == 0:
98-
continue
102+
assert nbits > 0, "RTLSim input stream %d has zero width." % i
99103
exp_ishape = tuple(self.get_normal_input_shape(i))
100104
folded_ishape = self.get_folded_input_shape(i)
101105
inp_val = context[inp]

src/finn/transformation/fpgadataflow/specialize_layers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ def apply(self, model):
389389
node.input,
390390
node.output,
391391
domain="finn.custom_op.fpgadataflow." + impl_style,
392-
name=node.name,
393392
)
394393
# add all attributes
395394
for attribute in node.attribute:

tests/fpgadataflow/test_fpgadataflow_addclstoken.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ def _prepare_addclstoken_stitched_ip_model(simd=1, pad_tokens=0):
120120
return model, cls_values
121121

122122

123+
def _make_input_dict(model, patches):
124+
return {model.graph.input[0].name: patches}
125+
126+
123127
@pytest.mark.fpgadataflow
124128
def test_convert_concat_to_addclstoken():
125129
model, cls_values = _make_concat_model()
126130
patches = np.arange(12, dtype=np.float32).reshape(1, 3, 4)
127131
expected = np.concatenate([cls_values, patches], axis=1)
128132

129-
ret = execute_onnx(model, {"patches": patches})
133+
ret = execute_onnx(model, _make_input_dict(model, patches))
130134
assert (ret["out"] == expected).all()
131135

132136
model = model.transform(InferAddCLSTokenLayer())
@@ -139,13 +143,13 @@ def test_convert_concat_to_addclstoken():
139143
assert inst.get_normal_output_shape() == (1, 4, 4)
140144
assert inst.get_exp_cycles() == 16
141145

142-
ret = execute_onnx(model, {"patches": patches})
146+
ret = execute_onnx(model, _make_input_dict(model, patches))
143147
assert (ret["out"] == expected).all()
144148

145149
model = model.transform(SpecializeLayers(FPGA_PART))
150+
model = model.transform(GiveUniqueNodeNames())
146151
assert model.graph.node[0].op_type == "AddCLSToken_rtl"
147152
assert model.graph.node[0].domain == "finn.custom_op.fpgadataflow.rtl"
148-
assert model.graph.node[0].name == "AddCLSToken_concat_cls"
149153

150154

151155
@pytest.mark.fpgadataflow
@@ -157,7 +161,7 @@ def test_addclstoken_python_execution_with_padding():
157161
axis=1,
158162
)
159163

160-
ret = execute_onnx(model, {"patches": patches})
164+
ret = execute_onnx(model, _make_input_dict(model, patches))
161165
assert (ret["out"] == expected).all()
162166

163167

@@ -178,14 +182,15 @@ def test_addclstoken_rtl_codegen(tmp_path, finn_dtype, cls_values, expected_cls_
178182
cls_values=cls_values,
179183
)
180184
model = model.transform(SpecializeLayers(FPGA_PART))
185+
model = model.transform(GiveUniqueNodeNames())
181186

182187
node = model.graph.node[0]
183188
inst = getCustomOp(node)
184189
inst.set_nodeattr("code_gen_dir_ipgen", str(tmp_path))
185190
inst.code_generation_ipgen(model, FPGA_PART, CLK_NS)
186191

187192
topname = inst.get_nodeattr("gen_top_module")
188-
assert topname == "AddCLSToken_0"
193+
assert topname == node.name
189194
wrapper = tmp_path / (topname + ".v")
190195
core = tmp_path / "addclstoken.sv"
191196
assert wrapper.is_file()
@@ -244,7 +249,7 @@ def test_addclstoken_rtlsim(simd, pad_tokens):
244249
model = model.transform(SetExecMode("rtlsim"))
245250
model = model.transform(PrepareRTLSim())
246251

247-
ret = execute_onnx(model, {"patches": patches})
252+
ret = execute_onnx(model, _make_input_dict(model, patches))
248253
assert (ret["out"] == expected).all()
249254

250255
node = model.get_nodes_by_op_type("AddCLSToken_rtl")[0]
@@ -273,7 +278,7 @@ def test_addclstoken_stitched_ip_rtlsim(simd, pad_tokens):
273278

274279
model.set_metadata_prop("exec_mode", "rtlsim")
275280

276-
ret = execute_onnx(model, {"patches": patches})
281+
ret = execute_onnx(model, _make_input_dict(model, patches))
277282
assert (ret["out"] == expected).all()
278283

279284

0 commit comments

Comments
 (0)