2019年2月9日土曜日

Building ROCm on Gentoo

ROCm is a platform to utilze AMD GPU for computing.The most of the components are open source. HIP which is a part of ROCm allows to compile CUDA source.


I found crypt-coin specialized RX470 sold so cheap and get one of them to play with. The article is a nice starting point to try ROCm on Gentoo Linux.
Here is how I built ROCm.

The article shares a portage overlay of hcc, hsa-rocr, and hsakmt-rocr. They helped me to understand the package organization and my overlay is based on it. I added some more overlays for hip related components here.
It is a big pitfall that the stripped binary does not work at all. So my ebuild disables strip.

Register my overlay

# emerge layman
enable the line of "overlay_defs" in /etc/layman/layman.cfg
# wget https://raw.githubusercontent.com/yTakatsukasa/misc/master/layman/yutetsu.xml -O /etc/layman/overlays/yutetsu.xml
# layman -a yutetsu

Install ROCm including HIP

 # emerge -va rocm-meta

Because hip includes full set of clang and llvm, building the entire package takes some time.

Install AMD GPU Driver

The linux kernel configuration may need some change to enable CONFIG_DRM_AMDGPU.
The location is Device -> Drivers -> Graphics support.
The driver requires some binary blob as a firmware. So you need to emerge sys-kernel/linux-firmware too.

udev setting for /dev permission

To let non-root user use the GPU, I created the following file /etc/udev/rules.d/50-hsa.rule. The setting below assumes that the computer is not shared by other users.

SUBSYSTEM=="kfd", GROUP="video", MODE="0666"
KERNEL=="card[0-9]*",   NAME="dri/%k", GROUP="video", MODE="0666"
KERNEL=="renderD*",   NAME="dri/%k", GROUP="video", MODE="0666"

If the following command works, your configuration seems OK. Note that rocm-smi command internally invokes sudo, your password will be asked.
$  /opt/rocm/bin/rocm-smi

========================        ROCm System Management Interface        ========================
================================================================================================
GPU   Temp   AvgPwr   SCLK    MCLK    PCLK           Fan     Perf    PwrCap   SCLK OD   MCLK OD  GPU%
0     22.0c  15.001W  1169Mhz 300Mhz  8.0GT/s, x16   36.86%  auto    122.0W   0%        0%       0%      
1     N/A    N/A      N/A     N/A     N/A            0%      N/A     N/A      N/A       N/A      N/A     
================================================================================================
========================               End of ROCm SMI Log              ========================

0 件のコメント:

コメントを投稿