Skip to content

Commit 2955ec7

Browse files
committed
Finalize the simple accelerator selection proposal
Signed-off-by: Zoltan Kis <[email protected]>
1 parent 3a61a15 commit 2955ec7

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

device-selection-explainer.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,28 @@ Based on the answer, the developer may choose an option other than WebNN. Beside
237237
The following [proposal](https://github.com/webmachinelearning/webnn/issues/815#issuecomment-3198261369) gained support for a simple accelerator mapping solution (before using the previously discussed fine grained constraints):
238238
- Expose a context property (or event) to tell whether CPU fallback is active (or likely active).
239239
- Add a context creation option/hint (e.g. `accelerated: true`) for telling app preference for NPU and/or GPU accelerated ["massively parallel"](https://en.wikipedia.org/wiki/Massively_parallel) processing (MPP).
240-
- **Note**. This context option makes sense when an error is returned when the implementation overrides the option. Otherwise, if instead of returning an error a silent fallback is implemented (which seems the more generic behaviour), then applications could query the following proposed property on the context (albeit after context creation). If implementations could detect a CPU fallback, then they could also return an error. Whether to expose an error in this case is to be discussed, as it would allow detecting lack of massively parallel acceleration _before_ creating a context.
240+
Note that in [certain use cases](https://www.w3.org/2025/09/25-webmachinelearning-minutes.html) applications might prefer CPU inference, therefore specifying `accelerated: false` has legit use cases as well.
241241
- Add a context property named `"accelerated"` with possible values: `false` (for likely no support for neither GPU nor NPU), and `true` (e.g. fully controlled by the underlying platform which makes a best effort for MPP, yet CPU fallback may occur).
242+
- Add a context property named `"cpuFallbackActive"` that may be polled for detecting CPU fallbacks. In the future, depending on developer feedback, this may be turned into an event.
242243

243-
The following changes are proposed:
244+
The following Web IDL changes are proposed:
244245

245246
```js
246247
partial dictionary MLContextOptions {
247248
boolean accelerated = true;
248249
};
249250

250251
partial interface MLContext {
251-
boolean cpuFallbackActive;
252+
readonly attribute boolean accelerated;
253+
readonly attribute boolean cpuFallbackActive;
252254
};
253255
```
254256

255257
The behavior of [createContext()](https://webmachinelearning.github.io/webnn/#dom-ml-createcontext) is proposed to follow this policy:
256-
- return an error [in step 4](https://webmachinelearning.github.io/webnn/#create-a-context) if the context option `accelerated` has been set to `true`, but the platform cannot provide massive parallel processing at all,
257-
- and set the `accelerated` property to `false` when the platform could in principle provide massive parallel processing which may or may not be available at the moment.
258+
- Set the `accelerated` property to `false` when the platform could in principle provide massive parallel processing which may or may not be available at the moment. Applications may poll this property, together with `MLContext::cpuFallbackActive`.
259+
260+
In the future, more policy options could be considered, for instance:
261+
- Return an error [in step 4](https://webmachinelearning.github.io/webnn/#create-a-context) if the context option `accelerated` has been set to `true`, but the platform cannot provide massive parallel processing at all.
258262

259263
## History
260264

0 commit comments

Comments
 (0)