﻿{"id":2491,"date":"2023-02-16T15:35:36","date_gmt":"2023-02-16T07:35:36","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=2491"},"modified":"2023-09-04T15:47:16","modified_gmt":"2023-09-04T07:47:16","slug":"windows10%e5%ae%89%e8%a3%85tensorflow-gpu%e8%bf%87%e7%a8%8b%ef%bc%88gtx-3060%ef%bc%89","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/win\/2491","title":{"rendered":"Windows10\u5b89\u88c5Tensorflow-GPU\u8fc7\u7a0b\uff08GTX 3060\uff09"},"content":{"rendered":"<p>\u7b2c\u4e00\u6b65, \u786e\u8ba4Tensorflow\u7248\u672c\u5bf9\u5e94\u7684\u4e09\u4e2a\u7248\u672c\u4fe1\u606f: \u9a71\u52a8\u7248\u672c\u53f7, cuda\u7248\u672c\u53f7, cudnn\u7248\u672c\u53f7<\/p>\n<p>\u5230\u4e0b\u9762\u7f51\u5740\u67e5\u770btf\u7248\u672c\u5bf9\u5e94\u7684\u4e24\u4e2a\u7248\u672c\u4fe1\u606f\n<a href=\"https:\/\/www.tensorflow.org\/install\/source_windows?hl=zh-cn#gpu\">https:\/\/www.tensorflow.org\/install\/source_windows?hl=zh-cn#gpu<\/a><\/p>\n<p>\u6211\u7528tensorflow_gpu-2.6.0, \u5bf9\u5e94\u7684\u5c31\u662fCUDA 11.2, cuDNN 8.1\n<a href=\"https:\/\/developer.nvidia.com\/cuda-toolkit-archive\"><a href=\"https:\/\/developer.nvidia.com\/cuda-toolkit-archive\">https:\/\/developer.nvidia.com\/cuda-toolkit-archive<\/a><\/a>\n<a href=\"https:\/\/developer.nvidia.com\/rdp\/cudnn-archive\"><a href=\"https:\/\/developer.nvidia.com\/rdp\/cudnn-archive\">https:\/\/developer.nvidia.com\/rdp\/cudnn-archive<\/a><\/a><\/p>\n<p><del>\u4e24\u4e2a\u5148\u4e0b\u8f7d\u597d, \u7136\u540e\u627eCUDA 11.2\u5bf9\u5e94\u7684\u9a71\u52a8\u5b89\u88c5, \u4e0b\u9762\u94fe\u63a5\u7b2c2\u4e2atable<\/del>\n<del><a href=\"https:\/\/docs.nvidia.com\/cuda\/cuda-toolkit-release-notes\/index.html\"><a href=\"https:\/\/docs.nvidia.com\/cuda\/cuda-toolkit-release-notes\/index.html\">https:\/\/docs.nvidia.com\/cuda\/cuda-toolkit-release-notes\/index.html<\/a><\/a><\/del><\/p>\n<p><del>CUDA 11.2.x\u00a0 \u5bf9\u5e94\u7684\u7248\u672c\u53f7\u533a\u95f4\u662f >=452.39, \u5230\u4e0b\u9762\u7f51\u5740\u641c\u7d22\u5bf9\u5e94\u663e\u5361\u548c\u5bf9\u5e94\u7248\u672c\u7684\u9a71\u52a8<\/del>\n<del><a href=\"https:\/\/www.nvidia.cn\/Download\/Find.aspx?lang=cn\"><a href=\"https:\/\/www.nvidia.cn\/Download\/Find.aspx?lang=cn\">https:\/\/www.nvidia.cn\/Download\/Find.aspx?lang=cn<\/a><\/a><\/del><\/p>\n<p><del>\u6211\u4e0b\u8f7d\u7684\u662fGeForce Game Ready 472.12\u7248\u672c\u9a71\u52a8, \u5728\u9a71\u52a8\u4fe1\u606f\u91cc\u770b\u5230 NVCUDA64.DLL \u7248\u672c\u4fe1\u606f\u662f 11.4.136<\/del><\/p>\n<p>wsl \u7248\u672c\u5b89\u88c5\uff1a<a href=\"https:\/\/developer.nvidia.cn\/cuda-downloads?target_os=Linux&amp;target_arch=x86_64&amp;Distribution=WSL-Ubuntu&amp;target_version=2.0&amp;target_type=deb_local\">https:\/\/developer.nvidia.cn\/cuda-downloads?target_os=Linux&amp;target_arch=x86_64&amp;Distribution=WSL-Ubuntu&amp;target_version=2.0&amp;target_type=deb_local<\/a><\/p>\n<pre class=\"cudaBashBlock\"><code>&lt;span class=&quot;cudaBash&quot;&gt;wget https:\/\/developer.download.nvidia.com\/compute\/cuda\/repos\/wsl-ubuntu\/x86_64\/cuda-wsl-ubuntu.pin\n&lt;\/span&gt;\n&lt;span class=&quot;cudaBash&quot;&gt;sudo mv cuda-wsl-ubuntu.pin \/etc\/apt\/preferences.d\/cuda-repository-pin-600\n&lt;\/span&gt;\n&lt;span class=&quot;cudaBash&quot;&gt;wget https:\/\/developer.download.nvidia.com\/compute\/cuda\/12.2.2\/local_installers\/cuda-repo-wsl-ubuntu-12-2-local_12.2.2-1_amd64.deb\n&lt;\/span&gt;\n&lt;span class=&quot;cudaBash&quot;&gt;sudo dpkg -i cuda-repo-wsl-ubuntu-12-2-local_12.2.2-1_amd64.deb\n&lt;\/span&gt;\n&lt;span class=&quot;cudaBash&quot;&gt;sudo cp \/var\/cuda-repo-wsl-ubuntu-12-2-local\/cuda-*-keyring.gpg \/usr\/share\/keyrings\/\n&lt;\/span&gt;\n&lt;span class=&quot;cudaBash&quot;&gt;sudo apt-get update\n&lt;\/span&gt;\n&lt;span class=&quot;cudaBash&quot;&gt;sudo apt-get -y install cuda&lt;\/span&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u5b89\u88c5\u597d\u9a71\u52a8, cuda, cudnn\u540e, \u8bbe\u7f6e\u7cfb\u7edf\u73af\u5883\u53d8\u91cf, \u5728PATH\u91cc\u6dfb\u52a0\u4e24\u4e2a:\n%CUDA_PATH%\\bin\n%CUDA_PATH%\\lib\\x64<\/p>\n<p>\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u6210\u529f<\/p>\n<p>cmd\u547d\u4ee4\u884c\u8f93\u5165\uff1anvidia-smi<\/p>\n<p>&nbsp;<\/p>\n<p>\u5728\u7cfb\u7edf\u53d8\u91cf\u4e2d\uff0c\u589e\u52a0\u53d8\u91cf\u540dTF_GEFORCE_GPU_ALLOW_GROWTH\uff0c\u53d6\u503c\u4e3atrue<\/p>\n<p>&nbsp;<\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u5b89\u88c5tensorflow_gpu<\/p>\n<p>\u5728conda\u91cc\u521b\u5efapython 3.7\u73af\u5883, \u5728\u73af\u5883\u91cc\u5b89\u88c5tf, \u6211\u662f\u624b\u52a8\u4e0b\u8f7d\u7684\u5b89\u88c5\u5305, \u4e0b\u8f7d\u5bf9\u5e94py3.7\u7248\u672c\u7684:\n<a href=\"https:\/\/www.tensorflow.org\/install\/pip.html?hl=zh-cn#package-location\">https:\/\/www.tensorflow.org\/install\/pip.html?hl=zh-cn#package-location<\/a><\/p>\n<p>\u7528pip\u5b89\u88c5\u4e0b\u8f7d\u7684tf\u5b89\u88c5\u5305\u5373\u53ef<\/p>\n<p>&nbsp;<\/p>\n<p>\u6d4b\u8bd5\u4ee3\u7801\u5982\u4e0b:\nimport tensorflow as tf\nprint(&#8216;GPU&#8217;,tf.config.list_physical_devices(&#8216;GPU&#8217;))\nprint(&#8220;Num GPUs Available: &#8220;, len(tf.config.experimental.list_physical_devices(&#8216;GPU&#8217;)))<\/p>\n<p>\u6211\u53ea\u6709\u4e00\u5757GTX3060\u663e\u5361\uff0c\u6267\u884c\u540e\u8fd4\u56de:<\/p>\n<p>GPU [PhysicalDevice(name=&#8217;\/physical_device:GPU:0&#8242;, device_type=&#8217;GPU&#8217;)]\nNum GPUs Available: 1\n\u5230\u6b64\u4e3a\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b89\u88c5pytorch\u5bf9\u5e94cuda 11.1\u7248\u672c, \u5230\u4ee5\u4e0b\u94fe\u63a5\u4e0b\u8f7d\u5b89\u88c5\u5305:\n<a href=\"https:\/\/download.pytorch.org\/whl\/torch_stable.html\">https:\/\/download.pytorch.org\/whl\/torch_stable.html<\/a><\/p>\n<p>\u5206\u522b\u662f:\ntorch-1.9.0+cu111-cp37-cp37m-win_amd64.whl\ntorchvision-0.10.0+cpu-cp37-cp37m-win_amd64.whl\ntorchaudio-0.9.0-cp37-cp37m-win_amd64.whl<\/p>\n<p>\u7528pip\u5b89\u88c5\u4ee5\u4e0a3\u4e2a\u5b89\u88c5\u5305\u5373\u53ef<\/p>\n<p>\u6d4b\u8bd5\u4ee3\u7801:<\/p>\n<p>import torch<\/p>\n<h1>\u8fd4\u56de\u5f53\u524d\u8bbe\u5907\u7d22\u5f15<\/h1>\n<p>print(torch.cuda.current_device())<\/p>\n<h1>\u8fd4\u56deGPU\u7684\u6570\u91cf<\/h1>\n<p>print(torch.cuda.device_count())<\/p>\n<h1>\u8fd4\u56degpu\u540d\u5b57\uff0c\u8bbe\u5907\u7d22\u5f15\u9ed8\u8ba4\u4ece0\u5f00\u59cb<\/h1>\n<p>print(torch.cuda.get_device_name(0))<\/p>\n<h1>cuda\u662f\u5426\u53ef\u7528\uff0c\u4e3atrue\u5c31\u53ef\u7528\u4e86<\/h1>\n<p>print(torch.cuda.is_available())\n#\u67e5\u770bcudnn\u7248\u672c\nprint(torch.backends.cudnn.version())\n#\u67e5\u770btorch\u7248\u672c\nprint(torch.<strong>version<\/strong>)<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e00\u6b65, \u786e\u8ba4Tensorflow\u7248\u672c\u5bf9\u5e94\u7684\u4e09\u4e2a\u7248\u672c\u4fe1\u606f: \u9a71\u52a8\u7248\u672c\u53f7, cuda\u7248\u672c\u53f7, cudnn\u7248\u672c\u53f7 \u5230\u4e0b\u9762\u7f51\u5740\u67e5\u770btf\u7248\u672c\u5bf9\u5e94\u7684\u4e24\u4e2a\u7248\u672c\u4fe1\u606f <a href=\"https:\/\/www.tensorflow.o&#46;&#46;&#038;#46\">https:\/\/www.tensorflow.o&#46;&#46;&#038;#46<\/a>;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2491","post","type-post","status-publish","format-standard","hentry","category-win"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=2491"}],"version-history":[{"count":6,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2491\/revisions"}],"predecessor-version":[{"id":2592,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2491\/revisions\/2592"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=2491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=2491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=2491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}