From f7f1ada07c6627a27c03f884482eda721161dc76 Mon Sep 17 00:00:00 2001
From: Yaman Umuroglu <yamanu@xilinx.com>
Date: Fri, 6 Dec 2019 09:56:06 +0000
Subject: [PATCH] [Notebook] re-exec notebooks with latest StreamingFC changes

---
 notebooks/FCLayer_graph.onnx                  | Bin 822 -> 840 bytes
 .../FINN-CodeGenerationAndCompilation.ipynb   |  33 +++++++++--------
 notebooks/FINN-CustomOps.ipynb                |  34 ++++++++++--------
 3 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/notebooks/FCLayer_graph.onnx b/notebooks/FCLayer_graph.onnx
index 641ef704256c0c7af863cafc79b3f6af57d0abd5..4cd3fa2804a9960ed405da87d02b0b15b5909bf4 100644
GIT binary patch
delta 149
zcmdnSc7jcegH4DxEjcH#GPOuIH$Npc$7%x`*ZGNJF%x@a#6-FHk}~rWiz*}X@{4?d
zvJ#977?~z6_ZAW6;>pW*OfJbRODxIE&x446?3%opQDm|(lgQ-tj2x3sGxAIhW|EkE
nA4orDRDp_#0L29+?*`)MK()Jpa_1Q(Sobq9G}uqBVA=-&EJZOy

delta 191
zcmX@XwvA1UgH4DxEjcH#GPOuIH$Npc$7&uM*WQU@F(TYtEFr$Gz7h-z7@4$yoNyp#
zVvf?prCyU+7&|9lWR#e^mr;Om|70~L^~sV<B9m*GI3`;%@l5{9D8jj)fuX@3i1$yP
f$0!~M;=wRj6p0TL2hlJ&5RJ?R$)VuMT}=A`UQ{<R

diff --git a/notebooks/FINN-CodeGenerationAndCompilation.ipynb b/notebooks/FINN-CodeGenerationAndCompilation.ipynb
index f33d4baf7..e81bc5a36 100644
--- a/notebooks/FINN-CodeGenerationAndCompilation.ipynb
+++ b/notebooks/FINN-CodeGenerationAndCompilation.ipynb
@@ -13,7 +13,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": 3,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -45,7 +45,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": 4,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -64,7 +64,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 14,
+   "execution_count": 5,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -73,7 +73,6 @@
     "mh = 8\n",
     "pe = 4\n",
     "simd = 4\n",
-    "wmem = mw * mh // (pe * simd)\n",
     "nf = mh // pe\n",
     "sf = mw // simd\n"
    ]
@@ -87,7 +86,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 15,
+   "execution_count": 6,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -110,7 +109,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 16,
+   "execution_count": 7,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -127,8 +126,8 @@
     "        MH=mh,\n",
     "        SIMD=simd,\n",
     "        PE=pe,\n",
-    "        WMEM=wmem,\n",
-    "        TMEM=0,\n",
+    "        noActivation=1,\n",
+    "        binaryXnorMode=1,\n",
     "        inputDataType=idt.name,\n",
     "        weightDataType=wdt.name,\n",
     "        outputDataType=odt.name,\n",
@@ -144,7 +143,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 17,
+   "execution_count": 8,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -162,7 +161,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 18,
+   "execution_count": 9,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -185,7 +184,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 19,
+   "execution_count": 10,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -194,15 +193,13 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 20,
+   "execution_count": 11,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "\n",
-      "Stopping http://0.0.0.0:8081\n",
       "Serving 'FCLayer_graph.onnx' at http://0.0.0.0:8081\n"
      ]
     }
@@ -214,7 +211,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 21,
+   "execution_count": 12,
    "metadata": {},
    "outputs": [
     {
@@ -247,7 +244,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 22,
+   "execution_count": 13,
    "metadata": {},
    "outputs": [
     {
@@ -261,6 +258,8 @@
       "        for node in model.graph.node:\n",
       "            if node.domain == \"finn\":\n",
       "                backend_attribute = get_by_name(node.attribute, \"backend\")\n",
+      "                if backend_attribute is None:\n",
+      "                    continue\n",
       "                backend_value = backend_attribute.s.decode(\"UTF-8\")\n",
       "                if backend_value == \"fpgadataflow\":\n",
       "                    _codegen_single_node(node, model)\n",
@@ -283,7 +282,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 23,
+   "execution_count": 14,
    "metadata": {},
    "outputs": [
     {
diff --git a/notebooks/FINN-CustomOps.ipynb b/notebooks/FINN-CustomOps.ipynb
index 1f60546e3..6d0e3b33b 100644
--- a/notebooks/FINN-CustomOps.ipynb
+++ b/notebooks/FINN-CustomOps.ipynb
@@ -18,7 +18,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -56,12 +56,12 @@
     "    MH=mh,\n",
     "    SIMD=simd,\n",
     "    PE=pe,\n",
-    "    WMEM=wmem,\n",
-    "    TMEM=tmem,\n",
-    "    inputDataType=FINN-DataType,\n",
-    "    weightDataType=FINN-DataType,\n",
-    "    outputDataType=FINN-DataType,\n",
+    "    inputDataType=<FINN DataType>,\n",
+    "    weightDataType=<FINN DataType>,\n",
+    "    outputDataType=<FINN DataType>,\n",
     "    ActVal=actval,\n",
+    "    binaryXnorMode=<0/1>,\n",
+    "    noActivation=<0/1>\n",
     ")`"
    ]
   },
