pytorch AMD rocm 环境编译教程--A卡Ubuntu18.04 编译pytorch教程

编译环境:

cpu: Ryzen 7 1700

gpu:蓝宝石Vega56

ram:  16G

软件编译环境

Ubuntu 18.04 LTS

Anaconda3 (python=3.6)

Rocm 3.0

编译步骤

1按照AMD官方ROCm文档安装 opencl套件

https://github.com/RadeonOpenCompute/ROCm

2安装编译期间用到的依赖库

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下载源码(当然如果没有git需要先安装)

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设置必要的环境变量

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的函数转化

cd pytorch

python tools/amd_build/build_amd.py


6开始编译Pytorch 其中官方说明注明,MAX_JOBS = n时,我内存是16G 所以n设置为4,内存够大可以设置得大一点。

USE_ROCM=1 USE_LMDB=1 USE_OPENCV=1 MAX_JOBS=4 python setup.py install --user


7全部编译完成后进行测试

PYTORCH_TEST_WITH_ROCM=1 python test/run_test.py --verbose

你可能感兴趣的:(pytorch AMD rocm 环境编译教程--A卡Ubuntu18.04 编译pytorch教程)