zoukankan      html  css  js  c++  java
  • tensorflow2.4.0编译安装(适配CPU型号 flag)

    tensorflow2.4.0编译安装(适配CPU型号 flag)
    1.GCC编译器版本7.3.1
    https://www.jianshu.com/p/b3f96dde3f61
    gcc7.3.1
    sudo yum install centos-release-scl
    sudo yum install devtoolset-7-gcc*
    scl enable devtoolset-7 bash
    which gcc
    gcc --version
    # scl enable devtoolset-7 bash # bash生效
    # which gcc
    /opt/rh/devtoolset-7/root/usr/bin/gcc
    # gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
    Target: x86_64-redhat-linux
    Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
    Thread model: posix
    gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)
    2.安装python3环境
    安装tensorflow编译需要的依赖包
    pip3 install numpy==1.19.4 -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

    pip3 install wheel -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

    pip3 install keras_preprocessing --no-deps -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

    pip3 install setuptools==54.2.0 -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

    3.tensorflow 源代码 2.4.0
    从github上检出2.4.0分支 下载
    git clone https://github.com/tensorflow/tensorflow.git

    /opt/tflow/tensorflow-2.4.0/configure.py 包含tensorflow需要的bazel的版本信息
    tensorflow-2.4.0
    4. bazel 环境
    yum install unzip
    bazel 3.1.0
    https://github.com/bazelbuild/bazel/releases?after=3.3.1
    chmod +x bazel-3.1.0-installer-linux-x86_64.sh
    ./bazel-3.1.0-installer-linux-x86_64.sh
    5.编译tensorflow
    5.1 为安装TensorFlow配置环境
    /opt/tflow/tensorflow-2.4.0
    ./configure
    5.2 编译tensorflow
    gcc5以下版本
    bazel build --local_ram_resources=2048 -c opt --copt=-mssse3 --copt=-mcx16 --copt=-mavx --copt=-msse4.1 --copt=-msse4.2 --copt=-mpopcnt -k //tensorflow/tools/pip_package:build_pip_package


    gcc5以上版本
    bazel build --local_ram_resources=2048 --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" -c opt --copt=-mssse3 --copt=-mcx16 --copt=-mavx --copt=-msse4.1 --copt=-msse4.2 --copt=-mpopcnt -k //tensorflow/tools/pip_package:build_pip_package > log 2>&1 &

    6.构建软件包
    ------------------------------------------------------------------------------
    [root@node01 tensorflow-2.4.0]# ls
    ACKNOWLEDGMENTS bazel-tensorflow-2.4.0 configure ISSUE_TEMPLATE.md SECURITY.md
    arm_compiler.BUILD bazel-testlogs configure.cmd LICENSE tensorflow
    AUTHORS BUILD configure.py models.BUILD third_party
    bazel-bin CODE_OF_CONDUCT.md CONTRIBUTING.md README.md tools
    bazel-out CODEOWNERS ISSUES.md RELEASE.md WORKSPACE
    [root@node01 tensorflow-2.4.0]# ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
    Thu Apr 1 12:46:24 CST 2021 : === Preparing sources in dir: /tmp/tmp.wHCYLV3NHl
    /usr/local/src/tensorflow-2.4.0 /usr/local/src/tensorflow-2.4.0
    /usr/local/src/tensorflow-2.4.0
    /usr/local/src/tensorflow-2.4.0/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow /usr/local/src/tensorflow-2.4.0
    /usr/local/src/tensorflow-2.4.0
    /tmp/tmp.wHCYLV3NHl/tensorflow/include /usr/local/src/tensorflow-2.4.0
    /usr/local/src/tensorflow-2.4.0
    Thu Apr 1 12:46:48 CST 2021 : === Building wheel
    warning: no files found matching 'README'
    warning: no files found matching '*.pyd' under directory '*'
    warning: no files found matching '*.pyi' under directory '*'
    warning: no files found matching '*.pd' under directory '*'
    warning: no files found matching '*.dylib' under directory '*'
    warning: no files found matching '*.dll' under directory '*'
    warning: no files found matching '*.lib' under directory '*'
    warning: no files found matching '*.csv' under directory '*'
    warning: no files found matching '*.h' under directory 'tensorflow/include/tensorflow'
    warning: no files found matching '*.proto' under directory 'tensorflow/include/tensorflow'
    warning: no files found matching '*' under directory 'tensorflow/include/third_party'
    Thu Apr 1 12:47:26 CST 2021 : === Output wheel file is in: /tmp/tensorflow_pkg

    bazel build 命令会创建一个名为 build_pip_package 的可执行文件,此文件是用于构建 pip 软件包的程序。如下所示地运行该可执行文件,以在 /tmp/tensorflow_pkg 目录中构建 .whl 软件包。
    ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

    安装软件包
    生成的 .whl 文件的文件名取决于 TensorFlow 版本和您的平台。例如,使用 pip install 安装软件包:
    pip3 install /tmp/tensorflow_pkg/tensorflow-version-tags.whl
    pip3 install /tmp/tensorflow_pkg/NAME_OF_WHEEL.whl

    参考链接
    https://tech.amikelive.com/node-887/how-to-resolve-error-illegal-instruction-core-dumped-when-running-import-tensorflow-in-a-python-program/
    https://tech.amikelive.com/node-882/how-to-build-and-install-the-latest-tensorflow-without-cuda-gpu-and-with-optimized-cpu-performance-on-ubuntu/
    https://www.tensorflow.org/install/source

    libstdc++.so.6.0.24 放到 /usr/lib64/目录下
    [root@node04 ~]# cd /usr/lib64/
    [root@node04 lib64]# ll /usr/lib64/libstdc++.so.6
    lrwxrwxrwx. 1 root root 19 Mar 23 14:31 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.19
    [root@node04 lib64]# mv libstdc++.so.6 libstdc++.so.6_bak
    [root@node04 lib64]# ll libstdc++.so.6.0.24
    -rwxr-xr-x 1 root root 11482848 Apr 1 14:13 libstdc++.so.6.0.24
    [root@node04 lib64]# ln -s libstdc++.so.6.0.24 /usr/lib64/libstdc++.so.6
    [root@node04 lib64]# ll /usr/lib64/libstdc++.so.6
    lrwxrwxrwx 1 root root 19 Apr 1 14:15 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.24

  • 相关阅读:
    spring execution表达式用法
    spring2.0中使用Aspect方式进行AOP如何得到method对象
    mybatis if标签判断字符串相等
    Date和Timestamp区别
    正向代理与反向代理[转载]
    oracle中的对象创建及删除语句【原创】
    使用IDEA打war包并导出war包详细步骤
    Java面试题
    电脑上怎么登录几个微信(微信多开)
    批处理快速合并多分Excel文件并将指定列的数据去重复
  • 原文地址:https://www.cnblogs.com/songyuejie/p/14682088.html
Copyright © 2011-2022 走看看