我尝试自己编译 Tensorflow 以加快训练速度(使用预编译的轮子可以工作,但速度很慢)。我使用 ./configure 来配置并明确指定应使用 cuDNN 版本 5.1.10。在此之前,我下载了 cuDNN 5.1.10 并将我的文件复制到 Cuda 目录。
这是配置(.tf_configure.bazelrc)的样子:
build --action_env PYTHON_BIN_PATH="/home/ubuntu/project/venv/bin/python"
build --action_env PYTHON_LIB_PATH="/home/ubuntu/project/venv/lib/python3.5/site-packages"
build --define PYTHON_BIN_PATH="/home/ubuntu/project/venv/bin/python"
build --define PYTHON_LIB_PATH="/home/ubuntu/project/venv/lib/python3.5/site-packages"
build --force_python=py3
build --host_force_python=py3
build --python3_path="/home/ubuntu/project/venv/bin/python"
test --force_python=py3
test --host_force_python=py3
test --define PYTHON_BIN_PATH="/home/ubuntu/project/venv/bin/python"
test --define PYTHON_LIB_PATH="/home/ubuntu/project/venv/lib/python3.5/site-packages"
run --define PYTHON_BIN_PATH="/home/ubuntu/project/venv/bin/python"
run --define PYTHON_LIB_PATH="/home/ubuntu/project/venv/lib/python3.5/site-packages"
build --define with_jemalloc=true
build:opt --cxxopt=-march=native --copt=-march=native
build --action_env TF_NEED_CUDA="1"
build --action_env TF_NEED_OPENCL="0"
build --action_env TF_CUDA_CLANG="0"
build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"
build --action_env TF_CUDA_VERSION="8.0"
build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc"
build --action_env TF_CUDNN_VERSION="5.1.10"
build --action_env CUDNN_INSTALL_PATH="/usr/local/cuda-8.0"
build --action_env TF_CUDNN_VERSION="5.1.10"
build --action_env TF_CUDA_COMPUTE_CAPABILITIES="3.7"
build --config=cuda
test --config=cuda
注意 TF_CUDNN_VERSION="5.1.10" 部分。接下来我执行以下命令:
bazel build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip3 install --upgrade /tmp/tensorflow_pkg/tensorflow-1.2.0-cp35-cp35m-linux_x86_64.whl
最后,我收到以下错误消息
Loaded runtime CuDNN library: 5110 (compatibility version 5100) but source was compiled with 5005 (compatibility version 5000). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.
到底是怎么回事?尽管我指定了正确的版本,但不知何故 Tensorflow 是使用 cuDNN 5.0 编译的?!
系统为 Ubuntu 16,AWS p2 实例。