Skip to content

Commit 8353c46

Browse files
Wording change: Define power prefs & device type using WebIDL enums
Replace definitions for MLContext's device type and power preference which are used internally only, with the identical WebIDL-defined MLDeviceType and MLPowerPreference enums. Fixes #497
1 parent 479ce17 commit 8353c46

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

index.bs

+12-12
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,12 @@ Its <a>default allowlist</a> is <code>'self'</code>.
831831
1. Let |context| be a new {{MLContext}} object.
832832
1. If |options| is a {{GPUDevice}} object,
833833
1. Set |context|.{{[[contextType]]}} to "[=context type/webgpu=]".
834-
1. Set |context|.{{[[deviceType]]}} to "[=device type/gpu=]".
835-
1. Set |context|.{{[[powerPreference]]}} to "[=power preference/default=]".
834+
1. Set |context|.{{[[deviceType]]}} to {{MLDeviceType/"gpu"}}.
835+
1. Set |context|.{{[[powerPreference]]}} to {{MLPowerPreference/"default"}}.
836836
1. Otherwise,
837837
1. Set |context|.{{[[contextType]]}} to "[=context type/default=]".
838-
1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device type/cpu=]".
839-
1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power preference/default=]".
838+
1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to {{MLDeviceType/"cpu"}}.
839+
1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to {{MLPowerPreference/"default"}}.
840840
1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, return failure.
841841
1. Return |context|.
842842
</div>
@@ -1089,20 +1089,20 @@ The <dfn>context type</dfn> is the type of the execution context that manages th
10891089
</dl>
10901090

10911091
The <dfn>device type</dfn> indicates the kind of device used for the context. It is one of the following:
1092-
<dl dfn-for="device type">
1093-
<dt>"<dfn>cpu</dfn>"</dt>
1092+
<dl dfn-for="MLDeviceType">
1093+
<dt>"<dfn enum-value>cpu</dfn>"</dt>
10941094
<dd>Provides the broadest compatibility and usability across all client devices with varying degrees of performance.</dd>
1095-
<dt>"<dfn>gpu</dfn>"</dt>
1095+
<dt>"<dfn enum-value>gpu</dfn>"</dt>
10961096
<dd>Provides the broadest range of achievable performance across graphics hardware platforms from consumer devices to professional workstations.</dd>
10971097
</dl>
10981098

10991099
The <dfn>power preference</dfn> indicates preference as related to power consumption. It is one of the following:
1100-
<dl dfn-for="power preference">
1101-
<dt>"<dfn>default</dfn>"</dt>
1100+
<dl dfn-for="MLPowerPreference">
1101+
<dt>"<dfn enum-value>default</dfn>"</dt>
11021102
<dd>Let the user agent select the most suitable behavior.</dd>
1103-
<dt>"<dfn ignore>high-performance</dfn>"</dt>
1103+
<dt>"<dfn enum-value>high-performance</dfn>"</dt>
11041104
<dd>Prioritizes execution speed over power consumption.</dd>
1105-
<dt>"<dfn ignore>low-power</dfn>"</dt>
1105+
<dt>"<dfn enum-value>low-power</dfn>"</dt>
11061106
<dd>Prioritizes power consumption over other considerations such as execution speed.</dd>
11071107
</dl>
11081108

@@ -1129,7 +1129,7 @@ interface MLContext {};
11291129
</div>
11301130

11311131
<div class="note">
1132-
When the {{[[contextType]]}} is set to [=context type/default=] with the {{MLContextOptions}}.{{deviceType}} set to [=device type/gpu=], the user agent is responsible for creating an internal GPU device that operates within the context and is capable of ML workload submission on behalf of the calling application. In this setting however, only {{ArrayBufferView}} inputs and outputs are allowed in and out of the graph execution since the application has no way to know what type of internal GPU device is being created on their behalf. In this case, the user agent is responsible for automatic uploads and downloads of the inputs and outputs to and from the GPU memory using this said internal device.
1132+
When the {{[[contextType]]}} is set to [=context type/default=] with the {{MLContextOptions}}.{{deviceType}} set to {{MLDeviceType/"gpu"}}, the user agent is responsible for creating an internal GPU device that operates within the context and is capable of ML workload submission on behalf of the calling application. In this setting however, only {{ArrayBufferView}} inputs and outputs are allowed in and out of the graph execution since the application has no way to know what type of internal GPU device is being created on their behalf. In this case, the user agent is responsible for automatic uploads and downloads of the inputs and outputs to and from the GPU memory using this said internal device.
11331133
</div>
11341134

11351135
### Synchronous Execution ### {#api-mlcontext-sync-execution}

0 commit comments

Comments
 (0)