Skip to content
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

[js/webgpu] allow setting env.webgpu.adapter #19940

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix error introduced by conflict resolving
  • Loading branch information
fs-eire committed Mar 15, 2024
commit 0a586ea70f07430061a070705a7ba85b31a276cf
8 changes: 8 additions & 0 deletions js/web/lib/wasm/wasm-core-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ export const initEp = async(env: Env, epName: string): Promise<void> => {
if (typeof navigator === 'undefined' || !navigator.gpu) {
throw new Error('WebGPU is not supported in current environment');
}

let adapter = env.webgpu.adapter as GPUAdapter | null;
if (!adapter) {
// if adapter is not set, request a new adapter.
const powerPreference = env.webgpu.powerPreference;
if (powerPreference !== undefined && powerPreference !== 'low-power' &&
powerPreference !== 'high-performance') {
Expand All @@ -111,12 +113,18 @@ export const initEp = async(env: Env, epName: string): Promise<void> => {
'You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.');
fs-eire marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
// if adapter is set, validate it.
if (typeof adapter.limits !== 'object' || typeof adapter.features !== 'object' ||
typeof adapter.requestDevice !== 'function') {
throw new Error('Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.');
}
}

if (!env.wasm.simd) {
throw new Error(
'Not supported for WebGPU=ON and SIMD=OFF. Please set `env.wasm.simd` to true when using `webgpu` EP');
}

await initJsep('webgpu', getInstance(), env, adapter);
}
if (epName === 'webnn') {
Expand Down
Loading