win10安裝cuda


 

精簡模式安裝cuda9  

  • 默認路徑,不要改到D盤。
  • 不要選擇自定義模式,用精簡模式。選了自定義模式,哪怕不改路徑,在編譯Samples的時候,還是會報路徑錯誤。查看后發現,在找不到文件的路徑下,文件的版本不對,還是舊版本,就算手動改成現在的版本,后面又會報版本錯誤。可能是因為自定義模式沒有改VC++庫里相關的屬性。后來直接用精簡模式就好了。
未找到導入的項目“D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\...\CUDA 9.0.props

 

 

CUDA Samples測試:

1. 打開C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.2\里的Samples_vs2017.exe

2. 載入成功后,選擇任意一個項目,如Simulations\oceanFFT,調整好項目屬性:

  - 

 

  - 第一次生成時出現錯誤:

unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!

  解決辦法:修改CUDA頭文件(原文:https://blog.csdn.net/u010974701/article/details/79807190)

      • 打開 - %CUDA_PATH%\include\crt\host_config.h -
      • #if _MSC_VER < 1600 || _MSC_VER > 1911
        //把1911 改為1920即可,保存

         

 (感人。。。)

 

由cuda9.2改為cuda9.0

- 由於在import tensorflow as tf時,出現了找不到cuxxx_90.*的錯誤,對應路徑下的文檔是cuxxx_92.*,所以將一開始安裝的cuda9.2卸載,從新安裝cuda9.0。除了之前遇到的問題,還遇到了下面的報錯(截了一小段):

1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xtr1common(59): error : class "std::enable_if<<error-constant>, void>" has no member "type"
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xmemory0(364): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xmemory0(982): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xmemory0(1311): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xstring(1922): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xutility(301): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\memory(1454): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\memory(1461): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\memory(2507): error : expression must have a constant value
1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xstring(1984): error : more than one instance of overloaded function "std::_Deallocate_plain" matches the argument list:

  解決辦法:

  • 參考:https://devtalk.nvidia.com/default/topic/1022648/cuda-setup-and-installation/cuda-9-unsupported-visual-studio-version-error/3
  • 安裝VS2015 SDK,在項目屬性中,設置平台工具集為VS2015,(這里順便把Windows SDK 版本也換成了默認的10.0.15063.0),這樣后續也不用改SDK版本了。
  • 生成的執行文檔在C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\bin\win64\Debug里。

  

測試tensorflow是否使用GPU:

>>> import tensorflow as tf
D:\Anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
>>> a = tf.test.is_built_with_cuda()  # 判斷CUDA是否可以用
>>> b = tf.test.is_gpu_available(
...     cuda_only=False,
...     min_cuda_compute_capability=None
... )                                  # 判斷GPU是否可以用
2018-07-26 16:19:56.860793: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-07-26 16:19:57.224782: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1392] Found device 0 with properties:
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.392
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.29GiB
2018-07-26 16:19:57.232122: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1471] Adding visible gpu devices: 0
2018-07-26 16:22:34.485518: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-26 16:22:34.489209: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:958]      0
2018-07-26 16:22:34.491046: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:971] 0:   N
2018-07-26 16:22:34.493085: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1084] Created TensorFlow device (/device:GPU:0 with 3019 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>>
>>> print(a)
True
>>> print(b)
True

 

 總結:

Win10 + 1050Ti + Cuda9.0 + Keras + Tensorflow + VS2017的安裝:

- 之前已經安裝過Anaconda,Tensorflow,Keras, VS2017。

- 下載CUDA9.0精簡模式安裝。

- 用VS2017 installer安裝VS2015(v140)平台工具集,以及對應的SDK(10.0.15063.0)

(否則會出現各種報錯比如,找不到源文件,expect contant value等等)。

- 安裝DXSDK_Jun10(不知道干什么用,按攻略來的)。

- 下載cuDNN9.0(對應版本),解壓后放在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0。

- 測試CUDA Samples的時候,項目屬性的平台工具集選VS2015。

- 必要的話改一下CUDA頭文件。

- 安裝pip install tensorflow-gpu。

- 測試。

 

(終於看到GPU被用起來了。。。)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM