Skip to content

Instantly share code, notes, and snippets.

@renxida
Created September 24, 2019 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renxida/6f4649b73d400f91aea438fca1bd3f0a to your computer and use it in GitHub Desktop.
Save renxida/6f4649b73d400f91aea438fca1bd3f0a to your computer and use it in GitHub Desktop.
/venkathw1.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Exercise 1.5"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## (a)"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import pandas as pd",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df=pd.DataFrame(columns=[\"Metric\", \"A\", \"B\", \"diff\"])",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "p = 0.4",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ET_a = 100\nET_b = 100 * (1-p) + 100*p/4\ndf.loc[0] = [\n \"Runtime\",\n ET_a,\n ET_b,\n ET_a/ET_b]",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "E_a = ET_a * 0.5 # time * wattage\nE_b = ET_a * (1-p) * 0.5 + (ET_a * p / 4) * 4 * 0.5\nassert E_a == E_b",
"execution_count": 6,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.loc[1] = [\n \"Energy\",\n E_a,\n E_b,\n 1 - E_a/E_b]",
"execution_count": 7,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "EDP_a = E_a * ET_a\nEDP_b = E_b * ET_b\nEDP_diff = 1 - EDP_b/EDP_a",
"execution_count": 8,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.loc[2] = [\n \"EDP\",\n EDP_a,\n EDP_b,\n 1 - EDP_b/EDP_a]",
"execution_count": 9,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df",
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 10,
"data": {
"text/plain": " Metric A B diff\n0 Runtime 100 70.0 1.428571\n1 Energy 50 50.0 0.000000\n2 EDP 5000 3500.0 0.300000",
"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>Metric</th>\n <th>A</th>\n <th>B</th>\n <th>diff</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Runtime</td>\n <td>100</td>\n <td>70.0</td>\n <td>1.428571</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Energy</td>\n <td>50</td>\n <td>50.0</td>\n <td>0.000000</td>\n </tr>\n <tr>\n <th>2</th>\n <td>EDP</td>\n <td>5000</td>\n <td>3500.0</td>\n <td>0.300000</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "markdown",
"source": "## (b) "
},
{
"metadata": {},
"cell_type": "markdown",
"source": "The changes scale runtime by the frequency scaling factor.\n\nSince power = fv^2C, the new power has to be scaled by "
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "time_factor = 1/1.19\npower_factor = 1.19*0.88**2*0.56\nenergy_factor = time_factor * power_factor",
"execution_count": 17,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df1=pd.DataFrame(columns=[\"Metric\", \"B\", \"B'\", \"diff\"])\ndf1[\"B\"] = df[\"B\"]",
"execution_count": 19,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df1[\"Metric\"] = [\n \"Runtime\",\n \"Energy\",\n \"EDP\"\n]",
"execution_count": 45,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import numpy as np",
"execution_count": 46,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df1[\"B'\"] = np.array([\n time_factor,\n energy_factor,\n energy_factor * time_factor\n]) * df1[\"B\"]",
"execution_count": 47,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "time_factor",
"execution_count": 48,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 48,
"data": {
"text/plain": "0.8403361344537815"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "power_factor",
"execution_count": 49,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 49,
"data": {
"text/plain": "0.51606016"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "energy_factor",
"execution_count": 50,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 50,
"data": {
"text/plain": "0.433664"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df1[\"diff\"] = [\n 1 / time_factor,\n 1 - power_factor,\n 1 - energy_factor\n]",
"execution_count": 51,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df1",
"execution_count": 52,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 52,
"data": {
"text/plain": " Metric B B' diff\n0 Runtime 70.0 58.823529 1.190000\n1 Energy 50.0 21.683200 0.483940\n2 EDP 3500.0 1275.482353 0.566336",
"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>Metric</th>\n <th>B</th>\n <th>B'</th>\n <th>diff</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Runtime</td>\n <td>70.0</td>\n <td>58.823529</td>\n <td>1.190000</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Energy</td>\n <td>50.0</td>\n <td>21.683200</td>\n <td>0.483940</td>\n </tr>\n <tr>\n <th>2</th>\n <td>EDP</td>\n <td>3500.0</td>\n <td>1275.482353</td>\n <td>0.566336</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## (c) big core, small core"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import pandas as pd",
"execution_count": 53,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df=pd.DataFrame(columns=[\"Metric\", \"B\", \"C\", \"diff\"])",
"execution_count": 55,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "p = 0.4",
"execution_count": 56,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ET_b = 100 * (1-p) + 100*p/4\nET_c = 100 * (1-p) / 2.5 + 100*p / 5\ndf.loc[0] = [\n \"Runtime\",\n ET_b,\n ET_c,\n ET_b/ET_c]",
"execution_count": 72,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "E_a = ET_a * 0.5 # time * wattage\nE_b = ET_a * (1-p) * 0.5 + (ET_a * p / 4) * 4 * 0.5\nE_c = ET_a * (1-p) * 0.8 / 2.5 + ET_a * p * (0.8 + 5*0.2) / 5\n#assert E_a == E_b",
"execution_count": 74,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.loc[1] = [\n \"Energy\",\n E_b,\n E_c,\n 1 - E_c/E_b]",
"execution_count": 81,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "EDP_a = E_a * ET_a\nEDP_b = E_b * ET_b\nEDP_c = E_c * ET_c\nEDP_diff = 1 - EDP_c/EDP_b",
"execution_count": 85,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.loc[2] = [\n \"EDP\",\n EDP_b,\n EDP_c,\n 1 - EDP_c/EDP_b]",
"execution_count": 88,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df",
"execution_count": 89,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 89,
"data": {
"text/plain": " Metric B C diff\n0 Runtime 70.0 32.0 2.1875\n1 Energy 50.0 33.6 0.3280\n2 EDP 3500.0 1075.2 0.6928",
"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>Metric</th>\n <th>B</th>\n <th>C</th>\n <th>diff</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Runtime</td>\n <td>70.0</td>\n <td>32.0</td>\n <td>2.1875</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Energy</td>\n <td>50.0</td>\n <td>33.6</td>\n <td>0.3280</td>\n </tr>\n <tr>\n <th>2</th>\n <td>EDP</td>\n <td>3500.0</td>\n <td>1075.2</td>\n <td>0.6928</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {}
}
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.7.3",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"gist": {
"id": "",
"data": {
"description": "/venkathw1.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment