精简模式安装cuda9
- 默认路径,不要改到D盘。
- 不要选择自定义模式,用精简模式。选了自定义模式,哪怕不改路径,在编译Samples的时候,还是会报路径错误。查看后发现,在找不到文件的路径下,文件的版本不对,还是旧版本,就算手动改成现在的版本,后面又会报版本错误。可能是因为自定义模式没有改VC++库里相关的属性。后来直接用精简模式就好了。
未找到导入的项目“D:Program Files (x86)Microsoft Visual Studio2017Community...CUDA 9.0.props
CUDA Samples测试:
1. 打开C:ProgramDataNVIDIA CorporationCUDA Samplesv9.2里的Samples_vs2017.exe
2. 载入成功后,选择任意一个项目,如SimulationsoceanFFT,调整好项目属性:
-
- 第一次生成时出现错误:
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%includecrthost_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 Studio2017CommunityVCToolsMSVC14.14.26428includextr1common(59): error : class "std::enable_if<<error-constant>, void>" has no member "type" 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includexmemory0(364): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includexmemory0(982): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includexmemory0(1311): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includexstring(1922): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includexutility(301): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includememory(1454): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includememory(1461): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includememory(2507): error : expression must have a constant value 1>D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428includexstring(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:ProgramDataNVIDIA CorporationCUDA Samplesv9.0inwin64Debug里。
测试tensorflow是否使用GPU:
>>> import tensorflow as tf D:Anaconda3libsite-packagesh5py\__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:srcgithub ensorflow ensorflowcoreplatformcpu_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:srcgithub ensorflow ensorflowcorecommon_runtimegpugpu_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:srcgithub ensorflow ensorflowcorecommon_runtimegpugpu_device.cc:1471] Adding visible gpu devices: 0 2018-07-26 16:22:34.485518: I T:srcgithub ensorflow ensorflowcorecommon_runtimegpugpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-07-26 16:22:34.489209: I T:srcgithub ensorflow ensorflowcorecommon_runtimegpugpu_device.cc:958] 0 2018-07-26 16:22:34.491046: I T:srcgithub ensorflow ensorflowcorecommon_runtimegpugpu_device.cc:971] 0: N 2018-07-26 16:22:34.493085: I T:srcgithub ensorflow ensorflowcorecommon_runtimegpugpu_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 FilesNVIDIA GPU Computing ToolkitCUDAv9.0。
- 测试CUDA Samples的时候,项目属性的平台工具集选VS2015。
- 必要的话改一下CUDA头文件。
- 安装pip install tensorflow-gpu。
- 测试。
(终于看到GPU被用起来了。。。)