基於openeuler aarch_64 下,從源碼的角度搭建Tensorflow

爲何從源碼編譯Tensorflow?

  • 安裝過的人們都知道若是python

    pip install tensorflowlinux

的話會報錯Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 git

  • 考慮到操做系統的的兼容性,現有的編譯好的二進制安裝包不適用openeuler,因此考慮這些因素,咱們要本身搭建。github

  • 咱們須要bazel交叉編譯軟件,有點相似cmake(上游下載的開源.sh文件已上傳到倉庫)bazel下載地址app

  • chmod +x bazel-0.28.0-installer-linux-x86_64.shgitlab

  • ./bazel-0.28.0-installer-linux-x86_64.sh --userui

  • bazel version查看版本,configure.py查看tf所支持的版本(2.3版本所支持的bazel)this

_TF_MIN_BAZEL_VERSION = '0.27.1'google

_TF_MAX_BAZEL_VERSION = '0.29.1'操作系統

下載TF

  • git clone https://github.com/tensorflow/tensorflow
  • git barach -a 查看全部發行版本
  • git checkout <version> 將分支同步到本地

開始編譯

  • bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so(C文件庫)

  • bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package(wheel文件)

  • bazel build --config=opt --config=cuda //tensorflow:libtensorflow.so(生成C庫)

  • bazel build --config=opt //tensorflow/lite:libtensorflowlite.so (Lite庫)

bazel編譯有的時候會出issue現bug,詳見issue

openeuler搭建Bulid Not Successfully 的Bug狀況彙總

源碼編譯連接

官網上說安裝須要pip19以上

關於openeulerpip源默認指向python2該如何修改:

#!/usr/bin/python2=====>!/usr/bin/python3
  
# -*- coding: utf-8 -*-
import re
import sys

from pip._internal.cli.main import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

二、修改默認指向因爲版本不一樣所發生的bug

from pip import main
ImportError: cannot import name 'main' from 'pip' (/usr/lib/python3.7/site-packages/pip/__init__.py)

source code change to this

from pip import __main__  //這行也要修改
if __name__ == '__main__':  
    sys.exit(__main__._main())//增長__main__._

PRODUCT

[root@openeuler lzb]# pip -V
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

安裝 TensorFlow pip 軟件包依賴項(若是使用虛擬環境,請省略 --user 參數):

pip install -U --user pip six numpy wheel setuptools mock 'future>=0.17.1'
pip install -U --user keras_applications --no-deps
pip install -U --user keras_preprocessing --no-deps

setup.py 💯 we can know the vesion and dependence on REQUIRED_PACKAGES

> REQUIRED_PACKAGES = [
>     'absl-py >= 0.7.0',
>     'astunparse == 1.6.3',
>     'flatbuffers >= 1.12',
>     'gast == 0.3.3',
>     'google_pasta >= 0.1.8',
>     'h5py >= 2.10.0, < 2.11.0',
>     'keras_preprocessing >= 1.1.1, < 1.2',
>     # TODO(mihaimaruseac): numpy 1.19.0 has ABI breakage
>     # https://github.com/numpy/numpy/pull/15355
>     'numpy >= 1.16.0, < 1.19.0',
>     'opt_einsum >= 2.3.2',
>     'protobuf >= 3.9.2',
>     'tensorboard >= 2.3.0, < 3',
>     'tensorflow_estimator >= 2.3.0, < 2.4.0',
>     'termcolor >= 1.1.0',
>     'wrapt >= 1.11.1',
>     'w**h*eel >= 0.26',
>     'six >= 1.12.0',
> ]
相關文章
相關標籤/搜索