Tensorflow2.2 CPU編譯過程記錄

編譯Tensorflow CPU 版本

  1. 安裝 Anaconda3-2020.02-Windows-x86_64.exe (管理python)

  2. 安裝 Visual Studio 2019 配置VS2019編譯環境 (Windows 需要)
    添加系統變量 BAZEL_VC C:\Program Files (x86)\ Microsoft Visual Studio\2019\Community\VC
    BAZEL_VS C:\Program Files (x86)\ Microsoft Visual Studio\2019\Community

  3. 使用conda創建python虛擬環境 conda create -n xxx python=3.7

  4. 轉到新創建的虛擬環境下 conda activate xxx

  5. 安裝編譯過程需要用到的模塊(如果下載速度慢,可以修改pip源) pip install numpy six keras_preprocessing
    conda install protobuf

  6. 安裝 git 和 bazel2.0.0
    windows: 直接配置bazel.exe的環境變量
    linux : sudo rm -rf ~/.bazel
    sudo rm -rf ~/bin
    sudo rm -rf /usr/bin/bazel
    sudo cp bazel /usr/bin/bazel
    sudo chmod a+x /usr/bin/bazel

  7. 安裝 msys2 pacman -S zip unzip patch diffutils git (Windows需要)

  8. 下載tensorflow源碼 https://github.com/tensorflow/tensorflow/releases/tag/v2.2.0

  9. cd tensorflow

  10. 在創建的python虛擬環境下 python configure.py

                                                Please specify the location of python. [Default is xxx\Anaconda3\envs\pythonVersion3\python.exe]:
    
    
                                                Found possible Python library paths:
                                                xxx\Anaconda3\envs\pythonVersion3\lib\site-packages
                                                Please input the desired Python library path to use.  Default is [xxx\Anaconda3\envs\pythonVersion3\lib\site-packages]
    
                                                Do you wish to build TensorFlow with ROCm support? [y/N]: n
                                                No ROCm support will be enabled for TensorFlow.
    
                                                Do you wish to build TensorFlow with CUDA support? [y/N]: n
                                                No CUDA support will be enabled for TensorFlow.
    
                                                Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is /arch:AVX]:
    
    
                                                Would you like to override eigen strong inline for some C++ compilation to reduce the compilation time? [Y/n]: n
                                                Not overriding eigen strong inline, some compilations could take more than 20 mins.
    
                                                Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
                                                Not configuring the WORKSPACE for Android builds.
    
                                                Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
                                                        --config=mkl            # Build with MKL support.
                                                        --config=monolithic     # Config for mostly static monolithic build.
                                                        --config=ngraph         # Build with Intel nGraph support.
                                                        --config=numa           # Build with NUMA support.
                                                        --config=dynamic_kernels        # (Experimental) Build kernels into separate shared objects.
                                                        --config=v2             # Build TensorFlow 2.x instead of 1.x.
                                                Preconfigured Bazel build configs to DISABLE default on features:
                                                        --config=noaws          # Disable AWS S3 filesystem support.
                                                        --config=nogcp          # Disable GCP support.
                                                        --config=nohdfs         # Disable HDFS support.
                                                        --config=nonccl         # Disable NVIDIA NCCL support.
    
  11. 開始使用bazel編譯 bazel --output_user_root=“你的緩存目錄” build --noincompatible_do_not_split_linking_cmdline --verbose_failures --config=opt //tensorflow:tensorflow_cc.dll

  12. 經過漫長的等待編譯完成

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章