-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support WebGPU #110
Support WebGPU #110
Conversation
af09efb
to
84414b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great and super quick in Chrome!!
However, I could not get the example to work in Safari and Firefox. I'd expect a gracefull fallback to lower-performance runtimes until one is found that works in the browser
packages/web/src/onnx.ts
Outdated
ort.env.wasm.wasmPaths = { | ||
'ort-wasm-simd-threaded.wasm': | ||
capabilities.simd && capabilities.threads | ||
useThreads && useSimd | ||
? await loadAsUrl( | ||
'/onnxruntime-web/ort-wasm-simd-threaded.wasm', | ||
useWebGPU | ||
? '/onnxruntime-web/ort-wasm-simd-threaded.jsep.wasm' | ||
: '/onnxruntime-web/ort-wasm-simd-threaded.wasm', | ||
config | ||
) | ||
: undefined, | ||
'ort-wasm-simd.wasm': | ||
capabilities.simd && !capabilities.threads | ||
? await loadAsUrl('/onnxruntime-web/ort-wasm-simd.wasm', config) | ||
!useThreads && useSimd | ||
? await loadAsUrl( | ||
useWebGPU | ||
? '/onnxruntime-web/ort-wasm-simd.jsep.wasm' | ||
: '/onnxruntime-web/ort-wasm-simd.wasm', | ||
config | ||
) | ||
: undefined, | ||
'ort-wasm-threaded.wasm': | ||
!capabilities.simd && capabilities.threads | ||
!useWebGPU && useThreads && !useSimd | ||
? await loadAsUrl('/onnxruntime-web/ort-wasm-threaded.wasm', config) | ||
: undefined, | ||
'ort-wasm.wasm': | ||
!capabilities.simd && !capabilities.threads | ||
!useWebGPU && !useThreads && !useSimd | ||
? await loadAsUrl('/onnxruntime-web/ort-wasm.wasm', config) | ||
: undefined | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this code path seems a bit hard to scan, I'd personally like to simplify this logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feeded your comment to CoPilot and my sidekick wants to change it to this:
const wasmPaths = {
'ort-wasm-simd-threaded.wasm': useThreads && useSimd,
'ort-wasm-simd.wasm': !useThreads && useSimd,
'ort-wasm-threaded.wasm': !useWebGPU && useThreads && !useSimd,
'ort-wasm.wasm': !useWebGPU && !useThreads && !useSimd
};
for (const [key, value] of Object.entries(wasmPaths)) {
if (value) {
const wasmPath = useWebGPU && key.includes('simd') ? /onnxruntime-web/${key.replace('.wasm', '.jsep.wasm')}
: /onnxruntime-web/${key}
;
ort.env.wasm.wasmPaths[key] = await loadAsUrl(wasmPath, config);
}
}
packages/web/changelog/1.4.5/20242602190400-Added_ThirdPartyLicenses_json_Added.yaml
Outdated
Show resolved
Hide resolved
8b26f6f
to
eda7074
Compare
Added support for
Added "device" parameter with options "cpu | gpu". For now "cpu" is default.