okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
9caf39495
main
1import { tr } from '../lib/i18n' ; 2import { memoryInventory } from '../lib/hardware-summary' ; 3import { sizeGb } from '../lib/format' ; 4import type { Hardware } from '../lib/types' ; 5import type { NativeState } from '../lib/native' ; 6import { Icon } from './ui' ; 7export function OnboardingMemory ({ hardware, native} :{ 8hardware :Hardware | null ; 9native :NativeState [ 'hardware' ] | undefined ; 10}) { 11// The Windows host probe (Win32_VideoController) cannot read the VRAM of AMD cards and reports 0 for them; the engine's own list has 12// the real size. For a dedicated card the host reports as 0, take the engine's figure for the card of the same name, or for the 13// card in the same position when both lists have the same length. A card the engine does not list stays at 0. 14const nativeGpus = native ?. gpus ?? []; 15const hostGpus = hardware ?hardware . gpus . filter ( gpu => gpu . backend !== 'cpu' ) :[]; 16const engineVram = ( name :string , position :number ) => { 17const norm = ( value :string ) => value . toLowerCase (). replace ( / [^a-z0-9] / g , '' ); 18const byName = nativeGpus . find ( g => norm ( g . name ). includes ( norm ( name )) || norm ( name ). includes ( norm ( g . name ))); 19return ( byName ?? ( nativeGpus . length === hostGpus . length ?nativeGpus [ position ] :undefined ))?. vram_gb || 0 ; 20}; 21const gpus = hardware ?hostGpus . map (( gpu , position ) => ({ id :gpu . id ?? String ( gpu . index ), name :gpu . name , memory :gpu . unified || gpu . vramGb > 0 ?gpu . vramGb :engineVram ( gpu . name , position ), shared :gpu . unified })) :nativeGpus . map ( gpu => ({ id :String ( gpu . index ), name :gpu . name , memory :gpu . vram_gb , shared :false })); 22const dedicatedCount = gpus . filter ( gpu => ! gpu . shared ). length ; 23const base = hardware ?memoryInventory ( hardware ) :null ; 24const memory = base ?( base . shared ?base :{ ...base , vram :gpus . reduce (( sum , gpu ) => sum + ( gpu . shared ?0 :Math . max ( 0 , gpu . memory || 0 )), 0 ) }) :native ?{ ram :native . ram_gb , vram :native . gpus . reduce (( sum , gpu ) => sum + Math . max ( 0 , gpu . vram_gb || 0 ), 0 ), total :0 , shared :false } :null ; 25if ( ! memory ) 26return < div className = "onboard-hardware" role = "group" aria-label = { tr ( "Computer memory" )}>< div className = "onboard-memory-intro" >< Icon name = "memory" size = { 18 }/>< span >{ tr ( "Reading memory\u2026" )}</ span ></ div ></ div >; 27const total = memory . ram + memory . vram ; 28return < div className = "onboard-hardware" role = "group" aria-label = { tr ( "Computer memory" )} data-shared = { memory . shared } title = { tr ( memory . shared ?'CPU and GPU use the same memory pool. Shared VRAM is counted once in the total.' :'Total physical capacity across RAM and all dedicated GPUs. Model placement determines how it is used.' )}> 29< div className = "onboard-memory-header" >< div className = "onboard-memory-intro" >< Icon name = "computer" size = { 18 }/>< span >{ tr ( "Your computer" )}</ span ></ div >{ tr ( memory . shared ?< small >{ tr ( "One shared memory pool" )}</ small > :null )}</ div > 30< div className = "onboard-memory-equation" > 31< div className = "onboard-memory-stat" >< small >{ tr ( "RAM" )}</ small >< div className = "onboard-memory-value" >< Icon name = "memory" size = { 20 }/>< strong >{ tr ( sizeGb ( memory . ram ))}</ strong ></ div ></ div > 32< span className = "onboard-memory-operator" aria-hidden = "true" >{ tr ( memory . shared ?'↔' :'+' )}</ span > 33< div className = "onboard-memory-stat" >< small >{ tr ( "VRAM" )}{ tr ( dedicatedCount > 1 ?< span > · { tr ( dedicatedCount )}{ tr ( " GPUs" )}</ span > :null )}</ small >< div className = "onboard-memory-value" >< Icon name = "gpu" size = { 20 }/>< strong >{ tr ( memory . shared ?'Shared' :sizeGb ( memory . vram ))}</ strong ></ div ></ div > 34< span className = "onboard-memory-operator" aria-hidden = "true" > = </ span > 35< div className = "onboard-memory-stat onboard-memory-total" >< small >{ tr ( "Total memory" )}</ small >< div className = "onboard-memory-value" >< Icon name = "layers" size = { 20 }/>< strong >{ tr ( sizeGb ( total ))}</ strong ></ div ></ div > 36</ div > 37{ tr ( gpus . length > 1 ?< details className = "onboard-memory-devices" >< summary >{ tr ( gpus . length )}{ tr ( " GPUs connected" )}< Icon name = "chevron" size = { 14 }/></ summary >< ul aria-label = { tr ( "GPU memory breakdown" )}>{ tr ( gpus . map ( gpu => < li key = { gpu . id }>< span >< Icon name = "gpu" size = { 16 }/>{ tr ( gpu . name )}</ span >< strong >{ tr ( gpu . shared ?'Shared with RAM' :sizeGb ( Math . max ( 0 , gpu . memory || 0 )))}</ strong ></ li >))}</ ul ></ details > :null )} 38</ div >; 39}