这篇博客是基于上一篇博客写的,是我整个DeepLearning学习过程中,配环境的流程,写出来后很简单,但是当时还是配置了很久。以下开始正文:
1. 由于GPU版的TensorFlow安装时(上一篇博客),安装的是CUDA8.0,而CUDA8.0最多支持VS2015,因此,两种解决方法:1.使用CPU版本的TensorFlow,卸载CUDA8.0,安装CUDA9.0以适用VS2017;2.使用双版本VS,即VS2015
2. 此处我们使用方法2。VS下载时,必须勾选C++语言的相应组件,否则无法建立CUDA项目。成功后,并没有像教程(https://blog.csdn.net/qq_25071449/article/details/77680246)中一样,在新建项目中,并没有找到CUDA8.0。解决方法:再次安装CUDA8.0,放在与配置TensorFlow安装CUDA一样的安装盘。记住,自定义安装CUDA时,还是只勾选第一个,否则会安装失败。安装成功后,如下图;(已安装那里没有for2012)
在重新安装CUDA前,无法在新建模板位置看到CUDA8.0项
CUDA安装成功后图
3. 此时,打开VS2015,已经在新建项目中显示了CUDA8.0,新建该项目后,按照https://blog.csdn.net/qq_25071449/article/details/77680246显示,进行VC++目录配置。
4. 对于新手(like me)如何找到VC++目录配置,参考https://jingyan.baidu.com/article/0f5fb0991833396d8234ea7f.html
5. 测试代码(来自https://www.cnblogs.com/yueqiuchen/p/6641998.html)
#include<iostream>
#include<stdio.h>
#include"cuda_runtime.h"
#include"device_launch_parameters.h"
boolInitCUDA()
{
int count;
cudaGetDeviceCount(&count);
if (count == 0)
{
fprintf(stderr, "There is nodevice.\n");
return false;
}
int i;
for (i = 0; i < count; i++)
{
cudaDeviceProp prop;
if(cudaGetDeviceProperties(&prop, i) == cudaSuccess)
{
if (prop.major >= 1)
{
break;
}
}
}
if (i == count)
{
fprintf(stderr, "There is nodevice supporting CUDA 1.x.\n");
return false;
}
cudaSetDevice(i);
return true;
}
intmain()
{
if (!InitCUDA())
{
return 0;
}
printf("HelloWorld, CUDA has beeninitialized.\n");
system("pause");
return 0;
}
结果:
这样,环境配置就成功了,终于开始了从配环境到放弃的深度学习阶段了希望看到这篇博客的人,大家一起加油吧。