How to build Ollama from source with a ROCm/HIP backend targeting the AMD RX 9070 XT (gfx1201) on WSL2, so it stops pegging your CPU at 100 % and actually uses the card you bought.
Out of the box, Ollama 0.23.1 falls back to CPU on the RX 9070 XT for two reasons:
gfx1201) is new enough that many prebuilt ROCm binaries don't include it as a target.
Additionally, the WSL2 GPU path is different from bare-metal Linux.
There is no /dev/kfd or /dev/dri
in WSL2. Instead, the GPU is exposed via /dev/dxg
(Microsoft's DirectX bridge), which ROCm must be told to use explicitly.
Kernel 6.6.x-microsoft-standard-WSL2 or later.
Same standard Adrenalin driver used by the WSL2 + ROCm setup. No WSL2-specific variant needed.
/opt/rocmTested with ROCm 7.2.1. Follow the WSL2 + ROCm survival guide first if you haven't installed it yet.
For the build artifacts. Bazel and CMake are not modest.
From WSL2 context, with the DXG detection envvar set:
HSA_ENABLE_DXG_DETECTION=1 HSA_OVERRIDE_GFX_VERSION=12.0.1 \ /opt/rocm/bin/rocminfo | grep -A5 "Agent 2"
You should see AMD Radeon RX 9070 XT listed.
sudo snap install go --classic go version
sudo apt install -y git build-essential gcc g++ \
rocm-dev hipblas-dev rocblas-dev python3-dev
cmake --version
# Need 3.21+
cd ~ git clone https://github.com/ollama/ollama cd ollama
Point CMake at your ROCm installation and set gfx1201 as the target:
cmake --preset "ROCm 6" \ -DAMDGPU_TARGETS="gfx1201" \ -DCMAKE_PREFIX_PATH="/opt/rocm-7.2.1;/opt/rocm"
You should see at the end:
-- HIP and hipBLAS found -- Configuring done -- Build files have been written to: /home/<user>/ollama/build
AMDGPU_TARGETS is deprecated warning is harmless — ignore it.cmake --build --preset "ROCm 6" -j$(nproc) 2>&1 | tee ~/ollama-build.log
A successful build ends with:
[100%] Linking HIP shared module .../libggml-hip.so [100%] Built target ggml-hip
go build -o ~/ollama/dist/ollama .
# Stop the running Ollama service sudo systemctl stop ollama # Back up the old binary (just in case) sudo cp /usr/local/bin/ollama /usr/local/bin/ollama.backup # Install the freshly built binary sudo cp ~/ollama/dist/ollama /usr/local/bin/ollama # Install the new ROCm/HIP backend libraries sudo cp ~/ollama/build/lib/ollama/libggml-hip.so /usr/local/lib/ollama/ sudo cp ~/ollama/build/lib/ollama/libggml-base.so* /usr/local/lib/ollama/
The WSL2 GPU path requires specific environment variables. Create a systemd override:
sudo mkdir -p /etc/systemd/system/ollama.service.d/ sudo nano /etc/systemd/system/ollama.service.d/override.conf
Paste the following:
[Service] Environment="HSA_ENABLE_DXG_DETECTION=1" Environment="HSA_OVERRIDE_GFX_VERSION=12.0.1" Environment="HIP_VISIBLE_DEVICES=0" Environment="HSA_ENABLE_SDMA=0" Environment="ROCM_PATH=/opt/rocm"
Save with Ctrl+O, Enter, Ctrl+X.
| Variable | Purpose |
|---|---|
| HSA_ENABLE_DXG_DETECTION=1 | Tells ROCm to find the GPU via /dev/dxg (WSL2's DirectX bridge) instead of /dev/kfd. |
| HSA_OVERRIDE_GFX_VERSION=12.0.1 | Forces ROCm to treat the GPU as gfx1201 (required for RX 9070 XT). |
| HIP_VISIBLE_DEVICES=0 | Selects the first GPU. |
| HSA_ENABLE_SDMA=0 | Disables SDMA — can cause issues in WSL2. |
| ROCM_PATH=/opt/rocm | Points to your ROCm installation. |
sudo systemctl daemon-reload
sudo systemctl start ollama
sleep 3
# Check that the GPU is detected
sudo journalctl -u ollama --since "1 minute ago" | grep -iE "hip|gpu|rocm|gfx"
You should see a line like:
inference compute id=GPU-d838d7edd6273f86 library=ROCm compute=gfx1201 description="AMD Radeon RX 9070 XT" total="15.8 GiB" available="11.3 GiB"
ollama run qwen3.6:latest "hello" ollama ps
Expected output:
NAME ID SIZE PROCESSOR CONTEXT qwen3.6:latest 07d35212591f 26 GB 58%/42% CPU/GPU 4096
cat > ~/rebuild-ollama.sh << 'EOF' #!/bin/bash cd ~/ollama git pull cmake --preset "ROCm 6" \ -DAMDGPU_TARGETS="gfx1201" \ -DCMAKE_PREFIX_PATH="/opt/rocm-7.2.1;/opt/rocm" cmake --build --preset "ROCm 6" -j$(nproc) go build -o ~/ollama/dist/ollama . sudo systemctl stop ollama sudo cp ~/ollama/dist/ollama /usr/local/bin/ollama sudo cp ~/ollama/build/lib/ollama/libggml-hip.so /usr/local/lib/ollama/ sudo cp ~/ollama/build/lib/ollama/libggml-base.so* /usr/local/lib/ollama/ sudo systemctl start ollama EOF chmod +x ~/rebuild-ollama.sh
Check which backend loaded:
sudo journalctl -u ollama --since "5 minutes ago" | grep -i "load_backend"
If it shows libggml-cpu-alderlake.so, the HIP library isn't being picked up. Confirm libggml-hip.so exists in /usr/local/lib/ollama/.
Expected on WSL2. The GPU is accessed via /dev/dxg. Confirm it exists:
ls -la /dev/dxg
If missing, run wsl --update from PowerShell (as Admin) and restart WSL2.
Add -DCMAKE_PREFIX_PATH="/opt/rocm-7.2.1;/opt/rocm" to your cmake command, and verify the hip config exists:
find /opt/rocm* -name "hip-config.cmake"
Also expected in WSL2 — rocm-smi uses the native Linux KFD driver which isn't present. Use rocminfo with HSA_ENABLE_DXG_DETECTION=1 instead to verify GPU detection.
PixInsight and other apps that use ROCm on this same WSL2 setup work
because they set HSA_ENABLE_DXG_DETECTION=1, which tells
ROCm's HSA runtime to find the GPU through Microsoft's
/dev/dxg DirectX bridge rather than the native Linux
/dev/kfd path.
The prebuilt Ollama binary never sets this, and also ships
without any ROCm backend compiled in — so building from source with
the correct gfx1201 target and adding the environment
variables is the complete fix.