{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "from pdfCropMargins import crop\n",
    "from importlib import reload\n",
    "\n",
    "import draw_graph_expr_3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(vCrc, unroll) drop 1 rows with incorrect output\n",
      "(vStringSearch, adaptive) drop 1 rows with incorrect output\n",
      "(vMatMul, pass_count) drop 1 rows with incorrect output\n",
      "(vConv2d, pass_count) drop 2 rows with incorrect output\n",
      "average improvement\n",
      "bench_name\n",
      "aes              2.130354\n",
      "basicmath        0.915543\n",
      "conv2d          51.671466\n",
      "crc              2.768751\n",
      "fft              0.990319\n",
      "matmul           5.924530\n",
      "sha              2.012104\n",
      "stringsearch    13.951360\n",
      "Name: time_taken, dtype: float64\n",
      "bench_name\n",
      "aes              43.152694\n",
      "basicmath         1.025165\n",
      "conv2d           33.875272\n",
      "crc               6.964916\n",
      "fft               1.342166\n",
      "matmul            4.046829\n",
      "sha               6.482037\n",
      "stringsearch    322.915095\n",
      "Name: time_taken, dtype: float64\n",
      "config    bench_name  \n",
      "adaptive  aes               3.147720\n",
      "          basicmath         9.897899\n",
      "          conv2d            0.202570\n",
      "          crc               2.500424\n",
      "          fft               5.098994\n",
      "          matmul            2.548279\n",
      "          sha               1.778276\n",
      "          stringsearch      0.840108\n",
      "counter   aes               6.705758\n",
      "          basicmath         9.061953\n",
      "          conv2d           10.467083\n",
      "          crc               6.923051\n",
      "          fft               5.049629\n",
      "          matmul           15.097355\n",
      "          sha               3.578076\n",
      "          stringsearch     11.720647\n",
      "unroll    aes             135.832597\n",
      "          basicmath        10.146976\n",
      "          conv2d            6.862110\n",
      "          crc              17.415242\n",
      "          fft               6.843699\n",
      "          matmul           10.312451\n",
      "          sha              11.526848\n",
      "          stringsearch    271.283511\n",
      "Name: time_taken, dtype: float64\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/ybkim/miniconda3/envs/embedded/lib/python3.11/site-packages/seaborn/axisgrid.py:123: UserWarning: The figure layout has changed to tight\n",
      "  self._figure.tight_layout(*args, **kwargs)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('plot_expr_3_cropped.pdf', None, None, None)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 73824 characters]",
      "text/plain": [
       "<Figure size 1215x450 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "reload(draw_graph_expr_3)\n",
    "fig = draw_graph_expr_3.draw_graph()\n",
    "output_file_name = \"plot_expr_3.pdf\"\n",
    "cropped_file_name = \"plot_expr_3_cropped.pdf\"\n",
    "fig.savefig(output_file_name, bbox_inches=\"tight\")\n",
    "crop([\"-o\", cropped_file_name, \"-p4\", \"10\", \"20\", \"0\", \"0\", output_file_name])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(vCrc, unroll) drop 1 rows with incorrect output\n",
      "(vStringSearch, adaptive) drop 1 rows with incorrect output\n",
      "(vMatMul, pass_count) drop 1 rows with incorrect output\n",
      "(vConv2d, pass_count) drop 2 rows with incorrect output\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 679688 characters]",
      "text/plain": [
       "<Figure size 5200x2200 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = draw_graph_expr_3.draw_checkpoint_count()\n",
    "output_file_name = \"plot_expr_3_detailed.pdf\"\n",
    "cropped_file_name = \"plot_expr_3_detailed_cropped.pdf\"\n",
    "fig.savefig(output_file_name, bbox_inches=\"tight\")\n",
    "cropped = crop([\"-o\", cropped_file_name, \"-p4\", \"10\", \"10\", \"10\", \"10\", output_file_name])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(vCrc, unroll) drop 1 rows with incorrect output\n",
      "(vStringSearch, adaptive) drop 1 rows with incorrect output\n",
      "(vMatMul, pass_count) drop 1 rows with incorrect output\n",
      "(vConv2d, pass_count) drop 2 rows with incorrect output\n",
      "                ckpt_trig  ckpt_exec  no_forward_progress\n",
      "bench_name                                               \n",
      "aes            663.900000   7.700000                  0.0\n",
      "basicmath       67.100000   7.600000                  0.0\n",
      "conv2d           7.700000   1.100000                  0.0\n",
      "crc            529.500000   6.400000                  0.0\n",
      "fft            118.500000   4.100000                  0.1\n",
      "matmul        2311.400000   8.300000                  0.0\n",
      "sha             27.900000   2.400000                  0.0\n",
      "stringsearch    47.222222   1.666667                  0.0\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 551324 characters]",
      "text/plain": [
       "<Figure size 4000x2480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = draw_graph_expr_3.draw_checkpoint_frequency_comparison()\n",
    "output_file_name = \"plot_expr_3_comparison.pdf\"\n",
    "cropped_file_name = \"plot_expr_3_comparison_cropped.pdf\"\n",
    "fig.savefig(output_file_name, bbox_inches=\"tight\")\n",
    "cropped = crop([\"-o\", cropped_file_name, \"-p4\", \"10\", \"10\", \"10\", \"10\", output_file_name])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(vCrc, unroll) drop 1 rows with incorrect output\n",
      "(vStringSearch, adaptive) drop 1 rows with incorrect output\n",
      "(vMatMul, pass_count) drop 1 rows with incorrect output\n",
      "(vConv2d, pass_count) drop 2 rows with incorrect output\n",
      "remove vs counter:\n",
      "              ckpt_trig  ckpt_exec\n",
      "bench_name                        \n",
      "aes            0.999728   0.581522\n",
      "basicmath      0.993077   0.714822\n",
      "conv2d         0.999999   0.966723\n",
      "crc            0.999793   0.664042\n",
      "fft            0.997570   0.710247\n",
      "matmul         0.999615   0.795195\n",
      "sha            0.999971   0.764706\n",
      "stringsearch   0.999990   0.946495\n",
      "mean:\n",
      "ckpt_trig    0.998718\n",
      "ckpt_exec    0.767969\n",
      "dtype: float64\n",
      "\n",
      "remove vs unroll:\n",
      "              ckpt_trig  ckpt_exec\n",
      "bench_name                        \n",
      "aes            0.999715   0.995598\n",
      "basicmath      0.798498   0.350427\n",
      "conv2d         0.999932   0.984441\n",
      "crc            0.997948   0.977216\n",
      "fft            0.995498   0.806604\n",
      "matmul         0.982891   0.924201\n",
      "sha            0.999840   0.971979\n",
      "stringsearch   0.999990   0.999353\n",
      "mean:\n",
      "ckpt_trig    0.971789\n",
      "ckpt_exec    0.876227\n",
      "dtype: float64\n",
      "\n"
     ]
    }
   ],
   "source": [
    "draw_graph_expr_3.print_summary()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "embedded",
   "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.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
