{"id":3759,"date":"2018-08-30T23:41:30","date_gmt":"2018-08-30T15:41:30","guid":{"rendered":"https:\/\/www.toodyao.com\/?p=3759"},"modified":"2019-03-30T23:47:01","modified_gmt":"2019-03-30T15:47:01","slug":"%e5%9c%a8-google-cloud-%e4%b8%8a%e4%bd%bf%e7%94%a8-gpu-%e8%bf%9b%e8%a1%8c%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0%e5%8a%a0%e9%80%9f","status":"publish","type":"post","link":"https:\/\/www.toodyao.com\/?p=3759","title":{"rendered":"\u5728 Google Cloud \u4e0a\u4f7f\u7528 GPU \u8fdb\u884c\u6df1\u5ea6\u5b66\u4e60\u52a0\u901f"},"content":{"rendered":"<p>\u6df1\u5ea6\u5b66\u4e60\u9700\u8981\u7528\u5230GPU\u7684\u5e76\u884c\u8ba1\u7b97\u80fd\u529b\u8fdb\u884c\u52a0\u901f\uff0c\u7531\u4e8e<span style=\"font-size: 1rem;\">\u4e0d\u65b9\u4fbf<\/span><span style=\"font-size: 1rem;\">\u5b89\u88c5\u53f0\u5f0f\u673a\uff0c\u8ba1\u5212\u7528\u4e91GPU\u8fdb\u884c\uff0c\u4ee5\u56fd\u5185\u67d0\u77e5\u540d\u4e91\u4e3a\u4f8b\uff1a<\/span><\/p>\n<p>CPU: E5 4vCPU\uff0c\u5185\u5b58: 30G\uff0cGPU: NVIDIA P100\uff0cSSD: 40G\uff0c\u7845\u8c37\u8282\u70b9(\u65e0\u56fd\u5185\u8282\u70b9)\uff0c\u5305\u67085460.80\u5143<\/p>\n<p>\u800cGoogle Cloud Compute Engine\u63d0\u4f9b\u4ee5\u5c0f\u65f6\u8ba1\u8d39\u7684GPU\u8ba1\u7b97\u5355\u5143(\u5173\u673a\u540e\u4e0d\u6536\u8d39)\uff0c\u76f8\u4f3c\u914d\u7f6e\u9700\u8981894.06\u7f8e\u5143\/\u6708\uff08\u7ea66000\u5143\uff09\uff0c\u5982\u679c\u6309\u5c0f\u65f6\u8ba1\u8d39\uff0c\u7ea61.225\u7f8e\u5143\/\u5c0f\u65f6\uff0c\u6240\u4ee5\u5982\u679c\u662f\u5b66\u4e60\u4e3a\u76ee\u7684\u7684\u8bddGoogle Cloud\u8fd8\u662f\u975e\u5e38\u5212\u7b97\u7684\u3002<\/p>\n<h2>1.\u521b\u5efaGoogle Compute Engine<\/h2>\n<p>\u9009\u62e9Compute Engine -&gt; VM instances -&gt; Create Instance<\/p>\n<p>\u9009\u62e9\u9002\u5408\u4f60\u7684CPU\u3001GPU\u3001\u5185\u5b58\u914d\u7f6e\uff0c\u53ef\u4ee5\u5148\u9009\u4f4e\u4e00\u70b9\uff0c\u540e\u671f\u968f\u65f6\u53ef\u4ee5\u8c03\uff0cGPU\u4e5f\u662f\uff0c\u6211\u9009\u62e9\u4e86\u5982\u4e0b\u914d\u7f6e\uff1a<!--more--><\/p>\n<p><a href=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2018\/08\/Screenshot-from-2019-03-30-23-21-39.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-5029\" src=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2018\/08\/Screenshot-from-2019-03-30-23-21-39-269x300.png\" alt=\"\" width=\"269\" height=\"300\" srcset=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2018\/08\/Screenshot-from-2019-03-30-23-21-39-269x300.png 269w, https:\/\/www.toodyao.com\/wp-content\/uploads\/2018\/08\/Screenshot-from-2019-03-30-23-21-39.png 491w\" sizes=\"auto, (max-width: 269px) 100vw, 269px\" \/><\/a><\/p>\n<p>\u63a5\u7740\u914d\u7f6e\u542f\u52a8\u78c1\u76d8\uff0c\u8fd9\u91cc\u9009\u62e9\u4e86\u5bf9\u65b0\u624b\u53cb\u597d\u7684Ubuntu\uff0c\u5982\u679c\u5bf9\u901f\u5ea6\u6709\u8981\u6c42\uff0c\u5efa\u8bae\u52fe\u9009SSD\uff08\u540e\u671f\u4e0d\u80fd\u66f4\u6539\u7c7b\u578b\uff0c\u4f46\u53ef\u4ee5\u66f4\u6539\u5bb9\u91cf\uff09\uff0c\u5927\u5c0f\u4e0d\u8981\u592a\u4f4e\uff0c\u4e5f\u4e0d\u7528\u592a\u9ad8\uff0c\u540e\u671f\u53ef\u4ee5\u518d\u52a0\u5b58\u50a8\uff1a<\/p>\n<p><a href=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-23-31.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-5031\" src=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-23-31-300x256.png\" alt=\"\" width=\"300\" height=\"256\" srcset=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-23-31-300x256.png 300w, https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-23-31.png 473w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u6700\u540e\u52fe\u9009\u4e0a\u5141\u8bb8HTTP\/HTTPS\uff0c\u70b9\u51fbCreate\u521b\u5efa\u3002<\/p>\n<h2>2.\u914d\u7f6e\u670d\u52a1\u5668<\/h2>\n<p>\u670d\u52a1\u5668\u521b\u5efa\u597d\u540e\u5c31\u81ea\u52a8\u542f\u52a8\u4e86\uff0c\u4f46\u662f\u6ca1\u6709\u6dfb\u52a0\u516c\u94a5\uff0c\u8fd8\u4e0d\u80fd\u8bbf\u95ee\uff0c\u5728\u672c\u673a\u751f\u6210SSH\u79c1\u94a5\u548c\u516c\u94a5\uff08\u8fc7\u7a0b\u7565\uff09\uff0c\u5728Compute Engine\u9875\u9762\u9009\u62e9Metadata -&gt; SSH Keys \u6dfb\u52a0\u3002\u53ef\u4ee5\u628a\u6700\u540e\u4e00\u884c==\u540e\u9762\u7684\u6539\u6210\u5bc6\u94a5\u7684\u540d\u79f0 (\u7b49\u53f7\u540e\u6709\u4e00\u4e2a\u7a7a\u683c)\uff0c\u4fdd\u5b58\u3002<\/p>\n<p><a href=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-29-07.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-5032 size-full\" src=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-29-07.png\" alt=\"\" width=\"830\" height=\"161\" srcset=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-29-07.png 830w, https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-29-07-300x58.png 300w, https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-29-07-768x149.png 768w\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" \/><\/a><\/p>\n<p>\u5982\u679c\u9700\u8981\u4f7f\u7528SSH \u7528\u6237\u540d\/\u5bc6\u7801 \u7684\u65b9\u5f0f\u767b\u5f55\uff0c\u9700\u8981\u8bbe\u7f6e\u5bc6\u7801\uff1a<\/p>\n<p>\u70b9\u51fbinstance\u65c1\u8fb9\u7f51\u9875\u7248\u7684SSH\uff1a<\/p>\n<p><a href=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-33-42.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5033\" src=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-33-42.png\" alt=\"\" width=\"117\" height=\"59\" \/><\/a><\/p>\n<p>\u8fde\u63a5\u540e<span class=\"lang:default decode:true crayon-inline \">sudo passwd username<\/span>\u00a0\u8bbe\u7f6e\u5bc6\u7801\u5373\u53ef<\/p>\n<p>\u63a5\u7740\u5c31\u53ef\u4ee5\u9009\u62e9\u4f60\u559c\u6b22\u7684SSH\u5ba2\u6237\u7aef\u767b\u5f55\u4e86<\/p>\n<p>\u4e3a\u4e86\u80fd\u6b63\u5e38\u4f7f\u7528jupyter notebook\uff0c\u9700\u8981\u914d\u7f6e\u9632\u706b\u5899\uff1a<\/p>\n<p>\u9009\u62e9VPC network -&gt; Firewall rules<\/p>\n<p><a href=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-33-42.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5033\" src=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-33-42.png\" alt=\"\" width=\"117\" height=\"59\" \/><\/a> <a href=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-36-18.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-5034\" src=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-36-18-300x192.png\" alt=\"\" width=\"300\" height=\"192\" srcset=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-36-18-300x192.png 300w, https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-36-18.png 453w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u6dfb\u52a0\u4e00\u6761\u5141\u8bb8jupyter8888\u7aef\u53e3\u901a\u8fc7\u7684\u89c4\u5219\uff1a<\/p>\n<p><a href=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-39-15.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-5035\" src=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-39-15-300x279.png\" alt=\"\" width=\"300\" height=\"279\" srcset=\"https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-39-15-300x279.png 300w, https:\/\/www.toodyao.com\/wp-content\/uploads\/2019\/03\/Screenshot-from-2019-03-30-23-39-15.png 472w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>3.\u5b89\u88c5anaconda<\/h2>\n<p>\u521b\u5efa\u73af\u5883<\/p>\n<p>\u8fdb\u5165Anconda\u7684\u4e0b\u8f7d\u9875\u9762: https:\/\/www.anaconda.com\/downloads\uff0c\u9009\u62e9Linux\uff0c\u4e0b\u8f7d\uff0c\u7136\u540e\u53d6\u6d88\u4e0b\u8f7d(\u56e0\u4e3a\u592a\u6162\uff0c\u800c\u4e14\u8fd8\u4e0d\u5728\u670d\u52a1\u5668\u4e0a)\uff0c\u8fdb\u5165\u4e0b\u8f7d\u9875\u9762\uff0c\u590d\u5236\u521a\u624d\u7684\u4e0b\u8f7d\u94fe\u63a5\uff0c\u4f8b\u5982\uff1ahttps:\/\/repo.anaconda.com\/archive\/Anaconda3-5.2.0-Linux-x86_64.sh<\/p>\n<p>\u8fdb\u5165\u670d\u52a1\u5668\uff0c\u4f7f\u7528wget\u4e0b\u8f7d\uff1a<\/p>\n<pre class=\"lang:default decode:true \">wget\u00a0https:\/\/repo.anaconda.com\/archive\/Anaconda3-5.2.0-Linux-x86_64.sh<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4e0b\u8f7d\u597d\u540e\u5b89\u88c5\uff1a<\/p>\n<pre class=\"lang:default decode:true \">sudo bash\u00a0Anaconda3-5.2.0-Linux-x86_64.sh<\/pre>\n<p>&nbsp;<\/p>\n<p>\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u4e00\u8defEnter\uff0c\u63a5\u53d7\u6761\u6b3eyes\uff0c\u52a0\u5165\u73af\u5883yes\uff0c\u5b89\u88c5VSCode No\uff08\u547d\u4ee4\u884c\u600e\u4e48\u7528VSCode\u5440\uff09<\/p>\n<p>\u91cd\u65b0\u52a0\u8f7dbashrc\uff1a<\/p>\n<pre class=\"lang:default decode:true \">source ~\/.bashrc<\/pre>\n<p>&nbsp;<\/p>\n<h2>4. \u5b89\u88c5\u76f8\u5173\u5305<\/h2>\n<p>\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u4e13\u7528\u7684\u73af\u5883\uff0c\u8fd9\u91cc\u7528python2.7<\/p>\n<pre class=\"lang:default decode:true \">conda create -n py27 python=2.7<\/pre>\n<p>&nbsp;<\/p>\n<p>\u6fc0\u6d3b\u73af\u5883<\/p>\n<pre class=\"lang:default decode:true \">source active py27<\/pre>\n<p>&nbsp;<\/p>\n<p>\u5b89\u88c5\u5305<\/p>\n<pre class=\"lang:default decode:true \">conda install\u00a0tensorflow-gpu matplotlib scipy future pyyaml cython opencv setuptools pillow jupyter<\/pre>\n<p>&nbsp;<\/p>\n<h2>5. \u5b89\u88c5CUDA<\/h2>\n<p>\u4f7f\u7528Google Cloud\u63d0\u4f9b\u7684\u811a\u672c\uff1a<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">#!\/bin\/bash\necho \"Checking for CUDA and installing.\"\n# Check for CUDA and try to install.\nif ! dpkg-query -W cuda-9-0; then\n  # The 16.04 installer works with 16.10.\n  curl -O http:\/\/developer.download.nvidia.com\/compute\/cuda\/repos\/ubuntu1604\/x86_64\/cuda-repo-ubuntu1604_9.0.176-1_amd64.deb\n  dpkg -i .\/cuda-repo-ubuntu1604_9.0.176-1_amd64.deb\n  apt-key adv --fetch-keys http:\/\/developer.download.nvidia.com\/compute\/cuda\/repos\/ubuntu1604\/x86_64\/7fa2af80.pub\n  apt-get update\n  apt-get install cuda-9-0 -y\nfi\n# Enable persistence mode\nnvidia-smi -pm 1<\/pre>\n<p>\u521b\u5efa\u6587\u4ef6\uff1a<span class=\"lang:default decode:true crayon-inline \">touch install-cuda.sh<\/span><\/p>\n<p>\u7f16\u8f91 <span class=\"lang:default decode:true crayon-inline \">vim install-cuda.sh<\/span>\u00a0 \u4fdd\u5b58\u9000\u51fa<\/p>\n<p>\u6267\u884c\uff1a<span class=\"lang:default decode:true crayon-inline \">sudo bash install-cuda.sh<\/span><\/p>\n<p>\u5b8c\u6210\u540e\u6267\u884c<span class=\"lang:default decode:true crayon-inline \">nvidia-smi<\/span>\u00a0\u6d4b\u8bd5\uff1a<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">+-----------------------------------------------------------------------------+\n| NVIDIA-SMI 396.44                 Driver Version: 396.44                    |\n|-------------------------------+----------------------+----------------------+\n| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |\n| Fan  Temp  Perf  Pwr:Usage\/Cap|         Memory-Usage | GPU-Util  Compute M. |\n|===============================+======================+======================|\n|   0  Tesla K80           Off  | 00000000:00:04.0 Off |                    0 |\n| N\/A   37C    P8    32W \/ 149W |     17MiB \/ 11441MiB |      0%      Default |\n+-------------------------------+----------------------+----------------------+\n                                                                               \n+-----------------------------------------------------------------------------+\n| Processes:                                                       GPU Memory |\n|  GPU       PID   Type   Process name                             Usage      |\n|=============================================================================|\n|    0      1705      G   \/usr\/lib\/xorg\/Xorg                            15MiB |\n+-----------------------------------------------------------------------------+\n<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u76f8\u5173GPU\u7684\u4fe1\u606f\uff0c\u5185\u5b58\uff0c\u6e29\u5ea6\uff0c\u5360\u7528\u7b49<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5ea6\u5b66\u4e60\u9700\u8981\u7528\u5230GPU\u7684\u5e76\u884c\u8ba1\u7b97\u80fd\u529b\u8fdb\u884c\u52a0\u901f\uff0c\u7531\u4e8e\u4e0d\u65b9\u4fbf\u5b89\u88c5\u53f0\u5f0f\u673a\uff0c\u8ba1\u5212\u7528\u4e91GPU\u8fdb\u884c\uff0c\u4ee5\u56fd\u5185\u67d0\u77e5\u540d\u4e91\u4e3a\u4f8b\uff1a  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,18],"tags":[],"class_list":["post-3759","post","type-post","status-publish","format-standard","hentry","category-linux","category-18"],"_links":{"self":[{"href":"https:\/\/www.toodyao.com\/index.php?rest_route=\/wp\/v2\/posts\/3759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.toodyao.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.toodyao.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.toodyao.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.toodyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3759"}],"version-history":[{"count":11,"href":"https:\/\/www.toodyao.com\/index.php?rest_route=\/wp\/v2\/posts\/3759\/revisions"}],"predecessor-version":[{"id":5041,"href":"https:\/\/www.toodyao.com\/index.php?rest_route=\/wp\/v2\/posts\/3759\/revisions\/5041"}],"wp:attachment":[{"href":"https:\/\/www.toodyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.toodyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.toodyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}