设为首页 收藏本站
云服务器等爆品抢先购,低至4.2元/月
查看: 704|回复: 0

[经验分享] Tensorflow Windows Build with GPU Support

[复制链接]

尚未签到

发表于 2017-6-28 12:13:47 | 显示全部楼层 |阅读模式
Step-by-step Windows build
  虽然Research一直在用Caffe,而且用的飞起,但还是很关注tensorflow社区的事情,最近发现TF有windows版本的了,就自己试了试。
  步骤:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/cmake
  Pre-requisites:
  Microsoft Windows 10


  • Microsoft Visual Studio Enterprise 2015 with Visual C++ 2015
  • Anaconda 4.1.1 (Python 3.5 64-bit)
  • Git for Windows version 2.9.2.windows.1
  • swigwin-3.0.10
  • NVidia CUDA Toolkit 8.0
  • NVidia CUDNN 5.1


  •   Install the pre-requisites detailed above, and set up your environment.

    •   The following commands assume that you are using the Windows Command Prompt (cmd.exe). You will need to set up your environment to use the appropriate toolchain, i.e. the 64-bit tools. (Some of the binary targets we will build are too large for the 32-bit tools, and they will fail with out-of-memory errors.) The typical command to do set up your environment is:

      D:\temp> "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvarsall.bat"
    •   When building with GPU support after installing the CUDNN zip file from NVidia, append its bin directory to your PATH environment variable. In case TensorFlow fails to find the CUDA dll's during initialization, check your PATH environment variable. It should contain the directory of the CUDA dlls and the directory of the CUDNN dll. For example:

      D:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
      D:\local\cuda\bin
    •   We assume that cmake and git are installed and in your %PATH%. If for example cmake is not in your path and it is installed in C:\Program Files (x86)\CMake\bin\cmake.exe, you can add this directory to your %PATH% as follows:

      D:\temp> set PATH="%PATH%;C:\Program Files (x86)\CMake\bin\cmake.exe"


  •   Clone the TensorFlow repository and create a working directory for your build:

    D:\temp> git clone https://github.com/tensorflow/tensorflow.git
    D:\temp> cd tensorflow\tensorflow\contrib\cmake
    D:\temp\tensorflow\tensorflow\contrib\cmake> mkdir build
    D:\temp\tensorflow\tensorflow\contrib\cmake> cd build
    D:\temp\tensorflow\tensorflow\contrib\cmake\build>
  •   Invoke CMake to create Visual Studio solution and project files.
      N.B. This assumes that cmake.exe is in your %PATH% environment variable. The other paths are for illustrative purposes only, and may be different on your platform. The ^ character is a line continuation and must be the last character on each line.

    D:\...\build> cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release ^
    More? -DSWIG_EXECUTABLE=C:/tools/swigwin-3.0.10/swig.exe ^
    More? -DPYTHON_EXECUTABLE=C:/Users/%USERNAME%/AppData/Local/Continuum/Anaconda3/python.exe ^
    More? -DPYTHON_LIBRARIES=C:/Users/%USERNAME%/AppData/Local/Continuum/Anaconda3/libs/python35.lib

      To build with GPU support add "^" at the end of the last line above following with:

    More? -Dtensorflow_ENABLE_GPU=ON ^
    More? -DCUDNN_HOME="D:\...\cudnn"

      Note that the -DCMAKE_BUILD_TYPE=Release flag must match the build configuration that you choose when invoking msbuild. The known-good values are Release and RelWithDebInfo. The Debug build type is not currently supported, because it relies on a Debug library for Python (python35d.lib) that is not distributed by default.
      There are various options that can be specified when generating the solution and project files:

    •   -DCMAKE_BUILD_TYPE=(Release|RelWithDebInfo): Note that the CMAKE_BUILD_TYPE option must match the build configuration that you choose when invoking MSBuild in step 4. The known-good values are Release and RelWithDebInfo. The Debug build type is not currently supported, because it relies on a Debug library for Python (python35d.lib) that is not distributed by default.

    •   -Dtensorflow_BUILD_ALL_KERNELS=(ON|OFF). Defaults to ON. You can build a small subset of the kernels for a faster build by setting this option to OFF.

    •   -Dtensorflow_BUILD_CC_EXAMPLE=(ON|OFF). Defaults to ON. Generate project files for a simple C++ example training program.

    •   -Dtensorflow_BUILD_PYTHON_BINDINGS=(ON|OFF). Defaults to ON. Generate project files for building a PIP package containing the TensorFlow runtime and its Python bindings.

    •   -Dtensorflow_ENABLE_GRPC_SUPPORT=(ON|OFF). Defaults to ON. Include gRPC support and the distributed client and server code in the TensorFlow runtime.

    •   -Dtensorflow_ENABLE_SSL_SUPPORT=(ON|OFF). Defaults to OFF. Include SSL support (for making secure HTTP requests) in the TensorFlow runtime. This support is incomplete, and will be used for Google Cloud Storage support.

    •   -Dtensorflow_ENABLE_GPU=(ON|OFF). Defaults to OFF. Include GPU support. If GPU is enabled you need to install the CUDA 8.0 Toolkit and CUDNN 5.1. CMake will expect the location of CUDNN in -DCUDNN_HOME=path_you_unziped_cudnn.

    •   -Dtensorflow_BUILD_CC_TESTS=(ON|OFF). Defaults to OFF. This builds cc unit tests. There are many of them and building will take a few hours. After cmake, build and execute the tests with

      MSBuild /p:Configuration=RelWithDebInfo ALL_BUILD.vcxproj
      ctest -C RelWithDebInfo
    •   -Dtensorflow_BUILD_PYTHON_TESTS=(ON|OFF). Defaults to OFF. This enables python kernel tests. After building the python wheel, you need to install the new wheel before running the tests. To execute the tests, use

      ctest -C RelWithDebInfo


  •   Invoke MSBuild to build TensorFlow.
      To build the C++ example program, which will be created as a .exe executable in the subdirectory .\Release:

    D:\...\build> MSBuild /p:Configuration=Release tf_tutorials_example_trainer.vcxproj
    D:\...\build> Release\tf_tutorials_example_trainer.exe

      To build the PIP package, which will be created as a .whl file in the subdirectory .\tf_python\dist:

    D:\...\build> MSBuild /p:Configuration=Release tf_python_build_pip_package.vcxproj
  在进行第四部的时候出了错,原因是在tensorflow\tensorflow\contrib\cmake\build\CMakeFiles\tf_core_gpu_kernels.dir\__\下面生成的cmake文件有问题,解决方案是:line 81处__VERSION__="MSVC"要改成__VERSION__=\"MSVC\"
  改了之后重新进行Step 4生成whl文件,pip install *.whl开始玩吧。。。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-388967-1-1.html 上篇帖子: Windows系统编程之进程间通信 下篇帖子: Windows下将gvim8配置为Python IDE
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表