tor-browser

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

sin.https.any.js (20009B)


      1 // META: title=test WebNN API element-wise sin 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-unary
     12 // Compute the sine of the input tensor, element-wise.
     13 //
     14 // MLOperand sin(MLOperand input);
     15 
     16 
     17 const getSinPrecisionTolerance = (graphResources) => {
     18  // Use the float accuracy for WGSL for float16:
     19  // https://gpuweb.github.io/gpuweb/wgsl/#concrete-float-accuracy
     20  const toleranceValueDict = {float32: 2 ** -10, float16: 2 ** -7};
     21  const expectedDataType =
     22      getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs);
     23  return {metricType: 'ATOL', value: toleranceValueDict[expectedDataType]};
     24 };
     25 
     26 const sinTests = [
     27  {
     28    'name': 'sin float32 0D scalar',
     29    'graph': {
     30      'inputs': {
     31        'sinInput': {
     32          'data': [-1.9008227506588398],
     33          'descriptor': {shape: [], dataType: 'float32'}
     34        }
     35      },
     36      'operators': [{
     37        'name': 'sin',
     38        'arguments': [{'input': 'sinInput'}],
     39        'outputs': 'sinOutput'
     40      }],
     41      'expectedOutputs': {
     42        'sinOutput': {
     43          'data': [-0.946033775806427],
     44          'descriptor': {shape: [], dataType: 'float32'}
     45        }
     46      }
     47    }
     48  },
     49  {
     50    'name': 'sin float32 1D constant tensor',
     51    'graph': {
     52      'inputs': {
     53        'sinInput': {
     54          'data': [
     55            -1.9008227506588398,  -1.5429342746260417,  -2.919790967326577,
     56            -0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
     57            2.39996318810816,     2.859002653752462,    2.3440884431888165,
     58            -1.2528136412249964,  3.0537582715247,      -3.0257774670813404,
     59            -0.13451073966544413, -1.9820843219915147,  -0.6088270346587095,
     60            0.8576429843428386,   -2.9220742702326064,  -1.334865713166927,
     61            -0.3998628457123843,  -0.6352694035366753,  -2.9027661165286602,
     62            0.8664462884635995,   -0.1507168293157335,  2.2272057850734086
     63          ],
     64          'descriptor': {shape: [24], dataType: 'float32'},
     65          'constant': true
     66        }
     67      },
     68      'operators': [{
     69        'name': 'sin',
     70        'arguments': [{'input': 'sinInput'}],
     71        'outputs': 'sinOutput'
     72      }],
     73      'expectedOutputs': {
     74        'sinOutput': {
     75          'data': [
     76            -0.946033775806427,   -0.9996118545532227,  -0.21998752653598785,
     77            -0.22639396786689758, -0.2618238627910614,  -0.9335716366767883,
     78            0.6754903197288513,   0.27884384989738464,  0.7156150341033936,
     79            -0.9498680830001831,  0.08772148936986923,  -0.11555644869804382,
     80            -0.13410548865795135, -0.9166066646575928,  -0.5719056725502014,
     81            0.7563026547431946,   -0.21775959432125092, -0.9722972512245178,
     82            -0.38929200172424316, -0.59339439868927,    -0.23656263947486877,
     83            0.7620325684547424,   -0.15014687180519104, 0.7921885848045349
     84          ],
     85          'descriptor': {shape: [24], dataType: 'float32'}
     86        }
     87      }
     88    }
     89  },
     90  {
     91    'name': 'sin float32 1D tensor',
     92    'graph': {
     93      'inputs': {
     94        'sinInput': {
     95          'data': [
     96            -1.9008227506588398,  -1.5429342746260417,  -2.919790967326577,
     97            -0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
     98            2.39996318810816,     2.859002653752462,    2.3440884431888165,
     99            -1.2528136412249964,  3.0537582715247,      -3.0257774670813404,
    100            -0.13451073966544413, -1.9820843219915147,  -0.6088270346587095,
    101            0.8576429843428386,   -2.9220742702326064,  -1.334865713166927,
    102            -0.3998628457123843,  -0.6352694035366753,  -2.9027661165286602,
    103            0.8664462884635995,   -0.1507168293157335,  2.2272057850734086
    104          ],
    105          'descriptor': {shape: [24], dataType: 'float32'}
    106        }
    107      },
    108      'operators': [{
    109        'name': 'sin',
    110        'arguments': [{'input': 'sinInput'}],
    111        'outputs': 'sinOutput'
    112      }],
    113      'expectedOutputs': {
    114        'sinOutput': {
    115          'data': [
    116            -0.946033775806427,   -0.9996118545532227,  -0.21998752653598785,
    117            -0.22639396786689758, -0.2618238627910614,  -0.9335716366767883,
    118            0.6754903197288513,   0.27884384989738464,  0.7156150341033936,
    119            -0.9498680830001831,  0.08772148936986923,  -0.11555644869804382,
    120            -0.13410548865795135, -0.9166066646575928,  -0.5719056725502014,
    121            0.7563026547431946,   -0.21775959432125092, -0.9722972512245178,
    122            -0.38929200172424316, -0.59339439868927,    -0.23656263947486877,
    123            0.7620325684547424,   -0.15014687180519104, 0.7921885848045349
    124          ],
    125          'descriptor': {shape: [24], dataType: 'float32'}
    126        }
    127      }
    128    }
    129  },
    130  {
    131    'name': 'sin float32 2D tensor',
    132    'graph': {
    133      'inputs': {
    134        'sinInput': {
    135          'data': [
    136            -1.9008227506588398,  -1.5429342746260417,  -2.919790967326577,
    137            -0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
    138            2.39996318810816,     2.859002653752462,    2.3440884431888165,
    139            -1.2528136412249964,  3.0537582715247,      -3.0257774670813404,
    140            -0.13451073966544413, -1.9820843219915147,  -0.6088270346587095,
    141            0.8576429843428386,   -2.9220742702326064,  -1.334865713166927,
    142            -0.3998628457123843,  -0.6352694035366753,  -2.9027661165286602,
    143            0.8664462884635995,   -0.1507168293157335,  2.2272057850734086
    144          ],
    145          'descriptor': {shape: [4, 6], dataType: 'float32'}
    146        }
    147      },
    148      'operators': [{
    149        'name': 'sin',
    150        'arguments': [{'input': 'sinInput'}],
    151        'outputs': 'sinOutput'
    152      }],
    153      'expectedOutputs': {
    154        'sinOutput': {
    155          'data': [
    156            -0.946033775806427,   -0.9996118545532227,  -0.21998752653598785,
    157            -0.22639396786689758, -0.2618238627910614,  -0.9335716366767883,
    158            0.6754903197288513,   0.27884384989738464,  0.7156150341033936,
    159            -0.9498680830001831,  0.08772148936986923,  -0.11555644869804382,
    160            -0.13410548865795135, -0.9166066646575928,  -0.5719056725502014,
    161            0.7563026547431946,   -0.21775959432125092, -0.9722972512245178,
    162            -0.38929200172424316, -0.59339439868927,    -0.23656263947486877,
    163            0.7620325684547424,   -0.15014687180519104, 0.7921885848045349
    164          ],
    165          'descriptor': {shape: [4, 6], dataType: 'float32'}
    166        }
    167      }
    168    }
    169  },
    170  {
    171    'name': 'sin float32 3D tensor',
    172    'graph': {
    173      'inputs': {
    174        'sinInput': {
    175          'data': [
    176            -1.9008227506588398,  -1.5429342746260417,  -2.919790967326577,
    177            -0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
    178            2.39996318810816,     2.859002653752462,    2.3440884431888165,
    179            -1.2528136412249964,  3.0537582715247,      -3.0257774670813404,
    180            -0.13451073966544413, -1.9820843219915147,  -0.6088270346587095,
    181            0.8576429843428386,   -2.9220742702326064,  -1.334865713166927,
    182            -0.3998628457123843,  -0.6352694035366753,  -2.9027661165286602,
    183            0.8664462884635995,   -0.1507168293157335,  2.2272057850734086
    184          ],
    185          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    186        }
    187      },
    188      'operators': [{
    189        'name': 'sin',
    190        'arguments': [{'input': 'sinInput'}],
    191        'outputs': 'sinOutput'
    192      }],
    193      'expectedOutputs': {
    194        'sinOutput': {
    195          'data': [
    196            -0.946033775806427,   -0.9996118545532227,  -0.21998752653598785,
    197            -0.22639396786689758, -0.2618238627910614,  -0.9335716366767883,
    198            0.6754903197288513,   0.27884384989738464,  0.7156150341033936,
    199            -0.9498680830001831,  0.08772148936986923,  -0.11555644869804382,
    200            -0.13410548865795135, -0.9166066646575928,  -0.5719056725502014,
    201            0.7563026547431946,   -0.21775959432125092, -0.9722972512245178,
    202            -0.38929200172424316, -0.59339439868927,    -0.23656263947486877,
    203            0.7620325684547424,   -0.15014687180519104, 0.7921885848045349
    204          ],
    205          'descriptor': {shape: [2, 3, 4], dataType: 'float32'}
    206        }
    207      }
    208    }
    209  },
    210  {
    211    'name': 'sin float32 4D tensor',
    212    'graph': {
    213      'inputs': {
    214        'sinInput': {
    215          'data': [
    216            -1.9008227506588398,  -1.5429342746260417,  -2.919790967326577,
    217            -0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
    218            2.39996318810816,     2.859002653752462,    2.3440884431888165,
    219            -1.2528136412249964,  3.0537582715247,      -3.0257774670813404,
    220            -0.13451073966544413, -1.9820843219915147,  -0.6088270346587095,
    221            0.8576429843428386,   -2.9220742702326064,  -1.334865713166927,
    222            -0.3998628457123843,  -0.6352694035366753,  -2.9027661165286602,
    223            0.8664462884635995,   -0.1507168293157335,  2.2272057850734086
    224          ],
    225          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
    226        }
    227      },
    228      'operators': [{
    229        'name': 'sin',
    230        'arguments': [{'input': 'sinInput'}],
    231        'outputs': 'sinOutput'
    232      }],
    233      'expectedOutputs': {
    234        'sinOutput': {
    235          'data': [
    236            -0.946033775806427,   -0.9996118545532227,  -0.21998752653598785,
    237            -0.22639396786689758, -0.2618238627910614,  -0.9335716366767883,
    238            0.6754903197288513,   0.27884384989738464,  0.7156150341033936,
    239            -0.9498680830001831,  0.08772148936986923,  -0.11555644869804382,
    240            -0.13410548865795135, -0.9166066646575928,  -0.5719056725502014,
    241            0.7563026547431946,   -0.21775959432125092, -0.9722972512245178,
    242            -0.38929200172424316, -0.59339439868927,    -0.23656263947486877,
    243            0.7620325684547424,   -0.15014687180519104, 0.7921885848045349
    244          ],
    245          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'}
    246        }
    247      }
    248    }
    249  },
    250  {
    251    'name': 'sin float32 5D tensor',
    252    'graph': {
    253      'inputs': {
    254        'sinInput': {
    255          'data': [
    256            -1.9008227506588398,  -1.5429342746260417,  -2.919790967326577,
    257            -0.22837392491749853, -0.26491150851276046, -1.9373400212124565,
    258            2.39996318810816,     2.859002653752462,    2.3440884431888165,
    259            -1.2528136412249964,  3.0537582715247,      -3.0257774670813404,
    260            -0.13451073966544413, -1.9820843219915147,  -0.6088270346587095,
    261            0.8576429843428386,   -2.9220742702326064,  -1.334865713166927,
    262            -0.3998628457123843,  -0.6352694035366753,  -2.9027661165286602,
    263            0.8664462884635995,   -0.1507168293157335,  2.2272057850734086
    264          ],
    265          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
    266        }
    267      },
    268      'operators': [{
    269        'name': 'sin',
    270        'arguments': [{'input': 'sinInput'}],
    271        'outputs': 'sinOutput'
    272      }],
    273      'expectedOutputs': {
    274        'sinOutput': {
    275          'data': [
    276            -0.946033775806427,   -0.9996118545532227,  -0.21998752653598785,
    277            -0.22639396786689758, -0.2618238627910614,  -0.9335716366767883,
    278            0.6754903197288513,   0.27884384989738464,  0.7156150341033936,
    279            -0.9498680830001831,  0.08772148936986923,  -0.11555644869804382,
    280            -0.13410548865795135, -0.9166066646575928,  -0.5719056725502014,
    281            0.7563026547431946,   -0.21775959432125092, -0.9722972512245178,
    282            -0.38929200172424316, -0.59339439868927,    -0.23656263947486877,
    283            0.7620325684547424,   -0.15014687180519104, 0.7921885848045349
    284          ],
    285          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'}
    286        }
    287      }
    288    }
    289  },
    290 
    291  // float16 tests
    292  {
    293    'name': 'sin float16 0D scalar',
    294    'graph': {
    295      'inputs': {
    296        'sinInput':
    297            {'data': [79.75], 'descriptor': {shape: [], dataType: 'float16'}}
    298      },
    299      'operators': [{
    300        'name': 'sin',
    301        'arguments': [{'input': 'sinInput'}],
    302        'outputs': 'sinOutput'
    303      }],
    304      'expectedOutputs': {
    305        'sinOutput': {
    306          'data': [-0.935546875],
    307          'descriptor': {shape: [], dataType: 'float16'}
    308        }
    309      }
    310    }
    311  },
    312  {
    313    'name': 'sin float16 1D constant tensor',
    314    'graph': {
    315      'inputs': {
    316        'sinInput': {
    317          'data': [
    318            -1.932, -1.549, -2.914,  -0.2247, -0.2673, -1.939, 2.398,   2.86,
    319            2.318,  -1.252, 3.05,    -3.027,  -0.1329, -1.979, -0.615,  0.8613,
    320            -2.92,  -1.326, -0.4004, -0.6274, -2.88,   0.8613, -0.1504, 2.234
    321          ],
    322          'descriptor': {shape: [24], dataType: 'float16'},
    323          'constant': true
    324        }
    325      },
    326      'operators': [{
    327        'name': 'sin',
    328        'arguments': [{'input': 'sinInput'}],
    329        'outputs': 'sinOutput'
    330      }],
    331      'expectedOutputs': {
    332        'sinOutput': {
    333          'data': [
    334            -0.935546875,     -0.99951171875,  -0.2254638671875,
    335            -0.2227783203125, -0.26416015625,  -0.9326171875,
    336            0.6767578125,     0.278564453125,  0.7333984375,
    337            -0.94970703125,   0.0906982421875, -0.114013671875,
    338            -0.1324462890625, -0.91796875,     -0.5771484375,
    339            0.7587890625,     -0.219970703125, -0.97021484375,
    340            -0.3896484375,    -0.5869140625,   -0.257568359375,
    341            0.7587890625,     -0.14990234375,  0.7880859375
    342          ],
    343          'descriptor': {shape: [24], dataType: 'float16'}
    344        }
    345      }
    346    }
    347  },
    348  {
    349    'name': 'sin float16 1D tensor',
    350    'graph': {
    351      'inputs': {
    352        'sinInput': {
    353          'data': [
    354            -1.932, -1.549, -2.914,  -0.2247, -0.2673, -1.939, 2.398,   2.86,
    355            2.318,  -1.252, 3.05,    -3.027,  -0.1329, -1.979, -0.615,  0.8613,
    356            -2.92,  -1.326, -0.4004, -0.6274, -2.88,   0.8613, -0.1504, 2.234
    357          ],
    358          'descriptor': {shape: [24], dataType: 'float16'}
    359        }
    360      },
    361      'operators': [{
    362        'name': 'sin',
    363        'arguments': [{'input': 'sinInput'}],
    364        'outputs': 'sinOutput'
    365      }],
    366      'expectedOutputs': {
    367        'sinOutput': {
    368          'data': [
    369            -0.935546875,     -0.99951171875,  -0.2254638671875,
    370            -0.2227783203125, -0.26416015625,  -0.9326171875,
    371            0.6767578125,     0.278564453125,  0.7333984375,
    372            -0.94970703125,   0.0906982421875, -0.114013671875,
    373            -0.1324462890625, -0.91796875,     -0.5771484375,
    374            0.7587890625,     -0.219970703125, -0.97021484375,
    375            -0.3896484375,    -0.5869140625,   -0.257568359375,
    376            0.7587890625,     -0.14990234375,  0.7880859375
    377          ],
    378          'descriptor': {shape: [24], dataType: 'float16'}
    379        }
    380      }
    381    }
    382  },
    383  {
    384    'name': 'sin float16 2D tensor',
    385    'graph': {
    386      'inputs': {
    387        'sinInput': {
    388          'data': [
    389            -1.932, -1.549, -2.914,  -0.2247, -0.2673, -1.939, 2.398,   2.86,
    390            2.318,  -1.252, 3.05,    -3.027,  -0.1329, -1.979, -0.615,  0.8613,
    391            -2.92,  -1.326, -0.4004, -0.6274, -2.88,   0.8613, -0.1504, 2.234
    392          ],
    393          'descriptor': {shape: [4, 6], dataType: 'float16'}
    394        }
    395      },
    396      'operators': [{
    397        'name': 'sin',
    398        'arguments': [{'input': 'sinInput'}],
    399        'outputs': 'sinOutput'
    400      }],
    401      'expectedOutputs': {
    402        'sinOutput': {
    403          'data': [
    404            -0.935546875,     -0.99951171875,  -0.2254638671875,
    405            -0.2227783203125, -0.26416015625,  -0.9326171875,
    406            0.6767578125,     0.278564453125,  0.7333984375,
    407            -0.94970703125,   0.0906982421875, -0.114013671875,
    408            -0.1324462890625, -0.91796875,     -0.5771484375,
    409            0.7587890625,     -0.219970703125, -0.97021484375,
    410            -0.3896484375,    -0.5869140625,   -0.257568359375,
    411            0.7587890625,     -0.14990234375,  0.7880859375
    412          ],
    413          'descriptor': {shape: [4, 6], dataType: 'float16'}
    414        }
    415      }
    416    }
    417  },
    418  {
    419    'name': 'sin float16 3D tensor',
    420    'graph': {
    421      'inputs': {
    422        'sinInput': {
    423          'data': [
    424            -1.932, -1.549, -2.914,  -0.2247, -0.2673, -1.939, 2.398,   2.86,
    425            2.318,  -1.252, 3.05,    -3.027,  -0.1329, -1.979, -0.615,  0.8613,
    426            -2.92,  -1.326, -0.4004, -0.6274, -2.88,   0.8613, -0.1504, 2.234
    427          ],
    428          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    429        }
    430      },
    431      'operators': [{
    432        'name': 'sin',
    433        'arguments': [{'input': 'sinInput'}],
    434        'outputs': 'sinOutput'
    435      }],
    436      'expectedOutputs': {
    437        'sinOutput': {
    438          'data': [
    439            -0.935546875,     -0.99951171875,  -0.2254638671875,
    440            -0.2227783203125, -0.26416015625,  -0.9326171875,
    441            0.6767578125,     0.278564453125,  0.7333984375,
    442            -0.94970703125,   0.0906982421875, -0.114013671875,
    443            -0.1324462890625, -0.91796875,     -0.5771484375,
    444            0.7587890625,     -0.219970703125, -0.97021484375,
    445            -0.3896484375,    -0.5869140625,   -0.257568359375,
    446            0.7587890625,     -0.14990234375,  0.7880859375
    447          ],
    448          'descriptor': {shape: [2, 3, 4], dataType: 'float16'}
    449        }
    450      }
    451    }
    452  },
    453  {
    454    'name': 'sin float16 4D tensor',
    455    'graph': {
    456      'inputs': {
    457        'sinInput': {
    458          'data': [
    459            -1.932, -1.549, -2.914,  -0.2247, -0.2673, -1.939, 2.398,   2.86,
    460            2.318,  -1.252, 3.05,    -3.027,  -0.1329, -1.979, -0.615,  0.8613,
    461            -2.92,  -1.326, -0.4004, -0.6274, -2.88,   0.8613, -0.1504, 2.234
    462          ],
    463          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
    464        }
    465      },
    466      'operators': [{
    467        'name': 'sin',
    468        'arguments': [{'input': 'sinInput'}],
    469        'outputs': 'sinOutput'
    470      }],
    471      'expectedOutputs': {
    472        'sinOutput': {
    473          'data': [
    474            -0.935546875,     -0.99951171875,  -0.2254638671875,
    475            -0.2227783203125, -0.26416015625,  -0.9326171875,
    476            0.6767578125,     0.278564453125,  0.7333984375,
    477            -0.94970703125,   0.0906982421875, -0.114013671875,
    478            -0.1324462890625, -0.91796875,     -0.5771484375,
    479            0.7587890625,     -0.219970703125, -0.97021484375,
    480            -0.3896484375,    -0.5869140625,   -0.257568359375,
    481            0.7587890625,     -0.14990234375,  0.7880859375
    482          ],
    483          'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'}
    484        }
    485      }
    486    }
    487  },
    488  {
    489    'name': 'sin float16 5D tensor',
    490    'graph': {
    491      'inputs': {
    492        'sinInput': {
    493          'data': [
    494            -1.932, -1.549, -2.914,  -0.2247, -0.2673, -1.939, 2.398,   2.86,
    495            2.318,  -1.252, 3.05,    -3.027,  -0.1329, -1.979, -0.615,  0.8613,
    496            -2.92,  -1.326, -0.4004, -0.6274, -2.88,   0.8613, -0.1504, 2.234
    497          ],
    498          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
    499        }
    500      },
    501      'operators': [{
    502        'name': 'sin',
    503        'arguments': [{'input': 'sinInput'}],
    504        'outputs': 'sinOutput'
    505      }],
    506      'expectedOutputs': {
    507        'sinOutput': {
    508          'data': [
    509            -0.935546875,     -0.99951171875,  -0.2254638671875,
    510            -0.2227783203125, -0.26416015625,  -0.9326171875,
    511            0.6767578125,     0.278564453125,  0.7333984375,
    512            -0.94970703125,   0.0906982421875, -0.114013671875,
    513            -0.1324462890625, -0.91796875,     -0.5771484375,
    514            0.7587890625,     -0.219970703125, -0.97021484375,
    515            -0.3896484375,    -0.5869140625,   -0.257568359375,
    516            0.7587890625,     -0.14990234375,  0.7880859375
    517          ],
    518          'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'}
    519        }
    520      }
    521    }
    522  }
    523 ];
    524 
    525 webnn_conformance_test(
    526    sinTests, buildAndExecuteGraph, getSinPrecisionTolerance);