Skip to content

jfinst1/FPGA-Simulator

Repository files navigation

🚀 Advanced FPGA Simulator

Python License Contributions Documentation

A comprehensive FPGA (Field-Programmable Gate Array) simulator featuring GPU acceleration, quantum computing integration, machine learning optimization, and realistic hardware modeling with power noise simulation.

🌟 Key Features

Core Architecture

  • Configurable Logic Blocks (CLBs) with GPU-accelerated Look-Up Tables
  • Block RAM (BRAM) with Error Correcting Code (ECC) support
  • DSP Blocks for high-speed signal processing (MAC, FFT, FIR)
  • Quantum Processing Unit (QPU) for quantum algorithm acceleration
  • HDL Compilation from Verilog to bitstream
  • Place & Route algorithms with ML optimization

Advanced Capabilities

  • 🎮 GPU Acceleration using CuPy for massive parallelism (10-100x speedup)
  • 🔬 Quantum Computing with Grover's search, QFT, and VQE algorithms
  • 🧠 Machine Learning for routing optimization and prediction
  • Power Noise Modeling with thermal, supply, and crosstalk simulation
  • 🛡️ Fault Tolerance with SEU injection and ECC recovery
  • 🌐 Web Interface for real-time monitoring and control

📋 Table of Contents

🔧 Installation

Basic Installation

# Clone the repository
git clone https://github.com/yourusername/fpga-simulator.git
cd fpga-simulator

# Install basic dependencies
pip install -r requirements.txt

# Or use make
make install

Full Installation (All Features)

# Install with all optional features
make install-all

# Or manually install components:
pip install numpy matplotlib flask  # Basic
pip install cupy-cuda11x           # GPU support (requires CUDA)
pip install qiskit qiskit-aer      # Quantum computing
pip install scikit-learn scipy     # Machine learning

Development Setup

# Install development dependencies
make install-dev

# Or manually:
pip install -e ".[dev]"

🚀 Quick Start

1. Basic Example

from fpga_simulator import AdvancedFPGAFabric

# Create an FPGA
fpga = AdvancedFPGAFabric(rows=8, cols=8, num_brams=4, num_dsps=2)

# Configure a CLB as an AND gate
clb = fpga.clbs[0][0]
clb.configure({'lut': [0]*15 + [1]})  # AND truth table

# Evaluate
result = clb.evaluate(np.array([1, 1, 0, 0]))
print(f"Output: {result.value}")

2. Web Interface

# Start the web interface
python app_simple.py

# Or with make
make run-web

Open http://localhost:5000 in your browser for interactive visualization.

3. Run Examples

# Run interactive examples menu
python examples/basic_example.py

# Or specific examples:
python examples/neural_network.py   # Neural network acceleration
python examples/quantum_search.py   # Quantum algorithms

📚 Examples

Basic Examples (examples/basic_example.py)

Interactive tutorial covering:

  • CLB configuration and evaluation
  • BRAM usage with ECC
  • DSP operations (multiplication, MAC, filtering)
  • Parallel processing
  • HDL compilation
  • Power and noise simulation
  • Fault tolerance demonstration

Neural Network Accelerator (examples/neural_network.py)

  • FPGA-accelerated neural network inference
  • Quantized weights stored in BRAM
  • DSP blocks for matrix multiplication
  • CLB-based activation functions
  • Performance benchmarking vs CPU
# Example: XOR learning on FPGA
fpga = AdvancedFPGAFabric(rows=8, cols=8, num_brams=2, num_dsps=4)
nn = FPGANeuralNetwork(fpga, input_size=2, hidden_size=4, output_size=1)

Quantum Algorithms (examples/quantum_search.py)

  • Grover's search algorithm
  • Quantum Fourier Transform (QFT)
  • Variational Quantum Eigensolver (VQE)
  • Quantum phase estimation
  • Quantum machine learning kernels
# Example: Quantum search for prime numbers
result = fpga.run_quantum_accelerated_search(32, is_prime)

HDL Examples (examples/adder.v)

Sample Verilog code for compilation:

