According to https://webmachinelearning.github.io/webnn/#dictdef-mlcontextoptions, the current WebNN specification states that the accelerated option has lower priority than powerPreference. This design creates logical contradictions and implementation difficulties, particularly in two scenarios:
low-power + accelerated = true:
If no low-power device NPU/iGPU is available, it seems we have to select CPU to satisfy the "low-power" requirement. This violates the developer's explicit intent to use hardware acceleration.
high-performance/low-power + accelerated = false:
The spec suggests choosing a "high-performance/low-power CPU mode". However, web browsers typically lack the granular control to force a CPU into a high-performance/low-power state (e.g., pinning to performance cores or boosting clock speeds), making this practically impossible to implement
So the logic should be inverted: accelerated has higher priority than powerPreference.
Rationale: accelerated defines the category of hardware (Dedicated Accelerator vs. CPU), while powerPreference should act as a hint for selecting within that category. If accelerated is true, the user agent MUST return an accelerated context (GPU/NPU) if available, regardless of power preference.
See the following table, this will make device selection implementation easier and avoid some confusions from contradictory combinations.
| accelerated |
powerPreference |
device should be selected |
| true |
"default"/"higher-performance" |
GPU |
| true |
"low-power" |
NPU; if no NPU, try to select iGPU |
| false |
ignored |
CPU |
@huningxin @fdwr
According to https://webmachinelearning.github.io/webnn/#dictdef-mlcontextoptions, the current WebNN specification states that the
acceleratedoption has lower priority thanpowerPreference. This design creates logical contradictions and implementation difficulties, particularly in two scenarios:low-power + accelerated = true:
If no low-power device NPU/iGPU is available, it seems we have to select CPU to satisfy the "low-power" requirement. This violates the developer's explicit intent to use hardware acceleration.
high-performance/low-power + accelerated = false:
The spec suggests choosing a "high-performance/low-power CPU mode". However, web browsers typically lack the granular control to force a CPU into a high-performance/low-power state (e.g., pinning to performance cores or boosting clock speeds), making this practically impossible to implement
So the logic should be inverted:
acceleratedhas higher priority thanpowerPreference.Rationale:
accelerateddefines the category of hardware (Dedicated Accelerator vs. CPU), whilepowerPreferenceshould act as a hint for selecting within that category. If accelerated is true, the user agent MUST return an accelerated context (GPU/NPU) if available, regardless of power preference.See the following table, this will make device selection implementation easier and avoid some confusions from contradictory combinations.
@huningxin @fdwr