Skip to content

Instantly share code, notes, and snippets.

@cathalmccabe
Last active July 30, 2021 14:34
Show Gist options
  • Save cathalmccabe/d57eca719c427bd77109d6e7ab89fd22 to your computer and use it in GitHub Desktop.
Save cathalmccabe/d57eca719c427bd77109d6e7ab89fd22 to your computer and use it in GitHub Desktop.
Notebook to test PYNQ MMIO speed
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test MMIO speed\n",
"\n",
"This notebook was run on PYNQ-Z2 running PYNQ v2.6\n",
"\n",
"13 July 2021"
]
},
{
"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",
"import time\n",
"\n",
"ol = Overlay(\"base.bit\")\n",
"\n",
"microblaze_bram = ol.iop_arduino.mb_bram_ctrl"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Time MMIO transaction"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MMIO WRITE: 0.0007576942443847656 seconds\n"
]
}
],
"source": [
"start = time.time()\n",
"microblaze_bram.write(0,0)\n",
"end = time.time()\n",
"timing= end-start\n",
"print(\"MMIO WRITE: \" + str(timing) + \" seconds\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MMIO READ: 0.0006608963012695312 seconds\n"
]
}
],
"source": [
"start = time.time()\n",
"microblaze_bram.read(0)\n",
"end = time.time()\n",
"timing= end-start\n",
"print(\"MMIO READ: \" + str(timing) + \" seconds\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternative way to time a cell using the IPython [%%timeit](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-timeit) magic"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10000 loops, best of 3: 22.3 µs per loop\n"
]
}
],
"source": [
"%%timeit\n",
"microblaze_bram.write(0,0)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10000 loops, best of 3: 23.3 µs per loop\n"
]
}
],
"source": [
"%%timeit\n",
"microblaze_bram.read(0)"
]
}
],
"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": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment