在使用tensorflow 的时候最头疼的问题就是跟cuda 之间的配套使用问题,加上Nvidia 新的 rtx 2080 ti 图灵架构目前官方声称只支持cuda-10, 以上版本,对于tensorflow 1.13.1 之下的版本是无法使用cuda-10的,很多项目是用老版本tensorflow 编写的,所以这有多蛋疼,用过的都懂。 今天介绍源码编译 tensorflow ,使低版本 tensorflow 也能用高版本 cuda, 解决高低搭配问题,其中编译的时候可以选 cuda 版本cudnn 版本,堪称万金油方法 。

这里涉及到目前在做的项目,目前刚入手一块RTX 2080 TI 想把代码迁移过来,发现有问题,目前2080 ti 的图灵架构只支持     CUDA-10以上版本,之前的代码都是跑在 CUDA-9.0 上。 耗时4天无数工程实践,加思考终于搞定,代码成功在RTX 2080 TI 上运行起来

Step 1 :更新系统,安装相关依赖项

sudo apt-get update

Step2 :  安装依赖库:

# for Python 2.7$ sudo apt-get install python-numpypython-dev python-pip python-wheel# for Python 3.x$ sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel

Step 3 :  Download NCCL 2.4.8

Download NCCL v2.4.8, for CUDA 10.0   https://developer.nvidia.com/nccl
  Choose Local installer for Ubuntu 16.04

Step4:  Install NCCL 2.3  ()

tar -xvf nccl_2.4.8–1+cuda10.0_x86_64.txz
cd nccl_2.4.8–1+cuda10.0_x86_64/
sudo mkdir /usr/local/cuda-10.0/nccl
sudo cp -R * /usr/local/cuda-10.0/nccl
cd /usr/local/cuda-10.0/nccl
mv LICENSE.txt NCCL-SLA.txt
sudo ldconfig

图中的版本号改为自己所用的版本 为准

Step 5 :

Bazel 依赖于 JDK , 首先安装JDK

$ sudo apt-get install openjdk-8-jdk

  安装bazel(apt):

$ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" |  sudo tee /etc/apt/sources.list.d/bazel.list$ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -$ sudo apt-get update && sudo apt-get install bazel

  安装bazel(binary installer):

$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python

Download bazel installer  https://github.com/bazelbuild/bazel/releases

这里注意对于不同的tensorflow 版本要选择合适的bazel 版本, 低版本tensorflow 对应低版本 bazel , 高版本tensorflow对应高版     本bazel,  bazel 版本选择不对,根本无法执行编译

$ chmod +x bazel--installer-linux-x86_64.sh$ ./bazel--installer-linux-x86_64.sh --user$ gedit ~/.bashrc添加:export PATH="$PATH:$HOME/bin"source ~./bashrc sudo ldconfig

Step 6 : 下载tensorflow 源码:

$ git clone https://github.com/tensorflow/tensorflow$ cd tensorflow*$ ./configure

配置文件选择:

Give python path inPlease specify the location of python. [Default is /usr/bin/python]/usr/bin/python3Press enter two timesDo you wish to build TensorFlow with Apache Ignite support? [Y/n]: nDo you wish to build TensorFlow with XLA JIT support? [Y/n]: nDo you wish to build TensorFlow with OpenCL SYCL support? [y/N]: nDo you wish to build TensorFlow with ROCm support? [y/N]: nDo you wish to build TensorFlow with CUDA support? [y/N]: YPlease specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 9.0]: 10.0Please specify the location where CUDA 10.0 toolkit is installed. Refer to Home for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0/Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.6.0Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: /usr/local/cuda-10.0/Do you wish to build TensorFlow with TensorRT support? [y/N]: NPlease specify the NCCL version you want to use. If NCCL 2.2 is not installed, then you can use version 1.3 that can be fetched automatically but it may have worse performance with multiple GPUs. [Default is 2.2]: 2.4.8Please specify the location where NCCL 2.3.5 is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: /usr/local/cuda-10.0/nccl/Now we need compute capability which we have noted at step 1 eg. 5.0Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 5.0] 7.5Do you want to use clang as CUDA compiler? [y/N]: NPlease specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gccDo you wish to build TensorFlow with MPI support? [y/N]: NPlease specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=nativeWould you like to interactively configure ./WORKSPACE for Android builds? [y/N]:NConfiguration finished

Step 7: 编译    参考官网  https://www.tensorflow.org/install/source

GPU Support

bazel build --config=opt --config=cuda
//tensorflow/tools/pip_package:build_pip_package

这大概会持续一段时间,网上说要3-4小时,也有的说要6个小时,但是笔者亲测只用了1个半小时左右

bazel 会生成一个 叫 build_pip_package 脚本

然后生成 .whl 安装文件 使用命令

bazel-bin/tensorflow/tools/pip_package/build_pip_package tensorflow_pkg

这会生成一个新的文件夹 tensorflow_pkg 并在其中包含 .whl 的 安装文件

Step 8 :  安装 生成的 .whl 文件

cd tensorflow_pkgsudo pip install *.whl

Step 9 : 验证安装是否正确

pythonimport tensorflow as tfhello = tf.constant('Hello, TensorFlow!')sess = tf.Session()print(sess.run(hello))

