centos6.5源碼編譯tensroflow1.4.0

前言

開始編譯前,務(wù)必做好持久戰(zhàn)的準(zhǔn)備!

準(zhǔn)備工作

1.一臺(tái)centos6.5的linux機(jī)子。推薦安裝虛擬機(jī),很多操作需要root權(quán)限。http://www.itdecent.cn/p/18207167b1e7
2.配置yum源。https://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html

開始編譯

1.安裝java

yum install java-1.8.0-openjdk-devel

2.安裝devtoolset-6-toolchain
我是通過(guò)yum安裝成功的

yum install devtoolset-6-toolchain

3.安裝依賴包

yum install python27 python27-numpy python27-python-devel python27-python-wheel

4.安裝bazel

scl enable devtoolset-6 bash
# download distribution archive
wget https://github.com/bazelbuild/bazel/releases/download/0.10.0/bazel-0.10.0-dist.zip
unzip bazel-0.10.0-dist.zip -d bazel-0.9.0-dist
cd bazel-0.9.0-dist
# compile
./compile.sh
# install
mkdir -p ~/bin
cp output/bazel ~/bin/
# exit from Software Collection environment
exit

5.下載tensorflow

scl enable devtoolset-6 python27 bash
# clone source code repository
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
# select version (optional)
git checkout v1.4.0

6.修改tensorflow/tensorflow.bzl

#修改前
def tf_extension_linkopts():
  return []  # No extension link opts
#修改后
def tf_extension_linkopts():
  return ["-lrt"]

7.修改repositories.bzl和workspace.bzl
所有的check_version("...") 改成check_version("0.10.0")
其中repositories.bzl的路徑是~/.cache/bazel/_bazel_nvidia/xxx/external/io_bazel_rules_closure/closure/repositories.bzl,xxx是_bazel_nvidia文件夾下的一個(gè)名字很長(zhǎng)的文件夾

#修改前
_check_bazel_version("Closure Rules", "0.4.5")
#修改后
_check_bazel_version("Closure Rules", "0.10.0-")

這是bazel的一個(gè)比較搞笑的bug,它會(huì)認(rèn)為0.10.0比0.4.5版本低
8.編譯tensorflow

./configure
#所有的y/n都選n,不是就選默認(rèn)
bazel build --config=opt --cxxopt='lrt' --incompatible_load_argument_is_label=false --incompatible_disallow_uncalled_set_constructor=false //tensorflow/tools/pip_package:build_pip_package

9.不要放棄
基本上只要把用到鏈接庫(kù)的地方改成‘lrt’就能編譯成功,java版本的編譯類似。

后記

部分命令記不清了,如果有還有bug請(qǐng)自行解決,解決的核心就是‘lrt’。

參考資料

https://blog.abysm.org/2016/06/building-tensorflow-centos-6/
https://bleedingfight.github.io/2018/01/18/tensorflowforjava/
http://aifuns.cc/2017/10/08/so-file-in-C.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容