{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import subprocess as sp\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from io import StringIO\n",
    "import os\n",
    "import re\n",
    "import shutil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#global parameters\n",
    "cudadir = \"/usr/common/software/cuda/10.2.89\"\n",
    "datadir = \"/global/cfs/cdirs/m2845/roofline/fastcalosim\"\n",
    "outputdir = \"/global/cfs/cdirs/m2845/roofline/fastcalosim\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def transpose_frame(metricdf):\n",
    "    selectkeys = [\"Kernel Name\"]\n",
    "    \n",
    "    tc_peak_perf_flops = 125*10**12\n",
    "    \n",
    "\n",
    "    ####### Get timing information\n",
    "    \n",
    "    # get cycles and rates\n",
    "    cyclesdf = metricdf.loc[(metricdf[\"Metric Name\"]==\"smsp__cycles_elapsed\") & (metricdf[\"Metric Type\"]==\"total\"),\n",
    "                            selectkeys+[\"Metric Unit\", \"Metric Value\"]].copy().reset_index(drop=True).rename(columns={\"Metric Value\": \"CUDA Cycles\"})\n",
    "    ratesdf = metricdf.loc[(metricdf[\"Metric Name\"]==\"smsp__cycles_elapsed\") & (metricdf[\"Metric Type\"]==\"rate\"),\n",
    "                           selectkeys+[\"Metric Unit\", \"Metric Value\"]].copy().reset_index(drop=True).rename(columns={\"Metric Value\": \"CUDA Rates\"})\n",
    "    \n",
    "    # adjust metric unit\n",
    "    ratesdf.loc[ratesdf[\"Metric Unit\"].str.contains(\"cycle/nsecond\"), [\"CUDA Rates\"]] *= 1e9\n",
    "\n",
    "    # combine & cleanup\n",
    "    profiledf = pd.concat([cyclesdf, ratesdf], axis=1)\n",
    "    del profiledf[\"Metric Unit\"]\n",
    "    profiledf = profiledf.loc[:,~profiledf.columns.duplicated()]\n",
    "    \n",
    "    # compute CUDA time\n",
    "    profiledf[\"CUDA Time\"] = profiledf[\"CUDA Cycles\"] / profiledf[\"CUDA Rates\"]\n",
    "    \n",
    "    # cleanups\n",
    "    del profiledf[\"CUDA Cycles\"]\n",
    "    del profiledf[\"CUDA Rates\"]\n",
    "    profiledf = profiledf.groupby('Kernel Name').sum().reset_index()\n",
    "    #display(profiledf)\n",
    "        \n",
    "    ####### Get number of FLOPs\n",
    "    \n",
    "    ### FMA FLOPs = number of FMA instructions x 2\n",
    "    metricdf.loc[metricdf[\"Metric Name\"].str.contains(\"fma_pred_on\"), [\"Metric Value\"]] *= 2\n",
    "    \n",
    "\n",
    "    ### FP64 FLOPs\n",
    "    metrics = ['smsp__sass_thread_inst_executed_op_dadd_pred_on',\n",
    "               'smsp__sass_thread_inst_executed_op_dfma_pred_on',\n",
    "               'smsp__sass_thread_inst_executed_op_dmul_pred_on']\n",
    "    tmpdf = metricdf.loc[ metricdf[\"Metric Name\"].isin(metrics), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    tmpdf = tmpdf.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"FP64 FLOPs\"})\n",
    "\n",
    "    profiledf = profiledf.merge(tmpdf, on=selectkeys, how=\"inner\")\n",
    "    \n",
    "    ### FP32 FLOPs\n",
    "    metrics = ['smsp__sass_thread_inst_executed_op_fadd_pred_on',\n",
    "               'smsp__sass_thread_inst_executed_op_ffma_pred_on',\n",
    "               'smsp__sass_thread_inst_executed_op_fmul_pred_on']\n",
    "    tmpdf = metricdf.loc[ metricdf[\"Metric Name\"].isin(metrics), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    tmpdf = tmpdf.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"FP32 FLOPs\"})\n",
    "    \n",
    "    profiledf = profiledf.merge(tmpdf, on=selectkeys, how=\"inner\")\n",
    "    \n",
    "    ### Total FLOPs\n",
    "    profiledf[\"FLOPs\"] = profiledf[\"FP32 FLOPs\"] + profiledf[\"FP64 FLOPs\"]\n",
    "\n",
    "    \n",
    "    ####### Get number of bytes\n",
    "    \n",
    "    ### Shared transactions\n",
    "    # project out\n",
    "    shareddf = metricdf.loc[metricdf[\"Metric Name\"].str.contains(\"l1tex__data_pipe_lsu_wavefronts_mem_shared_op\"), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    shareddf = shareddf.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"Shared Transactions\"})\n",
    "    # merge with output\n",
    "    profiledf = profiledf.merge(shareddf, on=selectkeys, how=\"inner\")\n",
    "    \n",
    "    ### L1 atomic transactions\n",
    "    # project out\n",
    "    metrics = ['l1tex__t_set_accesses_pipe_lsu_mem_global_op_atom',\n",
    "               'l1tex__t_set_accesses_pipe_lsu_mem_global_op_red',\n",
    "               'l1tex__t_set_accesses_pipe_tex_mem_surface_op_atom',\n",
    "               'l1tex__t_set_accesses_pipe_tex_mem_surface_op_red']\n",
    "    atomicdf = metricdf.loc[ metricdf[\"Metric Name\"].isin(metrics), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    atomicdf = atomicdf.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"L1 Atomic Transactions\"})\n",
    "    # merge with output\n",
    "    profiledf = profiledf.merge(atomicdf, on=selectkeys, how=\"inner\")\n",
    "\n",
    "    ### Local transactions \n",
    "    # project out\n",
    "    localdf = metricdf.loc[metricdf[\"Metric Name\"].str.contains(\"l1tex__t_sectors_pipe_lsu_mem_local_op\"), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    localdf = localdf.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"Local Transactions\"})\n",
    "    # merge with output\n",
    "    profiledf = profiledf.merge(localdf, on=selectkeys, how=\"inner\")\n",
    " \n",
    "    ### Global transactions \n",
    "    # project out\n",
    "    globaldf = metricdf.loc[metricdf[\"Metric Name\"].str.contains(\"l1tex__t_sectors_pipe_lsu_mem_global_op\"), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    globaldf = globaldf.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"Global Transactions\"})\n",
    "    # merge with output\n",
    "    profiledf = profiledf.merge(globaldf, on=selectkeys, how=\"inner\")  \n",
    "    \n",
    "    ### L1 Bytes\n",
    "    profiledf[\"L1 Transactions\"] = (profiledf[\"Shared Transactions\"] + profiledf[\"L1 Atomic Transactions\"]\n",
    "                            + profiledf[\"Local Transactions\"] + profiledf[\"Global Transactions\"])\n",
    "    profiledf[\"L1 Bytes\"] = profiledf[\"L1 Transactions\"] * 32\n",
    "\n",
    "    # clean up\n",
    "    del profiledf[\"Shared Transactions\"]\n",
    "    del profiledf[\"L1 Atomic Transactions\"]\n",
    "    del profiledf[\"Local Transactions\"]\n",
    "    del profiledf[\"Global Transactions\"]\n",
    "        \n",
    "    \n",
    "    ### L2 atomic & reduction\n",
    "    metricdf.loc[(metricdf[\"Metric Name\"].str.contains(\"lts__t_sectors_op\")) & (metricdf[\"Metric Type\"]==\"total\"), [\"Metric Value\"]] *= 2\n",
    "    \n",
    "    ### L2 transactions\n",
    "    # project out\n",
    "    l2df = metricdf.loc[metricdf[\"Metric Name\"].str.contains(\"lts__t_sectors_op\"), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    l2df = l2df.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"L2 Transactions\"})\n",
    "    l2df[\"L2 Bytes\"] = l2df[\"L2 Transactions\"] * 32\n",
    "    # merge with output\n",
    "    profiledf = profiledf.merge(l2df, on=selectkeys, how=\"inner\")\n",
    "\n",
    "    \n",
    "    ### DRAM Bytes\n",
    "    # project out\n",
    "    dramdf = metricdf.loc[metricdf[\"Metric Name\"].str.contains(\"dram__sectors\"), selectkeys+[\"Metric Value\"] ].copy()\n",
    "    dramdf = dramdf.groupby(selectkeys).sum().reset_index().rename(columns={\"Metric Value\": \"DRAM Transactions\"})\n",
    "    dramdf[\"DRAM Bytes\"] = dramdf[\"DRAM Transactions\"] * 32\n",
    "    # merge with output\n",
    "    profiledf = profiledf.merge(dramdf, on=selectkeys, how=\"inner\")\n",
    "    \n",
    "\n",
    "    ### Get performance\n",
    "    profiledf[\"Performance GFlop/s\"]      = profiledf[\"FLOPs\"]      / (profiledf[\"CUDA Time\"]*10**9)\n",
    "    profiledf[\"FP64 Performance GFlop/s\"] = profiledf[\"FP64 FLOPs\"] / (profiledf[\"CUDA Time\"]*10**9)\n",
    "    profiledf[\"FP32 Performance GFlop/s\"] = profiledf[\"FP32 FLOPs\"] / (profiledf[\"CUDA Time\"]*10**9)\n",
    "\n",
    "    \n",
    "    ### Get AI\n",
    "    # L1\n",
    "    profiledf[\"L1 AI\"]        = profiledf[\"FLOPs\"]      / profiledf[\"L1 Bytes\"]\n",
    "    profiledf[\"FP64 L1 AI\"]   = profiledf[\"FP64 FLOPs\"] / profiledf[\"L1 Bytes\"]\n",
    "    profiledf[\"FP32 L1 AI\"]   = profiledf[\"FP32 FLOPs\"] / profiledf[\"L1 Bytes\"]\n",
    "    # L2\n",
    "    profiledf[\"L2 AI\"]        = profiledf[\"FLOPs\"]      / profiledf[\"L2 Bytes\"]\n",
    "    profiledf[\"FP64 L2 AI\"]   = profiledf[\"FP64 FLOPs\"] / profiledf[\"L2 Bytes\"]\n",
    "    profiledf[\"FP32 L2 AI\"]   = profiledf[\"FP32 FLOPs\"] / profiledf[\"L2 Bytes\"]\n",
    "    # DRAM\n",
    "    profiledf[\"DRAM AI\"]      = profiledf[\"FLOPs\"]      / profiledf[\"DRAM Bytes\"]\n",
    "    profiledf[\"FP64 DRAM AI\"] = profiledf[\"FP64 FLOPs\"] / profiledf[\"DRAM Bytes\"]\n",
    "    profiledf[\"FP32 DRAM AI\"] = profiledf[\"FP32 FLOPs\"] / profiledf[\"DRAM Bytes\"]\n",
    "\n",
    "    return profiledf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "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>Kernel Name</th>\n",
       "      <th>Metric Name</th>\n",
       "      <th>Metric Type</th>\n",
       "      <th>Metric Unit</th>\n",
       "      <th>Metric Value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>generate_seed_pseudo(__int64,__int64,__int64,c...</td>\n",
       "      <td>dram__sectors</td>\n",
       "      <td>read</td>\n",
       "      <td>sector</td>\n",
       "      <td>11981.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>generate_seed_pseudo(__int64,__int64,__int64,c...</td>\n",
       "      <td>dram__sectors</td>\n",
       "      <td>write</td>\n",
       "      <td>sector</td>\n",
       "      <td>55690.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>generate_seed_pseudo(__int64,__int64,__int64,c...</td>\n",
       "      <td>l1tex__data_pipe_lsu_wavefronts_mem_shared_op</td>\n",
       "      <td>read</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>generate_seed_pseudo(__int64,__int64,__int64,c...</td>\n",
       "      <td>l1tex__data_pipe_lsu_wavefronts_mem_shared_op</td>\n",
       "      <td>write</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>generate_seed_pseudo(__int64,__int64,__int64,c...</td>\n",
       "      <td>l1tex__t_sectors_pipe_lsu_mem_global_op</td>\n",
       "      <td>read</td>\n",
       "      <td>sector</td>\n",
       "      <td>5600957.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>144715</td>\n",
       "      <td>simulate_ct(Chain0_Args)</td>\n",
       "      <td>smsp__sass_thread_inst_executed_op_dfma_pred_on</td>\n",
       "      <td>total</td>\n",
       "      <td>inst</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>144716</td>\n",
       "      <td>simulate_ct(Chain0_Args)</td>\n",
       "      <td>smsp__sass_thread_inst_executed_op_dmul_pred_on</td>\n",
       "      <td>total</td>\n",
       "      <td>inst</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>144717</td>\n",
       "      <td>simulate_ct(Chain0_Args)</td>\n",
       "      <td>smsp__sass_thread_inst_executed_op_fadd_pred_on</td>\n",
       "      <td>total</td>\n",
       "      <td>inst</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>144718</td>\n",
       "      <td>simulate_ct(Chain0_Args)</td>\n",
       "      <td>smsp__sass_thread_inst_executed_op_ffma_pred_on</td>\n",
       "      <td>total</td>\n",
       "      <td>inst</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>144719</td>\n",
       "      <td>simulate_ct(Chain0_Args)</td>\n",
       "      <td>smsp__sass_thread_inst_executed_op_fmul_pred_on</td>\n",
       "      <td>total</td>\n",
       "      <td>inst</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>144720 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              Kernel Name  \\\n",
       "0       generate_seed_pseudo(__int64,__int64,__int64,c...   \n",
       "1       generate_seed_pseudo(__int64,__int64,__int64,c...   \n",
       "2       generate_seed_pseudo(__int64,__int64,__int64,c...   \n",
       "3       generate_seed_pseudo(__int64,__int64,__int64,c...   \n",
       "4       generate_seed_pseudo(__int64,__int64,__int64,c...   \n",
       "...                                                   ...   \n",
       "144715                           simulate_ct(Chain0_Args)   \n",
       "144716                           simulate_ct(Chain0_Args)   \n",
       "144717                           simulate_ct(Chain0_Args)   \n",
       "144718                           simulate_ct(Chain0_Args)   \n",
       "144719                           simulate_ct(Chain0_Args)   \n",
       "\n",
       "                                            Metric Name Metric Type  \\\n",
       "0                                         dram__sectors        read   \n",
       "1                                         dram__sectors       write   \n",
       "2         l1tex__data_pipe_lsu_wavefronts_mem_shared_op        read   \n",
       "3         l1tex__data_pipe_lsu_wavefronts_mem_shared_op       write   \n",
       "4               l1tex__t_sectors_pipe_lsu_mem_global_op        read   \n",
       "...                                                 ...         ...   \n",
       "144715  smsp__sass_thread_inst_executed_op_dfma_pred_on       total   \n",
       "144716  smsp__sass_thread_inst_executed_op_dmul_pred_on       total   \n",
       "144717  smsp__sass_thread_inst_executed_op_fadd_pred_on       total   \n",
       "144718  smsp__sass_thread_inst_executed_op_ffma_pred_on       total   \n",
       "144719  smsp__sass_thread_inst_executed_op_fmul_pred_on       total   \n",
       "\n",
       "       Metric Unit  Metric Value  \n",
       "0           sector       11981.0  \n",
       "1           sector       55690.0  \n",
       "2              NaN           0.0  \n",
       "3              NaN           0.0  \n",
       "4           sector     5600957.0  \n",
       "...            ...           ...  \n",
       "144715        inst           0.0  \n",
       "144716        inst           0.0  \n",
       "144717        inst           0.0  \n",
       "144718        inst           0.0  \n",
       "144719        inst           0.0  \n",
       "\n",
       "[144720 rows x 5 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Get raw data file\n",
    "filename = \"fastcalosim_roofline.csv\"\n",
    "metricdf = pd.read_csv(os.path.join(datadir,filename))\n",
    "\n",
    "#fuse read/write metrics together:\n",
    "unique_metrics = metricdf[\"Metric Name\"].unique()\n",
    "unique_metrics = set([x.replace(\".sum\",\"\").replace(\"_write\",\"\").replace(\"_read\",\"\").replace(\"_ld\",\"\").replace(\"_st\",\"\") for x in unique_metrics])\n",
    "#add the metric type\n",
    "metricdf[\"Metric Type\"] = \"total\"\n",
    "#read\n",
    "metricdf.loc[ metricdf[ \"Metric Name\" ].str.contains(\"_read\"), \"Metric Type\" ] = \"read\"\n",
    "metricdf.loc[ metricdf[ \"Metric Name\" ].str.contains(\"_ld\"), \"Metric Type\" ] = \"read\"\n",
    "#write\n",
    "metricdf.loc[ metricdf[ \"Metric Name\" ].str.contains(\"_write\"), \"Metric Type\" ] = \"write\"\n",
    "metricdf.loc[ metricdf[ \"Metric Name\" ].str.contains(\"_st\"), \"Metric Type\" ] = \"write\"\n",
    "#rate\n",
    "metricdf.loc[ metricdf[ \"Metric Name\" ].str.contains(\".per_second\"), \"Metric Type\" ] = \"rate\"\n",
    "#rename metrics\n",
    "for metric in unique_metrics:\n",
    "    metricdf.loc[ metricdf[ \"Metric Name\"].str.startswith(metric), \"Metric Name\" ] = metric\n",
    "\n",
    "metricdf = metricdf[[\"Kernel Name\", \"Metric Name\", \"Metric Type\", \"Metric Unit\", \"Metric Value\"]]\n",
    "    \n",
    "display(metricdf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Compute AI Results"
   ]
  },
  {
   "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>Kernel Name</th>\n",
       "      <th>CUDA Time</th>\n",
       "      <th>FP64 FLOPs</th>\n",
       "      <th>FP32 FLOPs</th>\n",
       "      <th>FLOPs</th>\n",
       "      <th>L1 Transactions</th>\n",
       "      <th>L1 Bytes</th>\n",
       "      <th>L2 Transactions</th>\n",
       "      <th>L2 Bytes</th>\n",
       "      <th>DRAM Transactions</th>\n",
       "      <th>...</th>\n",
       "      <th>FP32 Performance GFlop/s</th>\n",
       "      <th>L1 AI</th>\n",
       "      <th>FP64 L1 AI</th>\n",
       "      <th>FP32 L1 AI</th>\n",
       "      <th>L2 AI</th>\n",
       "      <th>FP64 L2 AI</th>\n",
       "      <th>FP32 L2 AI</th>\n",
       "      <th>DRAM AI</th>\n",
       "      <th>FP64 DRAM AI</th>\n",
       "      <th>FP32 DRAM AI</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>simulate_A(float,int,Chain0_Args)</td>\n",
       "      <td>0.057460</td>\n",
       "      <td>207954625.0</td>\n",
       "      <td>1.297726e+09</td>\n",
       "      <td>1.505681e+09</td>\n",
       "      <td>72551194.0</td>\n",
       "      <td>2.321638e+09</td>\n",
       "      <td>17333768.0</td>\n",
       "      <td>5.546806e+08</td>\n",
       "      <td>10074161.0</td>\n",
       "      <td>...</td>\n",
       "      <td>22.584738</td>\n",
       "      <td>0.648542</td>\n",
       "      <td>0.089572</td>\n",
       "      <td>0.558970</td>\n",
       "      <td>2.714501</td>\n",
       "      <td>0.374909</td>\n",
       "      <td>2.339592</td>\n",
       "      <td>4.670616</td>\n",
       "      <td>0.645074</td>\n",
       "      <td>4.025541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>simulate_ct(Chain0_Args)</td>\n",
       "      <td>0.008827</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>47190825.0</td>\n",
       "      <td>1.510106e+09</td>\n",
       "      <td>47500486.0</td>\n",
       "      <td>1.520016e+09</td>\n",
       "      <td>84113172.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>simulate_clean(Chain0_Args)</td>\n",
       "      <td>0.007031</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>46892542.0</td>\n",
       "      <td>1.500561e+09</td>\n",
       "      <td>47130519.0</td>\n",
       "      <td>1.508177e+09</td>\n",
       "      <td>45696050.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>generate_seed_pseudo(__int64,__int64,__int64,c...</td>\n",
       "      <td>0.001094</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>20917992.0</td>\n",
       "      <td>6.693757e+08</td>\n",
       "      <td>15618928.0</td>\n",
       "      <td>4.998057e+08</td>\n",
       "      <td>67671.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>void gen_sequenced&lt;curandStateXORWOW,float,int...</td>\n",
       "      <td>0.000272</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.840000e+07</td>\n",
       "      <td>3.840000e+07</td>\n",
       "      <td>3972864.0</td>\n",
       "      <td>1.271316e+08</td>\n",
       "      <td>3386592.0</td>\n",
       "      <td>1.083709e+08</td>\n",
       "      <td>3209646.0</td>\n",
       "      <td>...</td>\n",
       "      <td>140.928050</td>\n",
       "      <td>0.302049</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.302049</td>\n",
       "      <td>0.354339</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.354339</td>\n",
       "      <td>0.373873</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.373873</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         Kernel Name  CUDA Time   FP64 FLOPs  \\\n",
       "0                  simulate_A(float,int,Chain0_Args)   0.057460  207954625.0   \n",
       "1                           simulate_ct(Chain0_Args)   0.008827          0.0   \n",
       "2                        simulate_clean(Chain0_Args)   0.007031          0.0   \n",
       "3  generate_seed_pseudo(__int64,__int64,__int64,c...   0.001094          0.0   \n",
       "4  void gen_sequenced<curandStateXORWOW,float,int...   0.000272          0.0   \n",
       "\n",
       "     FP32 FLOPs         FLOPs  L1 Transactions      L1 Bytes  L2 Transactions  \\\n",
       "0  1.297726e+09  1.505681e+09       72551194.0  2.321638e+09       17333768.0   \n",
       "1  0.000000e+00  0.000000e+00       47190825.0  1.510106e+09       47500486.0   \n",
       "2  0.000000e+00  0.000000e+00       46892542.0  1.500561e+09       47130519.0   \n",
       "3  0.000000e+00  0.000000e+00       20917992.0  6.693757e+08       15618928.0   \n",
       "4  3.840000e+07  3.840000e+07        3972864.0  1.271316e+08        3386592.0   \n",
       "\n",
       "       L2 Bytes  DRAM Transactions  ...  FP32 Performance GFlop/s     L1 AI  \\\n",
       "0  5.546806e+08         10074161.0  ...                 22.584738  0.648542   \n",
       "1  1.520016e+09         84113172.0  ...                  0.000000  0.000000   \n",
       "2  1.508177e+09         45696050.0  ...                  0.000000  0.000000   \n",
       "3  4.998057e+08            67671.0  ...                  0.000000  0.000000   \n",
       "4  1.083709e+08          3209646.0  ...                140.928050  0.302049   \n",
       "\n",
       "   FP64 L1 AI  FP32 L1 AI     L2 AI  FP64 L2 AI  FP32 L2 AI   DRAM AI  \\\n",
       "0    0.089572    0.558970  2.714501    0.374909    2.339592  4.670616   \n",
       "1    0.000000    0.000000  0.000000    0.000000    0.000000  0.000000   \n",
       "2    0.000000    0.000000  0.000000    0.000000    0.000000  0.000000   \n",
       "3    0.000000    0.000000  0.000000    0.000000    0.000000  0.000000   \n",
       "4    0.000000    0.302049  0.354339    0.000000    0.354339  0.373873   \n",
       "\n",
       "   FP64 DRAM AI  FP32 DRAM AI  \n",
       "0      0.645074      4.025541  \n",
       "1      0.000000      0.000000  \n",
       "2      0.000000      0.000000  \n",
       "3      0.000000      0.000000  \n",
       "4      0.000000      0.373873  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "profiledf = transpose_frame(metricdf)\n",
    "profiledf = profiledf.sort_values('CUDA Time', ascending=False).reset_index(drop=True)\n",
    "\n",
    "display(profiledf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Export Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "profiledf.to_csv(os.path.join(outputdir,\"full_profile.csv\"))"
   ]
  }
 ],
 "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.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
