mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
- The image is Node 24 on Debian trixie with glvnd and X11's libraries (libxext6 libx11-6 libgl1 libegl1), without which NVIDIA's Vulkan driver (mounted by the container runtime) doesn't load or gives no vkCreateInstance (driver 610.57 on Modal's T4, A10G and A10). The entrypoint opens NVIDIA's driver when the host passed a GPU in, else Mesa's; WGPU_BACKEND=vulkan, and on the CPU EGL's vendors are hidden, since NVIDIA's EGL would hand wgpu an OpenGL adapter over llvmpipe. RAEA_CLOUD_DEVICE=gpu fails at start on no GPU; /v1/health says the device. - /v1/jobs takes a project as a tar and gives back what the render made (CL14); deploy/modal/raea_cloud.py runs it on a Modal GPU list (L4, else A10G, else T4), one container that sleeps after five idle minutes. - RAEA_CLOUD_GPU_URL on a CPU box sends raea render to the worker and lands its files back (CL15, image/raea.sh and server/offload.ts); deploy/k8s.gpu.yaml is such a worker. - test/smoke.sh: worker and box, ten checks, all pass on 0.1.1-rc3. On Modal, test/gpu/edit.tsx (576 lit blocks, 1080p, 90 frames): T4 156 s against llvmpipe on the same machine's 8 cores 203 s; a box on a Mac handed it to an A10 (119 s) and the MP4 came back.
70 lines
2.7 KiB
TypeScript
70 lines
2.7 KiB
TypeScript
// Which device raea renders on here (docs/cloud.feature CL13): the Vulkan devices this container sees, from
|
|
// `vulkaninfo --summary` with the environment raea runs with. raea's 3D goes through wgpu, which takes a GPU over the
|
|
// CPU, so it renders on the first device that isn't the CPU's; with none it renders on Mesa's llvmpipe (the CPU).
|
|
// The entrypoint has already pointed the Vulkan loader at the GPU's driver when one opened (VK_DRIVER_FILES).
|
|
|
|
import { execFileSync } from "node:child_process"
|
|
|
|
export interface Gpu {
|
|
name: string
|
|
type: "discrete" | "integrated" | "virtual" | "cpu" | "other"
|
|
driver: string
|
|
vendor: string
|
|
}
|
|
|
|
export interface Device {
|
|
/** where raea's renders run */
|
|
renders: "gpu" | "cpu"
|
|
/** the device they run on */
|
|
name: string
|
|
gpus: Gpu[]
|
|
/** NVIDIA's own report, when nvidia-smi is here: name, memory, driver */
|
|
nvidia?: string[]
|
|
}
|
|
|
|
/** The devices in `vulkaninfo --summary`'s output. */
|
|
export function parseSummary(text: string): Gpu[] {
|
|
const out: Gpu[] = []
|
|
for (const block of text.split(/^GPU\d+:\s*$/m).slice(1)) {
|
|
const field = (k: string) => new RegExp(`^\\s*${k}\\s*=\\s*(.*)$`, "m").exec(block)?.[1].trim() ?? ""
|
|
const t = field("deviceType").replace("PHYSICAL_DEVICE_TYPE_", "").toLowerCase()
|
|
out.push({
|
|
name: field("deviceName"),
|
|
type: t === "discrete_gpu" ? "discrete" : t === "integrated_gpu" ? "integrated" : t === "virtual_gpu" ? "virtual" : t === "cpu" ? "cpu" : "other",
|
|
driver: [field("driverName"), field("driverInfo")].filter(Boolean).join(" "),
|
|
vendor: field("vendorID"),
|
|
})
|
|
}
|
|
return out
|
|
}
|
|
|
|
const RANK = { discrete: 0, integrated: 1, virtual: 2, other: 3, cpu: 4 }
|
|
|
|
export function pick(gpus: Gpu[]): Pick<Device, "renders" | "name"> {
|
|
const best = [...gpus].sort((a, b) => RANK[a.type] - RANK[b.type])[0]
|
|
return best && best.type !== "cpu" ? { renders: "gpu", name: best.name } : { renders: "cpu", name: best?.name || "llvmpipe" }
|
|
}
|
|
|
|
let cached: Device | undefined
|
|
|
|
export function device(env: NodeJS.ProcessEnv): Device {
|
|
if (cached) return cached
|
|
let gpus: Gpu[] = []
|
|
try {
|
|
gpus = parseSummary(execFileSync("vulkaninfo", ["--summary"], { encoding: "utf8", env, timeout: 30_000, stdio: ["ignore", "pipe", "ignore"] }))
|
|
} catch {
|
|
// no vulkaninfo, or the loader found nothing: raea falls back the same way
|
|
}
|
|
let nvidia: string[] | undefined
|
|
try {
|
|
nvidia = execFileSync("nvidia-smi", ["--query-gpu=name,memory.total,driver_version", "--format=csv,noheader"], { encoding: "utf8", timeout: 10_000, stdio: ["ignore", "pipe", "ignore"] })
|
|
.trim()
|
|
.split("\n")
|
|
.filter(Boolean)
|
|
} catch {
|
|
// not an NVIDIA host
|
|
}
|
|
cached = { ...pick(gpus), gpus, nvidia }
|
|
return cached
|
|
}
|