This project generates benchmarks for High-Level Synthesis (HLS) model checking by creating random computation graphs, compiling them to HDL using Vitis HLS, and producing miter circuits for equivalence checking. The tool generates pairs of functionally equivalent but structurally different C++ programs to test HLS optimization and verification tools.
- Random Graph Generation: Creates directed acyclic graphs representing computations with operations, arrays, loops, and branches
- Pragma Insertion: Automatically inserts different HLS optimization pragmas to create functionally equivalent but differently optimized designs
- HLS Compilation: Compiles C++ code to Verilog using Xilinx Vitis HLS
- Miter Generation: Creates miter circuits for equivalence checking between two HLS implementations
- BTOR2 Output: Converts miter circuits to BTOR2 format for SMT solvers
- BanditFuzz: Multi-agent reinforcement learning for performance-driven fuzzing
- Configurable Parameters: Supports customization of seeds, output directories, clock periods, and more
- Python 3.9+
networkx- For graph data structures and algorithmsnumpy- For numerical operationsmatplotlib- For graph visualization (optional)
- Xilinx Vitis HLS - Required for C++ to HDL synthesis
- Must be installed and
vitis_hlscommand available in PATH
- Must be installed and
- Yosys - Open-source synthesis tool for Verilog processing
- Used for flattening and BTOR2 conversion
- Bitwuzla - SMT solver for BTOR2 verification
- SMT-Sweeper - Alternative SMT solver for performance comparison
- clang-format (optional) - For C++ code formatting
-
Clone the repository:
git clone <repository-url> cd hls_model_checking_benchmark_generator
-
Install Python dependencies:
pip install networkx numpy matplotlib
-
Install external tools:
- Install Xilinx Vitis HLS and ensure
vitis_hlsis in your PATH - Install Yosys:
sudo apt-get install yosys(Ubuntu/Debian) or build from source - Optional: Install clang-format:
sudo apt-get install clang-format
- Install Xilinx Vitis HLS and ensure
Generate HLS benchmarks with default settings:
python src/main.pypython src/main.py [OPTIONS]Options:
--seed SEED- Random seed for graph generation (default: 42)--output-dir DIR- Output directory for generated files (default: ./output)--cpp-file FILE- Name of C++ output file (default: benchmark.cpp)--project-name NAME- HLS project name (default: hls_benchmark)--top-function NAME- Top-level function name (default: top)--action-count COUNT- Number of graph generation actions (default: 20)--skip-compilation- Skip Vitis HLS compilation step--bandit-fuzz- Enable BanditFuzz mode for performance optimization--bandit-iterations N- Number of BanditFuzz iterations (default: 100)--verbose, -v- Enable verbose output
-
Generate benchmarks with a specific seed:
python src/main.py --seed 123 --verbose
-
Generate only C++ files without compilation:
python src/main.py --skip-compilation --output-dir ./my_output
-
Custom project settings:
python src/main.py --project-name my_project --top-function compute --clock-period 5
-
Run BanditFuzz for performance optimization:
python src/main.py --seed 114512 --bandit-fuzz --bandit-iterations 5 # or python src/main.py --bandit-fuzz --bandit-iterations 50 --verbose -
Test BanditFuzz learning:
python test_bandit_learning.py
The tool generates the following output structure:
output/
├── benchmark_1.cpp # First C++ implementation
├── benchmark_2.cpp # Second C++ implementation (with different pragmas)
├── compile_1/ # Vitis HLS compilation results for first implementation
│ ├── hls_script_1.tcl # HLS synthesis script
│ ├── hls_compile_1.log # Compilation log
│ └── hls_benchmark_1/ # HLS project directory
│ └── solution1/
│ ├── syn/verilog/ # Generated Verilog files
│ └── ...
├── compile_2/ # Vitis HLS compilation results for second implementation
│ └── ...
└── miter/ # Miter generation results
├── merged_1.v # Merged Verilog from first implementation
├── merged_2.v # Merged Verilog from second implementation
├── miter.v # Generated miter circuit
└── miter.btor2 # BTOR2 format output
- Graph Generation: Creates a random computation graph with nodes representing operations, arrays, loops, and branches
- C++ Generation: Converts the graph to two functionally equivalent C++ programs with different optimization pragmas
- HLS Compilation: Compiles both C++ programs to Verilog using Vitis HLS
- Miter Creation: Merges the Verilog files and creates a miter circuit for equivalence checking
- BTOR2 Export: Converts the miter to BTOR2 format for SMT solver verification
- Multi-Agent Learning: Uses Thompson Sampling with two agents (strategy and action selection)
- Performance-Driven Generation: Iteratively generates benchmarks to maximize solver performance differences
- Adaptive Optimization: Learns which graph mutations and strategies produce better results
- Continuous Improvement: Updates agent parameters based on solver performance feedback
The project consists of several key modules:
main.py- Command-line interface and workflow orchestrationrandom_graph_manager.py- Random computation graph generationgraph_manager.py- Base graph management and C++ code generationbanditGen.py- BanditFuzz multi-agent reinforcement learning implementationagents/thompson.py- Thompson Sampling agent for action selectionvitis_hls_compiler.py- Vitis HLS compilation interfacemiter_generator.py- Miter circuit creationyosys_compiler.py- Yosys tool interface for Verilog processingnode.py- Graph node definitions and typesverilog_processing.py- Verilog file manipulation utilities
-
Vitis HLS not found:
- Ensure Vitis HLS is installed and
vitis_hlscommand is in your PATH - Check with:
which vitis_hls
- Ensure Vitis HLS is installed and
-
Yosys compilation errors:
- Verify Yosys installation:
yosys --version - Check that Verilog files are valid
- Verify Yosys installation:
-
Python import errors:
- Ensure all required packages are installed
- Verify Python path includes the src directory
Enable verbose output for detailed information:
python src/main.py --verbosepython train.py --data-path train.csv --output-dir artifacts --max-evals 20Test
python predict.py artifacts/models/rIC3_model.joblib sample_input.json