Research-Stack/4-Infrastructure/hardware/build_research_stack.sh
Brandon Schneider 9f304abab0 feat: fractal dimension — DBC algorithm (Python + FPGA)
Paper: 'Ultra-fast computation of fractal dimension for RGB images'
  (Pattern Analysis and Applications, 2025)

Python (fractal_dimension.py):
- DBC algorithm with numpy vectorization (29x faster than scalar)
- fd_compress_hint: FD → voltage mode (STORE/COMPUTE/APPROX/MORPHIC)
- 7/7 tests pass (Sierpinski, random, gradient, checkerboard, fBm, constant, RGB)
- Q16_16 integer arithmetic internally

FPGA (fractal_box_counter.v + fractal_fd_selector.v):
- 5-state FSM: IDLE → COLLECT → FINALIZE → STORE_LOG → REGRESS → DONE
- 8 power-of-two scales (2, 4, 8, ..., 256)
- Linear regression via Q16_16 64-bit arithmetic
- FD clamped to [1.0, 3.0] in Q16_16
- Selector: FD < 2.3 → STORE, < 2.6 → COMPUTE, < 2.9 → APPROX, >= 2.9 → MORPHIC
- Integrated into research_stack_top.v

FD drives adaptive compression:
  Low FD (smooth) → STORE mode (minimal compression)
  High FD (rough) → MORPHIC mode (aggressive compression)
2026-05-29 20:45:21 -05:00

43 lines
985 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
TOP="research_stack_top"
CST="research_stack_tangnano9k.cst"
JSON="research_stack_top.json"
PNR="research_stack_top_pnr.json"
FS="research_stack_top.fs"
DEVICE="GW1NR-LV9QN88PC6/I5"
FAMILY="GW1N-9C"
FREQ=27
Q16_V="../../5-Applications/out/verilog/q16_lut_core.v"
echo "=== Synthesis ==="
yosys -p "
read_verilog -sv \
${Q16_V} \
blitter_memory_map.v \
voltage_mode_controller.v \
scale_space_bram.v \
highs_pivot_accelerator.v \
fractal_box_counter.v \
fractal_fd_selector.v \
Blitter6502OISC_small.v \
research_stack_top.v;
synth_gowin -top ${TOP} -json ${JSON};
stat
"
echo ""
echo "=== Place & Route ==="
nextpnr-himbaechel --device "${DEVICE}" --json "${JSON}" --write "${PNR}" \
--freq "${FREQ}" --vopt "family=${FAMILY}" --vopt "cst=${CST}"
echo ""
echo "=== Bitstream ==="
gowin_pack -d "${FAMILY}" -o "${FS}" "${PNR}"
echo ""
echo "=== Done: ${FS} ==="
ls -lh "${FS}"