win10+cuda10.0+vs2015搭建tensorflow的C++编译环境

目录

一、显卡驱动版本和CUDA版本的确认和安装与更新

二、配置python环境

三、安装和配置Bazel工具

四、安装windows上的linux环境


一、显卡驱动版本和CUDA版本的确认和安装与更新

TensorFlow安装时需要cuda+对应的显卡驱动。这里给出英伟达官方的cuda和驱动的对应:

地址在这里

 然后在这里可下载最新的显卡驱动(英伟达公版的驱动,程序员友好型)

关于具体步骤请参考我的上一篇文章《如何查看电脑是否支持CUDA及支持的CUDA版本》

二、配置python环境

(E:\programfile\Anaconda3) C:\Users\TP>pip3 install six numpy wheel
Requirement already satisfied: six in e:\programfile\anaconda3\lib\site-packages (1.11.0)
Requirement already satisfied: numpy in e:\programfile\anaconda3\lib\site-packages (1.16.0)
Requirement already satisfied: wheel in e:\programfile\anaconda3\lib\site-packages (0.29.0)

(E:\programfile\Anaconda3) C:\Users\TP>pip3 install keras_applications==1.0.6 --no-deps
Collecting keras_applications==1.0.6
  Using cached Keras_Applications-1.0.6-py2.py3-none-any.whl (44 kB)
Installing collected packages: keras-applications
  Attempting uninstall: keras-applications
    Found existing installation: Keras-Applications 1.0.2
    Uninstalling Keras-Applications-1.0.2:
      Successfully uninstalled Keras-Applications-1.0.2
Successfully installed keras-applications-1.0.6

(E:\programfile\Anaconda3) C:\Users\TP>pip3 install keras_preprocessing==1.0.5 --no-deps
Collecting keras_preprocessing==1.0.5
  Using cached Keras_Preprocessing-1.0.5-py2.py3-none-any.whl (30 kB)
Installing collected packages: keras-preprocessing
  Attempting uninstall: keras-preprocessing
    Found existing installation: Keras-Preprocessing 1.0.1
    Uninstalling Keras-Preprocessing-1.0.1:
      Successfully uninstalled Keras-Preprocessing-1.0.1
Successfully installed keras-preprocessing-1.0.5

(E:\programfile\Anaconda3) C:\Users\TP>

三、在 Windows 上安装 Bazel

参考:https://blog.csdn.net/darkrabbit/article/details/81262524

前提

这些公共的 DLLs 是 Bazel 所需要的。你可能已经安装了它们。

获取 Bazel

从我们的 GitHub releases 页面下载 Windows 版本的 Bazel 。在页面中找到 bazel-<version>-windows-x86_64.exe ,例如:

bazel-0.13.0-windows-x86_64.exe

提示: 为了方便起见,将下载的二进制文件重命名为 bazel.exe ,并将其移动到你的 %PATH% 目录中,或者将它所在目录的路径添加进 %PATH% 。这样你就可以在任何目录中输入 bazel 来运行 Bazel 而不需要输入完整的路径。

注意: Bazel 包含一个嵌入式的 JDK ,所以你不需要单独安装它。如果你想要下载一个不包含 JDK 的 Bazel 。在 release 页面中找到 bazel-<version>-without-jdk-windows-x86_64.exe 。要使用它,你必须单独安装一个 JDK 8 (旧版本与新版本均不受支持),并设置 %JAVA_HOME% 的环境变量,例如:

set JAVA_HOME=c:\Program Files\Java\jdk1.8.0_171

要注意,不要使用引号(”)将路径包住(就像你在 Unixes 上那样)。

使用其它方式获取 Bazel

你也可以使用如下方式获取 Bazel :

使用 Chocolatey 安装 Bazel

你可以使用 Chocolatey package manager 来安装 Bazel:

choco install bazel

这条命令会安装可用且最新版本的 Bazel 与依赖包,例如 MSYS2 shell 。但并不会安装 Visual C++ 。

更多关于 Chocolatey 的信息,见 Chocolatey installation and package maintenance guide 。

 

https://github.com/bazelbuild/bazel/releases下载,下载0.230版本,下载完毕后,配置环境变量,就可以使用了,如下:

四、安装windows上的linux环境

1.在windows上安装配置msys2,并将目录D:\msys64\usr\bin添加到环境变量中。

安装参考:https://blog.csdn.net/hustlei/article/details/86687588

                 https://www.msys2.org/

 MSYS2 [1]  是MSYS的一个升级版,准确的说是集成了pacmanMingw-w64的Cygwin升级版, 提供了bash shell等linux环境、版本控制软件(git/hg)和MinGW-w64 工具链。与MSYS最大的区别是移植了 Arch Linux的软件包管理系统 Pacman(其实是与Cygwin的区别)。

