Skip to content

Commit 954ed19

Browse files
Editorial: Make "generically emulated" text a macro, update wording (#638)
Many complex operations in the spec are given decompositions, showing how the operation could be replaced through the use of more primitive operations. This text is repeated in many places. Improve this in two ways: * Use Bikeshed's Text Macro[1] to reduce the repetition. * Streamline the text, and make it explicit that if the underlying platform doesn't support an operation, WebNN API implementations can use the decomposition as a guide to emulate it. The macro [EMULATED] is used at the end of an intro sentence since there are variations - some of the decompositions are grouped, and some make assumptions (e.g. activation functions, layouts, etc). If we assume that implementations must implement all operations in the spec, either via the underlying platform or emulation, this fixes #187 [1] https://speced.github.io/bikeshed/#metadata-text-macro
1 parent c985a58 commit 954ed19

File tree

1 file changed

+26
-75
lines changed

1 file changed

+26
-75
lines changed

index.bs

+26-75
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Status Text: <p>
3636
<li>it has at least two independent, interoperable implementations of every feature defined in the specification, where interoperability can be verified by passing open test suites, and two or more implementations interoperating with each other;</li>
3737
<li>it has an open test suite of every feature defined in the specification.</li>
3838
</ul>
39-
39+
Text Macro: EMULATED generically emulated from the usage of other operations as follows, although user agents typically have a more efficient implementation. In cases where the underlying platform does not directly support an operation, this decomposition can be used as a template to guide the implementation.
4040
</pre>
4141
<pre class="anchors">
4242
urlPrefix: https://tc39.es/ecma262/; spec: ECMA-262
@@ -1586,7 +1586,7 @@ partial interface MLGraphBuilder {
15861586
<div class="note">
15871587
<details open>
15881588
<summary>
1589-
The behavior of this operation when the input tensor is 4-D of the {{MLInputOperandLayout/"nchw"}} layout and the activation is {{MLGraphBuilder/relu()}} 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 performance standpoint.
1589+
The behavior of this operation when the input tensor is 4-D of the {{MLInputOperandLayout/"nchw"}} layout and the activation is {{MLGraphBuilder/relu()}} can be [EMULATED]
15901590
</summary>
15911591
<pre highlight="js">
15921592
const shape = [1,null,1,1];
@@ -1658,10 +1658,7 @@ partial interface MLGraphBuilder {
16581658
<div class="note">
16591659
<details open>
16601660
<summary>
1661-
The behavior of this operation can be generically emulated from the usage of
1662-
other operations as follow. However, user agents typically have a more
1663-
efficient implementation for it, therefore its usage is encouraged from the
1664-
performance standpoint.
1661+
The behavior of this operation can be [EMULATED]
16651662
</summary>
16661663
<pre highlight="js">
16671664
if (options.minValue === undefined) {
@@ -2608,10 +2605,7 @@ partial interface MLGraphBuilder {
26082605
<div class="note">
26092606
<details open>
26102607
<summary>
2611-
The behavior of this operation can be generically emulated from the usage of
2612-
other operations as follow. However, user agents typically have a more
2613-
efficient implementation for it, therefore its usage is encouraged from the
2614-
performance standpoint.
2608+
The behavior of this operation can be [EMULATED]
26152609
</summary>
26162610
<pre highlight="js">
26172611
return builder.add(
@@ -2840,10 +2834,7 @@ partial interface MLGraphBuilder {
28402834
<div class="note">
28412835
<details open>
28422836
<summary>
2843-
The behavior of this operation can be generically emulated from the usage of
2844-
other operations as follows. However, user agents typically have a more
2845-
efficient implementation for it. Therefore its usage is encouraged from the
2846-
performance standpoint.
2837+
The behavior of this operation can be [EMULATED]
28472838
</summary>
28482839
<pre highlight="js">
28492840
return builder.mul(
@@ -2978,7 +2969,7 @@ partial interface MLGraphBuilder {
29782969
<div class="note">
29792970
<details open>
29802971
<summary>
2981-
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 performance standpoint.
2972+
The behavior of this operation can be [EMULATED]
29822973
</summary>
29832974
<pre highlight="js">
29842975
if (options.aTranspose)
@@ -3121,7 +3112,7 @@ partial interface MLGraphBuilder {
31213112
<div class="note">
31223113
<details open>
31233114
<summary>
3124-
The behavior of this operation can be generically emulated from the usage of other operations as follows. However, user agents typically have a more efficient implementation for it, therefore its usage is encouraged from the performance standpoint.
3115+
The behavior of this operation can be [EMULATED]
31253116
</summary>
31263117
<pre highlight="js">
31273118
function squeeze(builder, op) {
@@ -3276,7 +3267,7 @@ partial interface MLGraphBuilder {
32763267
<div class="note">
32773268
<details open>
32783269
<summary>
3279-
The behavior of this operation can be generically emulated via other operations as shown below, when the weight layout is the default {{MLGruWeightLayout/"zrn"}} layout, and the activation functions of the update/reset gate and new gate are {{MLGraphBuilder/sigmoid()}} and {{MLGraphBuilder/tanh()}} respectively.
3270+
The behavior of this operation when the weight layout is the default {{MLGruWeightLayout/"zrn"}} layout, and the activation functions of the update/reset gate and new gate are {{MLGraphBuilder/sigmoid()}} and {{MLGraphBuilder/tanh()}} respectively can be [EMULATED]
32803271
</summary>
32813272
<pre highlight="js">
32823273
const one = builder.constant(1);
@@ -3391,10 +3382,7 @@ partial interface MLGraphBuilder {
33913382
<div class="note">
33923383
<details open>
33933384
<summary>
3394-
The behavior of this operation can be generically emulated from the usage of
3395-
other operations as follow. However, user agents typically have a more
3396-
efficient implementation for it, therefore its usage is encouraged from the
3397-
performance standpoint.
3385+
The behavior of this operation can be [EMULATED]
33983386
</summary>
33993387
<pre highlight="js">
34003388
return builder.max(
@@ -3471,10 +3459,7 @@ partial interface MLGraphBuilder {
34713459
<div class="note">
34723460
<details open>
34733461
<summary>
3474-
The behavior of this operation can be generically emulated from the usage of
3475-
other operations as follow. However, user agents typically have a more
3476-
efficient implementation for it, therefore its usage is encouraged from the
3477-
performance standpoint.
3462+
The behavior of this operation can be [EMULATED]
34783463
</summary>
34793464
<pre highlight="js">
34803465
return builder.div(
@@ -3598,9 +3583,7 @@ partial interface MLGraphBuilder {
35983583
<div class="note">
35993584
<details open>
36003585
<summary>
3601-
The behavior of this operation when the input tensor is 4-D of the {{MLInputOperandLayout/"nchw"}} layout can be generically emulated from
3602-
the usage of other operations as follow. However, user agents typically have a more efficient implementation for it,
3603-
therefore its usage is encouraged from the performance standpoint.
3586+
The behavior of this operation when the input tensor is 4-D of the {{MLInputOperandLayout/"nchw"}} layout can be [EMULATED]
36043587
</summary>
36053588
<pre highlight="js">
36063589
// The reduction of the mean and variance values happens over the spatial dimensions of the input
@@ -3702,9 +3685,7 @@ partial interface MLGraphBuilder {
37023685
<div class="note">
37033686
<details open>
37043687
<summary>
3705-
The behavior of this operation when the axes parameter is set to [1,2,3] can be generically emulated from
3706-
the usage of other operations as follow. However, user agents typically have a more efficient implementation for it,
3707-
therefore its usage is encouraged from the performance standpoint.
3688+
The behavior of this operation when the axes parameter is set to [1,2,3] can be [EMULATED]
37083689
</summary>
37093690
<pre highlight="js">
37103691
// The reduction of the mean and variance values happens over the spatial dimensions
@@ -3751,10 +3732,7 @@ partial interface MLGraphBuilder {
37513732
<div class="note">
37523733
<details open>
37533734
<summary>
3754-
The behavior of this operation can be generically emulated from the usage of
3755-
other operations as follow. However, user agents typically have a more
3756-
efficient implementation for it, therefore its usage is encouraged from the
3757-
performance standpoint.
3735+
The behavior of this operation can be [EMULATED]
37583736
</summary>
37593737
<pre highlight="js">
37603738
return builder.add(builder.max(builder.constant(0), x),
@@ -3829,10 +3807,7 @@ partial interface MLGraphBuilder {
38293807
<div class="note">
38303808
<details open>
38313809
<summary>
3832-
The behavior of this operation can be generically emulated from the usage of
3833-
other operations as follow. However, user agents typically have a more
3834-
efficient implementation for it, therefore its usage is encouraged from the
3835-
performance standpoint.
3810+
The behavior of this operation can be [EMULATED]
38363811
</summary>
38373812
<pre highlight="js">
38383813
return builder.add(
@@ -4041,7 +4016,7 @@ partial interface MLGraphBuilder {
40414016
<div class="note">
40424017
<details open>
40434018
<summary>
4044-
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 performance standpoint.
4019+
The behavior of this operation can be [EMULATED]
40454020
</summary>
40464021
<pre highlight="js">
40474022
function squeeze(builder, op) {
@@ -4221,7 +4196,7 @@ partial interface MLGraphBuilder {
42214196
<div class="note">
42224197
<details open>
42234198
<summary>
4224-
The behavior of this operation can be generically emulated via other operations as shown below, when the weight layout is the default {{MLLstmWeightLayout/"iofg"}} layout, and the activation functions of the input/forget/output gate and the cell gate/the cell state's filter for the output hidden state are {{MLGraphBuilder/sigmoid()}} and {{MLGraphBuilder/tanh()}} respectively.
4199+
The behavior of this operation when the weight layout is the default {{MLLstmWeightLayout/"iofg"}} layout, and the activation functions of the input/forget/output gate and the cell gate/the cell state's filter for the output hidden state are {{MLGraphBuilder/sigmoid()}} and {{MLGraphBuilder/tanh()}} respectively can be [EMULATED]
42254200
</summary>
42264201
<pre highlight="js">
42274202
const zero = builder.constant(0);
@@ -4607,7 +4582,7 @@ partial interface MLGraphBuilder {
46074582
</div>
46084583

46094584
<div class="note">
4610-
A *global* pooling operation such as one for the max pooling operation is a variant of pooling where the window dimensions is the spatial dimensions (last two dimensions) of the input shape, as follow.
4585+
A *global* pooling operation such as one for the max pooling operation is a variant of pooling where the window dimensions is the spatial dimensions (last two dimensions) of the input shape, as follows.
46114586
<pre highlight="js">
46124587
// 'global' max pooling
46134588
builder.maxPool2d(input);
@@ -4766,10 +4741,7 @@ partial interface MLGraphBuilder {
47664741
<div class="note">
47674742
<details open>
47684743
<summary>
4769-
The behavior of this operation can be generically emulated from the usage of
4770-
other operations as follow. However, user agents typically have a more
4771-
efficient implementation for it, therefore its usage is encouraged from the
4772-
performance standpoint.
4744+
The behavior of this operation can be [EMULATED]
47734745
</summary>
47744746
<pre highlight="js">
47754747
return builder.add(builder.max(builder.constant(0), x),
@@ -4979,10 +4951,7 @@ partial interface MLGraphBuilder {
49794951
<div class="note">
49804952
<details open>
49814953
<summary>
4982-
The behavior of this operation can be generically emulated from the usage of
4983-
other operations as follow. However, user agents typically have a more
4984-
efficient implementation for it, therefore its usage is encouraged from the
4985-
performance standpoint.
4954+
The behavior of this operation can be [EMULATED]
49864955
</summary>
49874956
<pre highlight="js">
49884957
return builder.max(builder.constant(0), x);
@@ -5212,10 +5181,7 @@ partial interface MLGraphBuilder {
52125181
<div class="note">
52135182
<details open>
52145183
<summary>
5215-
The behavior of this operation can be generically emulated from the usage of
5216-
other operations as follow. However, user agents typically have a more
5217-
efficient implementation for it, therefore its usage is encouraged from the
5218-
performance standpoint.
5184+
The behavior of this operation can be [EMULATED]
52195185
</summary>
52205186
<pre highlight="js">
52215187
return builder.div(
@@ -5314,10 +5280,7 @@ partial interface MLGraphBuilder {
53145280
<div class="note">
53155281
<details open>
53165282
<summary>
5317-
The behavior of this operation can be generically emulated from the usage of
5318-
other operations as follow. However, user agents typically have a more
5319-
efficient implementation for it, therefore its usage is encouraged from the
5320-
performance standpoint.
5283+
The behavior of this operation can be [EMULATED]
53215284
</summary>
53225285
<pre highlight="js">
53235286
// This sample deploys a well-known implementation trick [1] to compute the
@@ -5389,10 +5352,7 @@ partial interface MLGraphBuilder {
53895352
<div class="note">
53905353
<details open>
53915354
<summary>
5392-
The behavior of this operation can be generically emulated from the usage of
5393-
other operations as follow. However, user agents typically have a more
5394-
efficient implementation for it, therefore its usage is encouraged from the
5395-
performance standpoint.
5355+
The behavior of this operation can be [EMULATED]
53965356
</summary>
53975357
<pre highlight="js">
53985358
return builder.div(
@@ -5465,10 +5425,7 @@ partial interface MLGraphBuilder {
54655425
<div class="note">
54665426
<details open>
54675427
<summary>
5468-
The behavior of this operation can be generically emulated from the usage of
5469-
other operations as follow. However, user agents typically have a more
5470-
efficient implementation for it, therefore its usage is encouraged from the
5471-
performance standpoint.
5428+
The behavior of this operation can be [EMULATED]
54725429
</summary>
54735430
<pre highlight="js">
54745431
return builder.div(x, builder.add(builder.constant(1), builder.abs(x)));
@@ -5577,10 +5534,7 @@ partial interface MLGraphBuilder {
55775534
<div class="note">
55785535
<details open>
55795536
<summary>
5580-
The behavior of this operation can be generically emulated from the usage of
5581-
other operations as follow. However, user agents typically have a more
5582-
efficient implementation for it, therefore its usage is encouraged from the
5583-
performance standpoint.
5537+
The behavior of this operation can be [EMULATED]
55845538
</summary>
55855539
<pre highlight="js">
55865540
// This sample shows the case that the splits parameter is an array.
@@ -5611,10 +5565,7 @@ partial interface MLGraphBuilder {
56115565
<div class="note">
56125566
<details open>
56135567
<summary>
5614-
The behavior of this operation can be generically emulated from the usage of
5615-
other operations as follow. However, user agents typically have a more
5616-
efficient implementation for it, therefore its usage is encouraged from the
5617-
performance standpoint.
5568+
The behavior of this operation can be [EMULATED]
56185569
</summary>
56195570
<pre highlight="js">
56205571
return builder.div(
@@ -5862,7 +5813,7 @@ partial interface MLGraphBuilder {
58625813
<div class="note">
58635814
<details open>
58645815
<summary>
5865-
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 performance standpoint.
5816+
The behavior of this operation can be [EMULATED]
58665817
</summary>
58675818
<pre highlight="js">
58685819
const c = builder.clamp(condition, {'minValue': 0, 'maxValue': 1});

0 commit comments

Comments
 (0)