webGpuSupport method
navigator.gpu.requestAdapter({powerPreference: 'high-performance'}):
the adapter @litert-lm/core itself asks for before it creates
a GPU engine (createDefaultWebGpuDevice in litertlm_web.js). The
adapter is only looked at: the runtime requests its own device from its
own adapter in EmbeddingEngine.create.
Implementation
@override
Future<LiteRtLmWebGpuSupport> webGpuSupport() async {
final navigator = globalContext['navigator'];
if (navigator == null || navigator.isUndefinedOrNull) {
return LiteRtLmWebGpuSupport.noWebGpu;
}
final gpu = (navigator as JSObject)['gpu'];
if (gpu == null || gpu.isUndefinedOrNull) {
return LiteRtLmWebGpuSupport.noWebGpu;
}
final options = JSObject()..['powerPreference'] = 'high-performance'.toJS;
final adapter = await (gpu as JSObject)
.callMethod<JSPromise<JSAny?>>('requestAdapter'.toJS, options)
.toDart;
return adapter == null || adapter.isUndefinedOrNull
? LiteRtLmWebGpuSupport.noAdapter
: LiteRtLmWebGpuSupport.available;
}