onnxruntime/js/common/lib
Yulong Wang 35697d2421
[js/webnn] update API of session options for WebNN (#20816)
### Description

This PR is an API-only change to address the requirements being
discussed in #20729.

There are multiple ways that users may create an ORT session by
specifying the session options differently.

All the code snippet below will use the variable `webnnOptions` as this:
```js
const myWebnnSession = await ort.InferenceSession.create('./model.onnx', {
   executionProviders: [
     webnnOptions
   ]
});
```

### The old way (backward-compatibility)

```js
// all-default, name only
const webnnOptions_0 = 'webnn';

// all-default, properties omitted
const webnnOptions_1 = { name: 'webnn' };

// partial
const webnnOptions_2 = {
  name: 'webnn',
  deviceType: 'cpu'
};

// full
const webnnOptions_3 = {
  name: 'webnn',
  deviceType: 'gpu',
  numThreads: 1,
  powerPreference: 'high-performance'
};
```

### The new way (specify with MLContext)

```js
// options to create MLcontext
const options = {
  deviceType: 'gpu',
  powerPreference: 'high-performance'
};

const myMlContext = await navigator.ml.createContext(options);

// options for session options
const webnnOptions = {
  name: 'webnn',
  context: myMlContext,
  ...options
};
```

This should throw (because no deviceType is specified):
```js
const myMlContext = await navigator.ml.createContext({ ... });
const webnnOptions = {
  name: 'webnn',
  context: myMlContext
};
```

### Interop with WebGPU
```js
// get WebGPU device
const adaptor = await navigator.gpu.requestAdapter({ ... });
const device = await adaptor.requestDevice({ ... });

// set WebGPU adaptor and device
ort.env.webgpu.adaptor = adaptor;
ort.env.webgpu.device = device;

const myMlContext = await navigator.ml.createContext(device);
const webnnOptions = {
  name: 'webnn',
  context: myMlContext,
  gpuDevice: device
};
```

This should throw (because cannot specify both gpu device and MLContext
option at the same time):
```js
const webnnOptions = {
  name: 'webnn',
  context: myMlContext,
  gpuDevice: device,
  deviceType: 'gpu'
};
```
2024-05-31 03:25:14 -07:00
..
backend-impl.ts [js/web] rewrite backend resolve to allow multiple EPs (#19735) 2024-03-15 11:47:45 -07:00
backend.ts [js/common] fix typedoc warnings (#19933) 2024-03-15 19:01:50 -07:00
env-impl.ts [js/common] allow import onnxruntime-common as ESM and CJS (#15772) 2023-06-12 12:05:11 -07:00
env.ts [js/web] optimize module export and deployment (#20165) 2024-05-20 09:51:16 -07:00
index.ts [js/common] fix typedoc warnings (#19933) 2024-03-15 19:01:50 -07:00
inference-session-impl.ts [js/web] rewrite backend resolve to allow multiple EPs (#19735) 2024-03-15 11:47:45 -07:00
inference-session.ts [js/webnn] update API of session options for WebNN (#20816) 2024-05-31 03:25:14 -07:00
onnx-model.ts [js] enable external data loading for ort-web (#19087) 2024-01-12 19:24:24 -08:00
onnx-value.ts [js/common] fix typedoc warnings (#19933) 2024-03-15 19:01:50 -07:00
tensor-conversion-impl.ts [js] using OffscreenCanvas when DOM is not available (#19033) 2024-01-12 13:54:05 -08:00
tensor-conversion.ts [js/common] allow import onnxruntime-common as ESM and CJS (#15772) 2023-06-12 12:05:11 -07:00
tensor-factory-impl.ts [js] using OffscreenCanvas when DOM is not available (#19033) 2024-01-12 13:54:05 -08:00
tensor-factory.ts [js/common] fix typedoc warnings (#19933) 2024-03-15 19:01:50 -07:00
tensor-impl-type-mapping.ts [js] changes to allow Float16Array if any polyfill is available (#19305) 2024-02-21 00:31:06 -08:00
tensor-impl.ts [js] changes to allow Float16Array if any polyfill is available (#19305) 2024-02-21 00:31:06 -08:00
tensor-utils-impl.ts [js/api] introducing IO binding for tensor (#16452) 2023-08-29 12:58:26 -07:00
tensor-utils.ts [js/common] allow import onnxruntime-common as ESM and CJS (#15772) 2023-06-12 12:05:11 -07:00
tensor.ts [js/common] fix typedoc warnings (#19933) 2024-03-15 19:01:50 -07:00
trace.ts [js/common] fix typedoc warnings (#19933) 2024-03-15 19:01:50 -07:00
training-session-impl.ts [js/web] rewrite backend resolve to allow multiple EPs (#19735) 2024-03-15 11:47:45 -07:00
training-session.ts [js/common] fix typedoc warnings (#19933) 2024-03-15 19:01:50 -07:00
version.ts Bump up version in main from 1.18.0 to 1.19.0 (#20489) 2024-04-29 20:21:41 -07:00