TensorFlow通過AMD GPU加速(ROCm/elementary OS 5.0)


https://www.jianshu.com/p/ff66c5dac823

elementary OS 5.0是基於Ubuntu 18.04制作,所以本流程也適用於Ubuntu 18.04。

ROCm升級1.91之后不需要安裝AMD的GPU驅動程序,如果安裝可能會出現問題。

安裝elementary OS 5 之后的一些配置

詳細配置請參閱:elementary OS 5.0安裝后配置

安裝軟件更新管理器

sudo apt update
sudo apt install software-properties-common software-properties-gtk

運行軟件更新管理器然后選擇合適的鏡像,我使用的是阿里雲。

sudo software-properties-gtk

更新系統

sudo apt update
sudo apt upgrade

安裝ROCm

添加ROCm庫

wget -qO - http://repo.radeon.com/rocm/apt/debian/rocm.gpg.key | sudo apt-key add -
sudo sh -c 'echo deb [arch=amd64] http://repo.radeon.com/rocm/apt/debian/ xenial main > /etc/apt/sources.list.d/rocm.list'

安裝必要的軟件包

sudo apt update && sudo apt install -y \
  build-essential \
  clang \
  clang-format \
  clang-tidy \
  cmake \
  cmake-qt-gui \
  ssh \
  curl \
  apt-utils \
  pkg-config \
  g++-multilib \
  git \
  libunwind-dev \
  libfftw3-dev \
  libelf-dev \
  libncurses5-dev \
  libpthread-stubs0-dev \
  vim \
  gfortran \
  libboost-program-options-dev \
  libssl-dev \
  libboost-dev \
  libboost-system-dev \
  libboost-filesystem-dev \
  rpm \
  wget 

安裝ROCm驅動

sudo apt update && \
    sudo apt install -y --allow-unauthenticated \
    rocm-dkms rocm-dev rocm-libs \
    rocm-device-libs \
    hsa-ext-rocr-dev hsakmt-roct-dev hsa-rocr-dev \
    rocm-opencl rocm-opencl-dev \
    rocm-utils \
    rocm-profiler cxlactivitylogger \
    miopen-hip miopengemm

添加用戶

sudo adduser $LOGNAME video
sudo reboot

安裝miniconda

在使用python時我們很多時候會用到conda,但是conda會改變python的一些配置。所以我們先安裝conda,這樣就不會出現在使用tensorflow時需要使用/usr/bin/python3這樣的命令。
下載地址(64位):https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh

cd 下載目錄
chmod +x ./Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

安裝之后我們發現conda的python是3.7,而ROCm版的tensorflow支持3.5和3.6,所以我們需要將python降為3.6。

conda install python=3.6

安裝python相關的軟件包

sudo apt update && sudo apt install -y \
    python3-numpy \
    python3-dev \
    python3-wheel \
    python3-mock \
    python3-future \
    python3-pip \
    python3-yaml \
    python3-setuptools

安裝TensorFlow

pip3 install --user tensorflow-rocm


作者:王胖BigWang
鏈接:https://www.jianshu.com/p/ff66c5dac823
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM