diff --git a/sdk/cloud/deploy/modal/farm.py b/sdk/cloud/deploy/modal/farm.py index 3ef74f15..04d9fc54 100644 --- a/sdk/cloud/deploy/modal/farm.py +++ b/sdk/cloud/deploy/modal/farm.py @@ -4,7 +4,7 @@ # # MODAL_PROFILE=raea modal deploy deploy/modal/farm.py # -# POST /v1/jobs?args=JSON[&gpus=N][&gpu=KIND][&max_usd=X] body: the project as a tar. {id} +# POST /v1/jobs?args=JSON[&gpus=N][&gpu=KIND][&max_usd=X][&nv=1|0] body: the project as a tar. {id} # GET /v1/jobs/ID?from=N {log, next, exit?}, held up to 20 s for more # GET /v1/jobs/ID/out?as=zst|gz|tar the files the job made or changed; the job is removed # GET /v1/jobs/ID/media with media=1: the job's media outputs [{path, oid, size}], @@ -814,7 +814,7 @@ def api(): if not isinstance(args, list) or not all(isinstance(a, str) for a in args): raise HTTPException(400, "args must be a JSON array of strings: raea's own arguments") q = req.query_params - opts = {"gpus": min(int(q.get("gpus", JOB_GPUS)), GPUS), "cpus": min(int(q.get("cpus", JOB_CPUS)), CPUS), "kept": q.get("kept", "1") != "0", "gpu": q.get("gpu"), "max_usd": float(q["max_usd"]) if "max_usd" in q else None, "media": q.get("media") == "1"} + opts = {"gpus": min(int(q.get("gpus", JOB_GPUS)), GPUS), "cpus": min(int(q.get("cpus", JOB_CPUS)), CPUS), "kept": q.get("kept", "1") != "0", "gpu": q.get("gpu"), "nv": q.get("nv") if q.get("nv") in ("0", "1") else None, "max_usd": float(q["max_usd"]) if "max_usd" in q else None, "media": q.get("media") == "1"} id = str(uuid.uuid4()) work = f"{JOBS}/{id}/work" async with gate.use(): diff --git a/sdk/cloud/deploy/modal/farm_plan.py b/sdk/cloud/deploy/modal/farm_plan.py index 61d8dfb6..40c4608e 100644 --- a/sdk/cloud/deploy/modal/farm_plan.py +++ b/sdk/cloud/deploy/modal/farm_plan.py @@ -365,7 +365,7 @@ def raea_render(args, opts, work, log, render, cpu_env, run, reload=lambda: None t = threading.Thread(target=lambda: run(["raea", *rest, "-o", sound], cwd=work, env=cpu_env)) t.start() video = out.endswith(VIDEO) - can_flat = bool(video and cpu_render and not opts.get("gpu")) + can_flat = bool(video and cpu_render and not opts.get("gpu") and opts.get("nv") != "1") # what each frame draws, as a key (farm_keys.py): read here with nothing drawn, when this raea has --keys keyed, keys_s = farm_keys.read(rest, work, run, cpu_env, f"/tmp/{id}-keys.json") if video and opts.get("keys") else (None, 0) @@ -409,8 +409,9 @@ def raea_render(args, opts, work, log, render, cpu_env, run, reload=lambda: None gpu_render, gpu_kind = render, kind # a piece with 3D in it keeps its GPU, and its runs use the GPU's encoder and decoder too (CR34): on a 2D piece NVENC # bought nothing (300 frames: 210 s against libx264's 215 s, 11% more bytes), the page and the clips are the work - nv = bool((p.get("manifest") or {}).get("has3d")) - flat = bool(video and cpu_render and not opts.get("gpu") and (p.get("manifest") or {}).get("has3d") is False) + # (opts nv "1" or "0" says so for the job, and "1" keeps it on GPUs: to measure what NVENC and NVDEC buy a cut) + nv = opts.get("nv") == "1" or (opts.get("nv") != "0" and bool((p.get("manifest") or {}).get("has3d"))) + flat = bool(video and cpu_render and not opts.get("gpu") and opts.get("nv") != "1" and (p.get("manifest") or {}).get("has3d") is False) r0 = None # a flat video whose keys said so goes out at once: no timed first run (FLAT_PART) quick = bool(flat and p.get("keys")) diff --git a/sdk/cloud/server/media.ts b/sdk/cloud/server/media.ts index fc662702..4e083b23 100644 --- a/sdk/cloud/server/media.ts +++ b/sdk/cloud/server/media.ts @@ -201,7 +201,7 @@ function hashes(file: string) { * farm's cache and named in the job's manifest with no href, so a render's tar holds the code and not the footage * (StreetTalk's 1.9 GB of interviews went in every render's tar, even one frame's). null when the farm has no cache. * `skip`: the tar's excludes. Links are left to the tar, as before. */ -export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string) => boolean = () => false, said: (s: string) => void = () => {}, store = path.join(os.homedir(), ".cache", "raea-offload", "hashes.json"), instead: Map = new Map()): Promise<{ media: Media[]; sent: number } | null> { +export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string) => boolean = () => false, said: (s: string) => void = () => {}, store = path.join(os.homedir(), ".cache", "raea-offload", "hashes.json"), instead: Map = new Map()): Promise<{ media: Media[]; sent: number; links: boolean } | null> { const found: { path: string; abs: string; id: string; size: number; mtime: number }[] = [] const walk = (dir: string) => { for (const e of readdirSync(dir, { withFileTypes: true })) { diff --git a/sdk/cloud/server/offload.ts b/sdk/cloud/server/offload.ts index 2ee04ef4..343d6cf1 100644 --- a/sdk/cloud/server/offload.ts +++ b/sdk/cloud/server/offload.ts @@ -36,12 +36,12 @@ function local(args: string[], why?: string, root?: string): never { if (why) say(`${why}, so this runs here, on the CPU`) // here every take is its light copy: the record says so, as the farm's would (CL20) const lit = lightCopies(root ?? process.cwd()) - if (lit.size) say(`NO ORIGINAL: a render here reads footage's light copies, so it's a draft that's never shown or published`) + if (lit.length) say(`NO ORIGINAL: a render here reads footage's light copies, so it's a draft that's never shown or published`) const r = spawnSync(REAL, args, { stdio: "inherit" }) const oi = args.indexOf("-o") const mi = args.indexOf("--manifest") const out = oi >= 0 ? path.resolve(process.cwd(), args[oi + 1] ?? "") : "" - if (lit.size && !r.status && out && existsSync(out)) keep(out, mi >= 0 ? path.resolve(process.cwd(), args[mi + 1] ?? "") : null, { read: [], light: [...lit].sort() }) + if (lit.length && !r.status && out && existsSync(out)) keep(out, mi >= 0 ? path.resolve(process.cwd(), args[mi + 1] ?? "") : null, { read: [], light: [...lit].sort() }) process.exit(r.status ?? 1) } @@ -181,9 +181,10 @@ async function main() { if (viaFarm && cached.length) say(`${cached.length} media files (${mb(cached)} MB) go by hash from the farm's cache${viaFarm.sent ? `, ${(viaFarm.sent / 1e6).toFixed(1)} MB of it sent now` : ""}`) else if (cached.length) say(`${cached.length} media files (${mb(cached)} MB) go by hash: the farm fetches them from R2`) else if (typeof lfs === "string" && existsSync(path.join(p.root, ".lfsconfig"))) say(`media goes in the tar: ${lfs}`) - // a render farm's choices (deploy/modal/farm.py): RAEA_CLOUD_GPUS, RAEA_CLOUD_GPU_KIND, RAEA_CLOUD_MAX_USD + // a render farm's choices (deploy/modal/farm.py): RAEA_CLOUD_GPUS, RAEA_CLOUD_GPU_KIND (the card: it went as "gpu", + // which the client never read, so a named card never reached the farm), RAEA_CLOUD_MAX_USD, RAEA_CLOUD_NV (1 or 0) const n = (v?: string) => (v ? Number(v) : undefined) - const farm = { gpus: n(process.env.RAEA_CLOUD_GPUS), cpus: n(process.env.RAEA_CLOUD_CPUS), kept: process.env.RAEA_CLOUD_KEPT === "0" ? false : undefined, gpu: process.env.RAEA_CLOUD_GPU_KIND, maxUsd: n(process.env.RAEA_CLOUD_MAX_USD), media: typeof lfs !== "string" } + const farm = { gpus: n(process.env.RAEA_CLOUD_GPUS), cpus: n(process.env.RAEA_CLOUD_CPUS), kept: process.env.RAEA_CLOUD_KEPT === "0" ? false : undefined, card: process.env.RAEA_CLOUD_GPU_KIND || undefined, maxUsd: n(process.env.RAEA_CLOUD_MAX_USD), nv: process.env.RAEA_CLOUD_NV === "1" ? true : process.env.RAEA_CLOUD_NV === "0" ? false : undefined, media: typeof lfs !== "string" } let finish: (() => Promise) | undefined const media = typeof lfs === "string" ? undefined : async (made: Parameters[2]) => { const o = await outputs(p.root, lfs, made) diff --git a/sdk/cloud/src/index.ts b/sdk/cloud/src/index.ts index 93b446b0..802aaf42 100644 --- a/sdk/cloud/src/index.ts +++ b/sdk/cloud/src/index.ts @@ -39,6 +39,9 @@ export interface Farm { kept?: boolean card?: string maxUsd?: number + /** NVIDIA's encoder and decoder (RAEA_NV) for every run: true on, false off; unset, only a piece with 3D in it (CR34). + * On forces the job onto GPUs */ + nv?: boolean /** the job's media outputs stay on the farm for `media` to send to R2 (docs/cloud-render.feature CR23) */ media?: boolean } @@ -169,6 +172,7 @@ export class RaeaCloud { if (farm.card) q.set("gpu", farm.card) if (farm.maxUsd !== undefined) q.set("max_usd", String(farm.maxUsd)) if (farm.media) q.set("media", "1") + if (farm.nv !== undefined) q.set("nv", farm.nv ? "1" : "0") const r = await this.fetch(`/v1/jobs?${q}`, { method: "POST", body: new Blob([folder as Uint8Array]), headers: { "content-type": "application/octet-stream" }, signal }) return ((await r.json()) as { id: string }).id } diff --git a/sdk/cloud/test/farm_plan.py b/sdk/cloud/test/farm_plan.py index 41e9b655..67c49ea0 100644 --- a/sdk/cloud/test/farm_plan.py +++ b/sdk/cloud/test/farm_plan.py @@ -263,6 +263,14 @@ g = Flat(root, name="T4") assert fp.raea_render(["render", "a.tsx", "-o", "out/a.mp4"], {"id": "jn", "gpus": 2, "cpus": 0}, os.path.join(root, "jobs", "jn", "work"), log, g, {}, run) == 0, lines assert g.nv and not any(g.nv), g.nv ok("a piece with 3D draws on GPUs with NVENC and NVDEC asked for; a 2D piece kept on GPUs doesn't ask") +# the job says so (opts nv): "1" puts a 2D piece on GPUs with them, "0" keeps a 3D piece's GPU without them +g, c = Flat(root, name="T4"), Flat(root) +assert fp.raea_render(["render", "a.tsx", "-o", "out/a.mp4"], {"id": "jn", "gpus": 2, "cpus": 8, "nv": "1"}, os.path.join(root, "jobs", "jn", "work"), log, g, {}, run, cpu_render=c) == 0, lines +assert not c.calls and g.nv and all(g.nv), (c.calls, g.nv) +g, c = Flat(root, name="T4", has3d=True), Flat(root) +assert fp.raea_render(["render", "a.tsx", "-o", "out/a.mp4"], {"id": "jn", "gpus": 2, "cpus": 8, "nv": "0"}, os.path.join(root, "jobs", "jn", "work"), log, g, {}, run, cpu_render=c) == 0, lines +assert not c.calls and g.nv and not any(g.nv), (c.calls, g.nv) +ok("a job's nv=1 draws a 2D piece on GPUs with NVENC and NVDEC; nv=0 keeps a 3D piece's GPU without them") # the join keeps every frame of runs that have B-frames, with the piece's sound (11-30: -shortest ended the joined # video 2 frames early, 892 of an 894-frame ad)