Docker 编译tensorflow-1.14.0 静态库
如果你需要动态库就用人家编译好的so
https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.15.0.tar.gz
安装Nvidia-docker
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \ sudo apt-key add - distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \ sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt-get update
apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
Docker pull 指定镜像
docker pull nvidia/cuda:10.0-cudnn7-devel-ubuntu16.04
run image:
nvidia-docker run -it -d XXXXimage bash
go into container:
docker exec -it XXXX bash
Container install deps:
apt-get update
apt-get install autoconf automake libtool curl make g++ unzip zlib1g-dev git python python-pip unzip wget
pip install future
2.
下载tensorflow 源码 1.14.0 wget https://github.com/tensorflow/tensorflow/archive/v1.14.0.tar.gz
下载bazel wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel-0.24.1-linux-x86_64
3. 装依赖
apt-get install python python-pip
pip install future
4. ./configure 不要选择ROMs MIT 之类的选项
5. 修改tensorflow/BUILD 末尾增加如下语句
cc_binary( name = "libtensorflow_gpu.a", linkstatic = 1, linkshared = 0, deps = [ "//tensorflow/c:c_api", "//tensorflow/core:tensorflow", ], )
6.
bazel build -c opt //tensorflow:libtensorflow_gpu.a
7. 安装
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /mnt # create package chown $HOST_PERMS /mnt/tensorflow-version-tags.whl
CUDA 和 tensorflow CUDNN 版本对照表
https://www.tensorflow.org/install/source?hl=zh-cn
参考资料:
https://github.com/tensorflow/tensorflow/issues/5511
编译遇到链接错误
gif_io.cc:(.text._ZN10tensorflow3gif6DecodeEPKviRKSt8functionIFPhiiiiEEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x722): undefined reference to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&)'
bazel-out/k8-opt/bin/tensorflow/core/kernels/libsampling_kernels.a(sampling_kernels.o): In function `tensorflow::functor::SamplingKernelTypeFromString(absl::string_view)':
sampling_kernels.cc:(.text._ZN10tensorflow7functor28SamplingKernelTypeFromStringEN4absl11string_viewE+0x28): undefined reference to `tensorflow::str_util::Lowercase[abi:cxx11](absl::string_view)'
bazel-out/k8-opt/bin/tensorflow/core/util/tensor_bundle/libnaming.a(naming.o): In function `tensorflow::MetaFilename[abi:cxx11](absl::string_view)':
naming.cc:(.text._ZN10tensorflow12MetaFilenameB5cxx11EN4absl11string_viewE+0x19): undefined reference to `tensorflow::strings::Printf[abi:cxx11](char const*, ...)'
bazel-out/k8-opt/bin/tensorflow/core/util/tensor_bundle/libnaming.a(naming.o): In function `tensorflow::DataFilename[abi:cxx11](absl::string_view, int, int)':
naming.cc:(.text._ZN10tensorflow12DataFilenameB5cxx11EN4absl11string_viewEii+0x1f): undefined reference to `tensorflow::strings::Printf[abi:cxx11](char const*, ...)'
bazel-out/k8-opt/bin/tensorflow/core/kernels/data/libstats_utils.a(stats_utils.o): In function `tensorflow::data::stats_utils::ExecutionTimeHistogramName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
stats_utils.cc:(.text._ZN10tensorflow4data11stats_utils26ExecutionTimeHistogramNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x69): undefined reference to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)'
bazel-out/k8-opt/bin/tensorflow/core/kernels/data/libstats_utils.a(stats_utils.o): In function `tensorflow::data::stats_utils::ThreadUtilizationScalarName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
stats_utils.cc:(.text._ZN10tensorflow4data11stats_utils27ThreadUtilizationScalarNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x69): undefined reference to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)'
bazel-out/k8-opt/bin/tensorflow/core/kernels/data/libstats_utils.a(stats_utils.o): In function `tensorflow::data::stats_utils::BufferSizeScalarName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
stats_utils.cc:(.text._ZN10tensorflow4data11stats_utils20BufferSizeScalarNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x69): undefined reference to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)'
bazel-out/k8-opt/bin/tensorflow/core/kernels/data/libstats_utils.a(stats_utils.o): In function `tensorflow::data::stats_utils::BufferCapacityScalarName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
stats_utils.cc:(.text._ZN10tensorflow4data11stats_utils24BufferCapacityScalarNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x69): undefined reference to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)'
bazel-out/k8-opt/bin/tensorflow/core/kernels/data/libstats_utils.a(stats_utils.o): In function `tensorflow::data::stats_utils::BufferUtilizationHistogramName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
stats_utils.cc:(.text._ZN10tensorflow4data11stats_utils30BufferUtilizationHistogramNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x69): undefined reference to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)'
bazel-out/k8-opt/bin/tensorflow/core/kernels/data/libstats_utils.a(stats_utils.o):stats_utils.cc:(.text._ZN10tensorflow4data11stats_utils25FilterdElementsScalarNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x69): more undefined references to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&, tensorflow::strings::AlphaNum const&)' follow
collect2: error: ld returned 1 exit status
Target //tensorflow:libtensorflow_gpu.a failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3939.495s, Critical Path: 398.23s
INFO: 5737 processes: 5737 local.
FAILED: Build did NOT complete successfully