tor-browser

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

relu.https.any.js (19826B)


      1 // META: title=test WebNN API relu 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-relu-method
     12 // Compute the rectified linear function of the input tensor.
     13 //
     14 // MLOperand relu(MLOperand input);
     15 
     16 const reluTests = [
     17  {
     18    'name': 'relu float32 1D constant tensor',
     19    'graph': {
     20      'inputs': {
     21        'reluInput': {
     22          'data': [
     23            79.04724884033203,  2.2503609657287598,  80.73938751220703,
     24            63.9039192199707,   77.67340850830078,   -71.0915756225586,
     25            -82.74703216552734, -26.81442642211914,  -99.16788482666016,
     26            -35.71083450317383, 18.361658096313477,  -37.36091613769531,
     27            -52.8386116027832,  -10.408374786376953, 60.6029167175293,
     28            -13.64419937133789, -76.5425033569336,   -8.132338523864746,
     29            51.51447296142578,  -51.63370132446289,  -64.56800079345703,
     30            -5.093302249908447, 15.354103088378906,  90.03858947753906
     31          ],
     32          'descriptor': {shape: [24], dataType: 'float32'},
     33          'constant': true
     34        }
     35      },
     36      'operators': [{
     37        'name': 'relu',
     38        'arguments': [{'input': 'reluInput'}],
     39        'outputs': 'reluOutput'
     40      }],
     41      'expectedOutputs': {
     42        'reluOutput': {
     43          'data': [
     44            79.04724884033203,
     45            2.2503609657287598,
     46            80.73938751220703,
     47            63.9039192199707,
     48            77.67340850830078,
     49            0,
     50            0,
     51            0,
     52            0,
     53            0,
     54            18.361658096313477,
     55            0,
     56            0,
     57            0,
     58            60.6029167175293,
     59            0,
     60            0,
     61            0,
     62            51.51447296142578,
     63            0,
     64            0,
     65            0,
     66            15.354103088378906,
     67            90.03858947753906
     68          ],
     69          'descriptor': {shape: [24], dataType: 'float32'}
     70        }
     71      }
     72    }
     73  },
     74  {
     75    'name': 'relu float32 0D tensor',
     76    'graph': {
     77      'inputs': {
     78        'reluInput': {
     79          'data': [79.04724884033203],
     80          'descriptor': {shape: [], dataType: 'float32'}
     81        }
     82      },
     83      'operators': [{
     84        'name': 'relu',
     85        'arguments': [{'input': 'reluInput'}],
     86        'outputs': 'reluOutput'
     87      }],
     88      'expectedOutputs': {
     89        'reluOutput': {
     90          'data': [
     91            79.04724884033203,
     92          ],
     93          'descriptor': {shape: [], dataType: 'float32'}
     94        }
     95      }
     96    }
     97  },
     98  {
     99    'name': 'relu float32 1D tensor',
    100    'graph': {
    101      'inputs': {
    102        'reluInput': {
    103          'data': [
    104            79.04724884033203,  2.2503609657287598,  80.73938751220703,
    105            63.9039192199707,   77.67340850830078,   -71.0915756225586,
    106            -82.74703216552734, -26.81442642211914,  -99.16788482666016,
    107            -35.71083450317383, 18.361658096313477,  -37.36091613769531,
    108            -52.8386116027832,  -10.408374786376953, 60.6029167175293,
    109            -13.64419937133789, -76.5425033569336,   -8.132338523864746,
    110            51.51447296142578,  -51.63370132446289,  -64.56800079345703,
    111            -5.093302249908447, 15.354103088378906,  90.03858947753906
    112          ],
    113          'descriptor': {shape: [24], dataType: 'float32'}
    114        }
    115      },
    116      'operators': [{
    117        'name': 'relu',
    118        'arguments': [{'input': 'reluInput'}],
    119        'outputs': 'reluOutput'
    120      }],
    121      'expectedOutputs': {
    122        'reluOutput': {
    123          'data': [
    124            79.04724884033203,
    125            2.2503609657287598,
    126            80.73938751220703,
    127            63.9039192199707,
    128            77.67340850830078,
    129            0,
    130            0,
    131            0,
    132            0,
    133            0,
    134            18.361658096313477,
    135            0,
    136            0,
    137            0,
    138            60.6029167175293,
    139            0,
    140            0,
    141            0,
    142            51.51447296142578,
    143            0,
    144            0,
    145            0,
    146            15.354103088378906,
    147            90.03858947753906
    148          ],
    149          'descriptor': {shape: [24], dataType: 'float32'}
    150        }
    151      }
    152    }
    153  },
    154  {
    155    'name': 'relu float32 2D tensor',
    156    'graph': {
    157      'inputs': {
    158        'reluInput': {
    159          'data': [
    160            79.04724884033203,  2.2503609657287598,  80.73938751220703,
    161            63.9039192199707,   77.67340850830078,   -71.0915756225586,
    162            -82.74703216552734, -26.81442642211914,  -99.16788482666016,
    163            -35.71083450317383, 18.361658096313477,  -37.36091613769531,
    164            -52.8386116027832,  -10.408374786376953, 60.6029167175293,
    165            -13.64419937133789, -76.5425033569336,   -8.132338523864746,
    166            51.51447296142578,  -51.63370132446289,  -64.56800079345703,
    167            -5.093302249908447, 15.354103088378906,  90.03858947753906
    168          ],
    169          'descriptor': {shape: [4, 6], dataType: 'float32'}
    170        }
    171      },
    172      'operators': [{
    173        'name': 'relu',
    174        'arguments': [{'input': 'reluInput'}],
    175        'outputs': 'reluOutput'
    176      }],
    177      'expectedOutputs': {
    178        'reluOutput': {
    179          'data': [
    180            79.04724884033203,
    181            2.2503609657287598,
    182            80.73938751220703,
    183            63.9039192199707,
    184            77.67340850830078,
    185            0,
    186            0,
    187            0,
    188            0,
    189            0,
    190            18.361658096313477,
    191            0,
    192            0,
    193            0,
    194            60.6029167175293,
    195            0,
    196            0,
    197            0,
    198            51.51447296142578,
    199            0,
    200            0,
    201            0,
    202            15.354103088378906,
    203            90.03858947753906
    204          ],
    205          'descriptor': {shape: [4, 6], dataType: 'float32'}
    206        }
    207      }
    208    }
    209  },
    210  {
    211    'name': 'relu float32 3D tensor',
    212    'graph': {
    213      'inputs': {
    214        'reluInput': {
    215          'data': [
    216            79.04724884033203,  2.2503609657287598,  80.73938751220703,
    217            63.9039192199707,   77.67340850830078,   -71.0915756225586,
    218            -82.74703216552734, -26.81442642211914,  -99.16788482666016,
    219            -35.71083450317383, 18.361658096313477,  -37.36091613769531,
    220            -52.8386116027832,  -10.408374786376953, 60.6029167175293,
    221            -13.64419937133789, -76.5425033569336,   -8.132338523864746,
    222            51.51447296142578,  -51.63370132446289,  -64.56800079345703,
    223            -5.093302249908447, 15.354103088378906,  90.03858947753906
    224          ],
    225          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    226        }
    227      },
    228      'operators': [{
    229        'name': 'relu',
    230        'arguments': [{'input': 'reluInput'}],
    231        'outputs': 'reluOutput'
    232      }],
    233      'expectedOutputs': {
    234        'reluOutput': {
    235          'data': [
    236            79.04724884033203,
    237            2.2503609657287598,
    238            80.73938751220703,
    239            63.9039192199707,
    240            77.67340850830078,
    241            0,
    242            0,
    243            0,
    244            0,
    245            0,
    246            18.361658096313477,
    247            0,
    248            0,
    249            0,
    250            60.6029167175293,
    251            0,
    252            0,
    253            0,
    254            51.51447296142578,
    255            0,
    256            0,
    257            0,
    258            15.354103088378906,
    259            90.03858947753906
    260          ],
    261          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    262        }
    263      }
    264    }
    265  },
    266  {
    267    'name': 'relu float32 4D tensor',
    268    'graph': {
    269      'inputs': {
    270        'reluInput': {
    271          'data': [
    272            79.04724884033203,  2.2503609657287598,  80.73938751220703,
    273            63.9039192199707,   77.67340850830078,   -71.0915756225586,
    274            -82.74703216552734, -26.81442642211914,  -99.16788482666016,
    275            -35.71083450317383, 18.361658096313477,  -37.36091613769531,
    276            -52.8386116027832,  -10.408374786376953, 60.6029167175293,
    277            -13.64419937133789, -76.5425033569336,   -8.132338523864746,
    278            51.51447296142578,  -51.63370132446289,  -64.56800079345703,
    279            -5.093302249908447, 15.354103088378906,  90.03858947753906
    280          ],
    281          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
    282        }
    283      },
    284      'operators': [{
    285        'name': 'relu',
    286        'arguments': [{'input': 'reluInput'}],
    287        'outputs': 'reluOutput'
    288      }],
    289      'expectedOutputs': {
    290        'reluOutput': {
    291          'data': [
    292            79.04724884033203,
    293            2.2503609657287598,
    294            80.73938751220703,
    295            63.9039192199707,
    296            77.67340850830078,
    297            0,
    298            0,
    299            0,
    300            0,
    301            0,
    302            18.361658096313477,
    303            0,
    304            0,
    305            0,
    306            60.6029167175293,
    307            0,
    308            0,
    309            0,
    310            51.51447296142578,
    311            0,
    312            0,
    313            0,
    314            15.354103088378906,
    315            90.03858947753906
    316          ],
    317          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
    318        }
    319      }
    320    }
    321  },
    322  {
    323    'name': 'relu float32 5D tensor',
    324    'graph': {
    325      'inputs': {
    326        'reluInput': {
    327          'data': [
    328            79.04724884033203,  2.2503609657287598,  80.73938751220703,
    329            63.9039192199707,   77.67340850830078,   -71.0915756225586,
    330            -82.74703216552734, -26.81442642211914,  -99.16788482666016,
    331            -35.71083450317383, 18.361658096313477,  -37.36091613769531,
    332            -52.8386116027832,  -10.408374786376953, 60.6029167175293,
    333            -13.64419937133789, -76.5425033569336,   -8.132338523864746,
    334            51.51447296142578,  -51.63370132446289,  -64.56800079345703,
    335            -5.093302249908447, 15.354103088378906,  90.03858947753906
    336          ],
    337          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
    338        }
    339      },
    340      'operators': [{
    341        'name': 'relu',
    342        'arguments': [{'input': 'reluInput'}],
    343        'outputs': 'reluOutput'
    344      }],
    345      'expectedOutputs': {
    346        'reluOutput': {
    347          'data': [
    348            79.04724884033203,
    349            2.2503609657287598,
    350            80.73938751220703,
    351            63.9039192199707,
    352            77.67340850830078,
    353            0,
    354            0,
    355            0,
    356            0,
    357            0,
    358            18.361658096313477,
    359            0,
    360            0,
    361            0,
    362            60.6029167175293,
    363            0,
    364            0,
    365            0,
    366            51.51447296142578,
    367            0,
    368            0,
    369            0,
    370            15.354103088378906,
    371            90.03858947753906
    372          ],
    373          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
    374        }
    375      }
    376    }
    377  },
    378 
    379  // float16 tests
    380  {
    381    'name': 'relu float16 1D constant tensor',
    382    'graph': {
    383      'inputs': {
    384        'reluInput': {
    385          'data': [
    386            79.0625,   2.25,      80.75,    63.90625,   77.6875,    -71.0625,
    387            -82.75,    -26.8125,  -99.1875, -35.71875,  18.359375,  -37.375,
    388            -52.84375, -10.40625, 60.59375, -13.640625, -76.5625,   -8.1328125,
    389            51.5,      -51.625,   -64.5625, -5.09375,   15.3515625, 90.0625
    390          ],
    391          'descriptor': {shape: [24], dataType: 'float16'},
    392          'constant': true
    393        }
    394      },
    395      'operators': [{
    396        'name': 'relu',
    397        'arguments': [{'input': 'reluInput'}],
    398        'outputs': 'reluOutput'
    399      }],
    400      'expectedOutputs': {
    401        'reluOutput': {
    402          'data': [
    403            79.0625, 2.25,      80.75, 63.90625, 77.6875,    0,        0, 0, 0,
    404            0,       18.359375, 0,     0,        0,          60.59375, 0, 0, 0,
    405            51.5,    0,         0,     0,        15.3515625, 90.0625
    406          ],
    407          'descriptor': {shape: [24], dataType: 'float16'}
    408        }
    409      }
    410    }
    411  },
    412  {
    413    'name': 'relu float16 0D tensor',
    414    'graph': {
    415      'inputs': {
    416        'reluInput':
    417            {'data': [79.0625], 'descriptor': {shape: [], dataType: 'float16'}}
    418      },
    419      'operators': [{
    420        'name': 'relu',
    421        'arguments': [{'input': 'reluInput'}],
    422        'outputs': 'reluOutput'
    423      }],
    424      'expectedOutputs': {
    425        'reluOutput':
    426            {'data': [79.0625], 'descriptor': {shape: [], dataType: 'float16'}}
    427      }
    428    }
    429  },
    430  {
    431    'name': 'relu float16 1D tensor',
    432    'graph': {
    433      'inputs': {
    434        'reluInput': {
    435          'data': [
    436            79.0625,   2.25,      80.75,    63.90625,   77.6875,    -71.0625,
    437            -82.75,    -26.8125,  -99.1875, -35.71875,  18.359375,  -37.375,
    438            -52.84375, -10.40625, 60.59375, -13.640625, -76.5625,   -8.1328125,
    439            51.5,      -51.625,   -64.5625, -5.09375,   15.3515625, 90.0625
    440          ],
    441          'descriptor': {shape: [24], dataType: 'float16'}
    442        }
    443      },
    444      'operators': [{
    445        'name': 'relu',
    446        'arguments': [{'input': 'reluInput'}],
    447        'outputs': 'reluOutput'
    448      }],
    449      'expectedOutputs': {
    450        'reluOutput': {
    451          'data': [
    452            79.0625, 2.25,      80.75, 63.90625, 77.6875,    0,        0, 0, 0,
    453            0,       18.359375, 0,     0,        0,          60.59375, 0, 0, 0,
    454            51.5,    0,         0,     0,        15.3515625, 90.0625
    455          ],
    456          'descriptor': {shape: [24], dataType: 'float16'}
    457        }
    458      }
    459    }
    460  },
    461  {
    462    'name': 'relu float16 2D tensor',
    463    'graph': {
    464      'inputs': {
    465        'reluInput': {
    466          'data': [
    467            79.0625,   2.25,      80.75,    63.90625,   77.6875,    -71.0625,
    468            -82.75,    -26.8125,  -99.1875, -35.71875,  18.359375,  -37.375,
    469            -52.84375, -10.40625, 60.59375, -13.640625, -76.5625,   -8.1328125,
    470            51.5,      -51.625,   -64.5625, -5.09375,   15.3515625, 90.0625
    471          ],
    472          'descriptor': {shape: [4, 6], dataType: 'float16'}
    473        }
    474      },
    475      'operators': [{
    476        'name': 'relu',
    477        'arguments': [{'input': 'reluInput'}],
    478        'outputs': 'reluOutput'
    479      }],
    480      'expectedOutputs': {
    481        'reluOutput': {
    482          'data': [
    483            79.0625, 2.25,      80.75, 63.90625, 77.6875,    0,        0, 0, 0,
    484            0,       18.359375, 0,     0,        0,          60.59375, 0, 0, 0,
    485            51.5,    0,         0,     0,        15.3515625, 90.0625
    486          ],
    487          'descriptor': {shape: [4, 6], dataType: 'float16'}
    488        }
    489      }
    490    }
    491  },
    492  {
    493    'name': 'relu float16 3D tensor',
    494    'graph': {
    495      'inputs': {
    496        'reluInput': {
    497          'data': [
    498            79.0625,   2.25,      80.75,    63.90625,   77.6875,    -71.0625,
    499            -82.75,    -26.8125,  -99.1875, -35.71875,  18.359375,  -37.375,
    500            -52.84375, -10.40625, 60.59375, -13.640625, -76.5625,   -8.1328125,
    501            51.5,      -51.625,   -64.5625, -5.09375,   15.3515625, 90.0625
    502          ],
    503          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    504        }
    505      },
    506      'operators': [{
    507        'name': 'relu',
    508        'arguments': [{'input': 'reluInput'}],
    509        'outputs': 'reluOutput'
    510      }],
    511      'expectedOutputs': {
    512        'reluOutput': {
    513          'data': [
    514            79.0625, 2.25,      80.75, 63.90625, 77.6875,    0,        0, 0, 0,
    515            0,       18.359375, 0,     0,        0,          60.59375, 0, 0, 0,
    516            51.5,    0,         0,     0,        15.3515625, 90.0625
    517          ],
    518          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    519        }
    520      }
    521    }
    522  },
    523  {
    524    'name': 'relu float16 4D tensor',
    525    'graph': {
    526      'inputs': {
    527        'reluInput': {
    528          'data': [
    529            79.0625,   2.25,      80.75,    63.90625,   77.6875,    -71.0625,
    530            -82.75,    -26.8125,  -99.1875, -35.71875,  18.359375,  -37.375,
    531            -52.84375, -10.40625, 60.59375, -13.640625, -76.5625,   -8.1328125,
    532            51.5,      -51.625,   -64.5625, -5.09375,   15.3515625, 90.0625
    533          ],
    534          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
    535        }
    536      },
    537      'operators': [{
    538        'name': 'relu',
    539        'arguments': [{'input': 'reluInput'}],
    540        'outputs': 'reluOutput'
    541      }],
    542      'expectedOutputs': {
    543        'reluOutput': {
    544          'data': [
    545            79.0625, 2.25,      80.75, 63.90625, 77.6875,    0,        0, 0, 0,
    546            0,       18.359375, 0,     0,        0,          60.59375, 0, 0, 0,
    547            51.5,    0,         0,     0,        15.3515625, 90.0625
    548          ],
    549          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
    550        }
    551      }
    552    }
    553  },
    554  {
    555    'name': 'relu float16 5D tensor',
    556    'graph': {
    557      'inputs': {
    558        'reluInput': {
    559          'data': [
    560            79.0625,   2.25,      80.75,    63.90625,   77.6875,    -71.0625,
    561            -82.75,    -26.8125,  -99.1875, -35.71875,  18.359375,  -37.375,
    562            -52.84375, -10.40625, 60.59375, -13.640625, -76.5625,   -8.1328125,
    563            51.5,      -51.625,   -64.5625, -5.09375,   15.3515625, 90.0625
    564          ],
    565          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
    566        }
    567      },
    568      'operators': [{
    569        'name': 'relu',
    570        'arguments': [{'input': 'reluInput'}],
    571        'outputs': 'reluOutput'
    572      }],
    573      'expectedOutputs': {
    574        'reluOutput': {
    575          'data': [
    576            79.0625, 2.25,      80.75, 63.90625, 77.6875,    0,        0, 0, 0,
    577            0,       18.359375, 0,     0,        0,          60.59375, 0, 0, 0,
    578            51.5,    0,         0,     0,        15.3515625, 90.0625
    579          ],
    580          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
    581        }
    582      }
    583    }
    584  },
    585 
    586  // int8 tests
    587  {
    588    'name': 'relu int8 4D tensor',
    589    'graph': {
    590      'inputs': {
    591        'reluInput': {
    592          'data': [
    593            // int8 range: [/* -(2**7) */ -128, /* 2**7 - 1 */ 127]
    594            -128, 0, 126, 127
    595          ],
    596          'descriptor': {shape: [1, 2, 2, 1], dataType: 'int8'}
    597        }
    598      },
    599      'operators': [{
    600        'name': 'relu',
    601        'arguments': [{'input': 'reluInput'}],
    602        'outputs': 'reluOutput'
    603      }],
    604      'expectedOutputs': {
    605        'reluOutput': {
    606          'data': [0, 0, 126, 127],
    607          'descriptor': {shape: [1, 2, 2, 1], dataType: 'int8'}
    608        }
    609      }
    610    }
    611  },
    612 
    613  // int32 tests
    614  {
    615    'name': 'relu int32 4D tensor',
    616    'graph': {
    617      'inputs': {
    618        'reluInput': {
    619          'data': [
    620            // int32 range: [/* -(2**31) */ -2147483648, /* 2**31 - 1 */ 2147483647]
    621            -2147483648, 0, 2147483646, 2147483647
    622          ],
    623          'descriptor': {shape: [1, 2, 2, 1], dataType: 'int32'}
    624        }
    625      },
    626      'operators': [{
    627        'name': 'relu',
    628        'arguments': [{'input': 'reluInput'}],
    629        'outputs': 'reluOutput'
    630      }],
    631      'expectedOutputs': {
    632        'reluOutput': {
    633          'data': [0, 0, 2147483646, 2147483647],
    634          'descriptor': {shape: [1, 2, 2, 1], dataType: 'int32'}
    635        }
    636      }
    637    }
    638  },
    639 
    640  // int64 tests
    641  {
    642    'name': 'relu int64 4D tensor',
    643    'graph': {
    644      'inputs': {
    645        'reluInput': {
    646          'data': [
    647            // int64 range: [/* -(2**63) */ –9223372036854775808,
    648            //               /* 2**63 - 1 */ 92233720368547758087]
    649            BigInt(-(2**63)) + 1n, -100n, 0n, 100n, BigInt(2**63) - 1n
    650          ],
    651          'descriptor': {shape: [1, 1, 1, 5], dataType: 'int64'}
    652        }
    653      },
    654      'operators': [{
    655        'name': 'relu',
    656        'arguments': [{'input': 'reluInput'}],
    657        'outputs': 'reluOutput'
    658      }],
    659      'expectedOutputs': {
    660        'reluOutput': {
    661          'data': [0n, 0n, 0n, 100n, BigInt(2**63) - 1n],
    662          'descriptor': {shape: [1, 1, 1, 5], dataType: 'int64'}
    663        }
    664      }
    665    }
    666  }
    667 ];
    668 
    669 webnn_conformance_test(reluTests, buildAndExecuteGraph, getPrecisionTolerance);