forked from zyb0408/zyb0408.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2018-11-19-安装TensorFlow-GPU.html
1814 lines (1127 loc) · 63.2 KB
/
2018-11-19-安装TensorFlow-GPU.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">
<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">
<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">
<meta name="keywords" content="深度学习,">
<meta name="description" content="安装GPU版本TensorFlow准备– 干净的系统,没有安装过Python,有的话就卸载了。 另外我的系统安装了VS2015 VS2017(这里我不知道是不是必备的)。现在TensorFlow和cuda以及cuDNN品名升级,所以这里采用了几乎是最新版的了(2018年11月19日) Anaconda——清华tuna下载 显卡驱动——点我去英伟达官网自行下载对应驱动 cuda9.0安装包——点我">
<meta name="keywords" content="深度学习">
<meta property="og:type" content="article">
<meta property="og:title" content="安装TensorFlow-GPU">
<meta property="og:url" content="https://zyb0408.github.io/2018-11-19-安装TensorFlow-GPU.html">
<meta property="og:site_name" content="小蜜蜂">
<meta property="og:description" content="安装GPU版本TensorFlow准备– 干净的系统,没有安装过Python,有的话就卸载了。 另外我的系统安装了VS2015 VS2017(这里我不知道是不是必备的)。现在TensorFlow和cuda以及cuDNN品名升级,所以这里采用了几乎是最新版的了(2018年11月19日) Anaconda——清华tuna下载 显卡驱动——点我去英伟达官网自行下载对应驱动 cuda9.0安装包——点我">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-11-19T14:07:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="安装TensorFlow-GPU">
<meta name="twitter:description" content="安装GPU版本TensorFlow准备– 干净的系统,没有安装过Python,有的话就卸载了。 另外我的系统安装了VS2015 VS2017(这里我不知道是不是必备的)。现在TensorFlow和cuda以及cuDNN品名升级,所以这里采用了几乎是最新版的了(2018年11月19日) Anaconda——清华tuna下载 显卡驱动——点我去英伟达官网自行下载对应驱动 cuda9.0安装包——点我">
<script type="text/javascript" id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Pisces',
version: '5.1.4',
sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
fancybox: true,
tabs: true,
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
duoshuo: {
userId: '0',
author: '博主'
},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<link rel="canonical" href="https://zyb0408.github.io/2018-11-19-安装TensorFlow-GPU.html">
<title>安装TensorFlow-GPU | 小蜜蜂</title>
</head>
<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container sidebar-position-left page-post-detail">
<div class="headband"></div>
<header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta custom-logo">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">小蜜蜂</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">Don't Hack Me</p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br>
首页
</a>
</li>
<li class="menu-item menu-item-about">
<a href="/about/" rel="section">
<i class="menu-item-icon fa fa-fw fa-user"></i> <br>
关于
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section">
<i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
标签
</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/" rel="section">
<i class="menu-item-icon fa fa-fw fa-th"></i> <br>
分类
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
归档
</a>
</li>
<li class="menu-item menu-item-search">
<a href="javascript:;" class="popup-trigger">
<i class="menu-item-icon fa fa-search fa-fw"></i> <br>
搜索
</a>
</li>
</ul>
<div class="site-search">
<div class="popup search-popup local-search-popup">
<div class="local-search-header clearfix">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<span class="popup-btn-close">
<i class="fa fa-times-circle"></i>
</span>
<div class="local-search-input-wrapper">
<input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
</div>
</div>
<div id="local-search-result"></div>
</div>
</div>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<div id="posts" class="posts-expand">
<article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="https://zyb0408.github.io/2018-11-19-安装TensorFlow-GPU.html">
<span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<meta itemprop="name" content="小蜜蜂">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/favicon-32x32-next.png">
</span>
<span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="小蜜蜂">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">安装TensorFlow-GPU</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-19T22:07:36+08:00">
2018-11-19
</time>
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">更新于:</span>
<time title="更新于" itemprop="dateModified" datetime="2018-11-19T22:07:36+08:00">
2018-11-19
</time>
</span>
<span class="post-category">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
<a href="/categories/Python/" itemprop="url" rel="index">
<span itemprop="name">Python</span>
</a>
</span>
,
<span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
<a href="/categories/Python/TensorFlow/" itemprop="url" rel="index">
<span itemprop="name">TensorFlow</span>
</a>
</span>
</span>
<span class="post-meta-divider">|</span>
<span class="page-pv"><i class="fa fa-file-o"></i>
<span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
</span>
<div class="post-wordcount">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-file-word-o"></i>
</span>
<span class="post-meta-item-text">字数统计:</span>
<span title="字数统计">
3.7k
</span>
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-clock-o"></i>
</span>
<span class="post-meta-item-text">阅读时长 ≈</span>
<span title="阅读时长">
21
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<div>
<div>
<div style="text-align:center;color: #636363;font-size:14px;letter-spacing: 10px">���Ľ�����<i class="fa fa-bell"></i>��л�����Ķ�</div>
</div>
</div>
<h2 id="安装GPU版本TensorFlow"><a href="#安装GPU版本TensorFlow" class="headerlink" title="安装GPU版本TensorFlow"></a>安装GPU版本TensorFlow</h2><h3 id="准备"><a href="#准备" class="headerlink" title="准备"></a>准备</h3><p>–</p>
<p>干净的系统,没有安装过Python,有的话就卸载了。 另外我的系统安装了VS2015 VS2017(这里我不知道是不是必备的)。<br>现在TensorFlow和cuda以及cuDNN品名升级,所以这里采用了几乎是最新版的了(2018年11月19日)</p>
<ul>
<li>Anaconda——<a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.0-Windows-x86_64.exe" target="_blank" rel="noopener">清华tuna下载</a></li>
<li>显卡驱动——<a href="https://www.nvidia.com/drivers" target="_blank" rel="noopener">点我去英伟达官网自行下载对应驱动</a></li>
<li>cuda9.0安装包——<a href="https://pan.baidu.com/s/1CyYsVpslQit4iZ_2PMZ_eA" target="_blank" rel="noopener">点我去百度云下载</a></li>
<li>cuDNN7.x安装包——<a href="https://pan.baidu.com/s/1xAML85MTqHGEjnrkn44Lhg" target="_blank" rel="noopener">点我去百度云下载</a></li>
</ul>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><p>–</p>
<blockquote>
<p>1、安装Anaconda 这里省略。注意一点,安装的选项加入path,都勾选。<br>2、安装显卡驱动 默认安装。<br>3、安装cuda9.0 默认安装。<br>4、安装cuDNN 7.x 将压缩包解压,放在C:\ProgramData\NVIDIA GPU Computing Toolkit\v9.0这个目录下。<br>然后将目录C:\ProgramData\NVIDIA GPU Computing Toolkit\v9.0\bin添加到环境变量PATH里。 </p>
</blockquote>
<h3 id="验证"><a href="#验证" class="headerlink" title="验证"></a>验证</h3><p>–</p>
<p>1、启动Anaconda Prompt 输入conda env list 显示只有一个base或者root的环境。表示只有一个环境。 </p>
<p>2、修改Anaconda的软件源 执行<br><figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">conda config --<span class="built_in">add</span> channels http<span class="variable">s:</span>//mirrors.tuna.tsinghua.edu.<span class="keyword">cn</span>/anaconda/pkgs/free/</span><br><span class="line">conda config --<span class="built_in">add</span> channels http<span class="variable">s:</span>//mirrors.tuna.tsinghua.edu.<span class="keyword">cn</span>/anaconda/pkgs/main/</span><br><span class="line">conda config --<span class="keyword">set</span> show_channel_urls yes</span><br></pre></td></tr></table></figure></p>
<p>表示将anaconda的软件下载源修改成清华Tuna的了。 </p>
<p>3、创建用于TensorFlow的Python环境<br><figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> conda create -n tf-gpu-py3<span class="number">.5</span> python=<span class="number">3.5</span></span><br><span class="line">``` </span><br><span class="line"></span><br><span class="line">例子:</span><br></pre></td></tr></table></figure></p>
<pre><code>D:\Users\zyb>conda create -n tf-gpu-py3.5 python=3.5
Solving environment: done
## Package Plan ##
environment location: C:\anaconda35\envs\tf-gpu-py3.5
added / updated specs:
- python=3.5
The following NEW packages will be INSTALLED:
certifi: 2018.8.24-py35_1001 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pip: 18.0-py35_1001 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python: 3.5.5-he025d50_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
setuptools: 40.4.3-py35_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
vc: 14.1-h21ff451_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123
vs2017_runtime: 15.4.27004.2010-1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123
wheel: 0.32.0-py35_1000 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
wincertstore: 0.2-py35_1002 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate tf-gpu-py3.5
#
# To deactivate an active environment, use
#
# $ conda deactivate
</code></pre><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">4</span>、激活刚刚创建的环境</span><br></pre></td></tr></table></figure>
<pre><code>conda activate tf-gpu-py3.5
</code></pre><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">5</span>、安装TensorFlow GPU版</span><br></pre></td></tr></table></figure>
<pre><code>conda install tensorflow-gpu
</code></pre><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">6</span>、代码验证 启动python 输入如下代码</span><br></pre></td></tr></table></figure>
<pre><code>import tensorflow as tf
</code></pre><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">查看是否报错。 如果报错,就使用conda <span class="keyword">install</span> 包名(比如numpy) 如果不报错,接着执行</span><br></pre></td></tr></table></figure>
<pre><code>a = tf.constant([1.0,2.0,3.0,4.0,5.0,6.0],shape=[2,3],name='a')
b = tf.constant([1.0,2.0,3.0,4.0,5.0,6.0],shape=[3,2],name='b')
c = tf.matmul(a,b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
#这步结束之后,会出现一个警告:
#Device mapping: no known devices.
#2018-11-19 22:18:15.899459: I T:\src\github\tensorflow\tensorflow\core\common_runtime\direct_session.cc:288] Device mapping:
#不用管,执行下一步
print(sess.run(c))
#输出如下:
MatMul: (MatMul): /job:localhost/replica:0/task:0/device:CPU:0
2018-11-19 22:18:23.059234: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:935] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:CPU:0
a: (Const): /job:localhost/replica:0/task:0/device:CPU:0
2018-11-19 22:18:23.064109: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:935] a: (Const)/job:localhost/replica:0/task:0/device:CPU:0
b: (Const): /job:localhost/replica:0/task:0/device:CPU:0
2018-11-19 22:18:23.069134: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:935] b: (Const)/job:localhost/replica:0/task:0/device:CPU:0
[[22. 28.]
[49. 64.]]
</code></pre><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">验证成功。</span><br><span class="line"></span><br><span class="line">## Ubuntu下安装GPU版TensorFlow</span><br><span class="line">=======================</span><br><span class="line"></span><br><span class="line">### 准备</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">> 1、Anaconda-Linux版本的——去清华tuna自行下载 </span><br><span class="line">> 2、显卡驱动——去官网自行下载 [点我去百度云下载3、4需要的文件](https://pan.baidu.com/s/1MjSKSkMKHjfqoY5nGuIXTQ) </span><br><span class="line">> 3、cuda9.0——去官网自行下载Linux版本的 </span><br><span class="line">> 4、cuDNN7.x——去官网下载Linux版本的(需要注册并且join)</span><br><span class="line"></span><br><span class="line">### 安装</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">1、Anaconda安装 这里需要注意,直接把软件安装在自己的家目录下即可。 安装完anaconda之后,需要去刷新你的环境变量。</span><br></pre></td></tr></table></figure>
<pre><code>source ~/home/tf/.bashrc
</code></pre><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">2</span>、安装显卡驱动 官网下载驱动,然后使用sudo安装。 安装的过程中,第一步需要你阅读安装协议。使用q退出。 </span><br><span class="line"></span><br><span class="line"><span class="number">3</span>、安装cuda9<span class="number">.0</span> 默认安装。 安装的过程中,第一步需要你阅读安装协议。使用q退出。 <span class="number">9.0</span>有一个base安装包还有<span class="number">4</span>个升级包。都是有序号的。 使用`sudo chmod +x *.run`给这<span class="number">5</span>个文件加上可执行权限 然后一个个安装。</span><br></pre></td></tr></table></figure>
<pre><code>tf@lolita-ThinkStation-P318:~$ ls
anaconda3 cuda_9.0.176.1_linux-1.run cuda_9.0.176_384.81_linux-base.run cuda_9.0.176.4_linux-4.run
Anaconda3-5.3.0-Linux-x86_64.sh cuda_9.0.176.2_linux-2.run cuda_9.0.176.3_linux-3.run examples.desktop
tf@lolita-ThinkStation-P318:~$ ./cuda_9.0.176_384.81_linux-base.run
Logging to /tmp/cuda_install_6527.log
Using more to view the EULA.
End User License Agreement
--------------------------
Preface
-------
The Software License Agreement in Chapter 1 and the Supplement
in Chapter 2 contain license terms and conditions that govern
the use of NVIDIA software. By accepting this agreement, you
agree to comply with all the terms and conditions applicable
to the product(s) included herein.
NVIDIA Driver
Description
This package contains the operating system driver and
fundamental system software components for NVIDIA GPUs.
NVIDIA CUDA Toolkit
Description
The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references.
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n
Install the CUDA 9.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-9.0 ]:
/usr/local/cuda-9.0 is not writable.
Do you wish to run the installation with 'sudo'?
(y)es/(n)o: y
Please enter your password:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: n
Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/tf ]:
Installing the CUDA Toolkit in /usr/local/cuda-9.0 ...
Installing the CUDA Samples in /home/tf ...
Copying samples to /home/tf/NVIDIA_CUDA-9.0_Samples now...
Finished copying samples.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-9.0
Samples: Installed in /home/tf
Please make sure that
- PATH includes /usr/local/cuda-9.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-9.0/lib64, or, add /usr/local/cuda-9.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 9.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run -silent -driver
Logfile is /tmp/cuda_install_6527.log
tf@lolita-ThinkStation-P318:~$ ./cuda_9.0.176.1_linux-1.run
Logging to /tmp/cuda_patch_7307.log
Welcome to the CUDA Patcher.
Detected pager as 'more'.
End User License Agreement
--------------------------
Preface
-------
The Software License Agreement in Chapter 1 and the Supplement
in Chapter 2 contain license terms and conditions that govern
the use of NVIDIA software. By accepting this agreement, you
agree to comply with all the terms and conditions applicable
to the product(s) included herein.
NVIDIA Driver
Description
This package contains the operating system driver and
fundamental system software components for NVIDIA GPUs.
NVIDIA CUDA Toolkit
Description
The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references.
Do you accept the previously read EULA?
accept/decline/quit: accept
Enter CUDA Toolkit installation directory
[ default is /usr/local/cuda-9.0 ]:
Installation directory '/usr/local/cuda-9.0' is not writable! Ensure you are running with the correct permissions.
Options:
--silent : Specify a command-line, silent installation
--installdir=dir : Customize installation directory
--accept-eula : Implies acceptance of the EULA
--help : Print help message
Specifying a silent installation also initiates a command-line installation.
tf@lolita-ThinkStation-P318:~$ ./cuda_9.0.176.2_linux-2.run
Logging to /tmp/cuda_patch_7348.log
Welcome to the CUDA Patcher.
Detected pager as 'more'.
End User License Agreement
--------------------------
Preface
-------
The Software License Agreement in Chapter 1 and the Supplement
in Chapter 2 contain license terms and conditions that govern
the use of NVIDIA software. By accepting this agreement, you
agree to comply with all the terms and conditions applicable
to the product(s) included herein.
NVIDIA Driver
Description
This package contains the operating system driver and
fundamental system software components for NVIDIA GPUs.
NVIDIA CUDA Toolkit
Description
The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references.
Do you accept the previously read EULA?
accept/decline/quit: accept
Enter CUDA Toolkit installation directory
[ default is /usr/local/cuda-9.0 ]:
Installation directory '/usr/local/cuda-9.0' is not writable! Ensure you are running with the correct permissions.
Options:
--silent : Specify a command-line, silent installation
--installdir=dir : Customize installation directory
--accept-eula : Implies acceptance of the EULA
--help : Print help message
Specifying a silent installation also initiates a command-line installation.
tf@lolita-ThinkStation-P318:~$ ./cuda_9.0.176.3_linux-3.run
Logging to /tmp/cuda_patch_7387.log
Welcome to the CUDA Patcher.
Detected pager as 'more'.
End User License Agreement
--------------------------
Preface
-------
The Software License Agreement in Chapter 1 and the Supplement
in Chapter 2 contain license terms and conditions that govern
the use of NVIDIA software. By accepting this agreement, you
agree to comply with all the terms and conditions applicable
to the product(s) included herein.
NVIDIA Driver
Description
This package contains the operating system driver and
fundamental system software components for NVIDIA GPUs.
NVIDIA CUDA Toolkit
Description
The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references.
Do you accept the previously read EULA?
accept/decline/quit: accept
Enter CUDA Toolkit installation directory
[ default is /usr/local/cuda-9.0 ]:
Installation directory '/usr/local/cuda-9.0' is not writable! Ensure you are running with the correct permissions.
Options:
--silent : Specify a command-line, silent installation
--installdir=dir : Customize installation directory
--accept-eula : Implies acceptance of the EULA
--help : Print help message
Specifying a silent installation also initiates a command-line installation.
tf@lolita-ThinkStation-P318:~$ ./cuda_9.0.176.4_linux-4.run
Logging to /tmp/cuda_patch_7428.log
Welcome to the CUDA Patcher.
Detected pager as 'more'.
End User License Agreement
--------------------------
Preface
-------
The Software License Agreement in Chapter 1 and the Supplement
in Chapter 2 contain license terms and conditions that govern
the use of NVIDIA software. By accepting this agreement, you
agree to comply with all the terms and conditions applicable
to the product(s) included herein.
NVIDIA Driver
Description
This package contains the operating system driver and
fundamental system software components for NVIDIA GPUs.
NVIDIA CUDA Toolkit
Description
The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references.
Do you accept the previously read EULA?
accept/decline/quit: accept
Enter CUDA Toolkit installation directory
[ default is /usr/local/cuda-9.0 ]:
Installation directory '/usr/local/cuda-9.0' is not writable! Ensure you are running with the correct permissions.
Options:
--silent : Specify a command-line, silent installation
--installdir=dir : Customize installation directory
--accept-eula : Implies acceptance of the EULA
--help : Print help message
Specifying a silent installation also initiates a command-line installation.
</code></pre><figure class="highlight dos"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">然后将安装完后的路径加入<span class="built_in">PATH</span>环境变量。</span><br></pre></td></tr></table></figure>
<pre><code>export PATH=/usr/local/cuda-9.0/bin:/usr/local/cuda-9.0/lib64:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
#使环境变量生效
source ~/home/tf/.bashrc
</code></pre><figure class="highlight actionscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">4</span>、安装cuDNN 解压出来两个文件夹一个是<span class="meta"><span class="meta-keyword">include</span> 一个是lib64</span></span><br></pre></td></tr></table></figure>
<pre><code>tf@lolita-ThinkStation-P318:~$ tar zxvf cudnn-9.0-linux-x64-v7.3.1.20.tar.gz
cuda/include/cudnn.h
cuda/NVIDIA_SLA_cuDNN_Support.txt
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.7
cuda/lib64/libcudnn.so.7.3.1
cuda/lib64/libcudnn_static.a
tf@lolita-ThinkStation-P318:~$ ls
anaconda3 cuda_9.0.176.1_linux-1.run cuda_9.0.176.3_linux-3.run examples.desktop
Anaconda3-5.3.0-Linux-x86_64.sh cuda_9.0.176.2_linux-2.run cuda_9.0.176.4_linux-4.run NVIDIA_CUDA-9.0_Samples
cuda cuda_9.0.176_384.81_linux-base.run cudnn-9.0-linux-x64-v7.3.1.20.tar.gz
tf@lolita-ThinkStation-P318:~$ sudo mv cuda/include/cudnn.h /usr/local/cuda-9.0/include/
tf@lolita-ThinkStation-P318:~$ sudo mv cuda/lib64/* /usr/local/cuda-9.0/lib64/
</code></pre><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## 验证</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">0、cuda验证</span><br></pre></td></tr></table></figure>
<pre><code>#进入样本目录
cd ~/home/tf/NVIDIA_CUDA-9.0_Samples
#编译样本
make -j8
#进入生成可执行文件的目录
cd bin/x86_64/linux/release
#执行设备测试程序
./deviceQuery
#输出如下
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 1070"
CUDA Driver Version / Runtime Version 10.0 / 9.0
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 8116 MBytes (8510701568 bytes)
(15) Multiprocessors, (128) CUDA Cores/MP: 1920 CUDA Cores
GPU Max Clock rate: 1683 MHz (1.68 GHz)
Memory Clock rate: 4004 Mhz
Memory Bus Width: 256-bit
L2 Cache Size: 2097152 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.0, CUDA Runtime Version = 9.0, NumDevs = 1
Result = PASS
#看到PASS后执行带宽测试
./bandwidthTest
#输出如下:
[CUDA Bandwidth Test] - Starting...
Running on...
Device 0: GeForce GTX 1070
Quick Mode
Host to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 12758.2
Device to Host Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 12867.2
Device to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 191582.5
Result = PASS
NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
#看到PASS表示测试通过,如果FAIL,重启然后重新执行即可。
</code></pre><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="number">1</span>、创建anaconda环境(和Windows一样)</span><br></pre></td></tr></table></figure>
<pre><code>conda create -n tf-gpu-py3.5 python=3.5
#
# To activate this environment, use
#
# $ conda activate tf-gpu-py3.5
#
# To deactivate an active environment, use
#
# $ conda deactivate
</code></pre><figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">2</span>、激活`tf-gpu-py3<span class="number">.5</span>`</span><br></pre></td></tr></table></figure>
<pre><code>conda activate tf-py-3.5-cpu
</code></pre><figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">3</span>、安装`tensorflow-gpu`</span><br></pre></td></tr></table></figure>
<pre><code>conda install tensorflow-gpu
</code></pre><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">4</span>、代码验证</span><br></pre></td></tr></table></figure>
<pre><code>(tf-gpu-py3.5) tf@lolita-ThinkStation-P318:~/anaconda3/envs$ python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> a = tf.constant([1.0,2.0,3.0,4.0,5.0,6.0],shape=[2,3],name='a')
>>> b = tf.constant([1.0,2.0,3.0,4.0,5.0,6.0],shape=[3,2],name='b')
>>> c = tf.matmul(a,b)
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
2018-11-19 22:43:27.732910: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-11-19 22:43:27.824810: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:897] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-11-19 22:43:27.825419: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties:
name: GeForce GTX 1070 major: 6 minor: 1 memoryClockRate(GHz): 1.683
pciBusID: 0000:01:00.0
totalMemory: 7.93GiB freeMemory: 7.64GiB
2018-11-19 22:43:27.825445: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0
2018-11-19 22:43:27.995777: I tensorflow/core/common_runtime/gpu/gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-11-19 22:43:27.995806: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0
2018-11-19 22:43:27.995826: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 0: N
2018-11-19 22:43:27.996035: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7377 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1
2018-11-19 22:43:28.026839: I tensorflow/core/common_runtime/direct_session.cc:288] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1
>>> print(sess.run(c))
MatMul: (MatMul): /job:localhost/replica:0/task:0/device:GPU:0
2018-11-19 22:44:23.662448: I tensorflow/core/common_runtime/placer.cc:935] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:GPU:0
a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2018-11-19 22:44:23.662561: I tensorflow/core/common_runtime/placer.cc:935] a: (Const)/job:localhost/replica:0/task:0/device:GPU:0
b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2018-11-19 22:44:23.662589: I tensorflow/core/common_runtime/placer.cc:935] b: (Const)/job:localhost/replica:0/task:0/device:GPU:0
[[22. 28.]
[49. 64.]]
</code></pre><p><code>`</code><br>验证完毕。</p>
</div>