Skip to content

Commit f21da72

Browse files
committed
First draft of enabling both cpp interfaces in cppsim
1 parent fe69308 commit f21da72

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

src/finn/custom_op/fpgadataflow/hlsbackend.py

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def get_nodeattr_types(self):
5454
"code_gen_dir_cppsim": ("s", False, ""),
5555
"executable_path": ("s", False, ""),
5656
"res_hls": ("s", False, ""),
57+
# temporary node attribute to keep track of interface style of hls ops
58+
"cpp_interface": ("s", False, "packed", {"packed", "hls_vector"}),
5759
}
5860

5961
def get_all_verilog_paths(self):
@@ -206,7 +208,13 @@ def code_generation_cppsim(self, model):
206208
self.dataoutstrm()
207209
self.save_as_npy()
208210

209-
template = templates.docompute_template
211+
if self.get_nodeattr("cpp_interface") == "hls_vector":
212+
self.timeout_value()
213+
self.timeout_condition()
214+
self.timeout_read_stream()
215+
template = templates.docompute_template_timeout
216+
else:
217+
template = templates.docompute_template
210218

211219
for key in self.code_gen_dict:
212220
# transform list into long string separated by '\n'
@@ -422,27 +430,42 @@ def dataoutstrm(self):
422430
if dtype == DataType["BIPOLAR"]:
423431
# use binary for bipolar storage
424432
dtype = DataType["BINARY"]
425-
elem_bits = dtype.bitwidth()
426-
packed_bits = self.get_outstream_width()
427-
packed_hls_type = "ap_uint<%d>" % packed_bits
428433
elem_hls_type = dtype.get_hls_datatype_str()
429434
npy_type = "float"
430435
npy_out = "%s/output.npy" % code_gen_dir
431436
oshape = self.get_folded_output_shape()
432437
oshape_cpp_str = str(oshape).replace("(", "{").replace(")", "}")
433438

434-
self.code_gen_dict["$DATAOUTSTREAM$"] = [
435-
'apintstream2npy<%s, %s, %d, %s>(out_%s, %s, "%s");'
436-
% (
437-
packed_hls_type,
438-
elem_hls_type,
439-
elem_bits,
440-
npy_type,
441-
self.hls_sname(),
442-
oshape_cpp_str,
443-
npy_out,
444-
)
445-
]
439+
cpp_interface = self.get_nodeattr("cpp_interface")
440+
441+
if cpp_interface == "packed":
442+
elem_bits = dtype.bitwidth()
443+
packed_bits = self.get_outstream_width()
444+
packed_hls_type = "ap_uint<%d>" % packed_bits
445+
446+
self.code_gen_dict["$DATAOUTSTREAM$"] = [
447+
'apintstream2npy<%s, %s, %d, %s>(out_%s, %s, "%s");'
448+
% (
449+
packed_hls_type,
450+
elem_hls_type,
451+
elem_bits,
452+
npy_type,
453+
self.hls_sname(),
454+
oshape_cpp_str,
455+
npy_out,
456+
)
457+
]
458+
else:
459+
self.code_gen_dict["$DATAOUTSTREAM$"] = [
460+
'vectorstream2npy<%s, %s, SIMD>(debug_out_%s, %s, "%s");'
461+
% (
462+
elem_hls_type,
463+
npy_type,
464+
self.hls_sname(),
465+
oshape_cpp_str,
466+
npy_out,
467+
)
468+
]
446469

447470
def save_as_npy(self):
448471
"""Function to generate the commands for saving data in .npy file in c++"""

0 commit comments

Comments
 (0)