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
Conventions: Ensure all dict members have definitions (#621)
* Conventions: Ensure all dict members have definitions
- Documents the convention.
- Dedupes `MLEluOptions`'s `alpha` definitions
- Dedupes `MLClampOptions`'s `minValue` and `maxValue`, and references
#396
- Moves `MLOperandDescriptor` member documentation out of IDL comments
- Introduces simple definitions for `MLComputeResult`'s `inputs` and
`outputs`
- Converts "device type" and "power preference" into definitions for
`MLContextOptions`'s `deviceType` and `powerPreference`.
Also includes these adjacent changes to improve the document flow:
- Moves the "context type" definition into the `MLContext` section.
- Moves the Permission Policy Integration section from API into
Programming Model which seems like a slightly better home for it.
Fixes#483
* Add subsection for MLContextOptions
* Feedback from @huningxin
Copy file name to clipboardExpand all lines: docs/SpecCodingConventions.md
+1-2
Original file line number
Diff line number
Diff line change
@@ -138,5 +138,4 @@ Example:
138
138
139
139
* Dictionary members are referenced using dotted property syntax. e.g. _options.padding_
140
140
* Note that this is contrary to Web IDL + Infra; formally, a JavaScript object has been mapped to a Web IDL [dictionary](https://webidl.spec.whatwg.org/#idl-dictionaries) and then processed into an Infra [map](ordered) by the time a spec is using it. So formally the syntax _options["padding"]_ should be used.
141
-
142
-
141
+
* Dictionary members should be given definitions somewhere in the text. This is usually done with a `<dl dfn-type=dict-member dfn-for=...>` for the dictionary as a whole, containing a `<dfn>` for each member.
Copy file name to clipboardExpand all lines: index.bs
+62-36
Original file line number
Diff line number
Diff line change
@@ -616,9 +616,9 @@ Unlike WebGPU, this API does not intrinsically support custom shader authoring;
616
616
617
617
The WebGPU API identifies <a href="https://gpuweb.github.io/gpuweb/#privacy-machine-artifacts">machine-specific artifacts</a> as a privacy consideration. Similarly, the WebNN API's compute unit scheduling may under certain circumstances introduce a fingerprint. However, similarly to WebGPU, such fingerprints are identical across most or all of the devices of each vendor, mitigating the concern. Furthermore, software implementations can be used to further eliminate such artifacts.
618
618
619
-
The WebNN API defines two developer-settable preferences to help inform [[#programming-model-device-selection]] and allow the implementation to better select the most appropriate underlying execution device for the workload. [=Device type=] normatively indicates the kind of device and is either {{MLDeviceType/"cpu"}} or {{MLDeviceType/"gpu"}}. If this type cannot be satisfied, an "{{OperationError}}" {{DOMException}} is thrown, thus this type can in some cases add two bits of entropy to the fingerprint. [=Power preference=] indicates preference as related to the power consumption and is considered a hint only and as such does not increase entropy of the fingerprint.
619
+
The WebNN API defines two developer-settable preferences to help inform [[#programming-model-device-selection]] and allow the implementation to better select the most appropriate underlying execution device for the workload. An {{MLDeviceType}} normatively indicates the kind of device and is either {{MLDeviceType/"cpu"}} or {{MLDeviceType/"gpu"}}. If this type cannot be satisfied, an "{{OperationError}}" {{DOMException}} is thrown, thus this type can in some cases add two bits of entropy to the fingerprint. An {{MLPowerPreference}} indicates preference as related to the power consumption and is considered a hint only and as such does not increase entropy of the fingerprint.
620
620
621
-
If a future version of this specification introduces support for new a [=device type=] that can only support a subset of {{MLOperandDataType}}s, that may introduce a new fingerprint.
621
+
If a future version of this specification introduces support for a new {{MLDeviceType}} that can only support a subset of {{MLOperandDataType}}s, that may introduce a new fingerprint.
622
622
623
623
In general, implementers of this API are expected to apply <a href="https://gpuweb.github.io/gpuweb/#privacy-considerations">WebGPU Privacy Considerations</a> to their implementations where applicable.
624
624
@@ -668,7 +668,7 @@ An {{MLContext}} interface represents a global state of neural network execution
668
668
669
669
In a situation when a GPU context executes a graph with a constant or an input in the system memory as an {{ArrayBufferView}}, the input content is automatically uploaded from the system memory to the GPU memory, and downloaded back to the system memory of an {{ArrayBufferView}} output buffer at the end of the graph execution. This data upload and download cycles will only occur whenever the execution device requires the data to be copied out of and back into the system memory, such as in the case of the GPU. It doesn't occur when the device is a CPU device. Additionally, the result of the graph execution is in a known layout format. While the execution may be optimized for a native memory access pattern in an intermediate result within the graph, the output of the last operation of the graph must convert the content back to a known layout format at the end of the graph in order to maintain the expected behavior from the caller's perspective.
670
670
671
-
When an {{MLContext}} is created with {{MLContextOptions}}, the user agent selects and creates the underlying execution device by taking into account the application's [=power preference=] and [=device type=] specified in the {{MLPowerPreference}} and {{MLDeviceType}} options.
671
+
When an {{MLContext}} is created with {{MLContextOptions}}, the user agent selects and creates the underlying execution device by taking into account the application's {{MLPowerPreference}} and {{MLDeviceType}} options.
@@ -678,6 +678,12 @@ The <dfn>ML task source</dfn> is a [=task source=] to be used for all [=tasks=]
678
678
<p>To <dfn>queue an ML task</dfn> given a [=global object=] |global| and a series of steps |steps|, [=queue a global task=] on the [=ML task source=] with |global| and |steps|.
The <dfn>context type</dfn> is the type of the execution context that manages the resources and facilitates the compilation and execution of the neural network graph:
732
-
<dl dfn-for="context type">
733
-
<dt>"<dfn>default</dfn>"</dt>
734
-
<dd>Context created per user preference options.</dd>
735
-
<dt>"<dfn>webgpu</dfn>"</dt>
736
-
<dd>Context created from WebGPU device.</dd>
737
-
</dl>
738
-
739
-
The <dfn>device type</dfn> indicates the kind of device used for the context. It is one of the following:
731
+
The <dfn dfn-for=MLContextOptions dfn-type=dict-member>deviceType</dfn> option is an <dfn dfn-type=enum>MLDeviceType</dfn> and indicates the application's preference for the kind of device used for the context. It is one of the following:
740
732
<dl dfn-for="MLDeviceType">
741
733
<dt>"<dfn enum-value>cpu</dfn>"</dt>
742
734
<dd>Provides the broadest compatibility and usability across all client devices with varying degrees of performance.</dd>
743
735
<dt>"<dfn enum-value>gpu</dfn>"</dt>
744
736
<dd>Provides the broadest range of achievable performance across graphics hardware platforms from consumer devices to professional workstations.</dd>
745
737
</dl>
746
738
747
-
The <dfn>power preference</dfn> indicates preference as related to power consumption. It is one of the following:
739
+
The <dfn dfn-for=MLContextOptions dfn-type=dict-member>powerPreference</dfn> option is an <dfn dfn-type=enum>MLPowerPreference</dfn>and indicates the application's preference as related to power consumption. It is one of the following:
748
740
<dl dfn-for="MLPowerPreference">
749
741
<dt>"<dfn enum-value>default</dfn>"</dt>
750
742
<dd>Let the user agent select the most suitable behavior.</dd>
@@ -754,6 +746,8 @@ The <dfn>power preference</dfn> indicates preference as related to power consump
754
746
<dd>Prioritizes power consumption over other considerations such as execution speed.</dd>
To <dfn>create a context</dfn> given [=realm=] |realm| and |options| (a {{GPUDevice}} or {{MLContextOptions}}), run these steps:
@@ -800,7 +794,7 @@ The <dfn>power preference</dfn> indicates preference as related to power consump
800
794
</details>
801
795
802
796
## {{MLContext}} interface ## {#api-mlcontext}
803
-
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=].
797
+
The {{MLContext}} interface represents a global state of neural network compute workload and execution processes. Each {{MLContext}} object has associated [=context type=], {{MLDeviceType}}and {{MLPowerPreference}}.
: <dfn>\[[contextType]]</dfn> of type [=context type=]
817
+
: <dfn>\[[contextType]]</dfn> of type [=context type=].
824
818
::
825
819
The {{MLContext}}'s [=context type=].
826
-
: <dfn>\[[deviceType]]</dfn> of type [=device type=]
820
+
: <dfn>\[[deviceType]]</dfn> of type {{MLDeviceType}}.
827
821
::
828
-
The {{MLContext}}'s [=device type=].
829
-
: <dfn>\[[powerPreference]]</dfn> of type [=power preference=]
822
+
The {{MLContext}}'s {{MLDeviceType}}.
823
+
: <dfn>\[[powerPreference]]</dfn> of type {{MLPowerPreference}}.
830
824
::
831
-
The {{MLContext}}'s [=power preference=].
825
+
The {{MLContext}}'s {{MLPowerPreference}}.
832
826
</dl>
833
827
</div>
834
828
829
+
The <dfn>context type</dfn> is the type of the execution context that manages the resources and facilitates the compilation and execution of the neural network graph:
830
+
<dl dfn-for="context type">
831
+
<dt>"<dfn>default</dfn>"</dt>
832
+
<dd>Context created per user preference options.</dd>
833
+
<dt>"<dfn>webgpu</dfn>"</dt>
834
+
<dd>Context created from WebGPU device.</dd>
835
+
</dl>
836
+
835
837
<div class="note">
836
838
When the {{MLContext/[[contextType]]}} is set to [=context type/default=] with the {{MLContextOptions}}.{{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.
837
839
</div>
838
840
841
+
<dl dfn-type=dict-member dfn-for=MLComputeResult>
842
+
: <dfn>inputs</dfn>
843
+
:: An object where the keys are the graph input names, and the values are the transferred {{ArrayBufferView}}s for the supplied input tensor values.
844
+
845
+
: <dfn>outputs</dfn>
846
+
:: An object where the keys are the graph output names, and the values are the transferred {{ArrayBufferView}}s for the computed output tensor values.
847
+
</dl>
848
+
839
849
<details open algorithm>
840
850
<summary>
841
851
To <dfn>validate graph resources</dfn>, given {{MLNamedArrayBufferViews}} |resources| and [=ordered map=] |descriptors|, run the following steps:
@@ -1015,15 +1025,19 @@ enum MLOperandDataType {
1015
1025
};
1016
1026
1017
1027
dictionary MLOperandDescriptor {
1018
-
// The operand type.
1019
1028
required MLOperandDataType dataType;
1020
-
1021
-
// The dimensions field is empty for scalar operands,
- *options*: an optional {{MLClampOptions}}. The optional parameters of the operation.
1669
-
- *minValue*: a {{float}} scalar. Specifies the minimum value of the range. When it is not specified, the clamping is not performed on the lower limit of the range.
1670
-
- *maxValue*: a {{float}} scalar. Specifies the maximum value of the range. When it is not specified, the clamping is not performed on the upper limit of the range.
1671
1694
**Returns:**
1672
1695
- an {{MLOperand}}. The output tensor of the same shape as *operand*.
- *options*: an optional {{MLClampOptions}}. The optional parameters of the operation.
1694
-
- *minValue*: a {{float}} scalar. Specifies the minimum value of the range. When it is not specified, the clamping is not performed on the lower limit of the range.
1695
-
- *maxValue*: a {{float}} scalar. Specifies the maximum value of the range. When it is not specified, the clamping is not performed on the upper limit of the range.
1696
1717
**Returns:**
1697
1718
- an {{MLActivation}}. The operator representing the clamp operation.
0 commit comments