

{"id":16966,"date":"2018-06-07T04:00:59","date_gmt":"2018-06-07T04:00:59","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=16966"},"modified":"2021-05-14T11:00:11","modified_gmt":"2021-05-14T05:30:11","slug":"gpu-in-tensorflow","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/","title":{"rendered":"Using GPU in TensorFlow Model &#8211; Single &amp; Multiple GPUs"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In our last TensorFlow tutorial, we studied <strong>Embeddings in TensorFlow<\/strong>. Today, in this <strong>TensorFlow<\/strong> Tutorial, we will look at &#8220;Using GPU in TensorFlow Model&#8221;. We\u2019ll study how to increase our computational workspace by making room for Tensorflow GPU. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, we will see device placement logging and manual device placement in TensorFlow GPU. In addition, we will discuss optimizing GPU memory. Also, we will cover single GPU in multiple GPU systems &amp; use multiple GPU in TensorFlow, also TensorFlow multiple GPU examples.<\/span><\/p>\n<p>So, let&#8217;s start using GPU in TensorFlow Model.<\/p>\n<h2><span style=\"font-weight: 400\">GPU in TensorFlow<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Your usual system may comprise of multiple devices for computation and as you already know TensorFlow, supports both CPU and GPU, which we represent as strings. For example:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">If you have a CPU, it might be addressed as &#8220;\/cpu:0&#8221;.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">TensorFlow GPU strings have index starting from zero. Therefore, to specify the first GPU, you should write \u201c\/device:GPU:0\u201d.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Similarly, the second GPU is &#8220;\/device:GPU:1&#8221;.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">By default, if your system has both a CPU and a GPU, the priority you give to the GPU in TensorFlow.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Device Placement Logging<\/span><\/h2>\n<p><span style=\"font-weight: 400\">You can find out which devices handle the particular operations by creating a session where <\/span><i><span style=\"font-weight: 400\">the log_device_placementconfiguration<\/span><\/i><span style=\"font-weight: 400\"> option is preset.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\"># Graph creation.\r\na = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')\r\nb = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')\r\nc = tf.matmul(a, b)\r\nsess = tf.Session(config=tf.ConfigProto(log_device_placement=True))\r\n# Running the operation.\r\nprint(sess.run(c))<\/pre>\n<p><span style=\"font-weight: 400\">The <strong>output<\/strong>\u00a0of TensorFlow GPU device placement logging shown as below:<\/span><\/p>\n<p><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\"> -&gt; device: <\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">, name: <\/span><span style=\"font-weight: 400\">Tesla<\/span><span style=\"font-weight: 400\"> K40c, pci bus<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">id: <\/span><span style=\"font-weight: 400\">0000<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">05<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">00.0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">b: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">a: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">MatMul<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">[[ <\/span><span style=\"font-weight: 400\">22.<\/span><span style=\"font-weight: 400\"> \u00a0<\/span><span style=\"font-weight: 400\">28.<\/span><span style=\"font-weight: 400\">]<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">\u00a0[ <\/span><span style=\"font-weight: 400\">49.<\/span><span style=\"font-weight: 400\"> \u00a0<\/span><span style=\"font-weight: 400\">64.<\/span><span style=\"font-weight: 400\">]]<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Manual Device Placement<\/span><\/h2>\n<p><span style=\"font-weight: 400\">At times you may want to decide on which device your operation should be running and you can do this by creating a context with <\/span><i><span style=\"font-weight: 400\">tf.device <\/span><\/i><span style=\"font-weight: 400\">wherein you assign the specific device, i.e., CPU or a GPU that should do the computation, as shown below.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\"># Graph Creation.\r\nwith tf.device('\/cpu:0'):\r\n  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')\r\n  b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')\r\nc = tf.matmul(a, b)\r\nsess = tf.Session(config=tf.ConfigProto(log_device_placement=True))\r\n# Running the operation.\r\nprint(sess.run(c))<\/pre>\n<p>The above code of TensorFlow GPU assigns the constants a and b to cpu:0. In the second part of the code, since there is no explicit declaration of which device is to perform the task, a GPU by default is chosen if available and it copies the multi-dimensional arrays between devices if required.<\/p>\n<pre class=\"EnlighterJSRAW\">Device mapping:\r\n\/job:localhost\/replica:0\/task:0\/device:GPU:0 -&gt; device: 0, name: Tesla K40c, pci bus\r\nid: 0000:05:00.0\r\nb: \/job:localhost\/replica:0\/task:0\/cpu:0\r\na: \/job:localhost\/replica:0\/task:0\/cpu:0\r\nMatMul: \/job:localhost\/replica:0\/task:0\/device:GPU:0\r\n[[ 22.  28.]\r\n [ 49.  64.]]<\/pre>\n<h2><span style=\"font-weight: 400\">Optimizing TensorFlow GPU Memory<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Memory fragmentation is done to optimize memory resources by mapping almost all of the TensorFlow GPUs memory that is visible to the processor, thus saving a lot of potential resources.<\/span><\/p>\n<p><span style=\"font-weight: 400\">TensorFlow GPU offers two configuration options to control the allocation of a subset of memory if and when required by the processor to save memory and these TensorFlow GPU optimizations are described below:<\/span><br \/>\n<i><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">allow_growth<\/span><\/i><span style=\"font-weight: 400\">, which allocates a limited amount of GPU memory in TensorFlow according to the runtime: it is dynamic in the sense that it initially allocates little memory and keeps widening it according to the running sessions, thus extending the GPU memory required by the process.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> The memory isn\u2019t released as it will lead to fragmentation which is not desired. <\/span><i><span style=\"font-weight: 400\">ConfigProto<\/span><\/i><span style=\"font-weight: 400\"> is used for this purpose:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">config = tf.ConfigProto()\r\nconfig.gpu_options.allow_growth = True\r\nsession = tf.Session(config=config, ...)<\/pre>\n<p><i style=\"font-family: Verdana, Geneva, sans-serif;font-weight: inherit\">per_process_gpu_memory_fraction<\/i><span style=\"font-weight: 400\">, is the second choice and it decides the segment of the total memory should be allocated for each GPU in use. Given below is an example which will tell tensorflow to allocate 40% of the memory:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">config = tf.ConfigProto()\r\nconfig.gpu_options.per_process_gpu_memory_fraction = 0.4\r\nsession = tf.Session(config=config, ...)<\/pre>\n<p>It will use only in cases where you already know the specifics of the computation and are sure that they will not change during the course of processing.<\/p>\n<h2><span style=\"font-weight: 400\">Single GPU in Multi-GPU System<\/span><\/h2>\n<p><span style=\"font-weight: 400\">In multi TensorFlow GPU systems, the device with the lowest identity is selected by default. It is again to the user to decide the specific GPU if the default user does not need one: <\/span><\/p>\n<pre class=\"EnlighterJSRAW\"># Creates a graph.\r\nwith tf.device('\/device:GPU:2'):\r\n  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')\r\n  b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')\r\n  c = tf.matmul(a, b)\r\n# Creates a session with log_device_placement set to True.\r\nsess = tf.Session(config=tf.ConfigProto(log_device_placement=True))\r\n# Runs the op.\r\nprint(sess.run(c))<\/pre>\n<p><span style=\"font-weight: 400\">The <\/span><i><span style=\"font-weight: 400\">InvalidArgumentError<\/span><\/i><span style=\"font-weight: 400\"> is obtained when the TensorFlow GPU specified by the user does not exist as shown below:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">InvalidArgumentError: Invalid argument: Cannot assign a device to node 'b':\r\nCould not satisfy explicit device specification '\/device:GPU:2'\r\n   [[Node: b = Const[dtype=DT_FLOAT, value=Tensor&lt;type: float shape: [3,2]\r\n   values: 1 2 3...&gt;, _device=\"\/device:GPU:2\"]()]]<\/pre>\n<p><span style=\"font-weight: 400\">If you want to specify the default device in such cases when there is no existing or supported device found by TensoFflow, you could use <\/span><i><span style=\"font-weight: 400\">allow_soft_placement<\/span><\/i><span style=\"font-weight: 400\"> and set it in the configuration option when the session is created as illustrated by the code below.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">with tf.device('\/device:GPU:2'):\r\n  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')\r\n  b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')\r\n  c = tf.matmul(a, b)\r\nsess = tf.Session(config=tf.ConfigProto(\r\n      allow_soft_placement=True, log_device_placement=True))\r\n# Running the operation.\r\nprint(sess.run(c))<\/pre>\n<h2>Using Multiple GPU in TensorFlow<\/h2>\n<p><span style=\"font-weight: 400\">You are already aware of the towers in TensorFlow and each tower we can assign to a GPU, making a multi tower structural model for working with TensorFlow multiple GPUs. Let&#8217;s see an example &#8211;\u00a0<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">c = []\r\nfor d in ['\/device:GPU:2', '\/device:GPU:3']:\r\n  with tf.device(d):\r\n    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3])\r\n    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2])\r\n    c.append(tf.matmul(a, b))\r\nwith tf.device('\/cpu:0'):\r\n  sum = tf.add_n(c)\r\nsess = tf.Session(config=tf.ConfigProto(log_device_placement=True))\r\n# Running the operations.\r\nprint(sess.run(sum))<\/pre>\n<p><span style=\"font-weight: 400\">The<strong> output of TensorFlow GPU<\/strong>\u00a0is as follows:<\/span><\/p>\n<p><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\"> -&gt; device: <\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">, name: <\/span><span style=\"font-weight: 400\">Tesla<\/span><span style=\"font-weight: 400\"> K20m, pci bus<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">id: <\/span><span style=\"font-weight: 400\">0000<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">02<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">00.0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">\/job:localhost\/replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">1<\/span><span style=\"font-weight: 400\"> -&gt; device: <\/span><span style=\"font-weight: 400\">1<\/span><span style=\"font-weight: 400\">, name: <\/span><span style=\"font-weight: 400\">Tesla<\/span><span style=\"font-weight: 400\"> K20m, pci bus<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">id: <\/span><span style=\"font-weight: 400\">0000<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">03<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">00.0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">\/job:localhost\/replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">2<\/span><span style=\"font-weight: 400\"> -&gt; device: <\/span><span style=\"font-weight: 400\">2<\/span><span style=\"font-weight: 400\">, name: <\/span><span style=\"font-weight: 400\">Tesla<\/span><span style=\"font-weight: 400\"> K20m, pci bus<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">id: <\/span><span style=\"font-weight: 400\">0000<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">83<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">00.0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">\/job:localhost\/replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">3<\/span><span style=\"font-weight: 400\"> -&gt; device: <\/span><span style=\"font-weight: 400\">3<\/span><span style=\"font-weight: 400\">, name: <\/span><span style=\"font-weight: 400\">Tesla<\/span><span style=\"font-weight: 400\"> K20m, pci bus<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">id: <\/span><span style=\"font-weight: 400\">0000<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">84<\/span><span style=\"font-weight: 400\">:<\/span><span style=\"font-weight: 400\">00.0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">Const_3<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">3<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">Const_2<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">3<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">MatMul_1<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">3<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">Const_1<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">2<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">Const<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">2<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">MatMul<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/device:GPU:<\/span><span style=\"font-weight: 400\">2<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">AddN<\/span><span style=\"font-weight: 400\">: <\/span><span style=\"font-weight: 400\">\/job:localhost\/<\/span><span style=\"font-weight: 400\">replica:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/task:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">\/cpu:<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">[[ \u00a0<\/span><span style=\"font-weight: 400\">44.<\/span><span style=\"font-weight: 400\"> \u00a0 <\/span><span style=\"font-weight: 400\">56.<\/span><span style=\"font-weight: 400\">]<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">\u00a0[ \u00a0<\/span><span style=\"font-weight: 400\">98.<\/span><span style=\"font-weight: 400\"> \u00a0<\/span><span style=\"font-weight: 400\">128.<\/span><span style=\"font-weight: 400\">]]<\/span><\/p>\n<p><span style=\"font-weight: 400\">You can test this multiple GPU model with a simple dataset such as CIFAR10 to experiment and understand working with GPUs.<\/span><\/p>\n<p>So, this was all about how to use GPU in TensorFlow. Hope you like our explanation.<\/p>\n<h2><span style=\"font-weight: 400\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Hence, in this GPU in TensorFlow tutorial, we saw TensorFlow GPUs for graphical computations and that define as an array of parallel processors working together to perform high-level computations which are in contrast to CPUs. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This TensorFlow GPU tutorial briefed you about how to initialize GPUs, change the default configurations to suit your needs and optimize your computation. Moreover, we saw how to import GPU and TensorFlow GPU install. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we looked at TensorFlow cannot find GPU &amp; TensorFlow disable GPU. Furthermore, if you have any query regarding GPU in TensorFlow Model, feel free to ask through the comment section.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last TensorFlow tutorial, we studied Embeddings in TensorFlow. Today, in this TensorFlow Tutorial, we will look at &#8220;Using GPU in TensorFlow Model&#8221;. We\u2019ll study how to increase our computational workspace by making&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":16967,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[3805,5123,6618,8513,9302,14527,14539,14550,14551,14552,14582,14586,15291],"class_list":["post-16966","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tensorflow","tag-device-placement-logging","tag-gpu-in-tensorflow","tag-import-tensorflow-gpu","tag-manual-device-placement","tag-optimizing-memory","tag-tensorflow-cannot-find-gpu","tag-tensorflow-disable-gpu","tag-tensorflow-gpu","tag-tensorflow-gpu-install","tag-tensorflow-gpu-windows","tag-tensorflow-multiple-gpu-example","tag-tensorflow-not-using-gpu","tag-using-multiple-gpus"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using GPU in TensorFlow Model - Single &amp; Multiple GPUs - DataFlair<\/title>\n<meta name=\"description\" content=\"Using GPU in TensorFlow model, Device Placement Logging, Manual Device Placement, Optimizing GPU Memory, Single TensorFlow GPU in multiple GPU,Multiple GPUs\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using GPU in TensorFlow Model - Single &amp; Multiple GPUs - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Using GPU in TensorFlow model, Device Placement Logging, Manual Device Placement, Optimizing GPU Memory, Single TensorFlow GPU in multiple GPU,Multiple GPUs\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-07T04:00:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-14T05:30:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/GPU-with-TensorFlow-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using GPU in TensorFlow Model - Single &amp; Multiple GPUs - DataFlair","description":"Using GPU in TensorFlow model, Device Placement Logging, Manual Device Placement, Optimizing GPU Memory, Single TensorFlow GPU in multiple GPU,Multiple GPUs","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/","og_locale":"en_US","og_type":"article","og_title":"Using GPU in TensorFlow Model - Single &amp; Multiple GPUs - DataFlair","og_description":"Using GPU in TensorFlow model, Device Placement Logging, Manual Device Placement, Optimizing GPU Memory, Single TensorFlow GPU in multiple GPU,Multiple GPUs","og_url":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-06-07T04:00:59+00:00","article_modified_time":"2021-05-14T05:30:11+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/GPU-with-TensorFlow-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Using GPU in TensorFlow Model &#8211; Single &amp; Multiple GPUs","datePublished":"2018-06-07T04:00:59+00:00","dateModified":"2021-05-14T05:30:11+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/"},"wordCount":970,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/GPU-with-TensorFlow-01.jpg","keywords":["Device Placement Logging","GPU in TensorFlow","import TensorFlow GPU","Manual device placement","Optimizing Memory","TensorFlow cannot find gpu","tensorFlow disable gpu","tensorflow GPU","tensorflow gpu install","TensorFlow gpu windows","TensorFlow multiple gpu example","TensorFlow not using gpu","Using multiple GPUs"],"articleSection":["Tensorflow Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/","url":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/","name":"Using GPU in TensorFlow Model - Single &amp; Multiple GPUs - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/GPU-with-TensorFlow-01.jpg","datePublished":"2018-06-07T04:00:59+00:00","dateModified":"2021-05-14T05:30:11+00:00","description":"Using GPU in TensorFlow model, Device Placement Logging, Manual Device Placement, Optimizing GPU Memory, Single TensorFlow GPU in multiple GPU,Multiple GPUs","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/GPU-with-TensorFlow-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/GPU-with-TensorFlow-01.jpg","width":1200,"height":628,"caption":"Using GPU with TensorFlow model"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/gpu-in-tensorflow\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Tensorflow Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/tensorflow\/"},{"@type":"ListItem","position":3,"name":"Using GPU in TensorFlow Model &#8211; Single &amp; Multiple GPUs"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/16966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=16966"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/16966\/revisions"}],"predecessor-version":[{"id":94505,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/16966\/revisions\/94505"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/16967"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=16966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=16966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=16966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}