tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gatherND.https.any.js (18529B)


      1 // META: title=test WebNN API gatherND operation
      2 // META: global=window
      3 // META: variant=?cpu
      4 // META: variant=?gpu
      5 // META: variant=?npu
      6 // META: script=../resources/utils.js
      7 // META: timeout=long
      8 
      9 'use strict';
     10 
     11 // https://www.w3.org/TR/webnn/#api-mlgraphbuilder-gatherND
     12 // Gather values of the input tensor along a range of dimensions according to
     13 // the indices.
     14 //
     15 // MLOperand gatherND(
     16 //     MLOperand input, MLOperand indices,
     17 //     optional MLOperatorOptions options = {});
     18 
     19 const gatherNDTests = [
     20  {
     21    'name': 'gatherND float32 3D input and 2D indices',
     22    'graph': {
     23      'inputs': {
     24        'gatherNDInput': {
     25          'data': [
     26            -66.05901336669922, -68.9197006225586, -77.02045440673828,
     27            -26.158037185668945, 89.0337142944336, -45.89653396606445,
     28            43.84803771972656, 48.81806945800781, 51.79948425292969,
     29            41.94132614135742, -1.1303654909133911, -50.42131042480469,
     30            90.2870101928711, 55.620765686035156, 44.92119598388672,
     31            56.828636169433594
     32          ],
     33          'descriptor': {shape: [2, 2, 4], dataType: 'float32'}
     34        },
     35        'gatherNDIndices': {
     36          'data': [1, 0, 0, 1, 1, 1],
     37          'descriptor': {shape: [3, 2], dataType: 'int32'},
     38          'constant': true
     39        }
     40      },
     41      'operators': [{
     42        'name': 'gatherND',
     43        'arguments':
     44            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
     45        'outputs': 'gatherNDOutput'
     46      }],
     47      'expectedOutputs': {
     48        'gatherNDOutput': {
     49          'data': [
     50            51.79948425292969, 41.94132614135742, -1.1303654909133911,
     51            -50.42131042480469, 89.0337142944336, -45.89653396606445,
     52            43.84803771972656, 48.81806945800781, 90.2870101928711,
     53            55.620765686035156, 44.92119598388672, 56.828636169433594
     54          ],
     55          'descriptor': {shape: [3, 4], dataType: 'float32'}
     56        }
     57      }
     58    }
     59  },
     60  {
     61    'name': 'gatherND float32 4D input and 1D int32 indices',
     62    'graph': {
     63      'inputs': {
     64        'gatherNDInput': {
     65          'data': [
     66            -66.05901336669922, -68.9197006225586, -77.02045440673828,
     67            -26.158037185668945, 89.0337142944336, -45.89653396606445,
     68            43.84803771972656, 48.81806945800781, 51.79948425292969,
     69            41.94132614135742, -1.1303654909133911, -50.42131042480469,
     70            90.2870101928711, 55.620765686035156, 44.92119598388672,
     71            56.828636169433594
     72          ],
     73          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float32'}
     74        },
     75        'gatherNDIndices': {
     76          'data': [1, 0, 0],
     77          'descriptor': {shape: [3], dataType: 'int32'},
     78          'constant': true
     79        }
     80      },
     81      'operators': [{
     82        'name': 'gatherND',
     83        'arguments':
     84            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
     85        'outputs': 'gatherNDOutput'
     86      }],
     87      'expectedOutputs': {
     88        'gatherNDOutput': {
     89          'data': [51.79948425292969, 41.94132614135742],
     90          'descriptor': {shape: [2], dataType: 'float32'}
     91        }
     92      }
     93    }
     94  },
     95  {
     96    'name': 'gatherND float32 4D input and 1D uint32 indices',
     97    'graph': {
     98      'inputs': {
     99        'gatherNDInput': {
    100          'data': [
    101            -66.05901336669922, -68.9197006225586, -77.02045440673828,
    102            -26.158037185668945, 89.0337142944336, -45.89653396606445,
    103            43.84803771972656, 48.81806945800781, 51.79948425292969,
    104            41.94132614135742, -1.1303654909133911, -50.42131042480469,
    105            90.2870101928711, 55.620765686035156, 44.92119598388672,
    106            56.828636169433594
    107          ],
    108          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float32'}
    109        },
    110        'gatherNDIndices': {
    111          'data': [1, 0, 0],
    112          'descriptor': {shape: [3], dataType: 'uint32'},
    113          'constant': true
    114        }
    115      },
    116      'operators': [{
    117        'name': 'gatherND',
    118        'arguments':
    119            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    120        'outputs': 'gatherNDOutput'
    121      }],
    122      'expectedOutputs': {
    123        'gatherNDOutput': {
    124          'data': [51.79948425292969, 41.94132614135742],
    125          'descriptor': {shape: [2], dataType: 'float32'}
    126        }
    127      }
    128    }
    129  },
    130  {
    131    'name': 'gatherND float32 4D input and 1D int64 indices',
    132    'graph': {
    133      'inputs': {
    134        'gatherNDInput': {
    135          'data': [
    136            -66.05901336669922, -68.9197006225586, -77.02045440673828,
    137            -26.158037185668945, 89.0337142944336, -45.89653396606445,
    138            43.84803771972656, 48.81806945800781, 51.79948425292969,
    139            41.94132614135742, -1.1303654909133911, -50.42131042480469,
    140            90.2870101928711, 55.620765686035156, 44.92119598388672,
    141            56.828636169433594
    142          ],
    143          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float32'}
    144        },
    145        'gatherNDIndices': {
    146          'data': [1, 0, 0],
    147          'descriptor': {shape: [3], dataType: 'int64'},
    148          'constant': true
    149        }
    150      },
    151      'operators': [{
    152        'name': 'gatherND',
    153        'arguments':
    154            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    155        'outputs': 'gatherNDOutput'
    156      }],
    157      'expectedOutputs': {
    158        'gatherNDOutput': {
    159          'data': [51.79948425292969, 41.94132614135742],
    160          'descriptor': {shape: [2], dataType: 'float32'}
    161        }
    162      }
    163    }
    164  },
    165  {
    166    'name': 'gatherND float32 4D input and 1D minimum indices',
    167    'graph': {
    168      'inputs': {
    169        'gatherNDInput': {
    170          'data': [
    171            -66.05901336669922, -68.9197006225586, -77.02045440673828,
    172            -26.158037185668945, 89.0337142944336, -45.89653396606445,
    173            43.84803771972656, 48.81806945800781, 51.79948425292969,
    174            41.94132614135742, -1.1303654909133911, -50.42131042480469,
    175            90.2870101928711, 55.620765686035156, 44.92119598388672,
    176            56.828636169433594
    177          ],
    178          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float32'}
    179        },
    180        'gatherNDIndices': {
    181          'data': [-2, -2, -2],
    182          'descriptor': {shape: [3], dataType: 'int32'},
    183          'constant': true
    184        }
    185      },
    186      'operators': [{
    187        'name': 'gatherND',
    188        'arguments':
    189            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    190        'outputs': 'gatherNDOutput'
    191      }],
    192      'expectedOutputs': {
    193        'gatherNDOutput': {
    194          'data': [-66.05901336669922, -68.9197006225586],
    195          'descriptor': {shape: [2], dataType: 'float32'}
    196        }
    197      }
    198    }
    199  },
    200  {
    201    'name': 'gatherND float32 4D input and 1D maximum indices',
    202    'graph': {
    203      'inputs': {
    204        'gatherNDInput': {
    205          'data': [
    206            -66.05901336669922, -68.9197006225586, -77.02045440673828,
    207            -26.158037185668945, 89.0337142944336, -45.89653396606445,
    208            43.84803771972656, 48.81806945800781, 51.79948425292969,
    209            41.94132614135742, -1.1303654909133911, -50.42131042480469,
    210            90.2870101928711, 55.620765686035156, 44.92119598388672,
    211            56.828636169433594
    212          ],
    213          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float32'}
    214        },
    215        'gatherNDIndices': {
    216          'data': [1, 1, 1],
    217          'descriptor': {shape: [3], dataType: 'int32'},
    218          'constant': true
    219        }
    220      },
    221      'operators': [{
    222        'name': 'gatherND',
    223        'arguments':
    224            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    225        'outputs': 'gatherNDOutput'
    226      }],
    227      'expectedOutputs': {
    228        'gatherNDOutput': {
    229          'data': [44.92119598388672, 56.828636169433594],
    230          'descriptor': {shape: [2], dataType: 'float32'}
    231        }
    232      }
    233    }
    234  },
    235  {
    236    'name': 'gatherND float32 2D input and 2D negative indices',
    237    'graph': {
    238      'inputs': {
    239        'gatherNDInput': {
    240          'data': [
    241            -66.05901336669922, -68.9197006225586, -77.02045440673828,
    242            -26.158037185668945, 89.0337142944336, -45.89653396606445,
    243            43.84803771972656, 48.81806945800781, 51.79948425292969,
    244            41.94132614135742, -1.1303654909133911, -50.42131042480469,
    245            90.2870101928711, 55.620765686035156, 44.92119598388672,
    246            56.828636169433594
    247          ],
    248          'descriptor': {shape: [4, 4], dataType: 'float32'}
    249        },
    250        'gatherNDIndices': {
    251          'data': [-1, -2, -3, -4],
    252          'descriptor': {shape: [2, 2], dataType: 'int32'},
    253          'constant': true
    254        }
    255      },
    256      'operators': [{
    257        'name': 'gatherND',
    258        'arguments':
    259            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    260        'outputs': 'gatherNDOutput'
    261      }],
    262      'expectedOutputs': {
    263        'gatherNDOutput': {
    264          'data': [44.92119598388672, 89.0337142944336],
    265          'descriptor': {shape: [2], dataType: 'float32'}
    266        }
    267      }
    268    }
    269  },
    270  {
    271    // TODO(crbug.com/366412395): Need to finalize the behavior of out-of-bounds
    272    // indices. The result of this case is calculated by assuming the indices is
    273    // being clamped.
    274    'name': 'gatherND float32 1D input and 2D out-of-bounds indices',
    275    'graph': {
    276      'inputs': {
    277        'gatherNDInput': {
    278          'data': [
    279            -66.05901336669922, -68.9197006225586, -77.02045440673828,
    280            -26.158037185668945, 89.0337142944336, -45.89653396606445,
    281            43.84803771972656, 48.81806945800781, 51.79948425292969,
    282            41.94132614135742, -1.1303654909133911, -50.42131042480469,
    283            90.2870101928711, 55.620765686035156, 44.92119598388672,
    284            56.828636169433594
    285          ],
    286          'descriptor': {shape: [16], dataType: 'float32'}
    287        },
    288        'gatherNDIndices': {
    289          'data': [16, 20],
    290          'descriptor': {shape: [2, 1], dataType: 'int32'},
    291          'constant': true
    292        }
    293      },
    294      'operators': [{
    295        'name': 'gatherND',
    296        'arguments':
    297            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    298        'outputs': 'gatherNDOutput'
    299      }],
    300      'expectedOutputs': {
    301        'gatherNDOutput': {
    302          'data': [56.828636169433594, 56.828636169433594],
    303          'descriptor': {shape: [2], dataType: 'float32'}
    304        }
    305      }
    306    }
    307  },
    308  {
    309    'name': 'gatherND float32 2D input and 2D out-of-bounds indices',
    310    'graph': {
    311      'inputs': {
    312        'gatherNDInput': {
    313          'data': [
    314            -66.05901336669922, -68.9197006225586, -77.02045440673828,
    315            -26.158037185668945, 89.0337142944336, -45.89653396606445,
    316            43.84803771972656, 48.81806945800781, 51.79948425292969,
    317            41.94132614135742, -1.1303654909133911, -50.42131042480469,
    318            90.2870101928711, 55.620765686035156, 44.92119598388672,
    319            56.828636169433594
    320          ],
    321          'descriptor': {shape: [16, 1], dataType: 'float32'}
    322        },
    323        'gatherNDIndices': {
    324          'data': [16, 20],
    325          'descriptor': {shape: [2, 1], dataType: 'int32'},
    326          'constant': true
    327        }
    328      },
    329      'operators': [{
    330        'name': 'gatherND',
    331        'arguments':
    332            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    333        'outputs': 'gatherNDOutput'
    334      }],
    335      'expectedOutputs': {
    336        'gatherNDOutput': {
    337          'data': [56.828636169433594, 56.828636169433594],
    338          'descriptor': {shape: [2, 1], dataType: 'float32'}
    339        }
    340      }
    341    }
    342  },
    343 
    344  // float16 tests
    345  {
    346    'name': 'gatherND float16 3D input and 2D indices',
    347    'graph': {
    348      'inputs': {
    349        'gatherNDInput': {
    350          'data': [
    351            -66.0625, -68.9375, -77, -26.15625, 89.0625, -45.90625, 43.84375,
    352            48.8125, 51.8125, 41.9375, -1.1298828125, -50.40625, 90.3125,
    353            55.625, 44.90625, 56.84375
    354          ],
    355          'descriptor': {shape: [2, 2, 4], dataType: 'float16'}
    356        },
    357        'gatherNDIndices': {
    358          'data': [1, 0, 0, 1, 1, 1],
    359          'descriptor': {shape: [3, 2], dataType: 'int32'},
    360          'constant': true
    361        }
    362      },
    363      'operators': [{
    364        'name': 'gatherND',
    365        'arguments':
    366            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    367        'outputs': 'gatherNDOutput'
    368      }],
    369      'expectedOutputs': {
    370        'gatherNDOutput': {
    371          'data': [
    372            51.8125, 41.9375, -1.1298828125, -50.40625, 89.0625, -45.90625,
    373            43.84375, 48.8125, 90.3125, 55.625, 44.90625, 56.84375
    374          ],
    375          'descriptor': {shape: [3, 4], dataType: 'float16'}
    376        }
    377      }
    378    }
    379  },
    380  {
    381    'name': 'gatherND float16 4D input and 1D int32 indices',
    382    'graph': {
    383      'inputs': {
    384        'gatherNDInput': {
    385          'data': [
    386            -66.0625, -68.9375, -77, -26.15625, 89.0625, -45.90625, 43.84375,
    387            48.8125, 51.8125, 41.9375, -1.1298828125, -50.40625, 90.3125,
    388            55.625, 44.90625, 56.84375
    389          ],
    390          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float16'}
    391        },
    392        'gatherNDIndices': {
    393          'data': [1, 0, 0],
    394          'descriptor': {shape: [3], dataType: 'int32'},
    395          'constant': true
    396        }
    397      },
    398      'operators': [{
    399        'name': 'gatherND',
    400        'arguments':
    401            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    402        'outputs': 'gatherNDOutput'
    403      }],
    404      'expectedOutputs': {
    405        'gatherNDOutput': {
    406          'data': [51.8125, 41.9375],
    407          'descriptor': {shape: [2], dataType: 'float16'}
    408        }
    409      }
    410    }
    411  },
    412  {
    413    'name': 'gatherND float16 4D input and 1D uint32 indices',
    414    'graph': {
    415      'inputs': {
    416        'gatherNDInput': {
    417          'data': [
    418            -66.0625, -68.9375, -77, -26.15625, 89.0625, -45.90625, 43.84375,
    419            48.8125, 51.8125, 41.9375, -1.1298828125, -50.40625, 90.3125,
    420            55.625, 44.90625, 56.84375
    421          ],
    422          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float16'}
    423        },
    424        'gatherNDIndices': {
    425          'data': [1, 0, 0],
    426          'descriptor': {shape: [3], dataType: 'uint32'},
    427          'constant': true
    428        }
    429      },
    430      'operators': [{
    431        'name': 'gatherND',
    432        'arguments':
    433            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    434        'outputs': 'gatherNDOutput'
    435      }],
    436      'expectedOutputs': {
    437        'gatherNDOutput': {
    438          'data': [51.8125, 41.9375],
    439          'descriptor': {shape: [2], dataType: 'float16'}
    440        }
    441      }
    442    }
    443  },
    444  {
    445    'name': 'gatherND float16 4D input and 1D int64 indices',
    446    'graph': {
    447      'inputs': {
    448        'gatherNDInput': {
    449          'data': [
    450            -66.0625, -68.9375, -77, -26.15625, 89.0625, -45.90625, 43.84375,
    451            48.8125, 51.8125, 41.9375, -1.1298828125, -50.40625, 90.3125,
    452            55.625, 44.90625, 56.84375
    453          ],
    454          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float16'}
    455        },
    456        'gatherNDIndices': {
    457          'data': [1, 0, 0],
    458          'descriptor': {shape: [3], dataType: 'int64'},
    459          'constant': true
    460        }
    461      },
    462      'operators': [{
    463        'name': 'gatherND',
    464        'arguments':
    465            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    466        'outputs': 'gatherNDOutput'
    467      }],
    468      'expectedOutputs': {
    469        'gatherNDOutput': {
    470          'data': [51.8125, 41.9375],
    471          'descriptor': {shape: [2], dataType: 'float16'}
    472        }
    473      }
    474    }
    475  },
    476  {
    477    'name': 'gatherND float16 4D input and 1D minimum indices',
    478    'graph': {
    479      'inputs': {
    480        'gatherNDInput': {
    481          'data': [
    482            -66.0625, -68.9375, -77, -26.15625, 89.0625, -45.90625, 43.84375,
    483            48.8125, 51.8125, 41.9375, -1.1298828125, -50.40625, 90.3125,
    484            55.625, 44.90625, 56.84375
    485          ],
    486          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float16'}
    487        },
    488        'gatherNDIndices': {
    489          'data': [-2, -2, -2],
    490          'descriptor': {shape: [3], dataType: 'int32'},
    491          'constant': true
    492        }
    493      },
    494      'operators': [{
    495        'name': 'gatherND',
    496        'arguments':
    497            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    498        'outputs': 'gatherNDOutput'
    499      }],
    500      'expectedOutputs': {
    501        'gatherNDOutput': {
    502          'data': [-66.0625, -68.9375],
    503          'descriptor': {shape: [2], dataType: 'float16'}
    504        }
    505      }
    506    }
    507  },
    508  {
    509    'name': 'gatherND float16 4D input and 1D maximum indices',
    510    'graph': {
    511      'inputs': {
    512        'gatherNDInput': {
    513          'data': [
    514            -66.0625, -68.9375, -77, -26.15625, 89.0625, -45.90625, 43.84375,
    515            48.8125, 51.8125, 41.9375, -1.1298828125, -50.40625, 90.3125,
    516            55.625, 44.90625, 56.84375
    517          ],
    518          'descriptor': {shape: [2, 2, 2, 2], dataType: 'float16'}
    519        },
    520        'gatherNDIndices': {
    521          'data': [1, 1, 1],
    522          'descriptor': {shape: [3], dataType: 'int32'},
    523          'constant': true
    524        }
    525      },
    526      'operators': [{
    527        'name': 'gatherND',
    528        'arguments':
    529            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    530        'outputs': 'gatherNDOutput'
    531      }],
    532      'expectedOutputs': {
    533        'gatherNDOutput': {
    534          'data': [44.90625, 56.84375],
    535          'descriptor': {shape: [2], dataType: 'float16'}
    536        }
    537      }
    538    }
    539  },
    540  {
    541    'name': 'gatherND float16 2D input and 2D negative indices',
    542    'graph': {
    543      'inputs': {
    544        'gatherNDInput': {
    545          'data': [
    546            -66.0625, -68.9375, -77, -26.15625, 89.0625, -45.90625, 43.84375,
    547            48.8125, 51.8125, 41.9375, -1.1298828125, -50.40625, 90.3125,
    548            55.625, 44.90625, 56.84375
    549          ],
    550          'descriptor': {shape: [4, 4], dataType: 'float16'}
    551        },
    552        'gatherNDIndices': {
    553          'data': [-1, -2, -3, -4],
    554          'descriptor': {shape: [2, 2], dataType: 'int32'},
    555          'constant': true
    556        }
    557      },
    558      'operators': [{
    559        'name': 'gatherND',
    560        'arguments':
    561            [{'input': 'gatherNDInput'}, {'indices': 'gatherNDIndices'}],
    562        'outputs': 'gatherNDOutput'
    563      }],
    564      'expectedOutputs': {
    565        'gatherNDOutput': {
    566          'data': [44.90625, 89.0625],
    567          'descriptor': {shape: [2], dataType: 'float16'}
    568        }
    569      }
    570    }
    571  }
    572 ];
    573 
    574 webnn_conformance_test(
    575    gatherNDTests, buildAndExecuteGraph, getZeroULPTolerance);