Skip to content

Commit 32ebc88

Browse files
committed
feat: integrate mesa-2404 content snap for Vulkan support and add gpu-device selection
Use the mesa-2404 content snap to provide Vulkan ICDs and Mesa GPU drivers instead of staging libvulkan1 directly. This ensures the Vulkan loader can discover driver JSON files inside the snap, fixing Vulkan initialization failures. Add a gpu-device snap setting (nvidia, intel, amd) that filters Vulkan ICDs via VK_LOADER_DRIVERS_SELECT, allowing users on multi-GPU systems to target a specific GPU (e.g. discrete NVIDIA over integrated Intel).
1 parent 039356f commit 32ebc88

4 files changed

Lines changed: 74 additions & 8 deletions

File tree

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ The snap automatically detects your GPU and selects the best backend:
3535
- **AMD GPUs** - Uses ROCm for optimal performance
3636
- **Other GPUs** - Uses Vulkan
3737

38+
### GPU Drivers (Vulkan)
39+
40+
Vulkan support is provided by the `mesa-2404` content snap, which is installed
41+
automatically. If it isn't connected, connect it manually:
42+
43+
```bash
44+
sudo snap connect lemonade-server:gpu-2404 mesa-2404:gpu-2404
45+
sudo snap restart lemonade-server.daemon
46+
```
47+
3848
### Enable ROCm Support (AMD GPUs)
3949

4050
For ROCm GPU acceleration on AMD hardware, connect the `process-control` interface:
@@ -113,6 +123,10 @@ sudo snap set lemonade-server ctx-size=32768
113123

