Skip to content

[add][docs] add Part 5 VitisUnified accelerator backend tutorials - #130

Open
Tanawin1701d wants to merge 1 commit into
fastmachinelearning:mainfrom
Tanawin1701d:main
Open

Tanawin1701d wants to merge 1 commit into
fastmachinelearning:mainfrom
Tanawin1701d:main

Conversation

@Tanawin1701d

Copy link
Copy Markdown

Add Part 5: VitisUnified accelerator backend tutorials

This PR adds a new Part 5 with a set of notebooks for the VitisUnified backend
(hls4ml PR fastmachinelearning/hls4ml#1376), which produces a bitstream plus a PYNQ driver for
a SoC board (zcu102 or kv260).

What's added

New directory 5_accelerator_backends/vitis_unified/:

File Purpose
5_vu_a_predict.ipynb Convert a tiny Keras U-Net with the VitisUnified backend and check that predict() matches the plain Vitis backend
5_vu_b_csim.ipynb C synthesis + C simulation; compare csim output against the C++ bridge predictions
5_vu_c_cosim.ipynb RTL co-simulation; compare cosim output against the bridge predictions
5_vu_d_fifo_depth.ipynb Run the vitisunified:fifo_depth_optimization flow and inspect fifo_depths.json
5_vu_e_bitfile.ipynb Full system link + Vivado implementation; lists the export/ files (system.bit, system.hwh, PYNQ driver) to copy to the board
5_vu_f_platform_setup.md Step-by-step guide (with screenshots) for building the extensible Vitis platform in Vivado, needed for the axi_stream mode and the kv260

Supporting changes:

  • models.py: add create_simple_unet() (small Keras U-Net with one skip connection; random weights, since these notebooks exercise the flow, not accuracy).
  • _toc.yml: register the Part 5 chapters.
  • README.md: new "Accelerator backends (Part 5)" section with the Vitis/Vivado 2023.2 requirement and the pip install line for PR #1376.
  • images/part5f_*.png: screenshots for the platform setup guide.

- Add 5_accelerator_backends/vitis_unified/5_vu_{a..f}: predict, csim, cosim, FIFO depth optimization, bitfile build, and Vitis platform setup guide
- Use absolute output_dir for VitisUnified projects (backend resolves v++ --config relative to the workspace cwd)
- Add create_simple_unet Keras model to models.py for the Part 5 notebooks
- Add Part 5 screenshots (images/part5f_*.png) and register notebooks in _toc.yml
- Document Part 5 requirements (Vitis/Vivado 2023.2, hls4ml PR #1376) in README

TODO:
- [ ] Pin VitisUnified backend in environment.yml once hls4ml PR #1376 is merged
@nghielme

Copy link
Copy Markdown

I think this PR should now be considered, given that Vitis Unified backend has been merged to hls4ml

@nghielme
nghielme requested a review from JanFSchulte November 20, 2026 13:45
@JanFSchulte

Copy link
Copy Markdown
Collaborator

Hi! There are 2 things that are blocking this at the moment:

  • We still don't have a release that includes the backends and I don't think the tutorial should require installing from main. So I would in general wait until we make the next release and then update the instructions here to match.
  • The merged PR is slightly different to what this tutorial is based on, so it needs a few updates. I had Claude review it anyway and it has a few other suggestions:

Needs changes before merge

**1. Main also supports Alveo cards (alveo-u55c, alveo-u50, alveo-u280) through an XRT driver. Part 5 only covers the PYNQ SoC boards, which is fine, but "a supported board: zcu102 or kv260" should say this part covers the SoC boards and link to the hls4ml docs for the cards.

2. Update 5_vu_f_platform_setup.md to match the merged backend.

  • The converter now takes platform= and part= for a board that isn't in supported_boards.json. So "There is no option to pass a platform path from Python" is no longer true. Section 8 and the "Quick fix" can shrink to:
    hls_model = hls4ml.converters.convert_from_keras_model(
        model,
        hls_config=config,
        backend='VitisUnified',
        io_type='io_stream',
        output_dir='hls4ml_prj',
        board='myboard',
        part='<fpga part>',
        platform='/path/to/myboard_platform.xsa',
        axi_mode='axi_master',
    )
  • Driver templates now live in a shared templates/vitis_unified/drivers/ folder. kv260/python_drivers/ doesn't exist, so the cp command in 8.1 fails.
  • supported_boards.json entries no longer have python_driver or c_drivers keys, so both JSON examples are stale.

Correctness

  • 5d, when the FIFO step runs: the markdown says the FIFO-optimization co-simulation "happens inside compile()". hls4ml applies config['Flows'] in ModelGraph.from_layer_list, which runs during conversion. The 10–20 minute wait happens in the convert_from_keras_model cell.
  • 5d, output format: each entry in fifo_depths.json is {'initial': ..., 'optimized': ...}, so the loop prints raw dicts. A before/after table is the main thing this notebook should show. Adding BRAM usage before and after would be even better.
  • 5a, reason for io_stream: the notebook says io_stream is "required for the CNN layers", but hls4ml supports io_parallel for CNNs. The actual reason is that VitisUnified only supports io_stream and raises an error for anything else (see the Limitations section of its docs).
  • 5a, board part: the reference Vitis conversion hard-codes the zcu102 part (xczu9eg-ffvb1156-2-e) even when BOARD = 'kv260'. It doesn't affect predictions, but it should follow BOARD or have a comment.
  • 5e, when Vivado is needed: the markdown says Vivado must be on PATH only when the platform is built from Tcl (zcu102 with axi_stream, or kv260). The link step always runs vivado and xclbinutil, and build(bitfile=True) checks for both on every board. The notebook already adds $XILINX_VIVADO/bin unconditionally, so only the explanation needs fixing.

Teaching design

  • Model and reports: these notebooks are close ports of test/pytest/test_vitis_unified.py. They use a random-weight 4×4 U-Net and mostly assert that outputs match. The rest of the tutorial uses trained models and shows reports. Using a model trained earlier, such as the Part 1 jet tagger, would make on-board results meaningful. The merged backend also makes reports easy to show:
    • build() returns CSynthesisReport, CosimReport, and BitfileReport after bitfile=True.
    • vsynth=True and pnr=True give Vivado utilization and timing for the kernel alone, without the hour-plus bitfile run.
  • Duplication: 5b, 5c and 5d repeat the same setup, model-building and reference-prediction cells almost word for word. Consider combining them into one notebook, or having 5a save the model and data for later notebooks to load. The comparison could also use y_ref directly, since tb_output_predictions.dat is a copy of it.
  • Seeding: np.random.seed(0) doesn't seed Keras weight initialization, so each notebook builds a different model. keras.utils.set_random_seed(0) fixes this, or save and load the model once.
  • 5e ends before the board: a short on-board example (not executed) would complete the tutorial. hls4ml's test/board/vitis_unified_hw_test.py already loads the generated driver and compares against saved predictions, so a trimmed version of it would fit here. The markdown also says the .npy files go to the board, but the "files to copy" printout only lists export/.

Smaller items

  • Project folder names include AXI_MODE but not BOARD. Because build defaults to reset=False, switching boards reuses a folder with leftover build files.
  • The VitisUnified projects use os.path.abspath, but the Vitis reference project uses a relative path. Please make them consistent, or add a comment if the backend needs absolute paths.
  • models.py:
    • create_simple_unet is a Keras function in a module that imports torch.
    • The module docstring still points to 1b_train_pytorch.ipynb.
    • model.compile(...) isn't needed since the model is never trained.
    • This helper might fit better inside the Part 5 folder.
  • 5f step 7.1 says the DCP file must be deleted but doesn't say why.
  • The new README section repeats the existing "installtion" typo.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants