diff --git a/index.bs b/index.bs index 14778685..850564bd 100644 --- a/index.bs +++ b/index.bs @@ -754,6 +754,16 @@ To create MLOperand given |builder| and |desc|, run the following ste 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. If |operand|.{{MLOperand/[[name]]}} [=map/exists=], then 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`; @@ -769,16 +779,53 @@ Objects implementing the {{MLActivation}} interface represent activation functio +
+{{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.
+#### 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. 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. +
+ +
+ + 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} 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=]. @@ -1371,22 +1418,12 @@ dictionary MLClampOptions { }; partial interface MLGraphBuilder { - MLOperand clamp(MLOperand x, optional MLClampOptions options = {}); + MLOperand clamp(MLOperand operand, optional MLClampOptions options = {}); MLActivation clamp(optional MLClampOptions options = {}); }; -
- **Arguments:** - - *x*: an {{MLOperand}}. The input tensor. - - *options*: an optional {{MLClampOptions}}. The optional parameters of the operation. - - *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. - - *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. - - **Returns:** - - an {{MLOperand}}. The output tensor of the same shape as *x*. - - an {{MLActivation}}. The activation function representing the clamp operation. -
+
The behavior of this operation can be generically emulated from the usage of other operations as follow. However, user agents typically have a more efficient implementation for it, therefore its usage is encouraged from the @@ -1408,7 +1445,60 @@ partial interface MLGraphBuilder { } } -
+
+ +To check clamp options given |options|, run the following steps: + 1. If |options| is not an object that [=implements=] {{MLClampOptions}}, then return `false`. + 1. If |options|.{{MLClampOptions/minValue}} and |options|.{{MLClampOptions/maxValue}} are not a [=numeric type=], then then return `false`. + 1. If |options|.{{MLClampOptions/minValue}} is greater than |options|.{{MLClampOptions/maxValue}}, then return `false`. + 1. Return `true`. + +#### The {{MLGraphBuilder/clamp(operand, options)}} method #### {#api-mlgraphbuilder-clamp-operand-options} +
+ **Arguments:** + - *operand*: an {{MLOperand}}. The input tensor. + - *options*: an optional {{MLClampOptions}}. The optional parameters of the operation. + - *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. + - *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. + **Returns:** + - an {{MLOperand}}. The output tensor of the same shape as *operand*. +
+
+ The {{MLGraphBuilder/clamp(operand, options)}} method steps are: + 1. Let |operand| be the first argument. + 1. Let |options| be the second argument. + 1. If running the check clamp options steps with |options| returns `false`, then throw a "{{TypeError}}" {{DOMException}} and abort these steps. + 1. Let |result| be the result of invoking the copy MLOperand steps given |operand|. + 1. If that throws an error, re-throw the error and abort these steps. + 1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop. + 1. Make a request to the underlying platform to create an [=implementation-defined=] platform operand |operandImpl| given |result|.{{MLOperand/[[descriptor]]}}. + 1. Store a reference to |operandImpl| in |result|.{{MLOperand/[[operand]]}}. + 1. Make a request to the underlying platform to create an [=implementation-defined=] platform operator |operatorImpl| for clamp with |options|.{{MLClampOptions/minValue}} and |options|.{{MLClampOptions/minValue}}. + 1. Register the |operand|.{{MLOperand/[[operand]]}} as an input to |operatorImpl|. + 1. Register the |result|.{{MLOperand/[[operand]]}} as output to |operatorImpl|. + 1. Store a reference to |operatorImpl| in |result|.{{MLOperand/[[operator]]}}. + 1. Return |result|. +
+ +#### The {{MLGraphBuilder/clamp(options)}} method #### {#api-mlgraphbuilder-clamp-options} +
+ **Arguments:** + - *options*: an optional {{MLClampOptions}}. The optional parameters of the operation. + - *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. + - *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. + **Returns:** + - an {{MLActivation}}. The operator representing the clamp operation. +
+
+ The {{MLGraphBuilder/clamp(options)}} method steps are: + 1. Let |options| be the first argument. + 1. If running the check clamp options steps with |options| returns `false`, then throw a "{{TypeError}}" {{DOMException}} and abort these steps. + 1. Let |op| be the result of invoking the create MLActivation steps with `"clamp"` and |options|. + 1. If that throws an error, re-throw the error and abort these steps. + 1. If any of the following sub-steps fail, throw an "{{OperationError}}" {{DOMException}} and stop. + 1. Make a request to the underlying platform to connect |op| with the [=implementation-defined=] platform operator for clamp |operatorImpl|. + 1. Store a reference to |operatorImpl| in |op|.{{MLActivation/[[operator]]}}. + 1. Return |op|.
### The concat() method ### {#api-mlgraphbuilder-concat}