{"id":549,"date":"2022-07-06T20:34:46","date_gmt":"2022-07-06T10:34:46","guid":{"rendered":"https:\/\/www.samontab.com\/web\/?p=549"},"modified":"2022-07-06T20:34:46","modified_gmt":"2022-07-06T10:34:46","slug":"using-cuda-9-0-gpus-on-a-modern-ubuntu-install","status":"publish","type":"post","link":"https:\/\/www.samontab.com\/web\/2022\/07\/using-cuda-9-0-gpus-on-a-modern-ubuntu-install\/","title":{"rendered":"Using CUDA 9.0 GPUs on a modern Ubuntu install"},"content":{"rendered":"\n<p>If you have an older GPU that only supports CUDA 9.0 you can&#8217;t simply install the latest tools on a modern Ubuntu, they just won&#8217;t work as it requires an older version of many libraries.<\/p>\n\n\n\n<p>To make it work we&#8217;re going to isolate everything we need in a conda environment, and use that whenever we need to work with the GPU. Here&#8217;s what you have to do:<\/p>\n\n\n\n<p>Install <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.conda.io\/en\/latest\/miniconda.html\" data-type=\"URL\" data-id=\"https:\/\/docs.conda.io\/en\/latest\/miniconda.html\" target=\"_blank\">miniconda<\/a> and then execute this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nconda create -n cuda python=3.6\nconda activate cuda\nconda install gcc-6 cudatoolkit=9.0 tensorflow-gpu==1.12.0 numpy==1.16.0 -c pytorch -c hcc -c omgarcia\n<\/pre><\/div>\n\n\n<p>Now you can use your CUDA 9.0 GPU whenever you are in the cuda environment. Here&#8217;s how you can enter and exit your cuda environment at any time:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#To exit your cuda environment:\nconda deactivate\n\n#To enter your cuda environment:\nconda activate cuda\n<\/pre><\/div>\n\n\n<p> Now let&#8217;s test it with python (make sure you are in the cuda environment, otherwise it will say False):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport tensorflow as tf\nvalue = tf.test.is_gpu_available()\nprint(&quot;GPU available?: &quot;, value)\n<\/pre><\/div>\n\n\n<p>It should tell you:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nGPU available?:  True\n<\/pre><\/div>\n\n\n<p>Now let&#8217;s try CUDA with CMake in a simple example. Basically this project creates a function in CUDA that adds two integers, and then the main program uses it to calculate 5 + 3 in the GPU. Amazing stuff. Let&#8217;s see if it works:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ngit clone https:\/\/github.com\/Yannnnnnnnnnnn\/cuda_cmakelists.git\ncd cuda_cmakelists\nmkdir build\ncd build\ncmake ..\nmake\n.\/Demo\n<\/pre><\/div>\n\n\n<p>You should get the answer, which is 8 by the way. If you see that, it means you can now create a CUDA function, send data to your GPU, and then use that function on a program, all ready to use with CMake.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have an older GPU that only supports CUDA 9.0 you can&#8217;t simply install the latest tools on a modern Ubuntu, they just won&#8217;t work as it requires an older version of many libraries. To make it work we&#8217;re going to isolate everything we need in a conda environment, and use that whenever we [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[62,38,61,35],"class_list":["post-549","post","type-post","status-publish","format-standard","hentry","category-programming","tag-9-0","tag-cmake","tag-cuda","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/comments?post=549"}],"version-history":[{"count":0,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/549\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/media?parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/categories?post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/tags?post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}