正常输出 hello, Tensorflow 就算安装正确

补充:

卸载 Bazel 的方法 , 该命令适用于 (apt)安装方法

$ sudo apt-get --purge remove bazel$ sudo apt autoremove

对于binary installer 安装方法的卸载,笔者直接删除相关文件,并将添加到 ./bashrc 文件中的环境变量删除,然后选择合适的版本重新安装

拒绝踩坑!源码编译 tensorflow 解决 cuda 不配套 万金油方法相关推荐

  1. 撸啊撸,再次撸HashMap源码,踩坑源码中构造方法!!!每次都有收获

    前言 点赞在看,养成习惯. 点赞收藏,人生辉煌. 点击关注[微信搜索公众号:编程背锅侠],第一时间获得最新文章. HashMap系列文章 第一篇 HashMap源码中的成员变量你还不懂? 来来来!!! ...

  2. bazel源码编译Tensorflow

    因为研究需求,要从Tensorflow源码编译libtensorflow_cc.so和libtensorflow_framwork.so两个库,工具是bazel. 编译硬件需求:GCC4.8以上,ba ...

  3. python3.6源码编译安装 解决SSL报错

    从源码编译安装python3.6之后,用pip的时候可能会提示SSL错误,实际上是openssl和python的安装有问题,本文给出安装openssl和python3.6.6的完整过程. 1.编译安装 ...

  4. android源码编译 老罗,Rx_Android 的简单实用方法(参考老罗代码)

    Rx是响应式编程的意思, 本质是观察者模式, 是以观察者(Observer)和订阅者(Subscriber)为基础的异步响应方式. 在Android编程时, 经常会使用后台线程, 那么就可以使用这种方 ...

  5. Tensorflow源码编译

    相比源码编译各版本之间遇到的坑来说,pip安装真心省事.不过由于项目需要采用C++实现的整个感知模块,只能把DL前向传播这块也写成C++形式.这是我去年的编译过程,当时有不少坑没能记录下来,以后有机会 ...

  6. Ubuntu 16.04 源码编译安装GPU tensorflow(二)

    如前一篇在1.4.0版本的Tensorflow上安裝Tensorflow Object Detection API,在验证测试时出現serialized_options=None问题.需安装高版本Te ...

  7. Ubuntu 15.04 安装TensorFlow(源码编译) 及测试梵高作画

    介绍Google的TensorFlow机器学习开源库,在UbuntuKylin上的安装和和源码编译. 原始官方文档参见:http://www.tensorflow.org. 本电脑配置如下: 3.19 ...

  8. Linux16.04配置tensorflow(GPU源码编译)并深入了解tensorboard

    Tensorflow – Google推出的一个强大的"深度学习框架".于2015年11月在GIthub上开源,在2016年4月补充了分布式版本,并于2017年1月发布了1.0版本 ...

  9. python opencv源码_caffegpu源码编译

    软硬件环境 ubuntu 18.04 64bit NVidia GTX 1070Ti anaconda with python 3.7 CUDA 10.1 cuDNN 7.6 opencv 3.4.2 ...

最新文章

  1. IndexError: too many indices for array
  2. 4kyu Sum by Factors
  3. iOS 真机调试包集合 包含 iOS 12.4 不断更新
  4. 使用python学线性代数_二项式过程| 使用Python的线性代数
  5. Nice,涨薪近40%
  6. 计算机信息安全与信息伦理课件,信息安全实验室
  7. svm 文本分类 matlab,livsvm文本分类总结详解
  8. vs窗体程序常用工具_Visual Studio 2010(VS)--消消乐定制版①
  9. 计算机考试PPT主题背景没换,2013职称计算机考试:搞定PPT背景设置中的问题
  10. FPGA作为电力电子设备控制器的实践
  11. 如何购买银行理财子公司的理财产品?
  12. 六度分离(Floyd算法)
  13. 7个 优秀的远程“结对编程“编码工具
  14. MTK平台apnspn的配置
  15. 欧陆风云3实用修改代码
  16. 软件测试中7个令人吃惊的事实
  17. Autonomous Navigation of an Ultrasound Probe Towards Standard Scan Planes with Deep Reinforcement Le
  18. 温度报警程序c语言设计,单片机温度报警器与时钟显示C程序和原理图
  19. 捕获鼠标事件-JavaScript入门基础(005)
  20. nmap漏扫工具的使用

热门文章

  1. IOS版添加phonegap-银联支付插件教程
  2. 人工智能之父 艾伦·图灵 —— 我在战争中才华横溢,却在和平中寸步难行
  3. 2021FME博客大赛 —— 面向海量地貌数据的FME在线质检研究
  4. 根文件系统制作一制作根文件系统树
  5. Sequelize ORM
  6. 高级转录组分析和R数据可视化技术研讨会(2023.2)
  7. 【Hadoop】HBase 数据模型(Data Model)
  8. android note4 android版本,三星Galaxy Note4手机系统是什么?能升级安卓4.3吗?
  9. 日本金融监管机构将推出新的ICO法规
  10. 【Java基础】使用swing对话框编写一个程序:输入长和宽,计算矩形的周长和面积