This repository contains a comparative study and implementation of Machine Learning (ML) and Deep Learning (DL) algorithms on Field Programmable Gate Arrays (FPGA) and Graphics Processing Units (GPU). The goal of the study is to analyze and compare the performance of FPGA and GPU platforms in terms of processing speed, power efficiency, and accuracy.
The FPGA implementation is carried out using MATLAB HDL Coder, and the models are deployed on the Nexys A7 FPGA board. For the GPU implementation, the study leverages an Nvidia GeForce RTX 3060.
- Introduction
- Hardware and Tools
- Project Workflow
- Key Features
- Performance Metrics
- Requirements
- Installation
- Usage
- Results
- Contributing
- License
The increasing demand for high-performance machine learning (ML) and deep learning (DL) models has led to a focus on optimizing both hardware and software. This project explores the trade-offs between FPGAs and GPUs when running computational models, with an emphasis on:
- Speed: Time taken for model inference and training.
- Power Efficiency: Energy consumption during processing.
- Accuracy: Performance of the models deployed on both platforms.
By deploying the same ML/DL models on both FPGA and GPU, we can evaluate which platform is more suited for specific use cases, especially where low power and efficiency are critical.
-
Nexys A7 FPGA board:
- Operating Frequency: 60-90 MHz
- Used for running the ML and DL algorithms generated from HDL code.
-
Nvidia GeForce RTX 3060 GPU:
- VRAM: 6 GB
- Used for running the same ML and DL models optimized for GPU architecture.
-
Intel Core i7-12700H CPU
-
32 GB RAM
-
MATLAB:
- Used for designing and implementing ML/DL models.
- HDL Coder for generating VHDL/Verilog code from MATLAB models.
-
Vivado:
- For FPGA bitstream generation and programming.
-
Python and CUDA:
- Used for GPU implementation of the models using frameworks like PyTorch or TensorFlow.
-
Model Development:
- Create ML/DL models in MATLAB.
- Pre-train the models using MATLAB or Python (for GPU).
-
HDL Code Generation:
- Use MATLAB HDL Coder to generate HDL code from the models for FPGA implementation.
-
Deployment on FPGA:
- Program the Nexys A7 FPGA board using Vivado with the generated HDL code.
- Measure the processing speed and power efficiency on the FPGA.
-
Deployment on GPU:
- Deploy the pre-trained models on Nvidia RTX 3060.
- Measure the speed and energy consumption on the GPU.
-
Comparison:
- Evaluate the performance metrics such as speed, power consumption, and accuracy for both platforms.
-
Multi-platform comparison:
- Compare the speed, accuracy, and power consumption of the models running on FPGA and GPU platforms.
-
Scalability:
- Easily scalable to more complex models and hardware configurations.
-
HDL Coder:
- The study demonstrates how to use HDL Coder to convert MATLAB models into hardware-compatible VHDL/Verilog for FPGA deployment.
-
Power efficiency focus:
- Detailed analysis of energy consumption, making the project valuable for energy-constrained applications.
The performance is evaluated based on three primary metrics:
-
Processing Speed:
- Time taken to complete inference or training on both FPGA and GPU platforms.
-
Power Efficiency:
- Energy consumption during model execution. Lower power consumption is highly desirable in edge computing environments.
-
Accuracy:
- Performance of ML/DL models in terms of prediction accuracy after being deployed on each platform.
To replicate the study, you will need:
- Nexys A7 FPGA board
- Nvidia GPU (e.g., RTX 3060)
- Intel-based CPU or equivalent
- MATLAB with HDL Coder
- Xilinx Vivado (for FPGA programming)
- Python with TensorFlow/PyTorch (for GPU)
- CUDA Toolkit (for GPU)
-
Clone the repository:
git clone https://github.com/Monish-KS/FPGA_GPU_ML_Comparison.git cd FPGA_GPU_ML_Comparison -
MATLAB Setup:
- Ensure that MATLAB with HDL Coder is installed.
- Install necessary toolboxes for generating HDL code.
-
Vivado Setup:
- Install Xilinx Vivado for FPGA programming.
-
Python and GPU Setup:
- Set up the Python environment and install required libraries:
pip install torch tensorflow numpy
- Install CUDA Toolkit for GPU acceleration.
- Set up the Python environment and install required libraries:
- Load the ML/DL models in MATLAB.
- Use HDL Coder to generate HDL code.
- Program the Nexys A7 FPGA using Vivado with the generated bitstream.
- Measure performance metrics using onboard monitoring tools or external measurement tools.
- Run the models in Python (PyTorch or TensorFlow) using the RTX 3060 GPU.
- Measure speed and power usage using GPU monitoring tools - nvidia-smi and Vivado.
Once the models have been run on both FPGA and GPU, compare the results in terms of:
- Speed (latency, throughput)
- Power consumption
- Accuracy of predictions
This section should be updated with actual results from your experiments. A typical result would include a table comparing the speed, power consumption, and accuracy between the FPGA and GPU platforms. Here's a sample format:
| Model | Accuracy in FPGA (%) | Accuracy in GPU (%) |
|---|---|---|
| Regression Model | 97.40 | 92.21 |
| Image Classification Model | 85.42 | 82.29 |
| BERT Model | 96.45 | 97.47 |
Contributions are welcome! Feel free to submit issues, feature requests, or pull requests.
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Open a pull request
This project is licensed under the MIT License. See the LICENSE file for details.



