You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wording change: Streamline context creation and validation algorithms (#519)
Bundle validation right into context creation, rather than making it
a separate step.
Note that with the removal of the "validate MLContext" algorithm, a
handful of the internal enum members are never referenced; they are
implicitly mapped to identical enums defined in Web IDL. This is
discussed in #497 which proposes de-duping the enums. In the mean
time, the definitions are marked with "ignore" to silence warnings
about unreferenced defnitions.
Fixes#498
Copy file name to clipboardexpand all lines: index.bs
+8-27
Original file line number
Diff line number
Diff line change
@@ -837,6 +837,7 @@ Its <a>default allowlist</a> is <code>'self'</code>.
837
837
1. Set |context|.{{[[contextType]]}} to "[=context type/default=]".
838
838
1. If |options|["{{deviceType}}"][=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device type/cpu=]".
839
839
1. If |options|["{{powerPreference}}"][=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power preference/default=]".
840
+
1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, return failure.
840
841
1. Return |context|.
841
842
</div>
842
843
</details>
@@ -849,8 +850,7 @@ Its <a>default allowlist</a> is <code>'self'</code>.
849
850
1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, return [=a new promise=][=rejected=] with a "{{SecurityError}}" {{DOMException}}.
850
851
1. Let |promise| be [=a new promise=].
851
852
1. Return |promise| and run the following steps [=in parallel=].
852
-
1. Let |context| be the result of [=creating a context=] given |options|.
853
-
1. If [=validating MLContext=] given |context| returns false, [=reject=] |promise| with a "{{NotSupportedError}}" {{DOMException}}.
853
+
1. Let |context| be the result of [=creating a context=] given |options|. If that returns failure, then [=reject=] |promise| with a "{{NotSupportedError}}" {{DOMException}}.
854
854
1. [=Resolve=] |promise| with |context|.
855
855
</div>
856
856
</details>
@@ -863,8 +863,7 @@ Its <a>default allowlist</a> is <code>'self'</code>.
863
863
1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, return [=a new promise=][=rejected=] with a "{{SecurityError}}" {{DOMException}}.
864
864
1. Let |promise| be [=a new promise=].
865
865
1. Return |promise| and run the following steps [=in parallel=].
866
-
1. Let |context| be the result of [=creating a context=] given |gpuDevice|.
867
-
1. If [=validating MLContext=] given |context| returns false, [=reject=] |promise| with a "{{NotSupportedError}}" {{DOMException}}.
866
+
1. Let |context| be the result of [=creating a context=] given |gpuDevice|. If that returns failure, [=reject=] |promise| with a "{{NotSupportedError}}" {{DOMException}}.
868
867
1. [=Resolve=] |promise| with |context|.
869
868
</div>
870
869
</details>
@@ -877,8 +876,7 @@ Its <a>default allowlist</a> is <code>'self'</code>.
877
876
</summary>
878
877
<div class=algorithm-steps>
879
878
1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}}.
880
-
1. Let |context| be the result [=creating a context=] |options|.
881
-
1. If [=validating MLContext=] given |context| return false, then [=exception/throw=] a "{{NotSupportedError}}" {{DOMException}}.
879
+
1. Let |context| be the result of [=creating a context=] with |options|. If that returns failure, then [=exception/throw=] a "{{NotSupportedError}}" {{DOMException}}.
882
880
1. Return |context|.
883
881
</div>
884
882
</details>
@@ -889,8 +887,7 @@ Its <a>default allowlist</a> is <code>'self'</code>.
889
887
</summary>
890
888
<div class=algorithm-steps>
891
889
1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}}.
892
-
1. Let |context| be the result [=creating a context=] with |gpuDevice|.
893
-
1. If [=validating MLContext=] given |context| return false, then [=exception/throw=] a "{{NotSupportedError}}" {{DOMException}}.
890
+
1. Let |context| be the result of [=creating a context=] with |gpuDevice|. If that returns failure, then [=exception/throw=] a "{{NotSupportedError}}" {{DOMException}}.
894
891
1. Return |context|.
895
892
</div>
896
893
</details>
@@ -1103,9 +1100,9 @@ The <dfn>power preference</dfn> indicates preference as related to power consump
1103
1100
<dl dfn-for="power preference">
1104
1101
<dt>"<dfn>default</dfn>"</dt>
1105
1102
<dd>Let the user agent select the most suitable behavior.</dd>
1106
-
<dt>"<dfn>high-performance</dfn>"</dt>
1103
+
<dt>"<dfn ignore>high-performance</dfn>"</dt>
1107
1104
<dd>Prioritizes execution speed over power consumption.</dd>
1108
-
<dt>"<dfn>low-power</dfn>"</dt>
1105
+
<dt>"<dfn ignore>low-power</dfn>"</dt>
1109
1106
<dd>Prioritizes power consumption over other considerations such as execution speed.</dd>
1110
1107
</dl>
1111
1108
@@ -1135,21 +1132,6 @@ interface MLContext {};
1135
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.
To <dfn>validate MLContext</dfn>, given |context|, run these steps:
1143
-
</summary>
1144
-
<div class=algorithm-steps>
1145
-
1. If |context|.{{[[contextType]]}} is not "[=context type/webgpu=]" or "[=context type/default=]", return false.
1146
-
1. If |context|.{{[[deviceType]]}} is not "[=device type/cpu=]" or "[=device type/gpu=]", return false.
1147
-
1. If |context|.{{[[powerPreference]]}} is not "[=power preference/default=]" or "[=power preference/high-performance=]" or "[=power preference/low-power=]", return false.
1148
-
1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, return false.
Synchronously carries out the computational workload of a compiled graph {{MLGraph}} on the calling thread, which must be a worker thread, to produce results as defined by the operations in the graph. This method of execution requires an {{MLContext}} created with {{MLContextOptions}}. Otherwise, it [=exception/throws=] an "{{OperationError}}" {{DOMException}}.
1155
1137
@@ -1483,11 +1465,10 @@ Both {{MLGraphBuilder}}.{{MLGraphBuilder/build()}} and {{MLGraphBuilder}}.{{MLGr
1483
1465
1484
1466
<details open algorithm>
1485
1467
<summary>
1486
-
The [=new=]<dfn constructor for=MLGraphBuilder lt="MLGraphBuilder(context)">MLGraphBuilder(context)</dfn> constructor steps are:
1468
+
The [=new=]<dfn constructor for=MLGraphBuilder lt="MLGraphBuilder(context)">MLGraphBuilder(|context|)</dfn> constructor steps are:
1487
1469
</summary>
1488
1470
<div class=algorithm-steps>
1489
1471
1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, then [=exception/throw=] a "{{SecurityError}}" {{DOMException}}.
1490
-
1. If [=validating MLContext=] given |context| returns false, then [=exception/throw=] a "{{TypeError}}".
1491
1472
1. Set [=this=].{{MLGraphBuilder/[[context]]}} to |context|.
0 commit comments