Intel/AMD GPU telemetry in benchmark runs (hwmon power/temperature, amdgpu sysfs, Intel VRAM/utilization from DRM fdinfo via a minimal host-PID probe container), temperature for all GPUs, VRAM estimate for NVIDIA and Intel/AMD in the deployment form, /dev/dri group IDs added to Intel/AMD runtime containers, Intel llama.cpp presets seeded on first detection, ZES_ENABLE_SYSMAN=1 for the SYCL preset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ee6c623e2a
commit
e007a35143
16 files changed
+781
-98
No files matched your search
+71
-4
@@ -106,21 +106,46 @@ async function probeNvidia(c: DockerClient, image: string): Promise<{ gpus: Host
|
||||
}
|
||||
|
||||
/** Runs `nvidia-smi <args>` in a short-lived container (our own image) that gets every GPU; its output lines. */
|
||||
async function nvidiaSmi(c: DockerClient, image: string, args: string[]): Promise<string[]> {
|
||||
const created = await c.createContainer(`kaname-gpu-probe-${Date.now().toString(36)}`, {
|
||||
function nvidiaSmi(c: DockerClient, image: string, args: string[]): Promise<string[]> {
|
||||
return runProbe(c, {
|
||||
Image: image,
|
||||
Entrypoint: ["nvidia-smi"],
|
||||
Cmd: args,
|
||||
Env: ["NVIDIA_DRIVER_CAPABILITIES=utility"],
|
||||
Labels: { "kaname.managed": "true", "kaname.probe": "gpu" },
|
||||
HostConfig: { DeviceRequests: [{ Driver: "", Count: -1, Capabilities: [["gpu", "utility"]] }], NetworkMode: "none", Privileged: false },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Group IDs of the host's /dev/dri nodes (render, video), as a short-lived container with /dev/dri
|
||||
* sees them (Docker copies the host's owner and mode). Runtime containers get them as extra groups,
|
||||
* so images that don't run as root can open the GPU.
|
||||
*/
|
||||
async function probeDriGroups(c: DockerClient, image: string): Promise<number[]> {
|
||||
const lines = await runProbe(c, {
|
||||
Image: image,
|
||||
Entrypoint: ["sh", "-c", "stat -c '%n %g' /dev/dri/*"],
|
||||
Cmd: [],
|
||||
HostConfig: { Devices: [{ PathOnHost: "/dev/dri", PathInContainer: "/dev/dri", CgroupPermissions: "r" }], NetworkMode: "none", Privileged: false, ReadonlyRootfs: true },
|
||||
});
|
||||
return parseDriGroups(lines);
|
||||
}
|
||||
|
||||
/** "`/dev/dri/renderD128 993`" lines → the distinct non-root group IDs. */
|
||||
export function parseDriGroups(lines: string[]): number[] {
|
||||
const gids = lines.map((l) => l.trim().match(/^\/dev\/dri\/\S+\s+(\d+)$/)?.[1]).filter((g): g is string => !!g).map(Number);
|
||||
return [...new Set(gids.filter((g) => g > 0))].sort((a, b) => a - b);
|
||||
}
|
||||
|
||||
/** Runs a short-lived probe container from our own image and returns its output lines. */
|
||||
async function runProbe(c: DockerClient, spec: { Image: string; Entrypoint: string[]; Cmd: string[]; Env?: string[]; HostConfig: Record<string, unknown> }): Promise<string[]> {
|
||||
const created = await c.createContainer(`kaname-gpu-probe-${Date.now().toString(36)}`, { ...spec, Labels: { "kaname.managed": "true", "kaname.probe": "gpu" } });
|
||||
try {
|
||||
const lines: string[] = [];
|
||||
await c.startContainer(created.Id);
|
||||
await c.followLogs(created.Id, (_s, line) => lines.push(line), { tail: "all", signal: AbortSignal.timeout(30_000) });
|
||||
const st = await c.containerState(created.Id);
|
||||
if (st && st.ExitCode !== 0) throw new Error(`nvidia-smi exited with ${st.ExitCode}: ${lines.slice(-3).join(" ")}`);
|
||||
if (st && st.ExitCode !== 0) throw new Error(`${spec.Entrypoint[0]} exited with ${st.ExitCode}: ${lines.slice(-3).join(" ")}`);
|
||||
return lines;
|
||||
} finally {
|
||||
await c.removeContainer(created.Id).catch(() => {});
|
||||
@@ -161,6 +186,45 @@ async function seedGpuPresets() {
|
||||
await d.insert(settings).values({ key: CUDA_SEEDED_KEY, value: true }).onConflictDoNothing();
|
||||
}
|
||||
|
||||
const INTEL_SEEDED_KEY = "runtimes.intelPresetSeeded";
|
||||
|
||||
/** The first time an Intel GPU shows up, add the llama.cpp runtimes for it (SYCL and Vulkan, once). */
|
||||
async function seedIntelPresets() {
|
||||
const d = db();
|
||||
if (await d.query.settings.findFirst({ where: eq(settings.key, INTEL_SEEDED_KEY) })) return;
|
||||
for (const p of RUNTIME_PRESETS.filter((x) => x.id === "llama.cpp-intel" || x.id === "llama.cpp-vulkan")) {
|
||||
await d.insert(runtimes).values({
|
||||
name: p.name,
|
||||
engine: p.engine,
|
||||
accelerator: p.accelerator ?? "dri",
|
||||
image: p.image,
|
||||
description: p.description ?? null,
|
||||
env: p.env ?? {},
|
||||
devices: p.devices ?? [],
|
||||
preset: p.id,
|
||||
});
|
||||
log.info(`Intel GPU found: added the "${p.name}" runtime`);
|
||||
}
|
||||
await d.insert(settings).values({ key: INTEL_SEEDED_KEY, value: true }).onConflictDoNothing();
|
||||
}
|
||||
|
||||
let driCache: { at: number; gids: number[] } | null = null;
|
||||
|
||||
/** Render/video group IDs of /dev/dri, re-checked hourly while there are Intel or AMD GPUs. */
|
||||
async function driGroups(c: DockerClient, image: string | null, hardware: HostHardware | null): Promise<number[] | undefined> {
|
||||
if (!image || !hardware?.gpus.some((g) => g.vendor !== "nvidia")) return undefined;
|
||||
if (!driCache || Date.now() - driCache.at > GPU_PROBE_MS) {
|
||||
try {
|
||||
driCache = { at: Date.now(), gids: await probeDriGroups(c, image) };
|
||||
log.info(`/dev/dri groups: ${driCache.gids.join(", ") || "none besides root"}`);
|
||||
} catch (err) {
|
||||
driCache = { at: Date.now(), gids: [] };
|
||||
log.warn(`/dev/dri group check failed: ${message(err)}`);
|
||||
}
|
||||
}
|
||||
return driCache.gids;
|
||||
}
|
||||
|
||||
/** Report Docker connectivity and host facts in worker_state (null when DOCKER_HOST isn't set). */
|
||||
export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
const c = docker();
|
||||
@@ -181,6 +245,8 @@ export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
log.warn(`hardware detection failed: ${message(err)}`);
|
||||
return null;
|
||||
});
|
||||
if (hardware?.gpus.some((g) => g.vendor === "intel")) await seedIntelPresets();
|
||||
const driGids = await driGroups(c, self.image, hardware);
|
||||
info = {
|
||||
connected: true,
|
||||
error: null,
|
||||
@@ -194,6 +260,7 @@ export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
modelsSource: self.modelsSource,
|
||||
...gpu,
|
||||
hardware,
|
||||
...(driGids ? { driGroups: driGids } : {}),
|
||||
};
|
||||
} catch (err) {
|
||||
info = {
|
||||
|
||||
Reference in new issue
Block a user