我的博客

编译安装支持 GPU 的 Tensorflow

目录
  1. Step 1: Install required packages
  2. Step 2: Run the installer
  3. Step 3: Set up your environment
  • 错误
  • 官方文档

    1. 获取源码
    1
    2
    git clone https://github.com/tensorflow/tensorflow.git
    cd tensorflow

    这个 git clone 很耗时间。

    切换到想要编译的版本 git checkout v1.8.0,主要版本的依赖关系!!! 1.8.0 需要 bazel 0.10

    1. 安装依赖

      1
      2
      3
      4
      sudo apt install python-dev python-pip
      pip install -U --user pip six numpy wheel setuptools mock future>=0.17.1
      pip install -U --user keras_applications==1.0.6 --no-deps
      pip install -U --user keras_preprocessing==1.0.5 --no-deps

      安装 Bazel

      1
      2
      3
      4
      5
      6
      7
      sudo apt install curl
      curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
      echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

      sudo apt update && sudo apt install bazel
      sudo apt update && sudo apt full-upgrade
      sudo apt install bazel-1.0.0

      Step 1: Install required packages

      Bazel needs a C++ compiler and unzip / zip in order to work:

      1
      sudo apt install g++ unzip zip

      If you want to build Java code using Bazel, install a JDK:

      1
      2
      3
      4
      5
      # Ubuntu 16.04 (LTS) uses OpenJDK 8 by default:
      sudo apt-get install openjdk-8-jdk

      # Ubuntu 18.04 (LTS) uses OpenJDK 11 by default:
      sudo apt-get install openjdk-11-jdk

      Step 2: Run the installer

      Next, download the Bazel binary installer named bazel--installer-linux-x86_64.sh from the Bazel releases page on GitHub.

      Run it as follows:

      1
      2
      chmod +x bazel-<version>-installer-linux-x86_64.sh
      ./bazel-<version>-installer-linux-x86_64.sh --user

      The --user flag installs Bazel to the $HOME/bin directory on your system and sets the .bazelrc path to $HOME/.bazelrc. Use the --help command to see additional installation options.

      Step 3: Set up your environment

      If you ran the Bazel installer with the --user flag as above, the Bazel executable is installed in your $HOME/bin directory. It’s a good idea to add this directory to your default paths, as follows:

      1
      export PATH="$PATH:$HOME/bin"
    1. 编译安装

    进入 tensorflow 源码目录,执行 ./configure,是一个交互式命令,会问:

    1. 要使用的 python 的路径,我使用 python3 ,输入 /usr/bin/python3 它自动找到 python 的库的目录。
    2. 是否用cuda
    3. cuda 的版本和路径
    4. cudnn 的版本和路径
    5. 显卡的 cuda 兼容性(rtx 2080 ti 是 7.5)

    编译

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

    错误

    1. 如果 bazel 版本不对会报错

    2. Cuda Configuration Error: Cannot find cuda library libcublas.so.10.2

      sudo find /usr -name "libcublas*" 可以找到相关的库,我发现位于 /usr/lib/x86_64-linux-gnu/ 这里,有 /usr/lib/x86_64-linux-gnu/libcublas.so.10.2.2.89 以及它的软链接 libcublas.so.10,干脆手动创将一个 10.2 的软链接吧。sudo ln -s /usr/lib/x86_64-linux-gnu/libcublas.so.10.2.2.89 /usr/lib/x86_64-linux-gnu/libcublas.so.10.2

    3. Cuda Configuration Error: Cannot find cuda library libcusolver.so.10.2

      sudo ln -s /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcusolver.so.10.3.0.89 /usr/local/cuda-10.2/lib64/libcusolver.so.10.2

    4. Cuda Configuration Error: Cannot find cuda library libcurand.so.10.2

      sudo ln -s /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcurand.so.10.1.2.89 /usr/local/cuda-10.2/lib64/libcurand.so.10.2

    5. Cuda Configuration Error: Cannot find cuda library libcufft.so.10.2

      sudo ln -s /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcufft.so.10.1.2.89 /usr/local/cuda-10.2/lib64/libcufft.so.10.2

    6. Cuda Configuration Error: Cannot find cuda library libcudnn.so.7

    怎么缺了这么多库啊,我放弃了,还是弄个 cuda 10.0 试试吧

    评论无需登录,可以匿名,欢迎评论!