ROCm / HIP cookbook for any distro! Tested with Blender and Stable Diffusion on Tumbleweed with AMD Radeon 7600

Hi all,

I finally had some time to write down my adventures of getting ROCm to work on my machine. I got it working a couple of months ago, but now an update borked something and I had to redo most steps, so I finally have a good step by step guide for any distro (hopefully).

If you don’t already know what ROCm is, why are you even reading this? :sweat_smile:
If you want to learn more, read this first

https://rocm.docs.amd.com/en/latest/rocm.html

Now, let’s get started with the guide.

The first step to the magic is to install Distrobox and Podman

sudo zypper in distrobox podman

Not sure if this is necessary, but it shouldn’t hurt.
Add yourself to the render and video group like so

sudo groupadd render
sudo groupadd video
sudo usermod -aG render,video $LOGNAME

After that you have to create an Ubuntu 22.04 distrobox and name it rocm

distrobox create -i ubuntu:22.04 -n rocm
distrobox enter rocm
sudo apt update
sudo apt upgrade
sudo apt install build-essential

Now install ROCm, but first change your direction to your Downloads folder.
Otherwise you will always wonder why you have a .deb file in your home folder

cd ~/Downloads

https://rocm.docs.amd.com/en/latest/deploy/linux/installer/install.html

Strangely the newest version (5.7.1) doesn’t work with Blender (4.0.1), so I write the instructions for ROCm version 5.6.1 (which I confirmed working while testing). Also you don’t need the pro driver, don’t listen to their LIES :wink:

sudo apt update
wget https://repo.radeon.com/amdgpu-install/5.6.1/ubuntu/jammy/amdgpu-install_5.6.50601-1_all.deb
sudo apt install ./amdgpu-install_5.6.50601-1_all.deb
amdgpu-install --usecase=rocm --no-dkms

Now you should have a working ROCm installation and can always access it by entering the distrobox. If you have a CPU with graphic capability (Intel / AMD Ryzen 7000 series), you should disable the integrated graphics in your BIOS. Otherwise the ROCm stack will get confused and choose your CPU as your primary agent.

To get back into the distrobox, type

distrobox enter rocm

To test if ROCm is working, you can use these cli tools

  • rocminfo
  • rocm-smi
  • clinfo

Now to the applications.

Blender

For Blender, I also had to install two more libraries

sudo apt install libxkbcommon0 libsm6

Then you should be good to go. In this guide I will use the Steam version of Blender

~/.local/share/Steam/steamapps/common/Blender/blender

Go to Edit > Preferences > System > HIP and select your GPU if it isn’t already.
Then go into the scene properties on the right and select Cycles as your Render Engine and GPU Compute as your Device. If Blender freezes you have to hard restart your PC and install a different version of ROCm.

Now if you want to, you can create a .desktop file in ~/.local/share/applications/ and name it blender.desktop
Open it with a text editor (Kate) and replace everything with

[Desktop Entry]
Categories=Distrobox;System;Utility
Comment[en_US]=via Ubuntu ROCm distrobox
Comment=via Ubuntu ROCm distrobox
Exec=/usr/bin/distrobox enter rocm -- ./blender
GenericName[en_US]=Start Blender from Steam
GenericName=Start Blender from Steam
Icon=blender
Keywords=distrobox;
MimeType=
Name[en_US]=Blender
Name=Blender
NoDisplay=false
Path=~/.local/share/Steam/steamapps/common/Blender/
StartupNotify=true
Terminal=true
TerminalOptions=
TryExec=/usr/bin/distrobox
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Change the Path, if you installed Blender differently.

Stable Diffusion

Optional library for better performance

sudo apt install libtcmalloc-minimal4

https://ubuntu.pkgs.org/22.04/ubuntu-main-amd64/libtcmalloc-minimal4_2.9.1-0ubuntu3_amd64.deb.html

Now we will install the Stable Diffusion web UI by Automatic1111

GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI

You can try to install a different web UI, but this is the only one I got working while testing.
First, install the dependencies

sudo apt install wget git python3 python3-venv libgl1 libglib2.0-0

Then clone the repo to your favorite folder. For me it’s

cd ~/Documents/Git
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui && cd stable-diffusion-webui

Open the file webui-user.sh and add this to the end. Uncomment appropriately

#git pull #update the web UI on every start
#export HSA_OVERRIDE_GFX_VERSION=11.0.0 #7000 series GPU
#export HSA_OVERRIDE_GFX_VERSION=10.3.0 #6000 series GPU
export COMMANDLINE_ARGS="--medvram --upcast-sampling --opt-sub-quad-attention" #look in the wiki for what you actually need

Command Line Arguments and Settings · AUTOMATIC1111/stable-diffusion-webui Wiki · GitHub

Now just start the webui and let it do it’s magic

./webui.sh

If you get a segmentation fault error, you have the wrong HSA_OVERRIDE_GFX_VERSION value. Search the internet for your GPU model and change the webui-user.sh file.

https://github.com/DaniAndTheWeb/sd-data-amd-gpu/blob/main/HSA_GFX_VERSION.MD

There is currently a strange error with an import in one of the pip libraries, which will be fixed with the next update I think. Here is what helped me.

