okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
3.8 KiB42 linesraw
1import { tr } from '../lib/i18n';
2import type { Fit } from '../lib/native-fit';
3
4const gb = (n: number) => `${Number.isInteger(n) ? n : n.toFixed(1)} GB`;
5const about = (n: number) => `${Math.round(n)} GB`;
6
7/** What this computer has free right now (real readings of the host; null where one is not available). */
8export interface PcLive { vramTotalGb?: number; freeVramGb: number | null; freeRamGb: number | null; diskReadGbs: number | null }
9/** A model that is loaded: what it takes of graphics memory and RAM, and how much of it is read from the SSD (the app's estimate: the engine does not report this split). */
10export interface PcLoaded { id: string; label: string; fit: Fit }
11
12function FreeMeter({ label, total, free }: { label: string; total: number; free: number }) {
13  const used = total > 0 ? Math.max(0, Math.min(100, ((total - free) / total) * 100)) : 0;
14  return <div className="pc-meter" data-low={free / (total || 1) < 0.1 || undefined}>
15    <div className="pc-meter__top"><span>{tr(label)}</span><b>{tr("{0} free", [gb(free)])}</b><span className="muted">{tr("of {0}", [gb(total)])}</span></div>
16    <div className="pc-meter__track" role="img" aria-label={tr("{0}: {1} free of {2}", [tr(label), gb(free), gb(total)])}><i style={{ transform: `scaleX(${used / 100})` }}/></div>
17  </div>;
18}
19
20/**
21 * "This computer": how much graphics memory and RAM is free right now. While a model is loaded that is all the card shows: the hardware line, the model's
22 * name, "Loaded", what it takes and the SSD line are gone (owner, 11-01: the page already says what is loaded); only while the loaded model really reads
23 * from the SSD, how fast it reads right now. Before anything is loaded the card says what the chosen version would take. That a version does not fit in
24 * memory is said once, under the version picker ("may run slower"), not again here. (The n-gram table, which always sits on the SSD, is not counted.)
25 */
26export function PcFitCard({ gpuName, ramGb, vramGb, fit, inUse = null, live = null, loaded = [], selectedLoaded = false }: { gpuName?: string | null; ramGb: number | null; vramGb: number; fit: Fit | null; inUse?: { ramGb: number; vramGb: number } | null; live?: PcLive | null; loaded?: PcLoaded[]; selectedLoaded?: boolean }) {
27  const showFit = !!fit?.known && !selectedLoaded;
28  const isLoaded = loaded.length > 0;
29  const streamed = Math.max(0, ...loaded.map(m => (m.fit.known ? m.fit.spillGb : 0)));
30  return <section className="st-card pc-card" data-loaded={isLoaded ? true : undefined}>
31    {isLoaded ? <h2 className="h4">{tr("This computer")}</h2> : <div><h2 className="h4">{tr("This computer")}</h2>
32      <p className="small muted">{tr(gpuName ? tr("{0} · {1} graphics memory", [gpuName, gb(vramGb)]) : tr("No supported graphics card reported by this installation."))}{ramGb ? tr(" · {0} RAM", [gb(ramGb)]) : ''}</p></div>}
33    {tr(live && (live.freeVramGb !== null || live.freeRamGb !== null) ? <div className="pc-free">
34      <h3 className="pc-label">{tr("Free right now")}</h3>
35      {tr(live.freeVramGb !== null && vramGb > 0 ? <FreeMeter label="Graphics memory" total={live.vramTotalGb ?? vramGb} free={live.freeVramGb}/> : null)}
36      {tr(live.freeRamGb !== null && ramGb ? <FreeMeter label="RAM" total={ramGb} free={live.freeRamGb}/> : null)}
37    </div> : null)}
38    {tr(isLoaded && streamed >= 1 && live?.diskReadGbs && live.diskReadGbs >= 0.05 ? <p className="pc-note">{tr("Reading from your SSD now: {0}", [`${live.diskReadGbs.toFixed(1)} GB/s`])}</p> : null)}
39    {tr(inUse ? <p className="xs muted">{tr("Models that stay loaded use about {0} GB of RAM and {1} GB of this card’s memory.", [inUse.ramGb, inUse.vramGb])}</p> : null)}
40    {tr(showFit && !isLoaded && fit!.vramUseGb + fit!.ramUseGb > 0 ? <p className="pc-note">{tr("This version would take about {0} of graphics memory and {1} of RAM.", [about(fit!.vramUseGb), about(fit!.ramUseGb)])}</p> : null)}
41  </section>;
42}