快速安裝預編版tensorflow-gpu (setup tensorflow-GPU fast) === ### 可以完成: 安裝支援CUDA10.2 tensorflow 1.14版(或其他版) Setup tensorflow-gpu dependency fast **!Very IMPORTANT!** **Your cpu should support AVX instruction!!! Or you will GG face illegal instruction or core dump!!! T___T** How to check it `gcc -march=native=native -Q --help=target | grep enable` ![](https://i.imgur.com/IAgT8pi.jpg) #### 環境(Environment) 顯示卡硬體: (Nvidia GTX1080ti) 主機板: 環境: ubuntu18.04.3 CUDA 10.2 Cudnn 7.6.5 預編板tensorflow-gpu==1.14 --- ## ubuntu 雙系統安裝 要多切一小塊EFI格式 割256mb 重要! 記得Device for boot loader installation : --- ## Nvidia Driver 註: #### Important! driver版本會決定你的CUDA加速函式庫版本 一個號碼都不能少! CUDA version will bunddle to your Nvidia driver version! see: https://docs.nvidia.com/deeplearning/sdk/cudnn-support-matrix/index.html https://www.tensorflow.org/install/gpu 比如: tensorflow-gpu==1.14 keras 2.2.4 綁定 440 drive cuda-10-2 cudnn 7.6.5 另外即使你 apt install nvidia-driver-418 裝的還是440版驅動 ### 步驟(Install steps) ctrl+alt+T Open terminal: **sudo apt purge nvidia*** **sudo add-apt-repository ppa:graphics-drivers/ppa** **sudo apt update** **sudo apt install nvidia-driver-418 nvidia-settings** **sudo reboot** ![](https://i.imgur.com/rB4NeUI.png) --- ## Cudnn, cuda google drive: 下載 CUDA-10.2 Cudnn 7.6.5 https://drive.google.com/drive/folders/1z2QUf5iD8IEVLFSL3JbYCeNsOfOheGGH?usp=sharing ## cuda-10.2 ```bash= wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.debsudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub sudo apt-get update sudo apt-get install cuda ``` 編輯~/.bashrc ```bash= #cuda-10-2 export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64" export CUDA_HOME=/usr/local/cuda ``` --- ## cudnn 7.6.5 ```bash= tar -xzvf cudnn-10.2-linux-x64-v7.6.5.32.tgz sudo cp cuda/include/cudnn.h /usr/local/cuda/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* ``` --- ### How to fly(Test your nvidia driver and cuda install) **nvidia-smi** ![](https://i.imgur.com/5hLZeoF.png) **cat /proc/driver/nvidia/gpus/0000:05:00.0/information** ![](https://i.imgur.com/lXg50bf.png) https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html **nvcc -V** ![](https://i.imgur.com/Xr2aKLO.png) `~/.bashrc設定` ![](https://i.imgur.com/t6omnSP.png) ```bash= #cuda-10-2 export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64" export CUDA_HOME=/usr/local/cuda ``` --- ### Python虛擬環境設定 https://hackmd.io/80mY-tYSTGqjajNVFeAO3Q?view #### 安裝 sudo apt-get install python3-venv #### 使用 在你的工作目錄下 `python3 -m venv venv` 會建立一個venv資料夾,所有後來安裝python套件都會在裡面 一此移動只要帶著這個資料夾 啟動venv `source venv/bin/activate` (可以在.bashrc寫 alias) 比如 alias venv="source venv/bin/activate" 這時候終端機指令輸入前面多了(venv)可以開使用了! 註銷 deactivate 裝套件方法,像一般python打pip即可,只會裝在venv內 比如進入 (venv內) ```bash= pip install -r requirements.txt pip install setuptools==41.0.0 pip install notebook pip install tensorflow-gpu==1.14 ``` 匯出 `pip freeze >> requirements.txt` 另外 tensorflow 2.0後 只要 pip install tensorflow cpu gpu版都會裝 nightly版通常是指最新版的預編 --- ### 基本軟體安裝 #### Install open-ssh ```bash= sudo apt install openssh-server sudo apt install ibus-chewing sudo apt install vim ``` modified `sudo vim /etc/ssh/ssh_config` add ```shell= ForwardX11 yes ``` ![](https://i.imgur.com/Js9BcIL.png) #### 輸入法設定 ctrl+空白鍵換輸入法 ### install chewing, editor Settings-->Ibus Preferences ```bash= sudo apt-get install ibus-chewing vim ibus restart ``` ![](https://i.imgur.com/roXck21.png) ![](https://i.imgur.com/fD8xXHj.png) ![](https://i.imgur.com/NE96iuN.png) #### vim ~/.vimrc ```bash= set background=dark set nu set ic syntax on set ignorecase smartcase set undofile set undodir=~/.vim/undodir filetype plugin indent on set tabstop=4 set softtabstop=4 set expandtab set cursorline set cindent set number set pastetoggle=<F12> ``` --- ### 協作環境 sudo apt install git --- ### 其他 #### software(compilier gcc, posix,manpages) 如果你想build from source === 注意bazel版本 https://www.tensorflow.org/install/source 假如你的cpu沒有AVX指令集 ```bash= export TF_ENABLE_XLA=1 export CC_OPT_FLAGS="-march=native -mno-avx" ``` `./configure` **!注意要打路徑不要按enter!** **Do you want to use clang as CUDA compiler? [y/N]: n ** nvcc will be used as CUDA compiler. (要打n) ```bash= ./configure You have bazel 0.14.0 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3.6 Found possible Python library paths: /usr/local/lib/python3.6/dist-packages /usr/lib/python3.6/dist-packages Please input the desired Python library path to use. Default is [/usr/lib/python3.6/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [y/N]: n No XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: Y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA ]: 10 Please specify the location where CUDA 10 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.1]: 6.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: 7.6.5 Do you wish to build TensorFlow with TensorRT support? [y/N]: No TensorRT support will be enabled for TensorFlow. Please specify the NCCL version you want to use. If NCLL 2.2 is not installed, then you can use version 1.3 that can be fetched automatically but it may have worse performance with multiple GPUs. [Default is 2.2]: n Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 3.5,7.0] 6.1 **Do you want to use clang as CUDA compiler? [y/N]: n **(要打n !!) nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/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 tools/bazel.rc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. Configuration finished ``` ### run compilation ```bash= bazel build --config=opt --config=cuda --noincompatible_strict_action_env //tensorflow/tools/pip_package:build_pip_package ``` ### get wheel ```bash= bazel-bin/tensorflow/tools/pip_package/build_pip_package /my-devel/tensorflow_pkg1 ``` --- ### ubuntu雙系統安裝 *請用開機光碟片...* 製作開機光碟片請用[imgburn](https://www.azofreeware.com/2006/04/imgburn-1300.html) 開機USB用 https://unetbootin.github.io/ 什麼時代了還要光碟片!? 其實一些大型server bios沒有辦法USB0 安裝的 雙系統安裝 https://www.youtube.com/watch?v=rjpBTT6AmeU 磁碟壓縮-->割/, home -->選對bootloader安裝硬碟 700GB 磁碟分割 ![](https://i.imgur.com/jJrRHyt.jpg) 重要! 記得Device for boot loader installation : ![](https://i.imgur.com/zCkCrQM.jpg) ubuntu codec sudo apt install libdvdnav4 libdvdread4 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg ## 一些故事 --- https://hackmd.io/vhNHpogETYuMVxAAENvObQ?view https://hackmd.io/@kcchien/BJzHPQdSN?type=view ###### tags:`document` `ai-server`