Rate This Document
Findability
Accuracy
Completeness
Readability

Installation from Source Code

This section provides four compilation methods for installing different versions of TensorFlow 2.13.0: basic version, ACL-enabled version, TensorFlow v1.x-matched version, and NUMA-enabled version. Run the compilation commands for each specific version.

  1. Obtain the TensorFlow 2.13.0 source code.
    1. Download the TensorFlow source code using your local browser.

      https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.13.0.zip

      The source package name is tensorflow-2.13.0.zip.

    2. Upload the source package to the server.

    If the server is connected to the Internet, you can run the wget command on the server to download the source package.

    1
    wget -O tensorflow-2.13.0.zip https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.13.0.zip --no-check-certificate
    
  2. Install the dependencies.
    1
    2
    3
    4
    5
    6
    7
    yum install patchelf perl python3-devel
    pip3 install numpy==1.24.3
    pip3 install packaging
    pip3 install requests
    pip3 install wheel
    export C_INCLUDE_PATH=/usr/include/python3.9:$C_INCLUDE_PATH
    export CPLUS_INCLUDE_PATH=/usr/include/python3.9:$CPLUS_INCLUDE_PATH
    

    In the preceding commands for configuring environment variables, /usr/include/python3.9 is the directory where Python.h is located. Replace it with the actual directory in the compilation environment.

  3. Decompress the TensorFlow installation package.
    1
    unzip tensorflow-2.13.0.zip
    

    The directory generated after the decompression is tensorflow-2.13.0.

  4. Go to the tensorflow-2.13.0 directory.
    1
    cd tensorflow-2.13.0
    
  5. Run configure to set the configuration options.
    1
    ./configure
    

    The configuration procedure is as follows:

    1. Confirm the location of the Python executable program.
      1
      Please specify the location of python. [Default is /usr/bin/python3]:
      

      If the Python 3 path is the same as the preceding default path, press Enter. Otherwise, enter the correct Python 3 path.

    2. Confirm the location of the Python library.
      1
      Please input the desired Python library path to use.  Default is [/home/xxx/test]
      

      If the Python library path is the same as the preceding default path, press Enter. Otherwise, enter the correct Python library path.

    3. Determine whether to enable the ROCm feature.

      The AMD ROCm platform is an open source software platform designed to facilitate high-performance computing (HPC) using AMD graphics processing units (GPUs). If TensorFlow runs on AMD GPUs, enter y. Otherwise, enter N.

      1
      Do you wish to build TensorFlow with ROCm support? [y/N]:
      

      In this document, enter N.

      1
      No ROCm support will be enabled for TensorFlow.
      
    4. Determine whether to enable the CUDA feature.

      CUDA is a parallel computing platform and programming model developed by NVIDIA for general computing on GPUs. It accelerates applications such as scientific computing, graphics processing, and deep learning. If you want to use CUDA in the build, enter y. Otherwise, enter N.

      1
      Do you wish to build TensorFlow with CUDA support? [y/N]:
      

      In this document, enter N.

      1
      No CUDA support will be enabled for TensorFlow.
      
    5. Determine whether to use the latest Clang compiler.

      If the Clang compiler exists in the compilation environment, enter N. Otherwise, enter y.

      1
      Do you wish to download a fresh release of clang? (Experimental) [y/N]:
      

      In this document, enter N.

      1
      Clang will not be downloaded.
      
    6. Configure compilation options.
      1
      Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]:
      

      Press Enter to confirm.

    7. When building an Android application, determine whether to set a workspace.

      To build a non-Android application, enter N. Otherwise, enter y.

      1
      "Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:"
      

      In this document, enter N.

      1
      Not configuring the WORKSPACE for Android builds.
      
  6. Build TensorFlow.
    Table 1 Parameters of some extended features (For details, see the .bazelrc file in the source code directory.)

    config Parameter

    Description

    --config=mkl_aarch64

    Integrates oneDNN and the Arm Compute Library (ACL).

    --config=numa

    Integrates the NUMA feature.

    --config=v1

    Replaces TensorFlow 2.x APIs with TensorFlow 1.x APIs.

    • When TensorFlow is built from the source code, temporary compilation files are generated in the /root/.cache/bazel directory. Ensure that the remaining space of the root directory is greater than or equal to 8 GB.
    • Building TensorFlow from source code requires substantial memory. For memory-constrained systems, add the --local_ram_resources option to the build command. For example, --local_ram_resources=2048 indicates that the maximum memory overhead allowed is 2048 MB.
    • Building TensorFlow from source code requires substantial CPU power. You can add the --local_cpu_resources option to the build command to limit the CPU resource usage. For example, --local_cpu_resource=4 indicates that four CPUs are used. (Run the lscpu command on the terminal to check the number of CPUs and set local_cpu_resources based on your requirements.)

    The following describes four build methods. Select the one that best suits your requirements.

    • Build the basic version.
      1
      bazel build //tensorflow/tools/pip_package:build_pip_package
      

      If the command output displays the preceding information, the build is successful.

    • Compile the version in which mkl_aarch64 is enabled.
      1
      bazel build //tensorflow/tools/pip_package:build_pip_package --config=mkl_aarch64
      

      If the command output displays the preceding information, the build is successful.

    • Compile the version that matches TensorFlow v1.x.
      1
      bazel build //tensorflow/tools/pip_package:build_pip_package --config=v1
      

      If the command output displays the preceding information, the build is successful.

    • Compile the version in which NUMA is enabled.
      1
      bazel build //tensorflow/tools/pip_package:build_pip_package --config=numa
      

      If the command output displays the preceding information, the build is successful.

  7. Build the TensorFlow pip software package.
    1
    ./bazel-bin/tensorflow/tools/pip_package/build_pip_package ./output
    

    The generated pip software package is stored in the ./output directory.

    Alarms may be generated during the build. For details about how to handle the alarms, see Alarm Reported When Building the TensorFlow pip Software Package.

  8. Install the TensorFlow pip software package.
    1
    pip3 install ./output/tensorflow-2.13.0-cp39-cp39-linux_aarch64.whl