Erik Rigtorp

Installing ROCm 3.9 on Fedora 33

This is guide on how to install ROCm 3.9 on Fedora 33 using the official packages for RHEL8.

Add the ROCm RHEL8 repository:

$ sudo tee /etc/yum.repos.d/ROCm.repo <<EOF
[ROCm]
name=ROCm
baseurl=http://repo.radeon.com/rocm/centos8/rpm
enabled=1
gpgcheck=1
gpgkey=http://repo.radeon.com/rocm/rocm.gpg.key
EOF

Install packages required for compiling and running HIP kernels:

$ sudo dnf install rocm-device-libs hsakmt-roct hip-samples hipify-clang

Do not install the rocm-dkms package, it’s not needed on the recent kernels provided by Fedora 33. Do not install the devtoolset-7 environment it’s only required on RHEL, Fedora 33 already provides up to date compilers.

There is some differences in how RHEL8 and Fedora 33 handles python. This requires us to install rocminfo while ignoring dependencies:

$ dnf repoquery --location rocminfo
http://repo.radeon.com/rocm/centos8/rpm/rocminfo-1.4.0.1.rocm-rel-3.9-17-605b3a5.rpm
$ sudo rpm -Uvh --nodeps http://repo.radeon.com/rocm/centos8/rpm/rocminfo-1.4.0.1.rocm-rel-3.9-17-605b3a5.rpm

We also need to modify rocm_agent_enumerator to run on Fedora 33:

$ sudo sed -i 's/^#!.*/#!\/usr\/bin\/python/' /opt/rocm-3.9.0/bin/rocm_agent_enumerator

Now we can try compiling and running one of the samples:

$ cp /opt/rocm-3.9.0/hip/samples/0_Intro/square /tmp
$ cd /tmp/square
$ export PATH=/opt/rocm-3.9.0/bin:$PATH \
    ROCM_PATH=/opt/rocm-3.9.0 \
    HIP_PATH=/opt/rocm-3.9.0/hip 
$ hipconfig
$ make
/opt/rocm-3.9.0/hip/bin/hipify-perl square.cu > square.cpp
/opt/rocm-3.9.0/hip/bin/hipcc  square.cpp -o square.out
/opt/rocm-3.9.0/hip/bin/hipcc -use-staticlib  square.cpp -o square.out.static
$ ./square.out
info: running on device Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT]
info: allocate host mem (  7.63 MB)
info: allocate device mem (  7.63 MB)
info: copy Host2Device
info: launch 'vector_square' kernel
info: copy Device2Host
info: check result
PASSED!

Note HIP doesn’t seem to work if you are using a shell other than bash.

These are the packages I ended up installing from the ROCm RHEL8 repo:

$ dnf repository-packages ROCm list --installed
Installed Packages
comgr.x86_64               1.9.0.194_rocm_rel_3.9_17_0fa438b-1             @ROCm
hip-base.x86_64            3.9.20412_6d111f85-1                            @ROCm
hip-rocclr.x86_64          3.9.20412_6d111f85-1                            @ROCm
hip-samples.x86_64         3.9.20412_6d111f85-1                            @ROCm
hipblas.x86_64             0.36.0.438_17_e4d9e7b-1                         @ROCm
hipcub.x86_64              2.10.5.207_17_7bda2e4-1                         @ROCm
hipify-clang.x86_64        12.0.0-1                                        @ROCm
hipsparse.x86_64           1.9.4.306_17_c5e4633-1                          @ROCm
hsa-rocr-dev.x86_64        1.2.30900.0_rocm_rel_3.9_17_75f9b74a-1          @ROCm
hsakmt-roct.x86_64         20200924.0.55_mainline_20200924_0_gcd55f1f-1    @ROCm
hsakmt-roct-devel.x86_64   20200924.0.55_mainline_20200924_0_gcd55f1f-1    @ROCm
llvm-amdgpu.x86_64         12.0.dev-1                                      @ROCm
miopen-hip.x86_64          2.8.0.8181_17_e1e0f9cb-1                        @ROCm
rccl.x86_64                2.7.8.482_17_44fcde7-1                          @ROCm
rocblas.x86_64             2.30.0.2773_91e553c8-1                          @ROCm
rocfft.x86_64              1.0.7.941_17_e97ebb4-1                          @ROCm
rocm-clang-ocl.x86_64      0.5.0.64_rocm_rel_3.9_17_50fb51a-1              @ROCm
rocm-dbgapi.x86_64         0.36.0_rocm_rel_3.9_17-1                        @ROCm
rocm-debug-agent.x86_64    2.0.1_rocm_rel_3.9_17-1                         @ROCm
rocm-device-libs.x86_64    1.0.0.637_rocm_rel_3.9_17_db8c0c3-1             @ROCm
rocm-opencl.x86_64         3.6Beta_14_g0c40e05_rocm_rel_3.9_17-1           @ROCm
rocm-opencl-devel.x86_64   3.6Beta_14_g0c40e05_rocm_rel_3.9_17-1           @ROCm
rocm-utils.x86_64          3.9.0.30900-17.el8                              @ROCm
rocprim.x86_64             2.10.5.1099_17_fa69a09-1                        @ROCm
rocrand.x86_64             2.10.5.744_17_0728d21-1                         @ROCm
rocsparse.x86_64           1.17.6.851_17_a422ef5-1                         @ROCm
rocthrust.x86_64           2.10.5.807_17_a26200a-1                         @ROCm
roctracer-dev.x86_64       1.0.0-1                                         @ROCm

Building PyTorch with ROCm support for Navi 10 / 5700XT

Clone pytorch repository:

git clone --recursive https://github.com/pytorch/pytorch
cd pytorch

Install ROCm prerequisites:

$ sudo dnf install hipcub hipsparse hsakmt-roct-devel \
    miopen-hip rccl rocfft rocprim rocrand rocthrust roctracer-dev

Run “hipify” to prepare source code:

$ python tools/amd_build/build_amd.py

Build and install pytorch:

$ export PATH=/opt/rocm-3.9.0/bin:$PATH \
    ROCM_PATH=/opt/rocm-3.9.0 \
    HIP_PATH=/opt/rocm-3.9.0/hip 
$ export PYTORCH_ROCM_ARCH=gfx1010 # Navi 10
$ USE_ROCM=1 USE_DISTRIBUTED=0 python setup.py install --user

Currently the build succeeds for the gfx1010 (Navi 10, 5700XT) target, but pytorch fails to run. See https://github.com/ROCmSoftwarePlatform/pytorch/issues/718

Confirm working installation:

$ PYTORCH_TEST_WITH_ROCM=1 python test/run_test.py --verbose
python -c 'import torch; print(torch.rand(2,3).cuda())'

References: