File tree Expand file tree Collapse file tree 4 files changed +29
-14
lines changed
examples/piston-train-toy/src/lib Expand file tree Collapse file tree 4 files changed +29
-14
lines changed Original file line number Diff line number Diff line change 1717 controlSectionsOpen ,
1818 getGpuName ,
1919 gpuPowerPreference ,
20+ hasWebGPU ,
2021 setGpuName ,
2122 toggleControlSection
2223 } from ' $lib/workspace/ui.svelte' ;
7879 JSON .stringify (config .model );
7980 JSON .stringify (config .data );
8081 JSON .stringify (gpuPowerPreference .current );
81- setGpuName (null );
8282
8383 // Trigger parameter count when config changes, but triggerParameterCount itself needs to be untracked
8484 untrack (() => triggerModelInspection ());
8585 });
8686
87+ $effect (() => {
88+ // Recompute GPU name whenever WebGPU availability or power preference changes
89+ JSON .stringify (gpuPowerPreference .current );
90+ const has = hasWebGPU .current ;
91+ if (! has || typeof navigator === ' undefined' || ! (' gpu' in navigator )) {
92+ setGpuName (null );
93+ return ;
94+ }
95+ void (async () => {
96+ try {
97+ const adapter = await navigator .gpu .requestAdapter ({
98+ powerPreference: gpuPowerPreference .current
99+ });
100+ // Use info.description if available
101+ const name = adapter ?.info ?.description ;
102+ setGpuName (typeof name === ' string' && name .length > 0 ? name : null );
103+ } catch (error ) {
104+ console .error (' Error requesting WebGPU adapter:' , error );
105+ setGpuName (null );
106+ }
107+ })();
108+ });
109+
87110 // Preset selection wiring: local selection drives setPreset, stays in sync with config
88111 let lastAppliedPreset = $state <string | null >(null );
89112 let selectedPresetId = $state <string >(' ' );
Original file line number Diff line number Diff line change @@ -312,10 +312,8 @@ self.addEventListener('message', async (event) => {
312312
313313 // Apply GPU power preference before any GPU usage
314314 if ( gpuPowerPreference ) {
315- const name =
316- ( await piston . applyGpuPowerPreference ( gpuPowerPreference ) ) ?. adapterInfo ?. description ??
317- null ;
318- self . postMessage ( { type : 'gpu.info' , name : name ?? null } ) ;
315+ await piston . applyGpuPowerPreference ( gpuPowerPreference ) ;
316+ ( globalThis as unknown as { piston : typeof piston } ) . piston = piston ;
319317 }
320318
321319 console . debug ( 'Inspecting model...' ) ;
Original file line number Diff line number Diff line change @@ -42,12 +42,12 @@ export const gpuPowerPreference = new LocalStorage<'high-performance' | 'low-pow
4242 'gpuPowerPreference' ,
4343 'high-performance'
4444) ;
45- let gpuName = $state < string | null > ( null ) ;
45+ const gpuName = $state < { current : string | null } > ( { current : null } ) ;
4646export function setGpuName ( name : string | null ) {
47- gpuName = name ;
47+ gpuName . current = name ;
4848}
4949export function getGpuName ( ) {
50- return gpuName ;
50+ return gpuName . current ;
5151}
5252
5353export const setupUI = ( ) => {
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import { lastSessionStore } from './lastSessionStore';
99import { currentRun , log , runsMap } from './runs.svelte' ;
1010import {
1111 gpuPowerPreference ,
12- setGpuName ,
1312 triggerLowDiversityDatasetError ,
1413 triggerVramLimitFlash
1514} from './ui.svelte' ;
@@ -451,11 +450,6 @@ export async function initializeModelInspectionWorker() {
451450 case 'error' :
452451 console . error ( '[Main] Model inspection worker error:' , data . message ) ;
453452 break ;
454- case 'gpu.info' : {
455- const name = ( data as { name ?: string | null } ) . name ?? null ;
456- setGpuName ( name ?? null ) ;
457- break ;
458- }
459453 }
460454 } ;
461455
You can’t perform that action at this time.
0 commit comments