Skip to content

Commit 0a0c2b8

Browse files
committed
Use Vulkan GPU inside container to run AI models
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 5ba59c5 commit 0a0c2b8

File tree

4 files changed

+31
-152
lines changed

4 files changed

+31
-152
lines changed

pkg/driver/krunkit/hack/install-vulkan-gpu.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

pkg/driver/krunkit/krunkit_driver_darwin_arm64.go

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package krunkit
55

66
import (
77
"context"
8-
_ "embed"
98
"errors"
109
"fmt"
1110
"net"
@@ -39,25 +38,9 @@ type LimaKrunkitDriver struct {
3938
krunkitWaitCh chan error
4039
}
4140

42-
type KrunkitOpts struct {
43-
GPUAccel *bool `yaml:"gpuAccel,omitempty"`
44-
}
45-
46-
func NewKrunkitOpts(cfg *limatype.LimaYAML) (*KrunkitOpts, error) {
47-
var krunkitOpts KrunkitOpts
48-
if err := limayaml.Convert(cfg.VMOpts[vmType], &krunkitOpts, "vmOpts.krunkit"); err != nil {
49-
return nil, err
50-
}
51-
52-
return &krunkitOpts, nil
53-
}
54-
5541
var (
5642
_ driver.Driver = (*LimaKrunkitDriver)(nil)
5743
vmType limatype.VMType = "krunkit"
58-
59-
//go:embed hack/install-vulkan-gpu.sh
60-
gpuProvisionScript string
6144
)
6245

6346
func New() *LimaKrunkitDriver {
@@ -188,17 +171,6 @@ func validateConfig(cfg *limatype.LimaYAML) error {
188171
return fmt.Errorf("field `mountType` must be %q or %q for krunkit driver, got %q", limatype.VIRTIOFS, limatype.REVSSHFS, *cfg.MountType)
189172
}
190173

191-
// If GPU acceleration is requested, ensure Fedora image/template is used
192-
krunkitOpts, err := NewKrunkitOpts(cfg)
193-
if err != nil {
194-
return err
195-
}
196-
if krunkitOpts.GPUAccel != nil && *krunkitOpts.GPUAccel {
197-
if !isFedoraConfigured(cfg) {
198-
logrus.Warn("gpuAccel: true requires a Fedora image (use a Fedora base template or image)")
199-
}
200-
}
201-
202174
return nil
203175
}
204176

@@ -231,52 +203,20 @@ func (l *LimaKrunkitDriver) FillConfig(_ context.Context, cfg *limatype.LimaYAML
231203

232204
cfg.VMType = ptr.Of(vmType)
233205

234-
krunkitOpts, err := NewKrunkitOpts(cfg)
235-
if err != nil {
236-
return err
237-
}
238-
239-
if krunkitOpts.GPUAccel == nil {
240-
krunkitOpts.GPUAccel = ptr.Of(false)
241-
}
242-
243-
if *krunkitOpts.GPUAccel {
244-
gpuInstallScript := limatype.Provision{
245-
Mode: limatype.ProvisionModeData,
246-
Script: ptr.Of(gpuProvisionScript),
247-
ProvisionData: limatype.ProvisionData{
248-
Content: ptr.Of(gpuProvisionScript),
249-
Path: ptr.Of("/usr/local/bin/install-vulkan-gpu.sh"),
250-
Permissions: ptr.Of("0755"),
251-
Overwrite: ptr.Of(false),
252-
Owner: cfg.User.Name,
253-
},
254-
}
255-
cfg.Provision = append(cfg.Provision, gpuInstallScript)
256-
cfg.Message = "To enable GPU support for krunkit, run the following command inside the VM:\n\033[32msudo install-vulkan-gpu.sh\033[0m\n"
257-
}
258-
259206
return validateConfig(cfg)
260207
}
261208

262209
func (l *LimaKrunkitDriver) BootScripts() (map[string][]byte, error) {
263-
// Override default reboot-if-required with a no-op because Fedora does not support this well and
264-
// takes a long time to start up.
265-
krunkitOpts, err := NewKrunkitOpts(l.Instance.Config)
266-
if err != nil {
267-
return nil, err
268-
}
269-
if krunkitOpts.GPUAccel == nil || !*krunkitOpts.GPUAccel {
270-
return nil, nil
271-
}
272-
scripts := map[string][]byte{
273-
"00-reboot-if-required.sh": []byte(`#!/bin/sh
210+
//Disabled by krunkit driver for Fedora to make boot time faster
211+
if isFedoraConfigured(l.Instance.Config) {
212+
return map[string][]byte{
213+
"00-reboot-if-required.sh": []byte(`#!/bin/sh
274214
set -eu
275-
# Disabled by krunkit driver
276215
exit 0
277216
`),
217+
}, nil
278218
}
279-
return scripts, nil
219+
return nil, nil
280220
}
281221

282222
func (l *LimaKrunkitDriver) Create(_ context.Context) error {

templates/experimental/krunkit.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

website/content/en/docs/config/vmtype/krunkit.md

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,59 +31,52 @@ go build -o <PREFIX>/libexec/lima/lima-driver-krunkit ./cmd/lima-driver-krunkit/
3131
limactl info # "vmTypes" should include "krunkit"
3232
```
3333

34-
3534
## Quick start
3635

37-
- Non‑GPU (general workloads)
38-
```bash
39-
limactl start default --vm-type=krunkit
40-
```
41-
42-
- GPU (Vulkan via Venus)
43-
- Recommended distro: Fedora 40+ (smoothest Mesa/Vulkan setup; uses COPR “slp/mesa-krunkit” for patched mesa-vulkan-drivers).
44-
- Start from the krunkit template and follow the logs to complete GPU setup.
36+
Start a krunkit VM with rootful containerd (required for granting containers access to `/dev/dri` and the Vulkan API):
4537

4638
{{< tabpane text=true >}}
4739
{{% tab header="CLI" %}}
4840
```bash
49-
# GPU (Vulkan via Venus on Fedora)
50-
limactl start template:experimental/krunkit
41+
limactl start default --vm-type=krunkit --containerd=system
42+
limactl shell default
5143
```
5244
{{% /tab %}}
5345
{{% tab header="YAML" %}}
5446
```yaml
5547
vmType: krunkit
5648

57-
# For AI workloads, at least 4GiB memory and 4 CPUs are recommended.
58-
memory: 4GiB
59-
cpus: 4
60-
arch: aarch64
61-
62-
# Fedora 40+ is preferred for Mesa & Vulkan (Venus) support
6349
base:
64-
- template://_images/fedora
65-
66-
mounts:
67-
- location: "~"
68-
writable: true
69-
70-
mountType: virtiofs
50+
- template://_images/ubuntu
51+
- template://_default/mounts
7152

72-
vmOpts:
73-
krunkit:
74-
gpuAccel: true
53+
containerd:
54+
system: true
7555
```
7656
{{% /tab %}}
7757
{{< /tabpane >}}
7858
79-
After the VM is READY, inside the VM:
59+
Run AI models with [`llama.cpp`](https://github.com/ggml-org/llama.cpp) in a container using `nerdctl`:
60+
61+
1) Place a `.gguf` model inside the VM, e.g. `~/models/YourModel.gguf` or download it from [Hugging Face](https://huggingface.co/models?library=gguf)
62+
63+
2) Launch the container with GPU device nodes and bind‑mount the model directory:
64+
65+
```bash
66+
sudo nerdctl run --rm -ti \
67+
--device /dev/dri \
68+
-v ~/models:/models \
69+
quay.io/slopezpa/fedora-vgpu-llama
70+
```
71+
72+
3) Inside the container, run llama.cpp:
73+
8074
```bash
81-
sudo install-vulkan-gpu.sh
75+
llama-cli -m /models/YourModel.gguf -b 512 -ngl 99 -p "Introduce yourself"
8276
```
8377

8478
## Notes and caveats
8579
- macOS Ventura or later on Apple Silicon is required.
86-
- GPU mode requires a Fedora image/template; Fedora 40+ recommended for Mesa/Vulkan (Venus).
87-
- To verify GPU/Vulkan in the guest, use tools like `vulkaninfo` after running the install script.
88-
- `Libkrun` and [`Ramalama`](https://github.com/containers/ramalama)(a tool that simplifies running AI models locally) use CPU inferencing as of **July 2, 2025** and are actively working to support GPU inferencing. [More info](https://developers.redhat.com/articles/2025/07/02/supercharging-ai-isolation-microvms-ramalama-libkrun#current_limitations_and_future_directions__gpu_enablement).
80+
- Rootful containerd (`--containerd=system`) is necessary to pass through /dev/dri to containers.
81+
- To verify GPU/Vulkan in the guest container, use tools like `vulkaninfo`.
8982
- Driver architecture details: see [Virtual Machine Drivers](../../dev/drivers).

0 commit comments

Comments
 (0)