Skip to content
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 109 additions & 5 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -695,23 +695,128 @@ For instance, an {{MLOperand}} may represent a constant feeding to an operation
interface MLOperand {};
</script>

See also [[#security-new-ops]]
{{MLOperand}} has the following internal slots:
<dl dfn-type=attribute dfn-for="MLOperand">
: <dfn>\[[builder]]</dfn> of type {{MLGraphBuilder}}
::
The {{MLOperand}}'s associated builder object.

: <dfn>\[[descriptor]]</dfn> of type {{MLOperandDescriptor}}
::
The {{MLOperand}}'s descriptor.

: <dfn>\[[name]]</dfn> of type [=string=]
::
The {{MLOperand}}'s name (only for input operands).

: <dfn>\[[operand]]</dfn> of type [=object=]
::
Reference to {{MLOperand}}'s corresponding [=implementation-defined=] platform operand object.

: <dfn>\[[operator]]</dfn> of type [=object=]
::
Reference to {{MLOperand}}'s corresponding [=implementation-defined=] platform operator object.
</dl>

<div algorithm>
The <dfn for="MLOperand">rank</dfn> of an {{MLOperand}} |operand| is the value returned by the following steps:
1. Return the size of |operand|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}.
</div>

Since the {{MLOperand/[[builder]]}} object is bound by the {{MLGraphBuilder/constructor()}} constructor to an {{MLContext}} object, an {{MLOperand}} is also always bound to the same {{MLContext}} object.

#### Creating {{MLOperand}} #### {#api-mloperand-create}
The {{MLOperand}} objects are created by the methods of {{MLGraphBuilder}}, internally using the following algorithms.

To <dfn>create MLOperand</dfn> given |builder| and |desc|, run the following steps:
<div class=algorithm-steps>
1. If |builder| is not an instance of {{MLGraphBuilder}}, then throw a "{{TypeError}}" {{DOMException}} and stop.
1. If |desc| is not an [=object=] that [=implements=] {{MLOperandDescriptor}}, then throw a "{{TypeError}}" {{DOMException}} and stop.
1. Let |operand| be a new [=object=].
1. Set |operand|.{{MLOperand/[[builder]]}} to |builder|.
1. Set |operand|.{{MLOperand/[[descriptor]]}} to |desc|.
1. Return |operand|.
</div>

To <dfn>copy MLOperand</dfn> given |operand|, run the following steps:
<div class=algorithm-steps>
1. If |operand| is not an instance of {{MLOperand}}, then throw a "{{TypeError}}" and stop.
1. Let |result| be a new [=object=].
1. Set |result|.{{MLOperand/[[builder]]}} to |operand|.{{MLOperand/[[builder]]}}.
1. Set |result|.{{MLOperand/[[descriptor]]}} to |operand|.{{MLOperand/[[descriptor]]}}.
1. Set |result|.{{MLOperand/[[name]]}} to |operand|.{{MLOperand/[[name]]}}.
1. Return |result|.
</div>

To <dfn>check dimensions</dfn> given |dimensions| and |type|, run the following steps:
<div class=algorithm-steps>
1. If |dimensions| is not an array of positive numbers, return `false`;
1. If |dimensions|.length is 0, return `false`.
1. If |dimensions|.length is too large to be supported by the implementation, return `false`.
1. If any element of |dimensions| is not a positive number, or it is too large to be supported by the implementation given |type|, return `false`.
1. Return `true`.
</div>

To <dfn for="MLOperand">validate MLOperand</dfn> given |operand| and |builder|, run the following steps:
<div class=algorithm-steps>
1. If |operand|.{{MLOperand/[[builder]]}} is not an instance of {{MLGraphBuilder}}, return `false`.
1. If |builder| is not `undefined` and is not equal to |operand|.{{MLOperand/[[builder]]}}, return `false`.
1. Let |desc| be |operand|.{{MLOperand/[[descriptor]]}}.
1. If |desc| is not an [=object=] that [=implements=] {{MLOperandDescriptor}}, return `false`.
1. If |desc|.{{MLOperandDescriptor/dimensions}} [=map/exists=] and invoking <a>check dimensions</a> given |desc|.{{MLOperandDescriptor/dimensions}} and |desc|.{{MLOperandDescriptor/type}} returns `false`, then return `false`.
1. Return `true`.
</div>

### The MLActivation interface ### {#api-mlactivation}

Objects implementing the {{MLActivation}} interface represent activation function types.

<div class="note">
These activations function types are used to create other operations. One such use of this interface is for when an activation function is fused into another operation such as [[#api-mlgraphbuilder-conv2d]] or [[#api-mlgraphbuilder-batchnorm]] during a graph construction session. Such fused activation functions can provide a significant performance improvement when supported natively by the underlying implementation. This is intended as an optimization opportunity for implementers.
</div>

<script type=idl>
[SecureContext, Exposed=(Window, DedicatedWorker)]
interface MLActivation {};
interface MLActivation {
};
</script>

{{MLActivation}} has the following internal slots:
<dl dfn-type=attribute dfn-for="MLActivation">
: <dfn>\[[name]]</dfn> of type [=string=]
::
The {{MLActivation}}'s name.
: <dfn>\[[builder]]</dfn> of type {{MLGraphBuilder}}
::
The graph builder object this {{MLActivation}} belongs to.
: <dfn>\[[options]]</dfn> of type [=object=]
::
A dictionary containing {{MLActivation}} options.
: <dfn>\[[operator]]</dfn> of type [=object=]
::
Reference to {{MLActivation}}'s corresponding [=implementation-defined=] platform operator object.
</dl>

<div class="note">
These activations function types are used to create other operations. One such use of this interface is for when an activation function is fused into another operation such as [[#api-mlgraphbuilder-conv2d]] or [[#api-mlgraphbuilder-batchnorm]] during a graph construction session. Such fused activation functions can provide a significant performance improvement when supported natively by the underlying implementation. This is intended as an optimization opportunity for implementers.
The implementation of the {{MLActivation}} interface can simply be a struct that holds a string type of the activation function along with other properties needed. The actual creation of the activation function e.g. a [[#api-mlgraphbuilder-sigmoid]] or [[#api-mlgraphbuilder-relu]] can then be deferred until when the rest of the graph is ready to connect with it such as during the construction of [[#api-mlgraphbuilder-conv2d]] for example.
</div>

#### Creating {{MLActivation}} #### {#api-mlactivation-create}
<div class="note">
The implementation of the {{MLActivation}} interface can simply be a struct that holds a string type of the activation function along with other properties needed. The actual creation of the activation function e.g. a [[#api-mlgraphbuilder-sigmoid]] or [[#api-mlgraphbuilder-relu]] can then be deferred until when the rest of the graph is ready to connect with it such as during the construction of [[#api-mlgraphbuilder-conv2d]] for example.
The {{MLActivation}} objects (including the ones passed as input to methods) are created by the methods of {{MLGraphBuilder}} and are identified by their name. The |options| dictionary is defined by those methods.
</div>

To <dfn>create MLActivation</dfn> given |builder|, |name| and |options|, run the following steps:
<div class=algorithm-steps>
1. If |builder| is not an instance of {{MLGraphBuilder}}, throw a "{{TypeError}}" and abort these steps.
1. If |name| is `undefined` or `null`, throw a "{{TypeError}}" and abort these steps.
1. Let |activation| be a new [=object=].
1. Set |activation|.{{MLActivation/[[builder]]}} to |builder|.
1. Set |activation|.{{MLActivation/[[name]]}} to |name|.
1. If |options| is an [=object=], set |activation|.{{MLActivation/[[options]]}} to |options|.
1. Make a request to the underlying platform to bind the [=implementation-defined=] platform operator for |name| to |activation|.{{MLActivation/[[operator]]}}.
1. If that fails, throw a "{{TypeError}}" and abort these steps.
1. Return |activation|.
</div>

## The MLContext interface ## {#api-mlcontext}
Expand Down Expand Up @@ -1149,7 +1254,6 @@ The [=new=] {{MLGraphBuilder}} constructor 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}}" {{DOMException}} and abort these steps.
1. Let |context| be the first argument.
1. If the <a>validate MLContext</a> steps given |context| return `false`, throw a "{{TypeError}}" and abort these steps.

1. Set {{MLGraphBuilder/[[context]]}} to |context|.

### The batchNormalization() method ### {#api-mlgraphbuilder-batchnorm}
Expand Down