Skip to content

Commit

Permalink
Fix webmachinelearning#308: Add the validate MLContext algorithm. Upd…
Browse files Browse the repository at this point in the history
…ate the createContext() steps.

Signed-off-by: Zoltan Kis <[email protected]>
  • Loading branch information
zolkis committed Dec 8, 2022
1 parent b2c6b67 commit a4e3636
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 MLContext interface ## {#api-mlcontext}
Expand Down Expand Up @@ -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.
</div>

### The validate {{MLContext}} algorithm ### {#api-mlcontext-validate}
To <dfn lt="validate MLContext">validate {{MLContext}}</dfn>, 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.

Expand Down

0 comments on commit a4e3636

Please sign in to comment.