114124
# Set optional llamacpp-args
115125
sudo snap set lemonade-server llamacpp-args="--no-mmap --flash-attn on"
126+
127+
# Select a specific GPU for Vulkan (default: auto-detect all)
128+
# Useful on multi-GPU systems to target a discrete GPU
129+
sudo snap set lemonade-server gpu-device=nvidia
116130
```
117131

118132
Changes take effect after the service restarts automatically.
@@ -124,6 +138,7 @@ Changes take effect after the service restarts automatically.
124138
| `log-level` | info | Log verbosity (debug, info, warn) |
125139
| `ctx-size` | 4096 | Context window size in tokens |
126140
| `llamacpp-args` | "" | Optional args to pass to llamacpp-server |
141+
| `gpu-device` | "" | Vulkan GPU filter: `nvidia`, `intel`, `amd`, or empty for all |
127142

128143
### Model cache location
129144

@@ -180,13 +195,20 @@ sudo journalctl -u snap.lemonade-server.daemon.service --no-pager -n 50
180195

181196
### GPU not detected
182197

183-
Ensure you have the proper GPU drivers installed:
198+
Ensure the `gpu-2404` interface is connected:
184199
```bash
185-
# For AMD GPUs
186-
sudo apt install mesa-vulkan-drivers
200+
sudo snap connect lemonade-server:gpu-2404 mesa-2404:gpu-2404
201+
sudo snap restart lemonade-server.daemon
202+
```
187203

188-
# Check Vulkan support
189-
vulkaninfo | head -20
204+
### Vulkan crashes on multi-GPU systems
205+
206+
On systems with multiple GPUs (e.g. Intel integrated + NVIDIA discrete), the
207+
Vulkan backend may default to the integrated GPU. Use `gpu-device` to select
208+
the discrete GPU:
209+
210+
```bash
211+
sudo snap set lemonade-server gpu-device=nvidia
190212
```
191213

192214
### ROCm not working (AMD GPUs)

scripts/lemonade-server-wrapper

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ export LEMONADE_LOG_LEVEL=${LEMONADE_LOG_LEVEL:-info}
1616
export LEMONADE_CTX_SIZE=${LEMONADE_CTX_SIZE:-4096}
1717
export LEMONADE_LLAMACPP_ARGS=${LEMONADE_LLAMACPP_ARGS:-""}
1818

19+
# GPU device selection via Vulkan loader driver filtering
20+
LEMONADE_GPU_DEVICE=$(snapctl get gpu-device)
21+
if [ -n "$LEMONADE_GPU_DEVICE" ]; then
22+
case "$LEMONADE_GPU_DEVICE" in
23+
nvidia)
24+
export VK_LOADER_DRIVERS_SELECT='*nvidia*'
25+
echo "[Lemonade Wrapper] GPU device filter: nvidia only" >&2
26+
;;
27+
intel)
28+
export VK_LOADER_DRIVERS_SELECT='*intel*'
29+
echo "[Lemonade Wrapper] GPU device filter: intel only" >&2
30+
;;
31+
amd)
32+
export VK_LOADER_DRIVERS_SELECT='*radeon*'
33+
echo "[Lemonade Wrapper] GPU device filter: amd only" >&2
34+
;;
35+
*)
36+
echo "[Lemonade Wrapper] Unknown gpu-device value: $LEMONADE_GPU_DEVICE (ignoring)" >&2
37+
;;
38+
esac
39+
fi
40+
1941
BACKEND="vulkan" # default
2042

2143
# Supported ROCm architectures (must have matching backend binaries)

snap/hooks/install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ snapctl set ip-address=127.0.0.1
66
snapctl set log-level=info
77
snapctl set ctx-size=4096
88
snapctl set llamacpp-args=""
9+
snapctl set gpu-device=""

snap/snapcraft.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ layout:
5050
/usr/share/lemonade-server:
5151
symlink: $SNAP/usr/share/lemonade-server
5252

53+
plugs:
54+
gpu-2404:
55+
interface: content
56+
target: $SNAP/gpu-2404
57+
default-provider: mesa-2404
58+
5359
slots:
5460
# Adds a pseudo content interface to allow clients to express their
5561
# runtime dependency on lemonade-server
@@ -62,30 +68,35 @@ slots:
6268
apps:
6369
metrics:
6470
command: bin/metrics
71+
command-chain: [bin/gpu-2404-wrapper]
6572
plugs:
6673
- home
6774
- removable-media
6875
- network
6976
- network-bind
7077
- opengl
78+
- gpu-2404
7179
- process-control
7280
- hardware-observe
7381
- system-observe
7482
lemonade-server:
7583
command: usr/bin/lemonade-server
84+
command-chain: [bin/gpu-2404-wrapper]
7685
plugs:
7786
- home
7887
- removable-media
7988
- network
8089
- network-bind
8190
- opengl
91+
- gpu-2404
8292
- hardware-observe
8393
- system-observe
8494
environment:
85-
LD_LIBRARY_PATH: "$SNAP/usr/share/lemonade-server:$SNAP/usr/lib/llamacpp/vulkan:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/lib/x86_64-linux-gnu:/var/lib/snapd/lib/gl${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
95+
LD_LIBRARY_PATH: "$SNAP/usr/share/lemonade-server:$SNAP_COMMON/cache/lemonade/bin/llamacpp/vulka n:$SNAP_COMMON/cache/lemonade/bin/whispercpp/vulkan:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/lib/x86_64-linux-gnu:/var/lib/snapd/lib/gl${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
8696
PATH: "$SNAP/usr/bin:$PATH"
8797
daemon:
8898
command: bin/lemonade-server-wrapper serve
99+
command-chain: [bin/gpu-2404-wrapper]
89100
daemon: simple
90101
install-mode: enable
91102
restart-condition: on-failure
@@ -96,11 +107,12 @@ apps:
96107
- network
97108
- network-bind
98109
- opengl
110+
- gpu-2404
99111
- process-control
100112
- hardware-observe
101113
- system-observe
102114
environment:
103-
LD_LIBRARY_PATH: "$SNAP/usr/share/lemonade-server:$SNAP/usr/lib/llamacpp/vulkan:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/lib/x86_64-linux-gnu:/var/lib/snapd/lib/gl${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
115+
LD_LIBRARY_PATH: "$SNAP/usr/share/lemonade-server:$SNAP_COMMON/cache/lemonade/bin/llamacpp/vulka n:$SNAP_COMMON/cache/lemonade/bin/whispercpp/vulkan:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/lib/x86_64-linux-gnu:/var/lib/snapd/lib/gl${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
104116
PATH: "$SNAP/usr/bin:$PATH"
105117
HOME: "$SNAP_COMMON"
106118
LEMONADE_CACHE_DIR: "$SNAP_COMMON/cache/lemonade"
@@ -119,7 +131,6 @@ parts:
119131
- unzip # For extracting backends at runtime
120132
- libdrm-amdgpu1 # SD backends need this at runtime
121133
- libnuma1 # SD backends need this at runtime
122-
- libvulkan1
123134
override-build: |
124135
set +u # For unbound variables
125136
# workaround for build.snapcraft.io builds
@@ -160,6 +171,16 @@ parts:
160171
override-build: |
161172
craftctl default
162173
174+
gpu-snap:
175+
after: [lemonade-server, deps]
176+
source: https://github.com/canonical/gpu-snap.git
177+
plugin: dump
178+
override-prime: |
179+
craftctl default
180+
${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404
181+
prime:
182+
- bin/gpu-2404-wrapper
183+
163184
scripts:
164185
plugin: dump
165186
source: scripts/

0 commit comments

Comments
 (0)