Jean-Christophe Owens
Published

Super96s Cluster - Part 2

Creating a series of modules allowing you to connect for the first time a PYNQ acceleration distribution network for edge devices U96.

AdvancedFull instructions provided2 hours151
Super96s Cluster - Part 2

Things used in this project

Story

Read more

Code

HLS Overlay

Python
HLS | Jupyter Notebook Interface
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Imports "
   ]
  },
  {
   "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",
    "from pynq import allocate\n",
    "from pynq.lib.dma import DMA\n",
    "import numpy as np\n",
    "import PIL\n",
    "# from PIL import Image\n",
    "from IPython.display import Image\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "from pynq import allocate, Overlay"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load Bitstream and Overlays"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load Bitstream (HW/HLS/Vitis)\n",
    "# overlay = Overlay('design_5_mult.bit')\n",
    "overlay = Overlay('design_5_mult.bit')\n",
    "overlay?\n",
    "\n",
    "#DMA Initialize API\n",
    "dma = overlay.hier_0.axi_dma_0\n",
    "\n",
    "#boxfilter\n",
    "# boxF = overlay.hier_0.boxfilter_accel_0\n",
    "\n",
    "#Multiplier IP \n",
    "mult = overlay.hier_0.mult_constant_hls_0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Stream Multiplier Stream IP "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The initialization of the blocks (aka dam | mult) are now operational. Below we are looking at the register map of a certain unti (e.g. mult) and now creating an input buffer & output buffer. Providing the IP and indicating the multiplier of X Value, you can now create an array to the user, and thus because you created the stream link. Think of this as a hardware operation where you \"hardcode\" in hardware. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RegisterMap {\n",
       "  multiplier = Register(multiplier=0)\n",
       "}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Find the register mapped input\n",
    "mult.register_map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Create an input & output buffer - This creates the route lane to become active in the HW  \n",
    "in_buffer = allocate(shape=(6,), dtype=np.uint8)\n",
    "out_buffer = allocate(shape=(6,), dtype=np.uint8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Assign a multiplier value of 5 as an example\n",
    "mult.register_map.multiplier = 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Create a basic Array\n",
    "for i in range(6):\n",
    "    in_buffer [i] = i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PynqBuffer([0, 1, 2, 3, 4, 5], dtype=uint8)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Print the Buffer\n",
    "in_buffer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Allow the magic to occur - Sends data to multplier kernel and then captures the receive - Waits for transactions to occur and complete\n",
    "dma.sendchannel.transfer(in_buffer)\n",
    "dma.recvchannel.transfer(out_buffer)\n",
    "dma.sendchannel.wait()\n",
    "dma.recvchannel.wait()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PynqBuffer([ 0,  5, 10, 15, 20, 25], dtype=uint8)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Print new Values \n",
    "out_buffer"
   ]
  }
 ],
 "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
}

Credits

Jean-Christophe Owens

Jean-Christophe Owens

8 projects • 16 followers
Just a rogue hacker! Love to make embedded-related projects, playing mostly with Xilinx tools, Vivado and Vitis. Love making and inventing!
Thanks to Adam Taylor.

Comments