Skip to content

Commit e5e8a13

Browse files
committed
Make averaging window size configurable
1 parent a0544f3 commit e5e8a13

6 files changed

Lines changed: 21 additions & 7 deletions

File tree

custom_hls/instrumentation.template.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
ts1 = cnt_clk; // mark completion ^
292292

293293
// Sliding-window average update
294+
// TODO: II=1 but depth is ~70 cycles, can we optimize this?
294295
ap_uint<32> win = (avg_n == 0 || avg_n > AVG_N) ? ap_uint<32>(AVG_N) : avg_n;
295296
if(prev_avg_n != win) {
296297
avg_head = 0;

src/finn/builder/build_dataflow_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ def _fix_path(p: Path | None) -> Path | None:
538538
#: If enable_instrumentation is True, one can disable the DMA with this flag
539539
instrumentation_no_dma: Optional[bool] = False
540540

541+
#: (Only relevant if enable_instrumentation is True) Size of the averaging window
542+
#: (number of frames) used by the instrumentation wrapper for throughput measurement.
543+
instrumentation_avg_n: int = 64
544+
541545
#: Whether pdb postmortem debugging will be launched when the build fails.
542546
enable_build_pdb_debug: bool = False
543547

src/finn/builder/build_dataflow_steps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,7 @@ def step_synthesize_bitfile(model: ModelWrapper, cfg: DataflowBuildConfig):
15151515
cfg.enable_hw_debug,
15161516
cfg.enable_instrumentation,
15171517
cfg.instrumentation_no_dma,
1518+
cfg.instrumentation_avg_n,
15181519
cfg.live_fifo_sizing,
15191520
partition_model_dir=partition_model_dir,
15201521
)

src/finn/templates/python_driver/driver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def reset_accelerator(self):
601601
offset=self.ip_dict["axi_gpio_0"]["registers"]["GPIO_DATA"]["address_offset"], value=0
602602
)
603603

604-
def start_accelerator(self, throttle_interval=0):
604+
def start_accelerator(self, throttle_interval=0, avg_window_size=64):
605605
"""
606606
Start the accelerator. Input is throttled to the specified interval (in cycles)
607607
by pausing after each FM transmission. A throttle_interval of 0 means no throttling.
@@ -610,8 +610,9 @@ def start_accelerator(self, throttle_interval=0):
610610
lfsr_seed = (self.seed << 16) & 0xFFFF0000 # upper 16 bits
611611
self.instrumentation_write("seed", lfsr_seed)
612612

613-
# Set average measurement window size (in frames)
614-
self.instrumentation_write("avg_n", 65536) # max window size
613+
# Set average measurement window size (in frames),
614+
# maximum is configured in build config, default value = 64
615+
self.instrumentation_write("avg_n", avg_window_size)
615616

616617
# Start operation
617618
self.instrumentation_write("cfg", (throttle_interval << 1) | 1) # bit 0 = start

src/finn/transformation/fpgadataflow/instrumentation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ def __init__(
4343
self,
4444
fpga_part,
4545
clk_period_ns,
46+
avg_n=64,
4647
format="ip", # "ip" for Vivado (Zynq) or "xo" for Vitis (Alveo/Versal)
4748
):
4849
"""Initialize instrumentation IP generation with FPGA part and clock settings."""
4950
super().__init__()
5051
self.fpga_part = fpga_part
5152
self.clk_period_ns = clk_period_ns
53+
self.avg_n = avg_n
5254
self.format = format
5355

5456
def apply(self, model):
@@ -86,8 +88,7 @@ def apply(self, model):
8688
) as f:
8789
instrwrp_cpp = f.read()
8890
instrwrp_cpp = instrwrp_cpp.replace("@PENDING@", str(pending))
89-
# Fixed max average window size for now:
90-
instrwrp_cpp = instrwrp_cpp.replace("@AVG_N@", str(65536))
91+
instrwrp_cpp = instrwrp_cpp.replace("@AVG_N@", str(self.avg_n))
9192
instrwrp_cpp = instrwrp_cpp.replace("@ILEN@", str(ilen))
9293
instrwrp_cpp = instrwrp_cpp.replace("@OLEN@", str(olen))
9394
instrwrp_cpp = instrwrp_cpp.replace("@TI@", str(ti))

src/finn/transformation/fpgadataflow/make_zynq_proj.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ def __init__(
625625
enable_debug=False,
626626
enable_instrumentation=False,
627627
instrumentation_no_dma=False,
628+
instrumentation_avg_n=64,
628629
live_fifo_sizing=False,
629630
partition_model_dir=None,
630631
):
@@ -637,6 +638,7 @@ def __init__(
637638
self.enable_debug = enable_debug
638639
self.enable_instrumentation = enable_instrumentation
639640
self.instrumentation_no_dma = instrumentation_no_dma
641+
self.instrumentation_avg_n = instrumentation_avg_n
640642
self.live_fifo_sizing = live_fifo_sizing
641643
self.partition_model_dir = partition_model_dir
642644

@@ -652,14 +654,18 @@ def apply(self, model):
652654
if self.enable_instrumentation:
653655
if self.instrumentation_no_dma is True or self.live_fifo_sizing is True:
654656
prep_transforms = [
655-
GenerateInstrumentationIP(self.fpga_part, self.period_ns),
657+
GenerateInstrumentationIP(
658+
self.fpga_part, self.period_ns, self.instrumentation_avg_n
659+
),
656660
Floorplan(),
657661
CreateDataflowPartition(partition_model_dir=self.partition_model_dir),
658662
]
659663
else:
660664
# DMA & Instrumentation Wrapper Case
661665
prep_transforms = [
662-
GenerateInstrumentationIP(self.fpga_part, self.period_ns),
666+
GenerateInstrumentationIP(
667+
self.fpga_part, self.period_ns, self.instrumentation_avg_n
668+
),
663669
InsertIODMA(self.axi_port_width),
664670
InsertDWC(),
665671
SpecializeLayers(self.fpga_part),

0 commit comments

Comments
 (0)