Commit a55f6fac authored by Amir Poorsadeg Zadeh Yeganeh's avatar Amir Poorsadeg Zadeh Yeganeh
Browse files

Initial Commit

parents
Vitis-HLS/**/GJE
Vitis-HLS/**/vitis_hls.log
Vivado/*
!Vivado/GJE.tcl
!Vivado/GJE_IP
Vivado/GJE_IP/*
!Vivado/GJE_IP/Readme.txt
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Initializations"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
"try {\n",
"require(['notebook/js/codecell'], function(codecell) {\n",
" codecell.CodeCell.options_default.highlight_modes[\n",
" 'magic_text/x-csrc'] = {'reg':[/^%%microblaze/]};\n",
" Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n",
" Jupyter.notebook.get_cells().map(function(cell){\n",
" if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n",
" });\n",
"});\n",
"} catch (e) {};\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"try {\n",
"require(['notebook/js/codecell'], function(codecell) {\n",
" codecell.CodeCell.options_default.highlight_modes[\n",
" 'magic_text/x-csrc'] = {'reg':[/^%%pybind11/]};\n",
" Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n",
" Jupyter.notebook.get_cells().map(function(cell){\n",
" if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n",
" });\n",
"});\n",
"} catch (e) {};\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from pynq import Overlay\n",
"from pynq import allocate\n",
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"DIM = 128\n",
"ol = Overlay('GJE.bit')\n",
"dma = ol.axi_dma\n",
"gje_ip = ol.gje_ip"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"in_buffer = allocate(shape=(DIM, DIM), dtype=np.float32, cacheable=False)\n",
"out_buffer_hw = allocate(shape=(DIM, DIM), dtype=np.float32, cacheable=False)\n",
"out_buffer_sw = allocate(shape=(DIM, DIM), dtype=np.float32, cacheable=False)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"A = np.random.randint(1,10, (DIM,DIM))\n",
"in_buffer[:] = np.copy(A)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PL"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"CTRL_REG = 0x00\n",
"AP_START = (1<<0) # bit 0\n",
"AUTO_RESTART = (1<<7) # bit 7\n",
"\n",
"def hw_run():\n",
" dma.sendchannel.transfer(in_buffer)\n",
" dma.recvchannel.transfer(out_buffer_hw)\n",
" gje_ip.write(CTRL_REG, (AP_START | AUTO_RESTART))\n",
" dma.sendchannel.wait()\n",
" dma.recvchannel.wait()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100 loops, best of 10: 6.414 ms per loop\n"
]
}
],
"source": [
"hw_time = %timeit -o -p 4 -n 100 -r 10 hw_run()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PS"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def sw_run():\n",
" out_buffer_sw[:] = np.linalg.inv(in_buffer)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100 loops, best of 10: 41.837 ms per loop\n"
]
}
],
"source": [
"sw_time = %timeit -o -p 5 -n 100 -r 10 sw_run()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Comparison"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Mean Absolute Error (MAE):\n",
"Here, the precision error is calculated between the golden inverse and hardware inverse matrices."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MAE: 0.0000012030\n"
]
}
],
"source": [
"MAE = np.sum(np.absolute(out_buffer_hw - out_buffer_sw)) / (DIM*DIM)\n",
"print(\"MAE: \", '{:.10f}'.format(MAE))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Acceleration ratio:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Acceleration: 6.52 X\n"
]
}
],
"source": [
"accel_ratio = round(sw_time.best/hw_time.best,2)\n",
"print(\"Acceleration: \", accel_ratio, \"X\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Matrix fractions:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" <th>5</th>\n",
" <th>6</th>\n",
" <th>7</th>\n",
" <th>8</th>\n",
" <th>9</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3.0</td>\n",
" <td>7.0</td>\n",
" <td>4.0</td>\n",
" <td>4.0</td>\n",
" <td>1.0</td>\n",
" <td>8.0</td>\n",
" <td>4.0</td>\n",
" <td>2.0</td>\n",
" <td>9.0</td>\n",
" <td>3.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>9.0</td>\n",
" <td>4.0</td>\n",
" <td>1.0</td>\n",
" <td>7.0</td>\n",
" <td>5.0</td>\n",
" <td>4.0</td>\n",
" <td>2.0</td>\n",
" <td>1.0</td>\n",
" <td>9.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>6.0</td>\n",
" <td>6.0</td>\n",
" <td>1.0</td>\n",
" <td>6.0</td>\n",
" <td>2.0</td>\n",
" <td>2.0</td>\n",
" <td>5.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>6.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3 4 5 6 7 8 9\n",
"0 3.0 7.0 4.0 4.0 1.0 8.0 4.0 2.0 9.0 3.0\n",
"1 9.0 4.0 1.0 7.0 5.0 4.0 2.0 1.0 9.0 8.0\n",
"2 6.0 6.0 1.0 6.0 2.0 2.0 5.0 3.0 1.0 6.0"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Input Matrix\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" <th>5</th>\n",
" <th>6</th>\n",
" <th>7</th>\n",
" <th>8</th>\n",
" <th>9</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-0.004979</td>\n",
" <td>0.002431</td>\n",
" <td>0.072468</td>\n",
" <td>0.023406</td>\n",
" <td>-0.016428</td>\n",
" <td>-0.019313</td>\n",
" <td>0.022698</td>\n",
" <td>0.021252</td>\n",
" <td>-0.002174</td>\n",
" <td>-0.058535</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.003460</td>\n",
" <td>0.024615</td>\n",
" <td>0.095088</td>\n",
" <td>0.023363</td>\n",
" <td>-0.014134</td>\n",
" <td>-0.021923</td>\n",
" <td>0.008053</td>\n",
" <td>0.032577</td>\n",
" <td>0.001632</td>\n",
" <td>-0.070752</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>-0.012432</td>\n",
" <td>-0.023638</td>\n",
" <td>0.035489</td>\n",
" <td>0.031285</td>\n",
" <td>0.014753</td>\n",
" <td>0.023039</td>\n",
" <td>0.031863</td>\n",
" <td>0.011635</td>\n",
" <td>0.014776</td>\n",
" <td>-0.028205</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3 4 5 6 \\\n",
"0 -0.004979 0.002431 0.072468 0.023406 -0.016428 -0.019313 0.022698 \n",
"1 0.003460 0.024615 0.095088 0.023363 -0.014134 -0.021923 0.008053 \n",
"2 -0.012432 -0.023638 0.035489 0.031285 0.014753 0.023039 0.031863 \n",
"\n",
" 7 8 9 \n",
"0 0.021252 -0.002174 -0.058535 \n",
"1 0.032577 0.001632 -0.070752 \n",
"2 0.011635 0.014776 -0.028205 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hardware Inverse Matrix\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" <th>5</th>\n",
" <th>6</th>\n",
" <th>7</th>\n",
" <th>8</th>\n",
" <th>9</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-0.004979</td>\n",
" <td>0.002431</td>\n",
" <td>0.072470</td>\n",
" <td>0.023407</td>\n",
" <td>-0.016429</td>\n",
" <td>-0.019313</td>\n",
" <td>0.022698</td>\n",
" <td>0.021253</td>\n",
" <td>-0.002174</td>\n",
" <td>-0.058536</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.003460</td>\n",
" <td>0.024616</td>\n",
" <td>0.095091</td>\n",
" <td>0.023364</td>\n",
" <td>-0.014134</td>\n",
" <td>-0.021924</td>\n",
" <td>0.008053</td>\n",
" <td>0.032578</td>\n",
" <td>0.001632</td>\n",
" <td>-0.070753</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>-0.012432</td>\n",
" <td>-0.023638</td>\n",
" <td>0.035491</td>\n",
" <td>0.031286</td>\n",
" <td>0.014752</td>\n",
" <td>0.023038</td>\n",
" <td>0.031863</td>\n",
" <td>0.011636</td>\n",
" <td>0.014776</td>\n",
" <td>-0.028206</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3 4 5 6 \\\n",
"0 -0.004979 0.002431 0.072470 0.023407 -0.016429 -0.019313 0.022698 \n",
"1 0.003460 0.024616 0.095091 0.023364 -0.014134 -0.021924 0.008053 \n",
"2 -0.012432 -0.023638 0.035491 0.031286 0.014752 0.023038 0.031863 \n",
"\n",
" 7 8 9 \n",
"0 0.021253 -0.002174 -0.058536 \n",
"1 0.032578 0.001632 -0.070753 \n",
"2 0.011636 0.014776 -0.028206 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Golden Inverse Matrix\n"
]
}
],
"source": [
"display(pd.DataFrame(in_buffer[0:3,0:10]))\n",
"print(\"Input Matrix\")\n",
"display(pd.DataFrame(out_buffer_hw[0:3,0:10]))\n",
"print(\"Hardware Inverse Matrix\")\n",
"display(pd.DataFrame(out_buffer_sw[0:3,0:10]))\n",
"print(\"Golden Inverse Matrix\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
# Master Thesis
**Faculty:** Applied Computer Sciences
**Title:** Acceleration of Gaussian Elimination algorithm on an FPGA
**Supervisor:** Prof. Dr.-Ing. Gökçe Aydos
------
This repository presents the source code related with the study "Acceleration of Gaussian Elimination algorithm on an FPGA", carried out under the supervision of Prof. Gökçe Aydos in summer semester 2021 at Deggendorf Institute of Technology for the fulfillment of a Master's degree in Applied Computer Sciences.
The source code and project files are organized as follows. The source codes are documented internally.
- [Vitis HLS](Vitis-HLS)
- [Floating-Point Gauss-Jordan Elimination IP](Vitis-HLS/Floating-Point-GJE-IP)
- [Parameter: Matrix Size](Vitis-HLS/Floating-Point-GJE-IP/Parameter-Matrix-Size)
- [Parameter: Array Partitioning](Vitis-HLS/Floating-Point-GJE-IP/Parameter-Array-Partitioning)
- [Parameter: Loop Unrolling](Vitis-HLS/Floating-Point-GJE-IP/Parameter-Loop-Unrolling)
- [Fixed-Point Gauss-Jordan Elimination IP](Vitis-HLS/Fixed-Point-GJE-IP)
- [Vivado](Vivado)
- [Jupyter Notebook](Jupyter-Notebook)
In order to make and use the projects, following software and hardware are required.
- Vitis HLS 2020.2
- Vivado 2020.2
- [PYNQ-Z2](https://www.tul.com.tw/ProductsPYNQ-z2.html) development board
- Access to Jupyter Notebook environment on the board
### Making Vitis HLS Projects:
The *Vitis-HLS* folder represents the source code for all the works that have been carried out in this study in a categorized hierarchy. Each project can be made to a complete Vitis HLS project using the following steps.
1. Download the repository
3. Open a command line window
4. Browse to the desired project folder
5. Run the following command
```
> vitis_hls -f script.tcl
```
### Making Vivado Project:
The Vitis HLS projects in the *Vitis-HLS* folder, after being made, can be converted to a complete hardware implementation (overlay) using the following procedures.
1. Make the desired Vitis HLS project as described in the previous section
2. Navigate to *[path to the root folder of the desired Vitis HLS project]\GJE\solution1\impl*
3. Extract the contents of *export.zip* into *[path to the root folder of repository]\Vivado\GJE_IP*
4. Execute the Vivado 2020.2 Tcl Shell