Skip to content

Commit 5799e30

Browse files
committed
Merge branch 'pr/ibelem/890-1' into v3
2 parents 4ec77c1 + 3fefa17 commit 5799e30

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

src/backends/onnx.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { env, apis } from '../env.js';
2121
// NOTE: Import order matters here. We need to import `onnxruntime-node` before `onnxruntime-web`.
2222
// In either case, we select the default export if it exists, otherwise we use the named export.
2323
import * as ONNX_NODE from 'onnxruntime-node';
24-
import * as ONNX_WEB from 'onnxruntime-web/webgpu';
24+
import * as ONNX_WEB from 'onnxruntime-web/all';
2525

2626
export { Tensor } from 'onnxruntime-common';
2727

@@ -68,6 +68,9 @@ if (apis.IS_NODE_ENV) {
6868
if (apis.IS_WEBGPU_AVAILABLE) {
6969
supportedExecutionProviders.push('webgpu');
7070
}
71+
if(apis.IS_WEBNN_AVAILABLE) {
72+
supportedExecutionProviders.push('webnn');
73+
}
7174
supportedExecutionProviders.push('wasm');
7275
defaultExecutionProviders = ['wasm'];
7376
}

src/env.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const IS_BROWSER_ENV = typeof self !== 'undefined';
3333
const IS_WEBWORKER_ENV = IS_BROWSER_ENV && self.constructor.name === 'DedicatedWorkerGlobalScope';
3434
const IS_WEB_CACHE_AVAILABLE = IS_BROWSER_ENV && 'caches' in self;
3535
const IS_WEBGPU_AVAILABLE = typeof navigator !== 'undefined' && 'gpu' in navigator;
36+
const IS_WEBNN_AVAILABLE = typeof navigator !== 'undefined' && 'ml' in navigator;
3637

3738
const IS_PROCESS_AVAILABLE = typeof process !== 'undefined';
3839
const IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === 'node';
@@ -55,6 +56,9 @@ export const apis = Object.freeze({
5556
/** Whether the WebGPU API is available */
5657
IS_WEBGPU_AVAILABLE,
5758

59+
/** Whether the WebNN API is available */
60+
IS_WEBNN_AVAILABLE,
61+
5862
/** Whether the Node.js process API is available */
5963
IS_PROCESS_AVAILABLE,
6064

src/utils/devices.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const DEVICE_TYPES = Object.freeze({
88
cpu: 'cpu', // CPU
99
wasm: 'wasm', // WebAssembly
1010
webgpu: 'webgpu', // WebGPU
11+
webnn: 'webnn', // WebNN
1112
cuda: 'cuda', // CUDA
1213
dml: 'dml', // DirectML
1314
});

src/utils/dtypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const DEFAULT_DEVICE_DTYPE_MAPPING = Object.freeze({
4747
[DEVICE_TYPES.gpu]: DATA_TYPES.fp32,
4848
[DEVICE_TYPES.wasm]: DATA_TYPES.q8,
4949
[DEVICE_TYPES.webgpu]: DATA_TYPES.fp32,
50+
[DEVICE_TYPES.webnn]: DATA_TYPES.fp32,
5051
[DEVICE_TYPES.cuda]: DATA_TYPES.fp32,
5152
[DEVICE_TYPES.dml]: DATA_TYPES.fp32,
5253
});

0 commit comments

Comments
 (0)