@@ -76,12 +76,12 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "<font size=\"3\">Custom Ops are represented in Finn as ONNX nodes on the one hand and by a CustomOp class on the other hand. This allows easier access to the different attributes and introduces special custom op functions. See below for the standard CustomOp class.</font>"
+    "<font size=\"3\">Custom Ops are represented in FINN as ONNX nodes on the one hand and by a CustomOp class on the other hand. This allows easier access to the different attributes and introduces special custom op functions. See below for the standard CustomOp class.</font>"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 2,
    "metadata": {},
    "outputs": [
     {
@@ -188,7 +188,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 3,
    "metadata": {},
    "outputs": [
     {
@@ -399,7 +399,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 4,
    "metadata": {
     "scrolled": true
    },
@@ -431,15 +431,13 @@
       "                    self.get_nodeattr(\"SIMD\"),\n",
       "                    export_wdt.get_hls_datatype_str(),\n",
       "                    self.get_nodeattr(\"PE\"),\n",
-      "                    self.get_nodeattr(\"WMEM\"),\n",
+      "                    self.calc_wmem(),\n",
       "                )\n",
       "            )\n",
       "        else:\n",
       "            f_weights.write(\n",
       "                \"static BinaryWeights<{},{},{}> weights = \".format(\n",
-      "                    self.get_nodeattr(\"SIMD\"),\n",
-      "                    self.get_nodeattr(\"PE\"),\n",
-      "                    self.get_nodeattr(\"WMEM\"),\n",
+      "                    self.get_nodeattr(\"SIMD\"), self.get_nodeattr(\"PE\"), self.calc_wmem()\n",
       "                )\n",
       "            )\n",
       "        f_weights.write(weight_hls_code)\n",
@@ -453,6 +451,12 @@
       "                # use UINT32 threshold export for bipolar times bipolar\n",
       "                inp_is_bipolar = self.get_input_datatype() == DataType.BIPOLAR\n",
       "                wt_is_bipolar = self.get_weight_datatype() == DataType.BIPOLAR\n",
+      "                # reinterpret inp/wt as bipolar if bin_xnor_mode is iset\n",
+      "                inp_is_binary = self.get_input_datatype() == DataType.BINARY\n",
+      "                wt_is_binary = self.get_weight_datatype() == DataType.BINARY\n",
+      "                bin_xnor_mode = self.get_nodeattr(\"binaryXnorMode\") == 1\n",
+      "                inp_is_bipolar = inp_is_bipolar or (inp_is_binary and bin_xnor_mode)\n",
+      "                wt_is_bipolar = wt_is_bipolar or (wt_is_binary and bin_xnor_mode)\n",
       "                if inp_is_bipolar and wt_is_bipolar:\n",
       "                    tdt = DataType.UINT32\n",
       "                thresholds_hls_code = numpy_to_hls_code(\n",
@@ -470,7 +474,7 @@
       "                f_thresh.write(\n",
       "                    \"static ThresholdsActivation<{},{},{},{},{},{},{}> threshs \\\n",
       "                     = \".format(\n",
-      "                        self.get_nodeattr(\"TMEM\"),\n",
+      "                        self.calc_tmem(),\n",
       "                        self.get_nodeattr(\"PE\"),\n",
       "                        threshold_tensor.shape[-1],\n",
       "                        tdt_hls,\n",
-- 
GitLab