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

have you tried with the TW repos instead of distrobox (Parts of AMD ROCm (HIP & others) are available on Tumbleweed)?
I’ve tried on my laptop and although it installs the packages Ollama doesn’t seem to detect HIP this way. Maybe there’s a package missing on the repos or my install

@digigan Hi and welcome to the Forum :smile:
Is your GPU supported? ollama/docs/gpu.md at main · ollama/ollama · GitHub

1 Like

Thank you @malcolmlewis! I’ve been a long time unregistered lurker :sweat_smile: and I’ve seen the amount of support you provide here, its really appreciated.

It’s supported (unofficially) through Zluda (related wiki PR Ollama 780M iGPU support) by using the HSA_OVERRIDE_GFX_VERSION env var. But I could only make it work through an Ubuntu box. Maybe it uses one of the ROCm packages that are missing for TW. I’m on a 7840u thinkpad and the UMA set to 8G instead of auto just in case.

@digigan I’ve been disappointed in AMD with their limited support, hence the move back to Nvidia, everything works out of the box. I have a separate setup with a Kubernetes compute node and a Nvidia Tesla P4, I run ollama and open-webui installed via helm :wink:

1 Like

I personally use a 3090 on my main rig, interested in finally going for 555 and the open kernel modules.
For laptops I always go for iGpus, I was actually surprised that now we can do inference acceleration with either Vulkan (slower for now but works on almost any modern setup) or ROCm even if the support is limited. Hopefully it’ll keep improving.

That’s why I stopped experimenting with native repos for ROCm. Last year, I borked my system multiple times to get Stable Diffusion working, but luckily I could recover with BTRFS snapshots.

I will wait for the major updates coming to SD-Forge and want to experiment with the newly released Flux model, but until then I just use my current setup, which is working flawlessly.

I guess, I will use Distrobox when forge is stable again, but I’ll see what changes in the wacky world until then.

PS: Do you quantize the models yourself? I could never figure out how to do it and therefore only used TheBloke’s pre-quantized models.

AMD is certainly not perfect, but back when I used NVIDIA I always had problems. Also with the huge blunder of Intel with their 13th and 14th gen CPUs, I feel like AMD is the last beacon of hope…

By digging deeper I’ve found that HIP under TW repo don’t create a rocm path but instead drop all hip files under /usr/bin:

> rpm -ql hip
/usr/bin/hipcc
/usr/bin/hipcc.pl
/usr/bin/hipcc_cmake_linker_helper
/usr/bin/hipconfig
/usr/bin/hipconfig.pl
/usr/bin/hipdemangleatp
/usr/bin/hipvars.pm
/usr/bin/roc-obj
/usr/bin/roc-obj-extract
/usr/bin/roc-obj-ls
/usr/lib64/.hipInfo
/usr/share/doc/packages/hip
/usr/share/doc/packages/hip/LICENSE.txt
/usr/share/hip
/usr/share/hip/version

Programs looking on hip default locations or using HIP_PATH would not work, instructions under Hip #Verify Installation do not match for TW’s packages.

Only inference, I use the pre quantized binaries. You can download most q4 directly through Ollama CLI. I’m kind of surprised of how well and fast the latest Gemma2:2b works on the laptop, reminds me of GPT 3.5, but this is one that you can fine-tune and integrate with any tool you want.
I personally haven’t found a “productive” use for them, other than simple code snippets that are usually not worth the time (through continue.dev). But I believe that with proper fine-tunes, knowledge bases and context it could be a nice help for surfing through documentation or finding things between documents by context, so I like to be able to run them early.

1 Like

I wanted to know if there are any updates regarding the installation of AMD / ROCm drivers in tumbleweed. I keep having problems in particular OpenCL with darktable is not working. The only way is RustCL. The same goes for blender, HIP is not available. I have followed all the thread and documentation but nothing, I will surely wrong in something.

Can anyone make / point me to a recap to have rocm / hip / opencl available in tumbleweed?

Sorry, I don’t use Darktable, but I heard a lot of problems with getting it to work under ROCm. I suggest starting a new thread, so people can help you better.

Regarding Blender – I haven’t tested the new update yet, but my method should still work, I think. I will check that in the coming weeks … kinda busy lately.

https://en.opensuse.org/SDB:AMD_GPGPU

Rusticl for OpenCL. Possibly Distrobox can help with ROCm, or virtual machine with Leap/Ubuntu.

@boredcollie and anyone else who wants to use Darktable with ROCm.
I found a strange issue, where Blender won’t start in Distrobox when I install Darktable. So therefore, here is an assembly file only for Darktable.

[darktable]
image=ubuntu:24.04
init=false
additional_packages="darktable"
init_hooks="apt update -y;"
init_hooks="apt upgrade -y;"
init_hooks="cd /tmp/ && wget https://repo.radeon.com/amdgpu-install/6.2/ubuntu/noble/amdgpu-install_6.2.60200-1_all.deb && apt install -y ./amdgpu-install_6.2.60200-1_all.deb && cd ~/;"
init_hooks="amdgpu-install --usecase=rocm --no-dkms -y;"
nvidia=false
pull=true
root=false
replace=true
start_now=true

Save it somewhere with the name distrobox.ini and then open the console in the same folder and run:

distrobox assemble create

Then, go to ~/local/share/applications and open darktable.desktop with Kate or any other text editor and overwrite everything with:

[Desktop Entry]
Categories=Distrobox;Graphics;Photography;GTK;
Comment=Organize and develop images from digital cameras
Exec=/usr/bin/distrobox enter darktable -- darktable
GenericName=Virtual Lighttable and Darkroom via Distroboxd
Icon=darktable
Keywords=distrobox;
MimeType=application/x-darktable;image/x-dcraw;image/x-adobe-dng;image/x-canon-cr2;image/x-canon-crw;image/x-fuji-raf;image/x-kodak-dcr;image/x-kodak-kdc;image/x-minolta-mrw;image/x-nikon-nef;image/x-nikon-nrw;image/x-olympus-orf;image/x-panasonic-rw;image/x-panasonic-rw2;image/x-pentax-pef;image/x-sony-arw;image/x-sony-sr2;image/x-sony-srf;image/jpeg;image/png;image/tiff;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-portable-floatmap;image/vnd.radiance;image/avif;image/x-canon-cr3;image/x-exr;image/aces;image/heif;image/heic;image/jp2;image/jxl;image/webp;image/qoi
Name=Darktable ROCm
NoDisplay=false
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
TryExec=/usr/bin/distrobox
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

Or just start the Distrobox manually:

distrobox enter darktable

Once you’re in, you can check if everything is working by running darktable-cltest

1 Like