From 2f07a8f631ae0726d9413b78aa54dff863997acb Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Thu, 8 Dec 2022 19:01:57 +0200 Subject: [PATCH 01/13] Move the Permissions Policy Integration section Signed-off-by: Zoltan Kis --- index.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index 2f2c6f3b..63eccc16 100644 --- a/index.bs +++ b/index.bs @@ -583,6 +583,12 @@ interface ML { }; +### Permissions Policy Integration ### {#permissions-policy-integration} + +This specification defines a policy-controlled feature identified by the +string "webnn". +Its default allowlist is 'self'. + The {{ML/createContext()}} method steps are: 1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, then throw a "{{SecurityError!!exception}}" {{DOMException}} and abort these steps. 1. Let |promise| be [=a new promise=]. @@ -607,12 +613,6 @@ The {{ML/createContext()}} method steps are: 1. [=Resolve=] |promise| with a new {{NotSupportedError}}. 1. Return |promise|. -### Permissions Policy Integration ### {#permissions-policy-integration} - -This specification defines a policy-controlled feature identified by the -string "webnn". -Its default allowlist is 'self'. - ## The MLContext interface ## {#api-mlcontext} The {{MLContext}} interface represents a global state of neural network compute workload and execution processes. Each {{MLContext}} object has associated [=context type=], [=device type=] and [=power preference=]. From 10633383b4f38ca784a2c7d1b30e440433e6171a Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Thu, 8 Dec 2022 19:32:37 +0200 Subject: [PATCH 02/13] Improve the createContext() steps Signed-off-by: Zoltan Kis --- index.bs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/index.bs b/index.bs index 63eccc16..834645e8 100644 --- a/index.bs +++ b/index.bs @@ -589,29 +589,23 @@ This specification defines a policy-controlled feature identified by the string "webnn". Its default allowlist is 'self'. +### The {{ML/createContext()}} method ### {#api-ml-createcontext} The {{ML/createContext()}} method steps are: -1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, then throw a "{{SecurityError!!exception}}" {{DOMException}} and abort these steps. +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}}" and abort these steps. 1. Let |promise| be [=a new promise=]. +1. Return |promise| and run the following steps [=in parallel=]. 1. Let |context| be a new {{MLContext}} object. -1. Switch on the method's first argument: -
-
{{MLContextOptions}} -
Set |context|.{{[[contextType]]}} to [=default-context|default=]. -
Set |context|.{{[[deviceType]]}} to the value of {{MLContextOptions}}'s {{deviceType}}. -
Set |context|.{{[[powerPreference]]}} to the value of {{MLContextOptions}}'s {{powerPreference}}. - -
{{GPUDevice}} -
Set |context|.{{[[contextType]]}} to [=webgpu-context|webgpu=]. -
Set |context|.{{[[deviceType]]}} to "[=device-type-gpu|gpu=]". -
Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". -
-1. Issue the following steps to a separate timeline: - 1. If the User Agent can support the |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, then: - 1. Set |context|.{{MLContext/[[implementation]]}} to an implementation supporting |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}. - 1. [=Resolve=] |promise| with |context|. - 1. Else: - 1. [=Resolve=] |promise| with a new {{NotSupportedError}}. -1. Return |promise|. +1. Let |options| be the first argument. +1. If |options| is a {{GPUDevice}}, + 1. Set |context|.{{[[contextType]]}} to [=webgpu-context|webgpu=]. + 1. Set |context|.{{[[deviceType]]}} to "[=device-type-gpu|gpu=]". + 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". +1. Otherwise, + 1. Set |context|.{{[[contextType]]}} to [=default-context|default=]. + 1. Set |context|.{{[[deviceType]]}} to the value of |options|'s {{deviceType}} if defined, or to "[=device-type-cpu|cpu=]". + 1. Set |context|.{{[[powerPreference]]}} to the value of |options|'s {{powerPreference}} if defined, or to "[=power-preference-default|default=]". +1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. +1. [=Resolve=] |promise| with |context|. ## The MLContext interface ## {#api-mlcontext} The {{MLContext}} interface represents a global state of neural network compute workload and execution processes. Each {{MLContext}} object has associated [=context type=], [=device type=] and [=power preference=]. From b2c6b67925fbdbbf2170f62c35877367b482e7e4 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Thu, 8 Dec 2022 19:34:30 +0200 Subject: [PATCH 03/13] Remove the unused internal slot MLContext/[[implementation]] Signed-off-by: Zoltan Kis --- index.bs | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.bs b/index.bs index 834645e8..101de15f 100644 --- a/index.bs +++ b/index.bs @@ -655,9 +655,6 @@ interface MLContext {}; : \[[powerPreference]] of type [=power preference=] :: The {{MLContext}}'s [=power preference=]. - : \[[implementation]] - :: - The underlying implementation provided by the User Agent.
From a4e3636ebed9ba93caf2e5c15383acf453db9bd7 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Thu, 8 Dec 2022 19:52:13 +0200 Subject: [PATCH 04/13] Fix #308: Add the validate MLContext algorithm. Update the createContext() steps. Signed-off-by: Zoltan Kis --- index.bs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 101de15f..38f50229 100644 --- a/index.bs +++ b/index.bs @@ -597,14 +597,14 @@ The {{ML/createContext()}} method steps are: 1. Let |context| be a new {{MLContext}} object. 1. Let |options| be the first argument. 1. If |options| is a {{GPUDevice}}, - 1. Set |context|.{{[[contextType]]}} to [=webgpu-context|webgpu=]. + 1. Set |context|.{{[[contextType]]}} to "[=webgpu-context|webgpu=]". 1. Set |context|.{{[[deviceType]]}} to "[=device-type-gpu|gpu=]". 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". 1. Otherwise, - 1. Set |context|.{{[[contextType]]}} to [=default-context|default=]. + 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]. 1. Set |context|.{{[[deviceType]]}} to the value of |options|'s {{deviceType}} if defined, or to "[=device-type-cpu|cpu=]". 1. Set |context|.{{[[powerPreference]]}} to the value of |options|'s {{powerPreference}} if defined, or to "[=power-preference-default|default=]". -1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. +1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. ## The MLContext interface ## {#api-mlcontext} @@ -661,6 +661,14 @@ interface MLContext {}; When the {{[[contextType]]}} is set to [=default-context|default=] with the {{MLContextOptions}}.{{deviceType}} set to [=device-type-gpu|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.
+### The validate {{MLContext}} algorithm ### {#api-mlcontext-validate} +To validate {{MLContext}}, given |context|, run these steps: +1. If |context|.{{[[contextType]]}} is not "[=webgpu-context|webgpu=]" or "[=default-context|default=], return failure. +1. If |context|.{{[[deviceType]]}} is not "[=device-type-cpu|cpu=]" or "[=device-type-gpu|gpu=]", return failure. +1. If |context|.{{[[powerPreference]]}} is not "[=power-preference-default|default=]" or "[=power-preference-high-performance|high-performance=]" or "[=power-preference-low-power|low-power=]", return failure. +1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, return failure. +1. Return `true`; + ### Synchronous Execution ### {#api-mlcontext-sync-execution} 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 throws an {{OperationError}} exception. From f5e5cd46d12aa7db02641ce45c0c0061b8c64ddc Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Fri, 9 Dec 2022 10:59:45 +0200 Subject: [PATCH 05/13] Use 'exists' instead of 'defined' in createContext() Signed-off-by: Zoltan Kis --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index 38f50229..dc60c99b 100644 --- a/index.bs +++ b/index.bs @@ -602,8 +602,8 @@ The {{ML/createContext()}} method steps are: 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". 1. Otherwise, 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]. - 1. Set |context|.{{[[deviceType]]}} to the value of |options|'s {{deviceType}} if defined, or to "[=device-type-cpu|cpu=]". - 1. Set |context|.{{[[powerPreference]]}} to the value of |options|'s {{powerPreference}} if defined, or to "[=power-preference-default|default=]". + 1. Set |context|.{{[[deviceType]]}} to the value of |options|'s {{deviceType}} if it [=map/exists=], or to "[=device-type-cpu|cpu=]". + 1. Set |context|.{{[[powerPreference]]}} to the value of |options|'s {{powerPreference}} if it [=map/exists=], or to "[=power-preference-default|default=]". 1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. From 5b9b517004ab5fc2ccfc20df8873c7f60d063c44 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Fri, 9 Dec 2022 22:12:30 +0200 Subject: [PATCH 06/13] Reformulate 'exists' clauses in createContext() Signed-off-by: Zoltan Kis --- index.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.bs b/index.bs index dc60c99b..a376de0b 100644 --- a/index.bs +++ b/index.bs @@ -596,14 +596,14 @@ The {{ML/createContext()}} method steps are: 1. Return |promise| and run the following steps [=in parallel=]. 1. Let |context| be a new {{MLContext}} object. 1. Let |options| be the first argument. -1. If |options| is a {{GPUDevice}}, +1. If |options| is a {{GPUDevice}} object, 1. Set |context|.{{[[contextType]]}} to "[=webgpu-context|webgpu=]". 1. Set |context|.{{[[deviceType]]}} to "[=device-type-gpu|gpu=]". 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". 1. Otherwise, - 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]. - 1. Set |context|.{{[[deviceType]]}} to the value of |options|'s {{deviceType}} if it [=map/exists=], or to "[=device-type-cpu|cpu=]". - 1. Set |context|.{{[[powerPreference]]}} to the value of |options|'s {{powerPreference}} if it [=map/exists=], or to "[=power-preference-default|default=]". + 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". + 1. If |options|'s {{deviceType}} [=map/exists=], set |context|.{{[[deviceType]]}} to its value, otherwise to "[=device-type-cpu|cpu=]". + 1. If |options|'s {{powerPreference}} [=map/exists=], set |context|.{{[[powerPreference]]}} to its value, otherwise to "[=power-preference-default|default=]". 1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. From 5961fd861d647a17f3acd36c808e2dcb3e7a210b Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Fri, 9 Dec 2022 22:20:29 +0200 Subject: [PATCH 07/13] Add the createContextSync() section and algorithm, using factored-out 'create context' steps Signed-off-by: Zoltan Kis --- index.bs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/index.bs b/index.bs index a376de0b..f820fa32 100644 --- a/index.bs +++ b/index.bs @@ -594,19 +594,28 @@ The {{ML/createContext()}} method steps are: 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}}" and abort these steps. 1. Let |promise| be [=a new promise=]. 1. Return |promise| and run the following steps [=in parallel=]. -1. Let |context| be a new {{MLContext}} object. 1. Let |options| be the first argument. -1. If |options| is a {{GPUDevice}} object, - 1. Set |context|.{{[[contextType]]}} to "[=webgpu-context|webgpu=]". - 1. Set |context|.{{[[deviceType]]}} to "[=device-type-gpu|gpu=]". - 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". -1. Otherwise, - 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". - 1. If |options|'s {{deviceType}} [=map/exists=], set |context|.{{[[deviceType]]}} to its value, otherwise to "[=device-type-cpu|cpu=]". - 1. If |options|'s {{powerPreference}} [=map/exists=], set |context|.{{[[powerPreference]]}} to its value, otherwise to "[=power-preference-default|default=]". +1. Run the create context steps given |options|: + 1. Let |context| be a new {{MLContext}} object. + 1. If |options| is a {{GPUDevice}} object, + 1. Set |context|.{{[[contextType]]}} to "[=webgpu-context|webgpu=]". + 1. Set |context|.{{[[deviceType]]}} to "[=device-type-gpu|gpu=]". + 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". + 1. Otherwise, + 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". + 1. If |options|'s {{deviceType}} [=map/exists=], set |context|.{{[[deviceType]]}} to its value, otherwise to "[=device-type-cpu|cpu=]". + 1. If |options|'s {{powerPreference}} [=map/exists=], set |context|.{{[[powerPreference]]}} to its value, otherwise to "[=power-preference-default|default=]". 1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. +### The {{ML/createContextSync()}} method ### {#api-ml-createcontextsync} +The {{ML/createContextSync()}} method steps are: +1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, throw a "{{SecurityError}}" and abort these steps. +1. Let |options| be the first argument. +1. Let |context| be the result of running the create context steps given |options|. +1. If the validate MLContext steps given |context| return failure, throw a {{NotSupportedError}} and abort these steps. +1. Return |context|. + ## The MLContext interface ## {#api-mlcontext} The {{MLContext}} interface represents a global state of neural network compute workload and execution processes. Each {{MLContext}} object has associated [=context type=], [=device type=] and [=power preference=]. From 396327ff83b4f56f89776dcfec9ab2bfc952cefe Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Mon, 12 Dec 2022 11:29:21 +0200 Subject: [PATCH 08/13] Make 'then' clauses a sub-step in createContext() Signed-off-by: Zoltan Kis --- index.bs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index f820fa32..d387639c 100644 --- a/index.bs +++ b/index.bs @@ -603,8 +603,12 @@ The {{ML/createContext()}} method steps are: 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". 1. Otherwise, 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". - 1. If |options|'s {{deviceType}} [=map/exists=], set |context|.{{[[deviceType]]}} to its value, otherwise to "[=device-type-cpu|cpu=]". - 1. If |options|'s {{powerPreference}} [=map/exists=], set |context|.{{[[powerPreference]]}} to its value, otherwise to "[=power-preference-default|default=]". + 1. If |options|'s {{deviceType}} [=map/exists=], then: + 1. Set |context|.{{[[deviceType]]}} to |options|'s {{deviceType}}. + 1. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". + 1. If |options|'s {{powerPreference}} [=map/exists=], then: + 1. Set |context|.{{[[powerPreference]]}} to |options|'s {{powerPreference}}. + 1. Otherwise, set |options|'s {{powerPreference}} to "[=power-preference-default|default=]". 1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. From a3f3ecc54ed17a8f7da62c470287fabf08587469 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Mon, 12 Dec 2022 11:50:55 +0200 Subject: [PATCH 09/13] Re-align if clauses in createContext() Signed-off-by: Zoltan Kis --- index.bs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index d387639c..c91c5099 100644 --- a/index.bs +++ b/index.bs @@ -603,12 +603,8 @@ The {{ML/createContext()}} method steps are: 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". 1. Otherwise, 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". - 1. If |options|'s {{deviceType}} [=map/exists=], then: - 1. Set |context|.{{[[deviceType]]}} to |options|'s {{deviceType}}. - 1. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". - 1. If |options|'s {{powerPreference}} [=map/exists=], then: - 1. Set |context|.{{[[powerPreference]]}} to |options|'s {{powerPreference}}. - 1. Otherwise, set |options|'s {{powerPreference}} to "[=power-preference-default|default=]". + 1. If |options|'s {{deviceType}} [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|'s {{deviceType}}. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". + 1. If |options|'s {{powerPreference}} [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|'s {{powerPreference}}. Otherwise, set |options|'s {{powerPreference}} to "[=power-preference-default|default=]". 1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. From eed627bcfe6b8a9c5afa025ce19684a7fd06637f Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Mon, 12 Dec 2022 13:52:22 +0200 Subject: [PATCH 10/13] Use map-get convention in createContext() Signed-off-by: Zoltan Kis --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index c91c5099..8626a0e9 100644 --- a/index.bs +++ b/index.bs @@ -603,8 +603,8 @@ The {{ML/createContext()}} method steps are: 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". 1. Otherwise, 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". - 1. If |options|'s {{deviceType}} [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|'s {{deviceType}}. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". - 1. If |options|'s {{powerPreference}} [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|'s {{powerPreference}}. Otherwise, set |options|'s {{powerPreference}} to "[=power-preference-default|default=]". + 1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". + 1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". 1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. From 6c5b11b574be0ed903e241814c649dd7806c5824 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Tue, 13 Dec 2022 10:10:57 +0200 Subject: [PATCH 11/13] Fix review comments: false instead failure, title of MLContext validation section. Signed-off-by: Zoltan Kis --- index.bs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.bs b/index.bs index 8626a0e9..10323ff6 100644 --- a/index.bs +++ b/index.bs @@ -605,15 +605,15 @@ The {{ML/createContext()}} method steps are: 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". 1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". 1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". -1. If the validate MLContext steps given |context| return failure, [=reject=] |promise| with a new {{NotSupportedError}} and abort these steps. +1. If the validate MLContext steps given |context| return `false`, [=reject=] |promise| with a {{NotSupportedError}} and abort these steps. 1. [=Resolve=] |promise| with |context|. ### The {{ML/createContextSync()}} method ### {#api-ml-createcontextsync} The {{ML/createContextSync()}} method steps are: -1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, throw a "{{SecurityError}}" and abort these steps. +1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, throw a {{SecurityError}} and abort these steps. 1. Let |options| be the first argument. 1. Let |context| be the result of running the create context steps given |options|. -1. If the validate MLContext steps given |context| return failure, throw a {{NotSupportedError}} and abort these steps. +1. If the validate MLContext steps given |context| return `false`, throw a {{NotSupportedError}} and abort these steps. 1. Return |context|. ## The MLContext interface ## {#api-mlcontext} @@ -670,12 +670,12 @@ interface MLContext {}; When the {{[[contextType]]}} is set to [=default-context|default=] with the {{MLContextOptions}}.{{deviceType}} set to [=device-type-gpu|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. -### The validate {{MLContext}} algorithm ### {#api-mlcontext-validate} +### The {{MLContext}} validation algorithm ### {#api-mlcontext-validate} To validate {{MLContext}}, given |context|, run these steps: -1. If |context|.{{[[contextType]]}} is not "[=webgpu-context|webgpu=]" or "[=default-context|default=], return failure. -1. If |context|.{{[[deviceType]]}} is not "[=device-type-cpu|cpu=]" or "[=device-type-gpu|gpu=]", return failure. -1. If |context|.{{[[powerPreference]]}} is not "[=power-preference-default|default=]" or "[=power-preference-high-performance|high-performance=]" or "[=power-preference-low-power|low-power=]", return failure. -1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, return failure. +1. If |context|.{{[[contextType]]}} is not "[=webgpu-context|webgpu=]" or "[=default-context|default=], return `false`. +1. If |context|.{{[[deviceType]]}} is not "[=device-type-cpu|cpu=]" or "[=device-type-gpu|gpu=]", return `false`. +1. If |context|.{{[[powerPreference]]}} is not "[=power-preference-default|default=]" or "[=power-preference-high-performance|high-performance=]" or "[=power-preference-low-power|low-power=]", return `false`. +1. If the user agent cannot support |context|.{{[[contextType]]}}, |context|.{{[[deviceType]]}} and |context|.{{[[powerPreference]]}}, return `false`. 1. Return `true`; ### Synchronous Execution ### {#api-mlcontext-sync-execution} From fc8854c1df667451c80560a307ee9ad44fb04ec6 Mon Sep 17 00:00:00 2001 From: Zoltan Kis Date: Tue, 13 Dec 2022 17:44:25 +0200 Subject: [PATCH 12/13] Fix error handling, only for this PR Signed-off-by: Zoltan Kis --- index.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 10323ff6..7aa3e6b9 100644 --- a/index.bs +++ b/index.bs @@ -605,15 +605,15 @@ The {{ML/createContext()}} method steps are: 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". 1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". 1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". -1. If the validate MLContext steps given |context| return `false`, [=reject=] |promise| with a {{NotSupportedError}} and abort these steps. +1. If the validate MLContext steps given |context| return `false`, [=reject=] |promise| with a "{{NotSupportedError}}" and abort these steps. 1. [=Resolve=] |promise| with |context|. ### The {{ML/createContextSync()}} method ### {#api-ml-createcontextsync} The {{ML/createContextSync()}} method steps are: -1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, throw a {{SecurityError}} and abort these steps. +1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, throw a "{{SecurityError}}" and abort these steps. 1. Let |options| be the first argument. 1. Let |context| be the result of running the create context steps given |options|. -1. If the validate MLContext steps given |context| return `false`, throw a {{NotSupportedError}} and abort these steps. +1. If the validate MLContext steps given |context| return `false`, throw a "{{NotSupportedError}}" and abort these steps. 1. Return |context|. ## The MLContext interface ## {#api-mlcontext} From 579d815b4865845ece73743d40b7d577c6d62829 Mon Sep 17 00:00:00 2001 From: Anssi Kostiainen Date: Tue, 13 Dec 2022 19:35:21 +0200 Subject: [PATCH 13/13] Use the recommended DOMException notation 'Always favor the "SyntaxError" DOMException notation over just using SyntaxError to refer to the DOMException.' This notation applies to the following error names: https://webidl.spec.whatwg.org/#idl-DOMException-error-names --- index.bs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 7aa3e6b9..9b25c343 100644 --- a/index.bs +++ b/index.bs @@ -591,7 +591,8 @@ Its default allowlist is 'self'. ### The {{ML/createContext()}} method ### {#api-ml-createcontext} The {{ML/createContext()}} method steps are: -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}}" and abort these steps. +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}} and abort these steps. + 1. Let |promise| be [=a new promise=]. 1. Return |promise| and run the following steps [=in parallel=]. 1. Let |options| be the first argument. @@ -605,7 +606,7 @@ The {{ML/createContext()}} method steps are: 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]". 1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]". 1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]". -1. If the validate MLContext steps given |context| return `false`, [=reject=] |promise| with a "{{NotSupportedError}}" and abort these steps. +1. If the validate MLContext steps given |context| return `false`, [=reject=] |promise| with a "{{NotSupportedError}}" {{DOMException}} and abort these steps. 1. [=Resolve=] |promise| with |context|. ### The {{ML/createContextSync()}} method ### {#api-ml-createcontextsync} @@ -613,7 +614,7 @@ The {{ML/createContextSync()}} method steps are: 1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, throw a "{{SecurityError}}" and abort these steps. 1. Let |options| be the first argument. 1. Let |context| be the result of running the create context steps given |options|. -1. If the validate MLContext steps given |context| return `false`, throw a "{{NotSupportedError}}" and abort these steps. +1. If the validate MLContext steps given |context| return `false`, throw a "{{NotSupportedError}}" {{DOMException}} and abort these steps. 1. Return |context|. ## The MLContext interface ## {#api-mlcontext}