[Bug]: ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor' torchvision 0.17 promblem · Issue #13985 · AUTOMATIC1111/stable-diffusion-webui · GitHub

If the link is down, this is what worked

sed -i 's/from torchvision.transforms.functional_tensor import rgb_to_grayscale/from torchvision.transforms.functional import rgb_to_grayscale/' venv/lib/python3.10/site-packages/basicsr/data/degradations.py

Again, you can create a .desktop file in ~/.local/share/applications/ and name it stable-diffusion.desktop
Open it with a text editor (Kate) and replace everything with

[Desktop Entry]
Categories=Distrobox;System;Utility
Comment[en_US]=via Ubuntu ROCm distrobox
Comment=via Ubuntu ROCm distrobox
Exec=/usr/bin/distrobox enter rocm -- ./webui.sh
GenericName[en_US]=Start Stable Diffusion in default browser
GenericName=Start Stable Diffusion in default browser
Icon=
Keywords=distrobox;
MimeType=
Name[en_US]=Stable Diffusion
Name=Stable Diffusion
NoDisplay=false
Path=~/Documents/Git/stable-diffusion-webui/
StartupNotify=true
Terminal=true
TerminalOptions=
TryExec=/usr/bin/distrobox
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Don’t forget to change the Path, if you installed Stable Diffusion differently.

Good luck :+1:

5 Likes

BTW, I used distrobox assemble to automate the process of setting this up (at least for Stable Diffusion, I didn’t integrate the blender instructions)

Just create a distrobox.ini file somewhere and paste this in.

[rocm]
image=ubuntu:22.04
init=false
additional_packages="build-essential libtcmalloc-minimal4 wget git python3 python3-venv libgl1 libglib2.0-0"
init_hooks="apt update -y;"
init_hooks="apt upgrade -y;"
init_hooks="cd ~/Downloads && wget https://repo.radeon.com/amdgpu-install/5.6.1/ubuntu/jammy/amdgpu-install_5.6.50601-1_all.deb && apt install -y ./amdgpu-install_5.6.50601-1_all.deb && rm amdgpu-install_5.6.50601-1_all.deb;"
init_hooks="amdgpu-install --usecase=rocm --no-dkms -y;"
nvidia=false
pull=true
root=false
replace=true
start_now=true

Then run distrobox assemble create

You’ll need to clone the git repo for the webui and create your .desktop file separately though. I didn’t want to assume the locations on those. But you can do that on the host rather than in the container anyway so it’s not really distrobox’s issue.

2 Likes

Welcome to the forum @Nitrousoxide :wave: and thanks for the contribution!

That assemble file looks really good.
I’ll use it whenever the ROCm requirements for Stable Diffusion change :smiley:

Also it’s nice to get some feedback, since I wasn’t quite sure this method would work for other people :sweat_smile:

Trying to follow your steps, there is no way to avoid an error after:

distrobox enter rocm
Error: unable to start container "b5a088db25f07512440d246a6085d75284dde9913ed2c597fd2111e9a5bc7c7f": crun: make `/home/myuser/.local/share/containers/storage/overlay/812bbb868ef918f6d0680f4243aaed08cb7b43575e3b95e89100ff074167573f/merged` private: Permission denied: OCI permission denied

I tried removing rocm container and redoing steps, but same result.

1 Like

I encountered a problem with Distrobox after a few updates (including BIOS). Basically it was a strange permission problem inside the container. The solution was to uninstall runc and in turn all of docker, because I am using podman with crun. Somehow having both installed caused some strange problem even though I made sure that distrobox used podman and podman used crun…

Anyway if you encounter the same problem and you don’t need docker just uninstall runc and it should fix itself. No idea why.

works great. and by now, rocm 6 supports radeon 6000 series gpus and will automatically detect iGPUs, so that any processing happens on dGPUs only.
Got ollama to run on my 6500 XT without needing to disable my 4700u’s iGPU.
had to run “export HSA_OVERRIDE_GFX_VERSION=10.3.0” before running ollama though.

1 Like

Oh, thanks for the info :+1:
Also thanks again to @Nitrousoxide for the assemble file. Works really great and I modified it to include all the pre-requisites for the programs I currently use, which are:

distrobox.ini

[rocm]
image=ubuntu:22.04
init=false
additional_packages="build-essential libtcmalloc-minimal4 wget git python3 python3-venv libgl1 libglib2.0-0 libxkbcommon0 libsm6"
init_hooks="apt update -y;"
init_hooks="apt upgrade -y;"
init_hooks="cd ~/Downloads && wget https://repo.radeon.com/amdgpu-install/6.0.2/ubuntu/jammy/amdgpu-install_6.0.60002-1_all.deb && apt install -y ./amdgpu-install_6.0.60002-1_all.deb && rm amdgpu-install_6.0.60002-1_all.deb;"
init_hooks="amdgpu-install --usecase=rocm --no-dkms -y;"
init_hooks="mkdir -p ~/miniconda3 && wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh && bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 && rm -rf ~/miniconda3/miniconda.sh"
nvidia=false
pull=true
root=false
replace=true
start_now=true