編譯環(huán)境:
cpu: Ryzen 7 1700
gpu:藍(lán)寶石Vega56
ram:? 16G
軟件編譯環(huán)境
Ubuntu 18.04 LTS
Anaconda3 (python=3.6)
Rocm 3.0
編譯步驟
1按照AMD官方ROCm文檔安裝 opencl套件
https://github.com/RadeonOpenCompute/ROCm
2安裝編譯期間用到的依賴庫(kù)
sudo apt update
sudo apt install rock-dkms rocm-dev rocm-libs miopen-hip miopengemm hipsparse? rccl rocthrust hipcub roctracer-dev
sudo apt install git python-pip libopenblas-dev cmake libnuma-dev autoconf build-essential ca-certificates curl libgoogle-glog-dev libhiredis-dev libiomp-dev libleveldb-dev liblmdb-dev libopencv-dev libpthread-stubs0-dev libsnappy-dev sudo vim libprotobuf-dev protobuf-compiler
pip install enum34 numpy pyyaml setuptools typing cffi future hypothesis
3下載源碼(當(dāng)然如果沒(méi)有g(shù)it需要先安裝)
cd ~
git clone https://github.com/pytorch/pytorch.git or git clone https://github.com/ROCmSoftwarePlatform/pytorch.git
cd pytorch
git submodule update --init --recursiv
4設(shè)置必要的環(huán)境變量
sed -i 's/find_dependency(hip)/find_dependency(HIP)/g' /opt/rocm/rocsparse/lib/cmake/rocsparse/rocsparse-config.cmake
sed -i 's/find_dependency(hip)/find_dependency(HIP)/g' /opt/rocm/rocfft/lib/cmake/rocfft/rocfft-config.cmake
sed -i 's/find_dependency(hip)/find_dependency(HIP)/g' /opt/rocm/miopen/lib/cmake/miopen/miopen-config.cmake
sed -i 's/find_dependency(hip)/find_dependency(HIP)/g' /opt/rocm/rocblas/lib/cmake/rocblas/rocblas-config.cmake
sed -i 's/find_dependency(hip)/find_dependency(HIP)/g' /opt/rocm/hipsparse/lib/cmake/hipsparse/hipsparse-config.cmake
sed -i 's/find_dependency(hip)/find_dependency(HIP)/g' /opt/rocm/rccl/lib/cmake/rccl/rccl-config.cmake
然后在pytorch/cmake/External/rccl.cmake 里添加set(RCCL_DIR"/opt/rocm/rccl/lib/cmake/rccl")
5 Hipify CUDA的函數(shù)轉(zhuǎn)化
cd pytorch
python tools/amd_build/build_amd.py
6開(kāi)始編譯Pytorch 其中官方說(shuō)明注明萍诱,MAX_JOBS = n時(shí)啦撮,我內(nèi)存是16G 所以n設(shè)置為4苟呐,內(nèi)存夠大可以設(shè)置得大一點(diǎn)。
USE_ROCM=1 USE_LMDB=1 USE_OPENCV=1 MAX_JOBS=4 python setup.py install --user
7全部編譯完成后進(jìn)行測(cè)試
PYTORCH_TEST_WITH_ROCM=1 python test/run_test.py --verbose