tensorflow-keras-cpu-gpu/01. Matrix multiplication.ipynb

287 lines
27 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"import matplotlib\n",
"%matplotlib inline\n",
"matplotlib.rcParams['figure.figsize'] = (20, 10)\n",
"matplotlib.rcParams['font.size'] = 24\n",
"matplotlib.rcParams['lines.linewidth'] = 5\n",
"matplotlib.rcParams['lines.markersize'] = 20\n",
"\n",
"import tensorflow as tf\n",
"from tensorflow.python.client import device_lib\n",
"\n",
"import time\n",
"import numpy as np\n",
"from matplotlib import pyplot\n",
"from collections import defaultdict\n",
"from ipy_table import make_table, set_row_style, set_column_style\n",
"from jupyter_progressbar import ProgressBar"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Devices\n",
"\n",
"lists the devices found by tensorflow"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\" style=\"border:black; border-collapse:collapse;\"><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\"><b>name</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\"><b>type</b></td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">/device:CPU:0</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">CPU</td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">/device:GPU:0</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">GPU</td></tr></table>"
],
"text/plain": [
"<ipy_table.ipy_table.IpyTable at 0x7f58b3ab14a8>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"devices = device_lib.list_local_devices()\n",
"\n",
"make_table([[\"name\", \"type\"]] + [\n",
" [device.name, device.device_type]\n",
" for device in devices\n",
"])\n",
"set_row_style(0, bold=True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Use all devices once such that they are initialized"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"for device in devices:\n",
" with tf.device(device.name):\n",
" c = tf.constant(5.0)\n",
" x = tf.placeholder(tf.float32)\n",
" product = c * x\n",
"\n",
" with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as session:\n",
" result = session.run(product, feed_dict={x: 5.0})\n",
" assert result == 25.0, \"c * x for x == 5.0 should result in 25.0, but resulted in {} on device {} ({})\".format(\n",
" result, device.name, device.device_type)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Benchmark"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"start /device:CPU:0 10\n",
"start /device:GPU:0 10\n",
"start /device:CPU:0 20\n",
"start /device:GPU:0 20\n",
"start /device:CPU:0 50\n",
"start /device:GPU:0 50\n",
"start /device:CPU:0 100\n",
"start /device:GPU:0 100\n",
"start /device:CPU:0 1000\n",
"start /device:GPU:0 1000\n",
"start /device:CPU:0 5000\n",
"start /device:GPU:0 5000\n",
"start /device:CPU:0 10000\n",
"start /device:GPU:0 10000\n"
]
}
],
"source": [
"results = defaultdict(list)\n",
"\n",
"matrix_sizes = list(map(int, [10, 20, 50, 100, 1000, 5000, 1e4]))\n",
"\n",
"for size in ProgressBar(matrix_sizes):\n",
" for device in devices:\n",
" print('start', device.name, size)\n",
" with tf.device(device.name):\n",
" A = tf.random_uniform(shape=(size, size), minval=0, maxval=1, dtype=tf.float32)\n",
" B = tf.random_uniform(shape=(size, size), minval=0, maxval=1, dtype=tf.float32)\n",
" product = tf.matmul(A, B)\n",
" \n",
" with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as session:\n",
" t0 = time.time()\n",
" result = session.run(product)\n",
" t1 = time.time()\n",
" results[device.name].append(t1 - t0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Results"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.text.Text at 0x7f58b018b710>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAEPCAYAAABRHfM8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XeYVOX5//H3Ta+7LAiIdMQSCyLWXGhcRFQ0sYIFK5ZYozExavRrIJoGJrHFkhDUWLCgoCgQVGRtPzGKEBCxQAAREYSlC7Ll/v1xZpfZndllWOacmd39vK5rLmbOM3POPWeHuecp53nM3REREdmRBpkOQEREagclDBERSYkShoiIpEQJQ0REUqKEISIiKVHCEBGRlISaMMysi5m9YWbzzWyemf0stn2EmX1lZh/FbieGGYeIiOw6C/M6DDPbHdjd3eeYWStgFnAqcDaw0d3/GtrBRUQkrRqFuXN3/wb4JnZ/k5ktADrHii3MY4uISHpF1odhZj2AvsD7sU3XmNkcM/unmeVGFYeIiNRMJAkj1hz1PHC9u28CHgT2dPe+BDUQNU2JiGS5UPswAMysEfAKMNXd701S3h142d37JCnTRFciIjXg7mlv9o+ihvEI8El8soh1hpc5A/i4qhe7u27ujBgxIuMxZMtN50LnQuei+ltYQu30NrP+wHnAPDObDThwKzDMzPoCpcAS4Iow4xARkV0X9iipd4GGSYr+HeZxRUQk/XSldy2Rn5+f6RCyhs7FdjoX2+lchC/0Tu9dYWaezfGJiGQjM8ND6PQOtUlKRMLXo0cPli5dmukwJAO6d+/OkiVLIjueahgitVzs12Smw5AMqOpvH1YNQ30YIiKSEiUMERFJiRKGiIikRAlDRDJm+PDh/OY3v9nl/Zx00kk88cQTaYhIqqOEISKhWrFiBV27dg31GFOmTOGCCy5I+34///xzzjrrLNq3b09eXh59+/bl7rvvxt1ZunQpDRo0ICcnh5ycHHr16sWoUaMAystKS0sr7G9HCXLcuHH06NGD1q1bc8YZZ7Bu3bq0v6ddoYQhIqGaMmUKgwcPznQYO23RokUceeSRdO/enY8//pi1a9cyfvx4Zs2axcaNG4FgNNL69evZsGED48aN44477uDVV18tL9sZ8+fP58orr+Spp55i5cqVNG/enKuuuirt72tXKGGI1FVm4dx20pQpUzjppJMAmD17Nocccgi5ubmcc845bN26tcJzX3nlFQ4++GDy8vI46qijmDdvHgCjR49m6NChFZ57/fXX8/Of/xyAAQMG8Mgjj5SXjRkzhv3224+cnBwOOOAA5syZAwS1nSFDhtChQwf23HNP7r///irjHjlyJP379+euu+6iY8eOAOy11148+eST5OTklD+vbFjrkUceyf7778/HH1c5l2q1xo0bxymnnEL//v1p0aIFd955JxMmTGDz5s012l8YlDBEJDTFxcW89dZbDBo0iKKiIk4//XQuuugiCgsLGTp0KC+88EL5c2fPns2ll17KmDFjKCws5IorruCUU06hqKiIc845h6lTp5Z/eZaWljJ+/HjOO++8hGOOHz+eO+64gyeffJINGzYwadIk2rVrh7vzk5/8hIMPPpgVK1Ywffp07r33Xl577TUA3n33Xdq2bVu+n9dff50hQ4bs8D2WJYx3332XTz75hH79+qV0bpYtW0bbtm356quvgKCGcdBBB5WX9+rViyZNmvD555+ntL8oKGGISGjeeust+vbtS8uWLXnvvfcoLi7muuuuo2HDhpx55pkcdthh5c8dM2YMV155JYceeihmxgUXXEDTpk2ZOXMm3bp1o1+/fkycOBGA6dOn07JlywqvLzN27Fhuuumm8i/uXr160bVrVz744ANWr17NbbfdRsOGDenRoweXXXYZzzzzDAD9+/ensLCwfD9r1qyhU6dO1b4/d6d9+/a0a9eOn/70p4waNSrlOa26du1KYWEhXbp0AWDTpk3k5lZcfDQ3N7e8+SsbaGoQEQlNfHPUihUr6Ny5c4Xy7t27l99funQpjz/+eHkzkbtTVFTE119/DcC5557L008/zfnnn8/TTz/NsGHDkh5z2bJl7Lnnngnbly5dyvLly8trEe5OaWkpP/rRj5Lup127dqxYsaLa92dmrFmzJqG/olGj4Ku1qKiIpk2blm8vKiqicePGSffVqlUrNmzYUGHbhg0baN26dbUxREk1DBEJTXzC6NSpE8uXL69Q/uWXX5bf79q1K7fddhuFhYUUFhaydu1aNm3axNlnnw3A0KFDKSgoYPny5UycOLHKhNG1a1cWLVqUdHuvXr0q7H/9+vW8/PLLSfdz3HHHVWgyq0qyqTk6depE48aNE+Z5Wrx4cYUkGW///ffnv//9b/nj//3vf2zbto299957hzFUEOa8YpleGWoHq0a5iFQvW/+fLF682Pfcc8/yx9u2bfPu3bv7fffd50VFRf7CCy9448aN/fbbb3d39w8//NC7devm77//vru7b9q0ySdPnuybNm0q38fgwYN90KBB3q9fvwrHys/P97Fjx7q7+/jx471bt24+a9Ysd3dfuHChf/nll15SUuKHHHKIjxo1yrds2eLFxcX+8ccf+wcffJA0/kWLFnm7du38pptu8m+++cbd3b/44gs///zzff369b5kyRI3My8pKUn6+mHDhvmZZ57pa9as8aKiIh83bpzn5eX5qlWrkj5//vz5npub6++8845v2rTJzz//fB82bFi15zjhb//BB+6tW5dtT/t3smoYIhKKyZMnl9cuABo3bsyECRN49NFHadeuHePHj+fMM88sLz/kkEMYM2YM1157LW3btmXvvffmX//6V4V9Dhs2jOnTpyd0dsc3CQ0ZMoTbbruNYcOGkZOTw+mnn05hYSENGjTglVdeYc6cOfTs2ZMOHTpw+eWXlzcDvfPOOxVGP/Xq1Yv33nuPxYsXs//++5OXl8fQoUM57LDDypuJqhs6++CDD9K2bVv69OlDx44defDBB5kyZQrt27cHgqaznJyc8k7v/fbbj4cffphhw4ax++67s3nzZh544IHUT/i8eXDCCRBin4dm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vYKQdPYu7F1pL+v9LSHgOfdvSwGI6jxjKnmuCIZoyYpqWvKfsY/AvzW3edXKs9l+7z/w+O2byRYHnXHBwgSzQ0EzUaDzezwJM/p5e7z3X00wcyz+1YqvwZo5e53xW2eBlxiZi1jz9nDzNqnEpNIFJQwpK4p6yNY7u5/S1I+GviTmc2i4ud/BrBfWac3Va9kBvBP4JcerClwGTAmtnZLvJ+b2TwzmwNsI3H01S+BA+M6xn/q7q8RdNC/Z2ZzCZqrWqX0rkUioOnNRUQkJaphiIhISpQwREQkJUoYIiKSEiUMERFJiRKGiIikRAlDRERSooQhIiIpUcIQEZGU/H8HoYUh+6K8vgAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x7f58b025e390>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"colors = 'rgbcmyk'\n",
"marks = ['-', '--', '..']\n",
"\n",
"styles = (color+mark for mark in marks for color in colors)\n",
"\n",
"for style, (name, times) in zip(styles, results.items()):\n",
" pyplot.plot(matrix_sizes, times, style, label=name)\n",
"\n",
"pyplot.legend()\n",
"\n",
"pyplot.ylabel('Calculation time')\n",
"pyplot.xlabel('Matrix size')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\" style=\"border:black; border-collapse:collapse;\"><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>matrix&nbsp;size</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">time&nbsp;(s)&nbsp;on&nbsp;<b>/device:CPU:0</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">time&nbsp;(s)&nbsp;on&nbsp;<b>/device:GPU:0</b></td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>10</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0054</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.1705</td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>20</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0045</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0059</td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>50</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0053</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0081</td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>100</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0103</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0081</td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>1000</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0437</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.0106</td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>5000</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">2.8766</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">0.2573</td></tr><tr><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;text-align:right;\"><b>10000</b></td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">22.4699</td><td style=\"border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;\">1.6363</td></tr></table>"
],
"text/plain": [
"<ipy_table.ipy_table.IpyTable at 0x7f58b021afd0>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"devices = device_lib.list_local_devices()\n",
"\n",
"\n",
"make_table([[\"matrix size\"] + [\"time (s) on <b>{}</b>\".format(device.name) for device in devices]] + [\n",
" [size] + [results[device.name][size_index] for device in devices]\n",
" for size_index, size in enumerate(matrix_sizes)\n",
"])\n",
"set_column_style(0, bold=True, align='right')"
]
}
],
"metadata": {
"hide_input": false,
"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.5.2"
},
"widgets": {
"state": {
"7ba735bb37af497cac93b37f587e1d16": {
"views": [
{
"cell_index": 5
}
]
}
},
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}