module full_adder(sum, cout, a, b, cin);
    output sum, cout;
    input a, b, cin;
    // Implementation...
endmodule

🏗️ Architecture

Project Structure

fpga-simulator/
├── fpga_simulator.py          # Core simulator implementation
├── fpga_advanced_demo.py      # Advanced feature demonstrations
├── fpga_web_interface.html    # Interactive web visualization
├── app.py                     # Full Flask server
├── app_simple.py             # Minimal Flask server
├── requirements.txt          # Python dependencies
├── setup.py                  # Package installation
├── Makefile                  # Build automation
├── LICENSE                   # MIT License
├── README.md                 # This file
├── CONTRIBUTING.md           # Contribution guidelines
├── examples/                 # Example code
│   ├── basic_example.py     # Interactive tutorial
│   ├── neural_network.py    # NN accelerator demo
│   ├── quantum_search.py    # Quantum algorithms
│   └── adder.v             # Verilog examples
└── tests/                    # Unit tests
    └── test_basic.py        # Basic component tests

Component Hierarchy

AdvancedFPGAFabric
├── ConfigurableLogicBlock (CLB)
│   ├── GPUAcceleratedLUT
│   └── QuantumLogicBlock
├── BlockRAM (BRAM)
│   └── ECC Support
├── DSPBlock
│   ├── Multiply-Accumulate
│   └── FFT/FIR Processing
├── QuantumProcessingUnit (QPU)
│   ├── Grover's Algorithm
│   ├── QFT
│   └── VQE
└── Infrastructure
    ├── PlaceAndRoute
    ├── HDLParser
    ├── BitstreamGenerator
    └── MLOptimizedRouter

📊 Performance

Benchmarks

Operation CPU Only GPU Accelerated Quantum Speedup
64 CLB Evaluation 12.3ms 1.2ms - 10.3x
1k-point FFT 8.5ms 0.9ms - 9.4x
16-item Search 16 steps 16 steps 4 steps 4.0x
Neural Network (100 neurons) 45ms 4.8ms - 9.4x

Resource Utilization

  • CLBs: Up to 256 (16x16 grid)
  • BRAMs: Configurable (typically 4-8)
  • DSPs: Configurable (typically 2-4)
  • QPU: 5-qubit quantum processor

🧪 Testing

Run Tests

# Run all tests
make test

# With coverage
make coverage

# Specific test file
pytest tests/test_basic.py -v

Test Coverage

  • Basic components (CLB, BRAM, DSP)
  • Signal processing and noise models
  • Fault injection and recovery
  • Parallel execution
  • GPU acceleration (if available)
  • Quantum algorithms (if available)
  • ML optimization (if available)

🛠️ Development

Using the Makefile

make help          # Show all available commands
make check-deps    # Check installed dependencies
make lint          # Run code linting
make format        # Format code with black
make clean         # Clean generated files
make benchmark     # Run performance benchmarks

Quick Development Commands

# Check if everything works
make quick-test

# Run specific examples
make run-neural    # Neural network example
make run-quantum   # Quantum algorithms

# Development setup
make dev-setup

🌐 Web Interface

The simulator includes an interactive web interface with:

  • Real-time CLB activity visualization
  • Power grid heatmap
  • Performance metrics dashboard
  • Fault injection controls
  • Quantum state visualization

Features

  • 🎨 Modern, responsive design
  • 📊 Real-time performance graphs
  • 🔧 Interactive controls
  • 📈 Resource utilization monitoring
  • ⚡ Power and noise visualization

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Areas for Contribution

  • Additional HDL support (VHDL, SystemVerilog)
  • More quantum algorithms
  • Advanced routing algorithms
  • Power optimization
  • 3D visualization
  • Additional examples and tutorials

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • CuPy team for GPU acceleration
  • Qiskit community for quantum computing integration
  • scikit-learn for machine learning capabilities
  • Flask for web framework
  • Inspired by Xilinx Vivado and Intel Quartus

📞 Support


Made with ❤️ by the Jon. :D
⭐ Star us on GitHub!

About

FPGA Simulation framework with examples because I can't afford one in RL. So I have to MAKE one.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors