Skip to content

Commit

Permalink
Add the createContextSync() section and algorithm, using factored-out…
Browse files Browse the repository at this point in the history
… 'create context' steps

Signed-off-by: Zoltan Kis <zoltan.kis@intel.com>
  • Loading branch information
zolkis committed Dec 9, 2022
1 parent 5b9b517 commit 5961fd8
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dfn>create context</dfn> 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 <a>validate MLContext</a> 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 <a>create context</a> steps given |options|.
1. If the <a>validate MLContext</a> 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=].

Expand Down

0 comments on commit 5961fd8

Please sign in to comment.