GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — qwen_fpga/hdk at main · allthingssecurity/qwen_fpga

Expand file tree

/

hdk

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

hdk

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
cl
cl
 
 
design
design
 
 
host
host
 
 
verif
verif
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 

README.md

Outline

HDK / RTL path to silicon

This is the real hardware path: the verified RTL, wrapped as an AWS F2 custom logic (CL), built to a DCP, ingested into an AFI, and loaded on an f2 card. It is the flow that can actually make an FPGA image, unlike the Vitis flow (which only does hw_emu on F2).

What goes on the chip first

design/qwen_matvec_engine.sv is the first CL: the model-verified int8 matvec datapath (matvec_i8 = gemv_i8 + dequant) wrapped in an AXI4-Lite slave so the host drives it directly. The host writes the activation, per-row dequant multipliers, and a weight tile into on-chip BRAM, pulses start, polls done, and reads the int16 results. make -C rtl engine checks it over its own AXI bus against the golden dequant matvec (64/64 rows). This is the datapath every Qwen layer is built from, put on real silicon. The DDR/HBM weight-streaming controller for the full 24-layer model is the next CL on top of this.

The AFI (real, built)

Build 2 (LANES=1) closed timing at 250 MHz (WNS +0.021 ns), packaged a clean post-route DCP, and was ingested into an AFI:

  • FpgaImageId: afi-015d193d047cd142a
  • FpgaImageGlobalId: agfi-0571b2a727ab7ed78

This is a real FPGA image for the VU47P holding the int8 matvec datapath.

It ran on silicon and passed. Loaded agfi-01bd303a0be9536ce on an f2.6xlarge and ran test_qwen_engine: 64/64 rows correct (status=0x1), matching the golden dequant matvec over PCIe. Full transcript in ../artifacts/fpga_run.txt. (The first AFI, afi-015d193d047cd142a, read back status=0x0 because the AXI-Lite write needed AWVALID and WVALID in the same cycle; the fix latches them independently. v2 is the one that runs.)

Timing note (real bring-up finding)

F2 fixes clk_main_a0 at 250 MHz (4 ns) and does not allow lowering it, unlike F1. The first build routed but missed timing by 0.8 ns: the worst path was the LANES=4 int8 multiply-accumulate, a 17-level chain with 10 CARRY8 blocks off a BRAM read. Fix: LANES=1 (one int8 MAC per cycle), which roughly halves the carry chain and closes 250 MHz. The weight BRAM is larger at LANES=1, so it moved to its own address region (addr[20]). Throughput drops but this is a functional proof; the streaming controller will pipeline the MAC to get the width back.

The build, step by step (what was actually run)

On an FPGA Developer AMI instance (Vivado 2025.2, >=64 GiB RAM):

# 1. HDK
git clone --depth 1 -b f2 https://github.com/aws/aws-fpga.git
source /opt/Xilinx/2025.2/Vivado/settings64.sh   # Vivado first...
cd aws-fpga && source hdk_setup.sh                # ...then HDK (it checks for Vivado)

# 2. make a CL from the template and drop the engine in
cd hdk/cl/examples && cp -r CL_TEMPLATE CL_QWEN
mv CL_QWEN/design/CL_TEMPLATE.sv CL_QWEN/design/CL_QWEN.sv
cp <repo>/hdk/design/qwen_matvec_engine.sv <repo>/rtl/{matvec_i8,gemv_i8,dequant}.sv CL_QWEN/design/
#   rename module CL_TEMPLATE -> CL_QWEN, defines CL_NAME -> CL_QWEN,
#   rename build/scripts/synth_CL_TEMPLATE.tcl -> synth_CL_QWEN.tcl,
#   replace the OCL tie-off block with the qwen_matvec_engine instance (see cl/CL_QWEN.sv).
#   encrypt.tcl auto-globs design/*.sv, so no source list to edit.

# 3. sanity: out-of-context synth of just the engine for the VU47P (~5 min)
vivado -mode batch -source ooc.tcl   # synth_design -top qwen_matvec_engine
                                     # -part xcvu47p-fsvh2892-2-e -mode out_of_context
#   -> 0 errors, 0 critical warnings; DSPs for the MACs, BRAM/LUTRAM for the buffers.

# 4. full CL build -> DCP  (synth first, then place & route; hours)
export CL_DIR=$(pwd)/CL_QWEN
cd CL_QWEN/build/scripts
python3 aws_build_dcp_from_cl.py -c CL_QWEN
#   -> build/checkpoints/to_aws/*.Developer_CL.tar

# 5. ingest into an AFI
aws s3 cp build/checkpoints/to_aws/*.tar s3://<bucket>/dcp/
aws ec2 create-fpga-image \
    --input-storage-location Bucket=<bucket>,Key=dcp/<tar> \
    --logs-storage-location  Bucket=<bucket>,Key=logs/
#   -> FpgaImageId (afi-...) and FpgaImageGlobalId (agfi-...); wait for State=available.

# 6. load on an f2 and run the host
#    sudo fpga-load-local-image -S 0 -I <agfi-...>
#    then host peek/poke to the OCL BAR: load x/mult/weights, start, read y.

Anything that has not run to completion is called out in the top-level README status. The OCL AXI-Lite map the engine exposes is in design/qwen_matvec_engine.sv.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.