tor-browser

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

scatterND.https.any.js (5057B)


      1 // META: title=test WebNN API scatterND 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 const scatterNDTests = [
     12  {
     13    'name':
     14        'scatterND 1D float32 tensors (Insert individual elements in a tensor by index)',
     15    'graph': {
     16      'inputs': {
     17        'input': {
     18          'data': [1, 2, 3, 4, 5, 6, 7, 8],
     19          'descriptor': {shape: [8], dataType: 'float32'}
     20        },
     21        'indices': {
     22          'data': [4, 3, 1, 7],
     23          'descriptor': {shape: [4, 1], dataType: 'int32'}
     24        },
     25        'updates': {
     26          'data': [9, 10, 11, 12],
     27          'descriptor': {shape: [4], dataType: 'float32'}
     28        }
     29      },
     30      'operators': [{
     31        'name': 'scatterND',
     32        'arguments': [
     33          {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}
     34        ],
     35        'outputs': 'output'
     36      }],
     37      'expectedOutputs': {
     38        'output': {
     39          'data': [1, 11, 3, 10, 9, 6, 7, 12],
     40          'descriptor': {shape: [8], dataType: 'float32'}
     41        }
     42      }
     43    }
     44  },
     45  {
     46    'name':
     47        'scatterND 3D float32 tensors (Insert entire slices of a higher rank tensor)',
     48    'graph': {
     49      'inputs': {
     50        'input': {
     51          'data': [
     52            1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
     53            7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
     54            5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8
     55          ],
     56          'descriptor': {shape: [4, 4, 4], dataType: 'float32'}
     57        },
     58        'indices':
     59            {'data': [0, 2], 'descriptor': {shape: [2, 1], dataType: 'int32'}},
     60        'updates': {
     61          'data': [
     62            5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
     63            1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4
     64          ],
     65          'descriptor': {shape: [2, 4, 4], dataType: 'float32'}
     66        }
     67      },
     68      'operators': [{
     69        'name': 'scatterND',
     70        'arguments': [
     71          {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}
     72        ],
     73        'outputs': 'output'
     74      }],
     75      'expectedOutputs': {
     76        'output': {
     77          'data': [
     78            5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 1, 2, 3, 4, 5, 6,
     79            7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
     80            4, 4, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8
     81          ],
     82          'descriptor': {shape: [4, 4, 4], dataType: 'float32'}
     83        }
     84      }
     85    }
     86  },
     87 
     88  // float16 tests
     89  {
     90    'name':
     91        'scatterND 1D float16 tensors (Insert individual elements in a tensor by index)',
     92    'graph': {
     93      'inputs': {
     94        'input': {
     95          'data': [1, 2, 3, 4, 5, 6, 7, 8],
     96          'descriptor': {shape: [8], dataType: 'float16'}
     97        },
     98        'indices': {
     99          'data': [4, 3, 1, 7],
    100          'descriptor': {shape: [4, 1], dataType: 'int32'}
    101        },
    102        'updates': {
    103          'data': [9, 10, 11, 12],
    104          'descriptor': {shape: [4], dataType: 'float16'}
    105        }
    106      },
    107      'operators': [{
    108        'name': 'scatterND',
    109        'arguments': [
    110          {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}
    111        ],
    112        'outputs': 'output'
    113      }],
    114      'expectedOutputs': {
    115        'output': {
    116          'data': [1, 11, 3, 10, 9, 6, 7, 12],
    117          'descriptor': {shape: [8], dataType: 'float16'}
    118        }
    119      }
    120    }
    121  },
    122  {
    123    'name':
    124        'scatterND 3D float16 tensors (Insert entire slices of a higher rank tensor)',
    125    'graph': {
    126      'inputs': {
    127        'input': {
    128          'data': [
    129            1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
    130            7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
    131            5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8
    132          ],
    133          'descriptor': {shape: [4, 4, 4], dataType: 'float16'}
    134        },
    135        'indices':
    136            {'data': [0, 2], 'descriptor': {shape: [2, 1], dataType: 'int32'}},
    137        'updates': {
    138          'data': [
    139            5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
    140            1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4
    141          ],
    142          'descriptor': {shape: [2, 4, 4], dataType: 'float16'}
    143        }
    144      },
    145      'operators': [{
    146        'name': 'scatterND',
    147        'arguments': [
    148          {'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'}
    149        ],
    150        'outputs': 'output'
    151      }],
    152      'expectedOutputs': {
    153        'output': {
    154          'data': [
    155            5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 1, 2, 3, 4, 5, 6,
    156            7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
    157            4, 4, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8
    158          ],
    159          'descriptor': {shape: [4, 4, 4], dataType: 'float16'}
    160        }
    161      }
    162    }
    163  }
    164 ];
    165 
    166 webnn_conformance_test(
    167    scatterNDTests, buildAndExecuteGraph, getZeroULPTolerance);