9db4bdbad6
* broad lint fixes to sidestep CI scope glitch * runner: Remove CGO engines, use llama-server exclusively for GGML models Remove the vendored GGML and llama.cpp backend, CGO runner, Go model implementations, and sample. llama-server (built from upstream llama.cpp via FetchContent) is now the sole inference engine for GGUF-based models. (Safetensor based models continue to run on the new MLX engine.) This allows us to more rapidly pick up new capabilities and fixes from llama.cpp as they come out. On windows this now requires recent AMD driver versions to support ROCm v7 as llama.cpp currently does not support building against v6. * llama/compat: load Ollama-format GGUFs in llama-server Squashed from upstream/jmorganca/llama-compat on 2026-04-29. Source tip:0c33775d37. Original source commits: -25223160dllama/compat: add in-memory shim so llama-server can load Ollama-format GGUFs -7449b539allm,server: route Ollama-format gemma3 blobs through llama/compat -436f2e2b1llama/compat: make patch-apply idempotent -8c2c9d4c8llama/compat: extend gemma3 handler to cover 1B and 270M blobs -021389f7bllama/compat: shrink clip.cpp injection from 18 lines to 1 -61b367ec2llama/compat: shrink patch to pure call-site hooks (34 -> 20 lines) -36049361cllama/compat: simplify shim (gemma3-tested) -8fa664865llama/compat: add qwen35moe text handler -db0c74530llama/compat: add qwen35moe vision (clip) support -2a388da77llama/compat: split shared infra into a util TU -9a69a17dcllama/compat: document non-public API dependencies -d0f38a915llama/compat: add gpt-oss and lfm2 handlers -086071822llama/compat: add mistral3 text handler (vision TODO) -63bde9ff7llama/compat: add mistral3 vision (clip) support -3a57b89d5llama/compat: apply LLaMA RoPE permute to mistral3 vision Q/K -99cb87439llama/compat: add qwen35, gemma4, deepseek-ocr handlers -2c7850dballama/compat: add nemotron_h_moe handler (latent FFN + MTP skip) -9e3b54225llama/compat: add llama4 text + clip handlers -034fee349llama/compat: add gemma4 clip handler (gemma4v projector) -9945c5a93server: remove dhiltgen/* compat redirect table -5d4539101llama/compat: rewrite gemma4 tokenizer model to BPE -7e0765327llama/compat: add glm-ocr text handler + text-loader load-op hook -f1bd1a25allama/compat: add glm-ocr clip handler (glm4v projector) -4b5cf3420llama/compat: collapse text-loader hook back to one new patch line -eb4ecf4fcllama/compat: extend gemma4 clip handler to gemma4a (audio) -a23a5e76fllama/compat: fix gemma4a per-block norm tensor mapping -cd2dcaff4llama/compat: add embeddinggemma handler -1ce8a6b26llama/compat: add qwen3-vl + qwen2.5-vl handlers -fd98ffa1ellama/compat: add gemma3n + glm4moelite handlers -cc7bdf0bcllama/compat: handle null buft in maybe_load_tensor -0c33775d3llama/compat: disable mmap when load_op transforms text-side tensors * refine implementation * ci: fix windows MLX build * ci: fix windows llama-server build * ci: fix windows rocm build * ci: windows mlx tuning Shorten long-tail on build, and get OllamaSetup.exe back under 2g limit * ci: fix windows dependencies * win: fix dependency gathering * disable openmp * win: arm64 cross-compile build also DRY out CI steps * scheduler improvements * ci: improvements from #15982 * win: favor ninja for faster developer builds * win: fix build * win: fix arm64 cross-compile * win: avoid spaces in compiler path * misc discovery fixes, and bos handling * lint fixes * win: fix arm cross-compile build/CI bugs * llama.cpp update * win: handle multiple CRT dirs * vulkan: add windows iGPU detection * fix creation bugs for patched models, other refactoring work * tune batch size for better performance * ci and lint fixes * fix repeat_last_n bug * build: revamp build for better developer UX * amd, sampler, qwen3next fixes * version bump * fix mlx build * revamp GPU discovery Scanning the output of llama-server is turning out to be too error prone across llama.cpp updates, so this switches to a thin dynamic library load against the bundled GGML libraries so more details can be gathered from the API. * version bump * missing file * ci: fix cache miss on rocm build * refine vulkan dep handling * fix ps reporting bug on full GPU load * improve cmake wiring for customized local builds * version bump * docker build arg cleanup * improve windows exit error logs * fix community gemma4 support and ci flakes * fix mlx unit test * tighten up ps logic to avoid double counting fit log lines * version bump * fix ps view for full gpu layer offload * add MTP wiring for llama-server and create with GGUFs * pick best template by capabilities * version bump * ci: harden apt repos * remove unused cpu core discovery * adjust batch default logic to reduce OOMs * support larger tool calls * fix audio support, template show * qwen35 mtp patch support * flesh out dtypes * rocm deps * version bump * lint fix * block broken gfx1150 on windows * fix qwen3.5 moe mtp tensors in patch * mmproj oom fallback and vulkan on by default * qwen MTP compat fix * version bump * ci: fix WoA cross-compile * ci: workaround ui tool in cross-compile * version bump * win: enable OpenMP for CPU builds * build: improve developer UX * ci: windows path workaround for CPU build * win: fix WoA dependencies * win: fix large offset reads for mmproj patched loads * version bump * fix vulkan dup detection * add OLLAMA_IGPU_ENABLE and largely disable iGPUs by default * opt-in MTP, win large offset, integraton fixes * fix unit test scheduler interaction hang * fix multi-gpu filtering * version bump * review comments * fix thinking level * fix linux rocm ordering and granite 3.3 template * version bump * ci fix - non-shallow MLX checkout * bypass linux sysfs unit test on windows --------- Co-authored-by: jmorganca <jmorganca@gmail.com>
516 lines
16 KiB
Go
516 lines
16 KiB
Go
package discover
|
|
|
|
import (
|
|
"io"
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/ollama/ollama/logutil"
|
|
"github.com/ollama/ollama/ml"
|
|
)
|
|
|
|
func TestLlamaServerDiscovery(t *testing.T) {
|
|
originalProbe := probeLlamaServerVulkanDevices
|
|
probeLlamaServerVulkanDevices = func(_ []string) ([]vulkanPhysicalDevice, error) {
|
|
return nil, errWindowsVulkanProbeUnsupported
|
|
}
|
|
t.Cleanup(func() {
|
|
probeLlamaServerVulkanDevices = originalProbe
|
|
})
|
|
|
|
t.Run("output only trace", func(t *testing.T) {
|
|
original := slog.Default()
|
|
t.Cleanup(func() {
|
|
slog.SetDefault(original)
|
|
})
|
|
|
|
slog.SetDefault(logutil.NewLogger(io.Discard, slog.LevelDebug))
|
|
if got := llamaServerDiscoveryOutput(t.Context()); got != io.Discard {
|
|
t.Fatal("debug logging should discard raw llama-server discovery output")
|
|
}
|
|
|
|
slog.SetDefault(logutil.NewLogger(io.Discard, logutil.LevelTrace))
|
|
if got := llamaServerDiscoveryOutput(t.Context()); got == io.Discard {
|
|
t.Fatal("trace logging should emit raw llama-server discovery output")
|
|
}
|
|
})
|
|
|
|
t.Run("parse devices", func(t *testing.T) {
|
|
type wantDevice struct {
|
|
name string
|
|
library string
|
|
totalMiB uint64
|
|
compute string
|
|
driver string
|
|
gfxTarget string
|
|
checkIntegrated bool
|
|
integrated bool
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
output string
|
|
libDirs []string
|
|
want []wantDevice
|
|
}{
|
|
{
|
|
name: "NVIDIA CUDA",
|
|
output: `load_backend: loaded CUDA backend from /lib/ollama/cuda_v12/libggml-cuda.so
|
|
Available devices:
|
|
NVIDIA GeForce RTX 4090: NVIDIA CUDA (24564 MiB, 23592 MiB free)
|
|
`,
|
|
libDirs: []string{"/lib/ollama", "/lib/ollama/cuda_v12"},
|
|
want: []wantDevice{{
|
|
name: "NVIDIA GeForce RTX 4090",
|
|
library: "CUDA",
|
|
totalMiB: 24564,
|
|
driver: "12.0",
|
|
}},
|
|
},
|
|
{
|
|
name: "Metal",
|
|
output: `Available devices:
|
|
Metal: Apple M3 Max (98304 MiB, 98303 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "Metal",
|
|
library: "Metal",
|
|
totalMiB: 98304,
|
|
}},
|
|
},
|
|
{
|
|
name: "ROCm with gfx target",
|
|
output: ` Device 0: AMD Radeon RX 6700 XT, gfx1031 (0x1031), VMM: no, Wave Size: 32, VRAM: 12272 MiB
|
|
Available devices:
|
|
ROCm0: AMD Radeon RX 6700 XT (12272 MiB, 12248 MiB free)
|
|
`,
|
|
libDirs: []string{"/lib/ollama", "/lib/ollama/rocm_v7_2"},
|
|
want: []wantDevice{{
|
|
name: "ROCm0",
|
|
library: "ROCm",
|
|
totalMiB: 12272,
|
|
compute: "gfx1031",
|
|
gfxTarget: "gfx1031",
|
|
}},
|
|
},
|
|
{
|
|
name: "multi GPU",
|
|
output: `Available devices:
|
|
CUDA0: NVIDIA GeForce RTX 4090 (24564 MiB, 23592 MiB free)
|
|
CUDA1: NVIDIA GeForce RTX 3060 (12288 MiB, 11500 MiB free)
|
|
`,
|
|
libDirs: []string{"/lib/ollama", "/lib/ollama/cuda_v12"},
|
|
want: []wantDevice{
|
|
{name: "CUDA0", library: "CUDA", totalMiB: 24564},
|
|
{name: "CUDA1", library: "CUDA", totalMiB: 12288},
|
|
},
|
|
},
|
|
{
|
|
name: "Vulkan UMA",
|
|
output: `ggml_vulkan: 0 = Intel(R) Graphics (Intel open-source Mesa driver) | uma: 1 | fp16: 1 | bf16: 0 | warp size: 32 | shared memory: 65536 | int dot: 1 | matrix cores: none
|
|
Available devices:
|
|
Vulkan0: Intel(R) Graphics (16384 MiB, 12288 MiB free)
|
|
`,
|
|
libDirs: []string{"/lib/ollama", "/lib/ollama/vulkan"},
|
|
want: []wantDevice{{
|
|
name: "Vulkan0",
|
|
library: "Vulkan",
|
|
totalMiB: 16384,
|
|
checkIntegrated: true,
|
|
integrated: true,
|
|
}},
|
|
},
|
|
{
|
|
name: "Vulkan without UMA metadata",
|
|
output: `Available devices:
|
|
Vulkan0: AMD Radeon(TM) Graphics (32768 MiB, 31000 MiB free)
|
|
`,
|
|
libDirs: []string{"/lib/ollama", "/lib/ollama/vulkan"},
|
|
want: []wantDevice{{
|
|
name: "Vulkan0",
|
|
library: "Vulkan",
|
|
totalMiB: 32768,
|
|
checkIntegrated: true,
|
|
}},
|
|
},
|
|
{
|
|
name: "CUDA device filtered by compiled archs",
|
|
output: `ggml_cuda_init: found 1 CUDA devices (Total VRAM: 6063 MiB):
|
|
Device 0: NVIDIA GeForce GTX 1060 6GB, compute capability 6.1, VMM: yes, VRAM: 6063 MiB
|
|
load_backend: loaded CUDA backend from /lib/ollama/cuda_v13/libggml-cuda.so
|
|
system_info: n_threads = 4 | CUDA : ARCHS = 750,800,860,890,900,1000,1030,1100,1200,1210 |
|
|
Available devices:
|
|
CUDA0: NVIDIA GeForce GTX 1060 6GB (6063 MiB, 5900 MiB free)
|
|
`,
|
|
libDirs: []string{"/lib/ollama", "/lib/ollama/cuda_v13"},
|
|
},
|
|
{
|
|
name: "CUDA device kept by compiled archs",
|
|
output: `ggml_cuda_init: found 1 CUDA devices (Total VRAM: 16379 MiB):
|
|
Device 0: NVIDIA GeForce RTX 4060 Ti, compute capability 8.9, VMM: yes, VRAM: 16379 MiB
|
|
system_info: n_threads = 16 | CUDA : ARCHS = 750,800,860,890,900,1000,1030,1100,1200,1210 |
|
|
Available devices:
|
|
CUDA0: NVIDIA GeForce RTX 4060 Ti (16379 MiB, 14900 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "CUDA0",
|
|
library: "CUDA",
|
|
totalMiB: 16379,
|
|
compute: "8.9",
|
|
}},
|
|
},
|
|
{
|
|
name: "CUDA without compiled archs fails open",
|
|
output: `ggml_cuda_init: found 1 CUDA devices (Total VRAM: 6063 MiB):
|
|
Device 0: NVIDIA GeForce GTX 1060 6GB, compute capability 6.1, VMM: yes, VRAM: 6063 MiB
|
|
Available devices:
|
|
CUDA0: NVIDIA GeForce GTX 1060 6GB (6063 MiB, 5900 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "CUDA0",
|
|
library: "CUDA",
|
|
totalMiB: 6063,
|
|
compute: "6.1",
|
|
}},
|
|
},
|
|
{
|
|
name: "CUDA without compute capability fails open",
|
|
output: `system_info: n_threads = 4 | CUDA : ARCHS = 750,800 |
|
|
Available devices:
|
|
CUDA0: Some Future GPU (8192 MiB, 8000 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "CUDA0",
|
|
library: "CUDA",
|
|
totalMiB: 8192,
|
|
}},
|
|
},
|
|
{
|
|
name: "CUDA mixed arch support",
|
|
output: `ggml_cuda_init: found 2 CUDA devices:
|
|
Device 0: NVIDIA GeForce GTX 1060, compute capability 6.1, VMM: yes, VRAM: 6063 MiB
|
|
Device 1: NVIDIA GeForce RTX 4060 Ti, compute capability 8.9, VMM: yes, VRAM: 16379 MiB
|
|
system_info: n_threads = 8 | CUDA : ARCHS = 750,800,860,890 |
|
|
Available devices:
|
|
CUDA0: NVIDIA GeForce GTX 1060 (6063 MiB, 5900 MiB free)
|
|
CUDA1: NVIDIA GeForce RTX 4060 Ti (16379 MiB, 14900 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "CUDA1",
|
|
library: "CUDA",
|
|
totalMiB: 16379,
|
|
compute: "8.9",
|
|
}},
|
|
},
|
|
{
|
|
name: "ROCm gfx target with xnack suffix",
|
|
output: `ggml_cuda_init: found 2 ROCm devices (Total VRAM: 32736 MiB):
|
|
Device 0: AMD Radeon RX 6800, gfx1030 (0x1030), VMM: no, Wave Size: 32, VRAM: 16368 MiB
|
|
Device 1: AMD Radeon Pro VII, gfx906:sramecc+:xnack- (0x906), VMM: no, Wave Size: 64, VRAM: 16368 MiB
|
|
Available devices:
|
|
ROCm0: AMD Radeon RX 6800 (16368 MiB, 16342 MiB free)
|
|
ROCm1: AMD Radeon Pro VII (16368 MiB, 16348 MiB free)
|
|
`,
|
|
want: []wantDevice{
|
|
{name: "ROCm0", library: "ROCm", totalMiB: 16368, compute: "gfx1030", gfxTarget: "gfx1030"},
|
|
{name: "ROCm1", library: "ROCm", totalMiB: 16368, compute: "gfx906", gfxTarget: "gfx906"},
|
|
},
|
|
},
|
|
{
|
|
name: "unknown library",
|
|
output: `Available devices:
|
|
Future0: Mystery Accelerator (8192 MiB, 8000 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "Future0",
|
|
library: "Mystery Accelerator",
|
|
totalMiB: 8192,
|
|
}},
|
|
},
|
|
{
|
|
name: "no devices",
|
|
output: "Available devices:\n",
|
|
},
|
|
{
|
|
name: "empty output",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.libDirs == nil {
|
|
tt.libDirs = []string{"/lib/ollama"}
|
|
}
|
|
devices := parseLlamaServerDevices(tt.output, tt.libDirs)
|
|
if len(devices) != len(tt.want) {
|
|
t.Fatalf("got %d devices, want %d", len(devices), len(tt.want))
|
|
}
|
|
for i, want := range tt.want {
|
|
got := devices[i]
|
|
if want.name != "" && got.Name != want.name {
|
|
t.Errorf("device %d name = %q, want %q", i, got.Name, want.name)
|
|
}
|
|
if want.library != "" && got.Library != want.library {
|
|
t.Errorf("device %d library = %q, want %q", i, got.Library, want.library)
|
|
}
|
|
if want.totalMiB > 0 && got.TotalMemory != want.totalMiB*1024*1024 {
|
|
t.Errorf("device %d total memory = %d, want %d MiB", i, got.TotalMemory, want.totalMiB)
|
|
}
|
|
if want.compute != "" && got.Compute() != want.compute {
|
|
t.Errorf("device %d compute = %q, want %q", i, got.Compute(), want.compute)
|
|
}
|
|
if want.driver != "" && got.Driver() != want.driver {
|
|
t.Errorf("device %d driver = %q, want %q", i, got.Driver(), want.driver)
|
|
}
|
|
if want.gfxTarget != "" && got.GFXTarget != want.gfxTarget {
|
|
t.Errorf("device %d gfx target = %q, want %q", i, got.GFXTarget, want.gfxTarget)
|
|
}
|
|
if want.checkIntegrated && got.Integrated != want.integrated {
|
|
t.Errorf("device %d integrated = %v, want %v", i, got.Integrated, want.integrated)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
t.Run("parse fixtures", func(t *testing.T) {
|
|
type wantDevice struct {
|
|
name string
|
|
library string
|
|
totalMiB uint64
|
|
compute string
|
|
gfxTarget string
|
|
integrated bool
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
output string
|
|
libDirs []string
|
|
want []wantDevice
|
|
wantSkip string
|
|
}{
|
|
{
|
|
name: "cuda mixed archs filters unsupported device",
|
|
output: `ggml_cuda_init: found 2 CUDA devices:
|
|
Device 0: NVIDIA GeForce GTX 1060, compute capability 6.1, VMM: yes, VRAM: 6063 MiB
|
|
Device 1: NVIDIA GeForce RTX 4060 Ti, compute capability 8.9, VMM: yes, VRAM: 16379 MiB
|
|
system_info: n_threads = 8 | CUDA : ARCHS = 750,800,860,890 |
|
|
Available devices:
|
|
CUDA0: NVIDIA GeForce GTX 1060 (6063 MiB, 5900 MiB free)
|
|
CUDA1: NVIDIA GeForce RTX 4060 Ti (16379 MiB, 14900 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "CUDA1",
|
|
library: "CUDA",
|
|
totalMiB: 16379,
|
|
compute: "8.9",
|
|
}},
|
|
},
|
|
{
|
|
name: "rocm gfx targets preserve suffix-free compute",
|
|
output: `ggml_cuda_init: found 2 ROCm devices (Total VRAM: 32736 MiB):
|
|
Device 0: AMD Radeon RX 6800, gfx1030 (0x1030), VMM: no, Wave Size: 32, VRAM: 16368 MiB
|
|
Device 1: AMD Radeon Pro VII, gfx906:sramecc+:xnack- (0x906), VMM: no, Wave Size: 64, VRAM: 16368 MiB
|
|
Available devices:
|
|
ROCm0: AMD Radeon RX 6800 (16368 MiB, 16342 MiB free)
|
|
ROCm1: AMD Radeon Pro VII (16368 MiB, 16348 MiB free)
|
|
`,
|
|
want: []wantDevice{
|
|
{name: "ROCm0", library: "ROCm", totalMiB: 16368, compute: "gfx1030", gfxTarget: "gfx1030"},
|
|
{name: "ROCm1", library: "ROCm", totalMiB: 16368, compute: "gfx906", gfxTarget: "gfx906"},
|
|
},
|
|
},
|
|
{
|
|
name: "vulkan uma marks integrated",
|
|
output: `ggml_vulkan: 0 = Intel(R) Graphics (Intel open-source Mesa driver) | uma: 1 | fp16: 1 | bf16: 0 | warp size: 32 | shared memory: 65536 | int dot: 1 | matrix cores: none
|
|
Available devices:
|
|
Vulkan0: Intel(R) Graphics (16384 MiB, 12288 MiB free)
|
|
`,
|
|
want: []wantDevice{{
|
|
name: "Vulkan0",
|
|
library: "Vulkan",
|
|
totalMiB: 16384,
|
|
integrated: true,
|
|
}},
|
|
},
|
|
{
|
|
name: "windows vulkan without uma stays unclassified",
|
|
output: `load_backend: loaded Vulkan backend from C:\ollama\lib\ollama\vulkan\ggml-vulkan.dll
|
|
Available devices:
|
|
Vulkan0: AMD Radeon(TM) Graphics (32768 MiB, 31000 MiB free)
|
|
Vulkan1: AMD Radeon RX 7900 XTX (24564 MiB, 23000 MiB free)
|
|
`,
|
|
want: []wantDevice{
|
|
{name: "Vulkan0", library: "Vulkan", totalMiB: 32768},
|
|
{name: "Vulkan1", library: "Vulkan", totalMiB: 24564},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
libDirs := tt.libDirs
|
|
if libDirs == nil {
|
|
libDirs = []string{"/lib/ollama"}
|
|
}
|
|
|
|
got := parseLlamaServerDevices(tt.output, libDirs)
|
|
if len(got) != len(tt.want) {
|
|
t.Fatalf("got %d devices, want %d", len(got), len(tt.want))
|
|
}
|
|
for i, want := range tt.want {
|
|
if got[i].Name != want.name {
|
|
t.Fatalf("device %d name = %q, want %q", i, got[i].Name, want.name)
|
|
}
|
|
if got[i].Library != want.library {
|
|
t.Fatalf("device %d library = %q, want %q", i, got[i].Library, want.library)
|
|
}
|
|
if got[i].TotalMemory != want.totalMiB*1024*1024 {
|
|
t.Fatalf("device %d total memory = %d, want %d MiB", i, got[i].TotalMemory, want.totalMiB)
|
|
}
|
|
if want.compute != "" && got[i].Compute() != want.compute {
|
|
t.Fatalf("device %d compute = %q, want %q", i, got[i].Compute(), want.compute)
|
|
}
|
|
if want.gfxTarget != "" && got[i].GFXTarget != want.gfxTarget {
|
|
t.Fatalf("device %d gfx target = %q, want %q", i, got[i].GFXTarget, want.gfxTarget)
|
|
}
|
|
if got[i].Integrated != want.integrated {
|
|
t.Fatalf("device %d integrated = %v, want %v", i, got[i].Integrated, want.integrated)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
t.Run("skips mismatched Vulkan native metadata", func(t *testing.T) {
|
|
output := `Available devices:
|
|
Vulkan0: Intel(R) UHD Graphics 770 (32768 MiB, 31000 MiB free)
|
|
`
|
|
nativeDevices := []nativeProbeDevice{{
|
|
Library: "Vulkan",
|
|
Index: 0,
|
|
IndexMatchesBackend: true,
|
|
Description: "NVIDIA GeForce RTX 4060 Ti",
|
|
DeviceID: "0000:05:00.0",
|
|
IntegratedKnown: true,
|
|
TotalMemory: 16107 * 1024 * 1024,
|
|
}}
|
|
|
|
devices := parseLlamaServerDevicesWithNative(output, []string{"/lib/ollama", "/lib/ollama/vulkan"}, nativeDevices)
|
|
if len(devices) != 1 {
|
|
t.Fatalf("got %d devices, want 1", len(devices))
|
|
}
|
|
if devices[0].PCIID != "" {
|
|
t.Fatalf("PCIID = %q, want empty", devices[0].PCIID)
|
|
}
|
|
if devices[0].Integrated {
|
|
t.Fatal("Integrated = true, want false")
|
|
}
|
|
})
|
|
|
|
t.Run("cuda runtime version", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "libcudart.so.12.8.90"), nil, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
major, minor, ok := cudaRuntimeVersion([]string{dir})
|
|
if !ok || major != 12 || minor != 8 {
|
|
t.Fatalf("cudaRuntimeVersion = %d.%d, %v, want 12.8, true", major, minor, ok)
|
|
}
|
|
|
|
major, minor, ok = cudaRuntimeVersion([]string{filepath.Join(t.TempDir(), "cuda_v13")})
|
|
if !ok || major != 13 || minor != 0 {
|
|
t.Fatalf("cudaRuntimeVersion fallback = %d.%d, %v, want 13.0, true", major, minor, ok)
|
|
}
|
|
})
|
|
|
|
t.Run("refine windows vulkan devices", func(t *testing.T) {
|
|
makeDevices := func() []ml.DeviceInfo {
|
|
return []ml.DeviceInfo{
|
|
{DeviceID: ml.DeviceID{ID: "0", Library: "Vulkan"}, Description: "AMD Radeon(TM) Graphics"},
|
|
{DeviceID: ml.DeviceID{ID: "1", Library: "Vulkan"}, Description: "AMD Radeon RX 7900 XTX"},
|
|
{DeviceID: ml.DeviceID{ID: "0", Library: "CUDA"}, Description: "NVIDIA GeForce RTX 4090"},
|
|
}
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
devices []ml.DeviceInfo
|
|
probed []vulkanPhysicalDevice
|
|
want []bool
|
|
applied bool
|
|
}{
|
|
{
|
|
name: "fills missing integrated bit",
|
|
probed: []vulkanPhysicalDevice{
|
|
{Name: "AMD Radeon(TM) Graphics", Integrated: true},
|
|
{Name: "AMD Radeon RX 7900 XTX", Integrated: false},
|
|
},
|
|
want: []bool{true, false, false},
|
|
applied: true,
|
|
},
|
|
{
|
|
name: "matches names when order differs",
|
|
probed: []vulkanPhysicalDevice{
|
|
{Name: "AMD Radeon RX 7900 XTX", Integrated: false},
|
|
{Name: "AMD Radeon(TM) Graphics", Integrated: true},
|
|
},
|
|
want: []bool{true, false, false},
|
|
applied: true,
|
|
},
|
|
{
|
|
name: "skips when names do not line up",
|
|
probed: []vulkanPhysicalDevice{
|
|
{Name: "Wrong GPU", Integrated: true},
|
|
{Name: "AMD Radeon RX 7900 XTX", Integrated: false},
|
|
},
|
|
want: []bool{false, false, false},
|
|
},
|
|
{
|
|
name: "skips when counts do not line up",
|
|
probed: []vulkanPhysicalDevice{{Name: "AMD Radeon(TM) Graphics", Integrated: true}},
|
|
want: []bool{false, false, false},
|
|
},
|
|
{
|
|
name: "overwrites stale classification",
|
|
devices: []ml.DeviceInfo{
|
|
{DeviceID: ml.DeviceID{ID: "0", Library: "Vulkan"}, Description: "AMD Radeon(TM) Graphics", Integrated: true},
|
|
{DeviceID: ml.DeviceID{ID: "1", Library: "Vulkan"}, Description: "AMD Radeon RX 7900 XTX"},
|
|
},
|
|
probed: []vulkanPhysicalDevice{
|
|
{Name: "AMD Radeon(TM) Graphics", Integrated: false},
|
|
{Name: "AMD Radeon RX 7900 XTX", Integrated: false},
|
|
},
|
|
want: []bool{false, false},
|
|
applied: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
devices := tt.devices
|
|
if devices == nil {
|
|
devices = makeDevices()
|
|
}
|
|
applied := applyWindowsVulkanRefinement(devices, tt.probed)
|
|
if applied != tt.applied {
|
|
t.Fatalf("applied = %v, want %v", applied, tt.applied)
|
|
}
|
|
got := devices
|
|
if len(got) != len(tt.want) {
|
|
t.Fatalf("got %d devices, want %d", len(got), len(tt.want))
|
|
}
|
|
for i, want := range tt.want {
|
|
if got[i].Integrated != want {
|
|
t.Fatalf("device %d integrated = %v, want %v", i, got[i].Integrated, want)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|