Skip to content

Commit c90bc64

Browse files
Wording change: Define power prefs & device type using WebIDL enums (#535)
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 6ceabbd commit c90bc64

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
@@ -833,12 +833,12 @@ Its <a>default allowlist</a> is <code>'self'</code>.
833833
1. Let |context| be a new {{MLContext}} object.
834834
1. If |options| is a {{GPUDevice}} object,
835835
1. Set |context|.{{[[contextType]]}} to "[=context type/webgpu=]".
836-
1. Set |context|.{{[[deviceType]]}} to "[=device type/gpu=]".
837-
1. Set |context|.{{[[powerPreference]]}} to "[=power preference/default=]".
836+
1. Set |context|.{{[[deviceType]]}} to {{MLDeviceType/"gpu"}}.
837+
1. Set |context|.{{[[powerPreference]]}} to {{MLPowerPreference/"default"}}.
838838
1. Otherwise,
839839
1. Set |context|.{{[[contextType]]}} to "[=context type/default=]".
840-
1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device type/cpu=]".
841-
1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power preference/default=]".
840+
1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to {{MLDeviceType/"cpu"}}.
841+
1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to {{MLPowerPreference/"default"}}.
842842
1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, return failure.
843843
1. Return |context|.
844844
</div>
@@ -1091,20 +1091,20 @@ The <dfn>context type</dfn> is the type of the execution context that manages th
10911091
</dl>
10921092

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

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

@@ -1131,7 +1131,7 @@ interface MLContext {};
11311131
</div>
11321132

11331133
<div class="note">
1134-
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.
1134+
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.
11351135
</div>
11361136

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

0 commit comments

Comments
 (0)