diff --git a/index.bs b/index.bs index 10d1599b..77628745 100644 --- a/index.bs +++ b/index.bs @@ -695,23 +695,128 @@ For instance, an {{MLOperand}} may represent a constant feeding to an operation interface MLOperand {}; -See also [[#security-new-ops]] +{{MLOperand}} has the following internal slots: +
+ : \[[builder]] of type {{MLGraphBuilder}} + :: + The {{MLOperand}}'s associated builder object. + + : \[[descriptor]] of type {{MLOperandDescriptor}} + :: + The {{MLOperand}}'s descriptor. + + : \[[name]] of type [=string=] + :: + The {{MLOperand}}'s name (only for input operands). + + : \[[operand]] of type [=object=] + :: + Reference to {{MLOperand}}'s corresponding [=implementation-defined=] platform operand object. + + : \[[operator]] of type [=object=] + :: + Reference to {{MLOperand}}'s corresponding [=implementation-defined=] platform operator object. +
+ +
+ The rank of an {{MLOperand}} |operand| is the value returned by the following steps: + 1. Return the size of |operand|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. +
+ +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 create MLOperand given |builder| and |desc|, run the following 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|. +
+ +To copy MLOperand given |operand|, run the following 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|. +
+ +To check dimensions given |dimensions| and |type|, run the following 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`. +
+ +To validate MLOperand given |operand| and |builder|, run the following 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 check dimensions given |desc|.{{MLOperandDescriptor/dimensions}} and |desc|.{{MLOperandDescriptor/type}} returns `false`, then return `false`. + 1. Return `true`. +
### The MLActivation interface ### {#api-mlactivation} Objects implementing the {{MLActivation}} interface represent activation function types. +
+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. +
+ +{{MLActivation}} has the following internal slots: +
+ : \[[name]] of type [=string=] + :: + The {{MLActivation}}'s name. + : \[[builder]] of type {{MLGraphBuilder}} + :: + The graph builder object this {{MLActivation}} belongs to. + : \[[options]] of type [=object=] + :: + A dictionary containing {{MLActivation}} options. + : \[[operator]] of type [=object=] + :: + Reference to {{MLActivation}}'s corresponding [=implementation-defined=] platform operator object. +
+
-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.
+#### Creating {{MLActivation}} #### {#api-mlactivation-create}
-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. +
+ +To create MLActivation given |builder|, |name| and |options|, run the following 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|.
## The MLContext interface ## {#api-mlcontext} @@ -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 validate MLContext steps given |context| return `false`, throw a "{{TypeError}}" and abort these steps. - 1. Set {{MLGraphBuilder/[[context]]}} to |context|. ### The batchNormalization() method ### {#api-mlgraphbuilder-batchnorm}