2、安装相关工具

pacman.exe -S git patch unzip

 

五、下载tensorflow源码

https://github.com/tensorflow/tensorflow

E:\vmware\window_tensorflow_progect>git clone https://github.com/tensorflow/tensorflow
Cloning into 'tensorflow'...
remote: Enumerating objects: 217, done.
remote: Counting objects: 100% (217/217), done.
remote: Compressing objects: 100% (169/169), done.
remote: Total 878186 (delta 98), reused 157 (delta 48), pack-reused 877969R
Receiving objects: 100% (878186/878186), 510.77 MiB | 89.00 KiB/s, done.

Resolving deltas: 100% (712464/712464), done.
Checking out files: 100% (21487/21487), done.

E:\vmware\window_tensorflow_progect>cd tensorflow

E:\vmware\window_tensorflow_progect\tensorflow>git checkout r2.0
Checking out files: 100% (15123/15123), done.
Switched to a new branch 'r2.0'
Branch 'r2.0' set up to track remote branch 'r2.0' from 'origin'.

E:\vmware\window_tensorflow_progect\tensorflow>ls
ACKNOWLEDGMENTS  CODEOWNERS          ISSUE_TEMPLATE.md  SECURITY.md         configure.cmd  third_party
ADOPTERS.md      CODE_OF_CONDUCT.md  LICENSE            WORKSPACE           configure.py   tools
AUTHORS          CONTRIBUTING.md     README.md          arm_compiler.BUILD  models.BUILD
BUILD            ISSUES.md           RELEASE.md         configure           tensorflow

E:\vmware\window_tensorflow_progect\tensorflow>python ./configure.py
Cannot find bazel. Please install bazel.

E:\vmware\window_tensorflow_progect\tensorflow>python ./configure.py
You have bazel 3.0.0 installed.
Please downgrade your bazel installation to version 0.26.1 or lower to build TensorFlow! To downgrade: download the installer for the old version (from https://github.com/bazelbuild/bazel/releases) then run the installer.

E:\vmware\window_tensorflow_progect\tensorflow>

六、更新与tensorflow合适的bazel版本

从如上>python ./configure.py的执行log中可以知道bazel版本不符合,需要安装合适的版本。

打开页面“https://github.com/bazelbuild/bazel/releases”,点击页面最下方的“Next”按钮,找到要下载的版本,如下:

点击如上红色“Assets”,展开如下,找到对应的window版本即可。

直接点击下载会由于资源的问题,有时候后下载特别慢或者下载失败。

因为已经安装了MSYS2,我们可以使用linux 命令进行下载。

E:\vmware\window_tensorflow_progect>wget -c  https://github.com/bazelbuild/bazel/releases/download/0.26.1/bazel-0.26.1-windows-x86_64.exe

-C 允许断点下载,即再下载失败后,再次下载可以接着下载,而不是从新下载。

 

转载:https://blog.csdn.net/qq_32095699/article/details/80855402

继续编译tensorflow源码

 

 

参考链接:
1、https://blog.csdn.net/zzpong/article/details/80282814
2、https://blog.csdn.net/u013165921/article/details/77891913

总结一下方法:

1.安装vs2015
光驱地址:https://blog.csdn.net/guxiaonuan/article/details/73775519?locationNum=2&fps=1
先安装光驱,再装vs2015

2.下载cuda8.0
下载地址:https://developer.nvidia.com/cuda-toolkit-archive

3.安装cuda8.0
选择项自定义安装CUDA,并记下你所释放安装程序的路径
这里写图片描述
之后按照默认路径安装即可。

这里写图片描述
这里写图片描述

不要选 Visual Stdio Integration!!

4、VS integration

把文件夹:

D:\SOFTWARE\CUDA_setup**CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtension下的所有文件拷贝到C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\BuildCustomizations下(黑色字体为安装程序的路径**)
这里写图片描述

这里写图片描述

再将“**D:\SOFTWARE\CUDA_setup**CUDAVisualStudioIntegration\extras\visual_studio_integration”下的CudaProjectVsWizards文件夹整体拷贝到“C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions”(VS安装路径下找)下即可,
这里写图片描述

这里写图片描述
打开:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
这里写图片描述
管理员运行cmd:
这里写图片描述
就可以将CUDA 移入vs:
这里写图片描述
最后的最后,还可以把“**D:\SOFTWARE\CUDA_setup**CUDAVisualStudioIntegration”下的NVIDIA_Nsight_Visual_Studio_Edition_Win64_5.2.0.16321安装一下,它是CUDA给VS2015提供的一个调试插件。

安装成功

 

相关参考:https://blog.csdn.net/qq_32095699/article/details/80855402

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章