Add Bambu (PandA) HLS backend - #1509
Conversation
…earning#1448) Vendored here so this branch builds and tests on its own. This code is NOT part of this PR's contribution -- it is the content of open PR fastmachinelearning#1448 by the same author, on which the Bambu backend depends: * parse_vivado_report() split into per-report helpers; bambu_report.py reuses _parse_csim_results, _parse_rtl_cosim_results, _parse_implementation_report, _parse_timing_report, _parse_power_report * PATHS table and _path(), including the vivado_reports/post_route_*.rpt locations Bambu writes its own results into * statistics.tcl and the vivado_synth.tcl rewrite that produce them Review it in fastmachinelearning#1448, not here. When fastmachinelearning#1448 merges, rebasing drops this commit.
Firmware templates, build scripts and the nnet_utils header library used by the Bambu backend. Two submodules come with them: templates/bambu/ac_types ferrandi/ac_types, Bambu's fork templates/bambu/nnet_utils/gcem kthohr/gcem, constexpr math for tables ac_types diverges from the hlslibs/ac_types already vendored for Catapult, so it cannot be shared with that backend.
bb498a0 to
c2f5dff
Compare
Minimal proposed fix: process.communicate()
if process.returncode != 0:
raise RuntimeError(
f'Bambu failed with exit code {process.returncode}: {build_command}'
)The final implementation may use a dedicated exception type and include log |
|
About Known limitations. They are going to be addressed in this PandA-bambu PR ferrandi/PandA-bambu#396 |
BambuBackend converts hls4ml models to HLS C++ and drives Bambu/PandA to synthesizable Verilog, for both io_parallel and io_stream. partname_to_bambu maps hls4ml part names onto Bambu device names. Not registered yet -- registration lands with the writer and report modules it depends on.
bambu_writer.py emits the HLS C++ project; bambu_report.py parses Bambu's XML results and reuses the Vivado report helpers for the post-route utilization, timing and power numbers.
Only the Bambu lines: the accelerator layer registers itself separately.
test_build_bambu.py drives csim, cosim, synth and vsynth on the default Xilinx part. The existing keras/activation/softmax/pooling suites gain 'Bambu' alongside the other backends. conftest.py grows --backend-filter / --backend-exclude / --ci-exclude-nodeid so a pipeline without the Bambu toolchain can deselect these cases; the CI wiring that uses them is a separate PR.
c2f5dff to
336ec2d
Compare
`build()` awaited the Bambu process but never checked its exit status, so a failed run fell through to `parse_bambu_report()`. That returned an empty result which looked like success, or, with `reset=False`, a report left by an earlier run. In the accelerator backend it could reach wrapper and manifest generation without valid RTL. Raise a RuntimeError carrying the command, the exit code and the log paths, and cover it with a test that mocks a non-zero Bambu process. Reported by Fabrizio Ferrandi on fastmachinelearning#1509; backported here from that PR branch.
Picks up six upstream commits on ferrandi/ac_types dev/panda-hls since 35e101a, mostly hls::stream/ac_channel work: DEPTH template parameter on the stream copy constructor and assignment operator (#3), peek support (#4), a gcc 15 / system C++ library fix (#5), improved hls::stream channel data type support (#6), a cosim regression fix (#7), and better set_slc/set_slc2 (#8).
Since ac_types became a git submodule the headers live under ac_types/include, not at the top level, so the USE_HLS4ML_AC_TYPES escape hatch was passing an include path with no headers in it.
|
The binary distribution in the AppImage format has been released and it is available at this URL: https://release.bambuhls.eu/appimage/bambu.ginevra4.AppImage Release note — PandA-bambuHighlights
HLS and frontend fixes
CI, regressions, and toolchain
|
Description
Adds a new HLS backend targeting Bambu (PandA framework,
https://panda.deib.polimi.it), an open-source high-level synthesis tool. The backend
emits C++ from an hls4ml
ModelGraph, drives Bambu for synthesis and Veriloggeneration, and parses the results back into hls4ml's report objects.
Dependency — #1448. The first commit ("Vivado/Vitis build flow and report
improvements (from PR #1448)") is vendored from #1448: the Bambu report parser reuses
that PR's report-parsing helpers and its
vivado_reports/file convention, so thisbranch builds and tests standalone. Once #1448 merges it will be dropped in a rebase.
No divergence from #1448 is intended — I author and control that branch.
New backend surface:
hls4ml/backends/bambu/— backend + layer optimizer passeshls4ml/writer/bambu_writer.py— project/testbench/build-script emitterhls4ml/report/—parse_bambu_reporthls4ml/templates/bambu/— HLS C++nnet_utilsheaders + firmware templatesbambu/ac_types(ferrandi/ac_types, Bambu'sac_types fork) and
bambu/nnet_utils/gcem(compile-time math)docs/backend/bambu.rsttest_activations,test_dense_unrolled,test_multi_dense,test_pooling,test_softmax, …) andconftest.pyfilters(
--backend-filter,--backend-exclude,--ci-exclude-nodeid)Known limitations (documented in
bambu.rst):fix_softmax_table_sizeresizes the inverse LUT, Bambu's clang-16rejects the resulting
constexprtable (compile-time division by zero). Vivado/Vitisfill the LUT at runtime and are unaffected — the affected cases are skipped for Bambu.
-m64+ac_channelcrashes Bambu's InterfaceInfer; the default build path avoids it.Stack & dependencies
Part of a three-PR stack, review in order:
Depends on #1448 (Vivado/Vitis reporting rework): the first commit here vendors it
so the branch stands alone. #1448 must merge first, then this PR is rebased to drop
that vendored commit.
Type of change
Tests
test/pytest/test_build_bambu.pyruns the backend end to end (csim, cosim, synth,vsynth). Bambu cases were added to the shared activation/dense/softmax/pooling tests and
compared against the Keras/QKeras reference like the other backends.
Ran the full Bambu-parametrized suite in the Bambu CI image:
85 passed, 18 skipped, 0 failed; plus
test_build_bambu.pyandtest_report::test_bambu_report.Reproduce:
Test Configuration: image
gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.1.0.bambu,Bambu = PandA 2026.06,
USE_BAMBU_ARRAY_PARTITION=1.CI note
GitHub PR checks here cover pre-commit, the docs build, and the packaging step. The
pytest suite runs on hls4ml's self-hosted GitLab pipeline, which a maintainer triggers
with the
please testlabel. The Bambu test cases need a private image and Bambuitself, so they are gated off on upstream runners — the Bambu results reported above
(85 passed / 18 skipped / 0 failed) come from running that suite in the Bambu CI image
locally, not from upstream CI.
Acknowledgements
The Bambu backend grew out of a collaboration with Politecnico di Milano, developed over 30 merged PRs on the
bambu-backendbranch of this fork.Thanks to Prof. Fabrizio Ferrandi (
@fabrizioferrandi), who supervised the effort and contributed thennet_utilsfoundation for Bambu, a redesign of thehls::streamclass, softplus support, and numerical fixes to the activation helpers (exp_fcn_floatoverflow,iv_baseinitialisation,ac_int).And to the students who worked on it:
@brios-polimi) — theBambuBackend.build()flow, refactored over several rounds into the Vitis-like interface this PR ships, plus thebuild_bambu.shrewrite.@tommasopau) — compile-time activation LUTs (tanh, legacy softmax), softmax bug fixes and the Bambu cases intest_softmax.py, and initialisation fixes innnet_conv1d_resource.h.@danielecursano) — theac_channelconstructor fix, compile-time SELU/ELU tables, and the fixes that got Bambu C-simulation running end to end.@frabazz) — adapted the unrolled Dense codegen to Bambu and enabledtest_resource_unrolled_dense, added Bambu totest_dense, and raisedbuild_lib.shto C++14.@etabeta1) — dropped the vendoredap_typescopy in favour of the headers Bambu ships, and enabled cosimulation in the pooling tests.@pietrobenecchi) — agcem-based compile-time softsign.@Gab-San) — carried the pytest 9 fixture rework (Remove parametrized fixtures from pytests for pytest 9 compatability #1417) through the Bambu tests.@FilippoGarofalo) — a string bug fix intest_pooling.py.Checklist
pre-commiton the files I edited or added.