Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AMD GPU #30

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ storage, etc).
go install github.com/qubesome/cli/cmd/qubesome@latest
```

##### For Tumbleweed users
##### For Leap and Tumbleweed users
```
zypper install -y qubesome
```
Expand Down
8 changes: 3 additions & 5 deletions internal/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func Start(runner string, profile *types.Profile, cfg *types.Config) (err error)
go images.PreemptWorkloadImages(binary, cfg)

if profile.Gpus != "" {
if !gpu.Supported() {
if _, ok := gpu.Supported(runner); !ok {
profile.Gpus = ""
dbus.NotifyOrLog("qubesome error", "GPU support was not detected, disabling it for qubesome")
}
Expand Down Expand Up @@ -503,10 +503,8 @@ func createNewDisplay(bin string, ca, cert, key []byte, profile *types.Profile,
dockerArgs = append(dockerArgs, "-v="+xdgRuntimeDir+":/run/user/1000")
}
if profile.HostAccess.Gpus != "" {
if strings.HasSuffix(bin, "podman") {
dockerArgs = append(dockerArgs, "--device=nvidia.com/gpu=all")
} else {
dockerArgs = append(dockerArgs, "--gpus", profile.HostAccess.Gpus)
if gpus, ok := gpu.Supported(profile.Runner); ok {
dockerArgs = append(dockerArgs, gpus)
}
}

Expand Down
16 changes: 7 additions & 9 deletions internal/runners/docker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func Run(ew types.EffectiveWorkload) error {
return fmt.Errorf("failed to get named devices: %w", err)
}

if wl.HostAccess.Gpus != "" {
if !gpu.Supported() {
wl.HostAccess.Gpus = ""
dbus.NotifyOrLog("qubesome error", "GPU support was not detected, disabling it for qubesome")
}
}

var paths []string
// Mount localtime into container. This file may be a symlink, if so,
// mount the underlying file as well.
Expand Down Expand Up @@ -79,8 +72,13 @@ func Run(ew types.EffectiveWorkload) error {
}

if wl.HostAccess.Gpus != "" {
args = append(args, "--gpus", wl.HostAccess.Gpus)
args = append(args, "--runtime=nvidia")
gpu, ok := gpu.Supported("podman")
if !ok {
wl.HostAccess.Gpus = ""
dbus.NotifyOrLog("qubesome error", "GPU support was not detected, disabling it for qubesome")
} else {
args = append(args, gpu)
}
}

for _, cap := range wl.HostAccess.CapsAdd {
Expand Down
15 changes: 7 additions & 8 deletions internal/runners/podman/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func Run(ew types.EffectiveWorkload) error {
return fmt.Errorf("failed to get named devices: %w", err)
}

if wl.HostAccess.Gpus != "" {
if !gpu.Supported() {
wl.HostAccess.Gpus = ""
dbus.NotifyOrLog("qubesome error", "GPU support was not detected, disabling it for qubesome")
}
}

var paths []string
// Mount localtime into container. This file may be a symlink, if so,
// mount the underlying file as well.
Expand Down Expand Up @@ -82,7 +75,13 @@ func Run(ew types.EffectiveWorkload) error {
}

if wl.HostAccess.Gpus != "" {
args = append(args, "--device=nvidia.com/gpu=all")
gpu, ok := gpu.Supported("podman")
if !ok {
wl.HostAccess.Gpus = ""
dbus.NotifyOrLog("qubesome error", "GPU support was not detected, disabling it for qubesome")
} else {
args = append(args, gpu)
}
}

for _, cap := range wl.HostAccess.CapsAdd {
Expand Down
21 changes: 16 additions & 5 deletions internal/util/gpu/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ package gpu

import "os/exec"

// Supported checks whether nvidia gpu sharing is supported by the system.
// Supported checks whether GPU sharing is supported by the system, based
// on either NVidia or AMD toolkits being instead.
//
// At present it only checks whether nvidia-container-toolkit is in the PATH.
// At present it only checks whether nvidia-container-toolkit or
// rocm-smi are in the PATH.
// In the future, it should attempt to run a container to confirm it is
// properly configured and useable.
func Supported() bool {
path, err := exec.LookPath("nvidia-container-toolkit")
return path != "" && err == nil
func Supported(runner string) (string, bool) {
if path, _ := exec.LookPath("nvidia-container-toolkit"); path != "" {
if runner == "podman" {
return "--device=nvidia.com/gpu=all", true
}
return "--gpus=all", true
}
// AMD GPU.
if path, _ := exec.LookPath("rocm-smi"); path != "" {
return "--device=/dev/kfd", true
}
return "", false
}
Loading