add.https.any.js (39614B)
1 // META: title=test WebNN API element-wise add 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-binary 12 // Compute the element-wise binary addition of the two input tensors. 13 // MLOperand add(MLOperand a, MLOperand b); 14 15 const addTests = [ 16 { 17 'name': 'add float32 1D constant tensors', 18 'graph': { 19 'inputs': { 20 'inputA': { 21 'data': [ 22 -43.333316802978516, -67.89795684814453, 26.462739944458008, 23 36.74276351928711, -65.1773910522461, -87.70664978027344, 24 65.27881622314453, -74.05226135253906, -13.827810287475586, 25 6.981486797332764, 99.83751678466797, 55.802337646484375, 26 -75.57196044921875, 11.499507904052734, 17.110109329223633, 27 95.81167602539062, 57.4474983215332, -57.175872802734375, 28 27.719053268432617, -18.219209671020508, 52.653099060058594, 29 -69.99455261230469, 39.8216552734375, -29.986528396606445 30 ], 31 'descriptor': {shape: [24], dataType: 'float32'}, 32 'constant': true 33 }, 34 'inputB': { 35 'data': [ 36 -59.749725341796875, -44.81494140625, -87.93879699707031, 37 1.8843363523483276, 84.89464569091797, 47.553653717041016, 38 85.64292907714844, 43.02861404418945, -60.25821304321289, 39 15.60616683959961, 70.60614776611328, -7.454866409301758, 40 -30.20689582824707, -97.69825744628906, -0.00984330102801323, 41 -77.67960357666016, 30.196685791015625, -59.19007110595703, 42 89.3588638305664, 28.6798095703125, -29.72130584716797, 43 -90.6352310180664, 28.2818546295166, 27.662540435791016 44 ], 45 'descriptor': {shape: [24], dataType: 'float32'}, 46 'constant': true 47 } 48 }, 49 'operators': [{ 50 'name': 'add', 51 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 52 'outputs': 'output' 53 }], 54 'expectedOutputs': { 55 'output': { 56 'data': [ 57 -103.08303833007812, -112.71289825439453, -61.47605895996094, 58 38.627098083496094, 19.717254638671875, -40.15299606323242, 59 150.9217529296875, -31.02364730834961, -74.08602142333984, 60 22.58765411376953, 170.44366455078125, 48.34747314453125, 61 -105.77885437011719, -86.19874572753906, 17.100265502929688, 62 18.13207244873047, 87.64418029785156, -116.3659439086914, 63 117.07791900634766, 10.460599899291992, 22.931793212890625, 64 -160.62979125976562, 68.10350799560547, -2.3239879608154297 65 ], 66 'descriptor': {shape: [24], dataType: 'float32'} 67 } 68 } 69 } 70 }, 71 { 72 'name': 'add float32 1D tensors', 73 'graph': { 74 'inputs': { 75 'inputA': { 76 'data': [ 77 -43.333316802978516, -67.89795684814453, 26.462739944458008, 78 36.74276351928711, -65.1773910522461, -87.70664978027344, 79 65.27881622314453, -74.05226135253906, -13.827810287475586, 80 6.981486797332764, 99.83751678466797, 55.802337646484375, 81 -75.57196044921875, 11.499507904052734, 17.110109329223633, 82 95.81167602539062, 57.4474983215332, -57.175872802734375, 83 27.719053268432617, -18.219209671020508, 52.653099060058594, 84 -69.99455261230469, 39.8216552734375, -29.986528396606445 85 ], 86 'descriptor': {shape: [24], dataType: 'float32'} 87 }, 88 'inputB': { 89 'data': [ 90 -59.749725341796875, -44.81494140625, -87.93879699707031, 91 1.8843363523483276, 84.89464569091797, 47.553653717041016, 92 85.64292907714844, 43.02861404418945, -60.25821304321289, 93 15.60616683959961, 70.60614776611328, -7.454866409301758, 94 -30.20689582824707, -97.69825744628906, -0.00984330102801323, 95 -77.67960357666016, 30.196685791015625, -59.19007110595703, 96 89.3588638305664, 28.6798095703125, -29.72130584716797, 97 -90.6352310180664, 28.2818546295166, 27.662540435791016 98 ], 99 'descriptor': {shape: [24], dataType: 'float32'} 100 } 101 }, 102 'operators': [{ 103 'name': 'add', 104 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 105 'outputs': 'output' 106 }], 107 'expectedOutputs': { 108 'output': { 109 'data': [ 110 -103.08303833007812, -112.71289825439453, -61.47605895996094, 111 38.627098083496094, 19.717254638671875, -40.15299606323242, 112 150.9217529296875, -31.02364730834961, -74.08602142333984, 113 22.58765411376953, 170.44366455078125, 48.34747314453125, 114 -105.77885437011719, -86.19874572753906, 17.100265502929688, 115 18.13207244873047, 87.64418029785156, -116.3659439086914, 116 117.07791900634766, 10.460599899291992, 22.931793212890625, 117 -160.62979125976562, 68.10350799560547, -2.3239879608154297 118 ], 119 'descriptor': {shape: [24], dataType: 'float32'} 120 } 121 } 122 } 123 }, 124 { 125 'name': 'add float32 2D tensors', 126 'graph': { 127 'inputs': { 128 'inputA': { 129 'data': [ 130 -43.333316802978516, -67.89795684814453, 26.462739944458008, 131 36.74276351928711, -65.1773910522461, -87.70664978027344, 132 65.27881622314453, -74.05226135253906, -13.827810287475586, 133 6.981486797332764, 99.83751678466797, 55.802337646484375, 134 -75.57196044921875, 11.499507904052734, 17.110109329223633, 135 95.81167602539062, 57.4474983215332, -57.175872802734375, 136 27.719053268432617, -18.219209671020508, 52.653099060058594, 137 -69.99455261230469, 39.8216552734375, -29.986528396606445 138 ], 139 'descriptor': {shape: [4, 6], dataType: 'float32'} 140 }, 141 'inputB': { 142 'data': [ 143 -59.749725341796875, -44.81494140625, -87.93879699707031, 144 1.8843363523483276, 84.89464569091797, 47.553653717041016, 145 85.64292907714844, 43.02861404418945, -60.25821304321289, 146 15.60616683959961, 70.60614776611328, -7.454866409301758, 147 -30.20689582824707, -97.69825744628906, -0.00984330102801323, 148 -77.67960357666016, 30.196685791015625, -59.19007110595703, 149 89.3588638305664, 28.6798095703125, -29.72130584716797, 150 -90.6352310180664, 28.2818546295166, 27.662540435791016 151 ], 152 'descriptor': {shape: [4, 6], dataType: 'float32'} 153 } 154 }, 155 'operators': [{ 156 'name': 'add', 157 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 158 'outputs': 'output' 159 }], 160 'expectedOutputs': { 161 'output': { 162 'data': [ 163 -103.08303833007812, -112.71289825439453, -61.47605895996094, 164 38.627098083496094, 19.717254638671875, -40.15299606323242, 165 150.9217529296875, -31.02364730834961, -74.08602142333984, 166 22.58765411376953, 170.44366455078125, 48.34747314453125, 167 -105.77885437011719, -86.19874572753906, 17.100265502929688, 168 18.13207244873047, 87.64418029785156, -116.3659439086914, 169 117.07791900634766, 10.460599899291992, 22.931793212890625, 170 -160.62979125976562, 68.10350799560547, -2.3239879608154297 171 ], 172 'descriptor': {shape: [4, 6], dataType: 'float32'} 173 } 174 } 175 } 176 }, 177 { 178 'name': 'add float32 3D tensors', 179 'graph': { 180 'inputs': { 181 'inputA': { 182 'data': [ 183 -43.333316802978516, -67.89795684814453, 26.462739944458008, 184 36.74276351928711, -65.1773910522461, -87.70664978027344, 185 65.27881622314453, -74.05226135253906, -13.827810287475586, 186 6.981486797332764, 99.83751678466797, 55.802337646484375, 187 -75.57196044921875, 11.499507904052734, 17.110109329223633, 188 95.81167602539062, 57.4474983215332, -57.175872802734375, 189 27.719053268432617, -18.219209671020508, 52.653099060058594, 190 -69.99455261230469, 39.8216552734375, -29.986528396606445 191 ], 192 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 193 }, 194 'inputB': { 195 'data': [ 196 -59.749725341796875, -44.81494140625, -87.93879699707031, 197 1.8843363523483276, 84.89464569091797, 47.553653717041016, 198 85.64292907714844, 43.02861404418945, -60.25821304321289, 199 15.60616683959961, 70.60614776611328, -7.454866409301758, 200 -30.20689582824707, -97.69825744628906, -0.00984330102801323, 201 -77.67960357666016, 30.196685791015625, -59.19007110595703, 202 89.3588638305664, 28.6798095703125, -29.72130584716797, 203 -90.6352310180664, 28.2818546295166, 27.662540435791016 204 ], 205 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 206 } 207 }, 208 'operators': [{ 209 'name': 'add', 210 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 211 'outputs': 'output' 212 }], 213 'expectedOutputs': { 214 'output': { 215 'data': [ 216 -103.08303833007812, -112.71289825439453, -61.47605895996094, 217 38.627098083496094, 19.717254638671875, -40.15299606323242, 218 150.9217529296875, -31.02364730834961, -74.08602142333984, 219 22.58765411376953, 170.44366455078125, 48.34747314453125, 220 -105.77885437011719, -86.19874572753906, 17.100265502929688, 221 18.13207244873047, 87.64418029785156, -116.3659439086914, 222 117.07791900634766, 10.460599899291992, 22.931793212890625, 223 -160.62979125976562, 68.10350799560547, -2.3239879608154297 224 ], 225 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 226 } 227 } 228 } 229 }, 230 { 231 'name': 'add float32 4D tensors', 232 'graph': { 233 'inputs': { 234 'inputA': { 235 'data': [ 236 -43.333316802978516, -67.89795684814453, 26.462739944458008, 237 36.74276351928711, -65.1773910522461, -87.70664978027344, 238 65.27881622314453, -74.05226135253906, -13.827810287475586, 239 6.981486797332764, 99.83751678466797, 55.802337646484375, 240 -75.57196044921875, 11.499507904052734, 17.110109329223633, 241 95.81167602539062, 57.4474983215332, -57.175872802734375, 242 27.719053268432617, -18.219209671020508, 52.653099060058594, 243 -69.99455261230469, 39.8216552734375, -29.986528396606445 244 ], 245 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 246 }, 247 'inputB': { 248 'data': [ 249 -59.749725341796875, -44.81494140625, -87.93879699707031, 250 1.8843363523483276, 84.89464569091797, 47.553653717041016, 251 85.64292907714844, 43.02861404418945, -60.25821304321289, 252 15.60616683959961, 70.60614776611328, -7.454866409301758, 253 -30.20689582824707, -97.69825744628906, -0.00984330102801323, 254 -77.67960357666016, 30.196685791015625, -59.19007110595703, 255 89.3588638305664, 28.6798095703125, -29.72130584716797, 256 -90.6352310180664, 28.2818546295166, 27.662540435791016 257 ], 258 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 259 } 260 }, 261 'operators': [{ 262 'name': 'add', 263 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 264 'outputs': 'output' 265 }], 266 'expectedOutputs': { 267 'output': { 268 'data': [ 269 -103.08303833007812, -112.71289825439453, -61.47605895996094, 270 38.627098083496094, 19.717254638671875, -40.15299606323242, 271 150.9217529296875, -31.02364730834961, -74.08602142333984, 272 22.58765411376953, 170.44366455078125, 48.34747314453125, 273 -105.77885437011719, -86.19874572753906, 17.100265502929688, 274 18.13207244873047, 87.64418029785156, -116.3659439086914, 275 117.07791900634766, 10.460599899291992, 22.931793212890625, 276 -160.62979125976562, 68.10350799560547, -2.3239879608154297 277 ], 278 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 279 } 280 } 281 } 282 }, 283 { 284 'name': 'add float32 5D tensors', 285 'graph': { 286 'inputs': { 287 'inputA': { 288 'data': [ 289 -43.333316802978516, -67.89795684814453, 26.462739944458008, 290 36.74276351928711, -65.1773910522461, -87.70664978027344, 291 65.27881622314453, -74.05226135253906, -13.827810287475586, 292 6.981486797332764, 99.83751678466797, 55.802337646484375, 293 -75.57196044921875, 11.499507904052734, 17.110109329223633, 294 95.81167602539062, 57.4474983215332, -57.175872802734375, 295 27.719053268432617, -18.219209671020508, 52.653099060058594, 296 -69.99455261230469, 39.8216552734375, -29.986528396606445 297 ], 298 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 299 }, 300 'inputB': { 301 'data': [ 302 -59.749725341796875, -44.81494140625, -87.93879699707031, 303 1.8843363523483276, 84.89464569091797, 47.553653717041016, 304 85.64292907714844, 43.02861404418945, -60.25821304321289, 305 15.60616683959961, 70.60614776611328, -7.454866409301758, 306 -30.20689582824707, -97.69825744628906, -0.00984330102801323, 307 -77.67960357666016, 30.196685791015625, -59.19007110595703, 308 89.3588638305664, 28.6798095703125, -29.72130584716797, 309 -90.6352310180664, 28.2818546295166, 27.662540435791016 310 ], 311 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 312 } 313 }, 314 'operators': [{ 315 'name': 'add', 316 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 317 'outputs': 'output' 318 }], 319 'expectedOutputs': { 320 'output': { 321 'data': [ 322 -103.08303833007812, -112.71289825439453, -61.47605895996094, 323 38.627098083496094, 19.717254638671875, -40.15299606323242, 324 150.9217529296875, -31.02364730834961, -74.08602142333984, 325 22.58765411376953, 170.44366455078125, 48.34747314453125, 326 -105.77885437011719, -86.19874572753906, 17.100265502929688, 327 18.13207244873047, 87.64418029785156, -116.3659439086914, 328 117.07791900634766, 10.460599899291992, 22.931793212890625, 329 -160.62979125976562, 68.10350799560547, -2.3239879608154297 330 ], 331 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float32'} 332 } 333 } 334 } 335 }, 336 { 337 'name': 'add float32 broadcast 1D to 4D', 338 'graph': { 339 'inputs': { 340 'inputA': { 341 'data': [-59.361572265625], 342 'descriptor': {shape: [1], dataType: 'float32'} 343 }, 344 'inputB': { 345 'data': [ 346 -43.333316802978516, -67.89795684814453, 26.462739944458008, 347 36.74276351928711, -65.1773910522461, -87.70664978027344, 348 65.27881622314453, -74.05226135253906, -13.827810287475586, 349 6.981486797332764, 99.83751678466797, 55.802337646484375, 350 -75.57196044921875, 11.499507904052734, 17.110109329223633, 351 95.81167602539062, 57.4474983215332, -57.175872802734375, 352 27.719053268432617, -18.219209671020508, 52.653099060058594, 353 -69.99455261230469, 39.8216552734375, -29.986528396606445 354 ], 355 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 356 } 357 }, 358 'operators': [{ 359 'name': 'add', 360 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 361 'outputs': 'output' 362 }], 363 'expectedOutputs': { 364 'output': { 365 'data': [ 366 -102.69488525390625, -127.25952911376953, -32.898834228515625, 367 -22.61880874633789, -124.5389633178711, -147.06822204589844, 368 5.917243957519531, -133.41383361816406, -73.18938446044922, 369 -52.38008499145508, 40.47594451904297, -3.559234619140625, 370 -134.93353271484375, -47.862064361572266, -42.25146484375, 371 36.450103759765625, -1.9140739440917969, -116.53744506835938, 372 -31.642518997192383, -77.58078002929688, -6.708473205566406, 373 -129.3561248779297, -19.5399169921875, -89.34809875488281 374 ], 375 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 376 } 377 } 378 } 379 }, 380 { 381 'name': 'add float32 broadcast 2D to 4D', 382 'graph': { 383 'inputs': { 384 'inputA': { 385 'data': [ 386 -43.333316802978516, -67.89795684814453, 26.462739944458008, 387 36.74276351928711, -65.1773910522461, -87.70664978027344, 388 65.27881622314453, -74.05226135253906, -13.827810287475586, 389 6.981486797332764, 99.83751678466797, 55.802337646484375, 390 -75.57196044921875, 11.499507904052734, 17.110109329223633, 391 95.81167602539062, 57.4474983215332, -57.175872802734375, 392 27.719053268432617, -18.219209671020508, 52.653099060058594, 393 -69.99455261230469, 39.8216552734375, -29.986528396606445 394 ], 395 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 396 }, 397 'inputB': { 398 'data': [ 399 -17.981124877929688, -70.45854187011719, -12.762019157409668, 400 24.254032135009766, -68.12599182128906, 30.62627410888672 401 ], 402 'descriptor': {shape: [2, 3], dataType: 'float32'} 403 } 404 }, 405 'operators': [{ 406 'name': 'add', 407 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 408 'outputs': 'output' 409 }], 410 'expectedOutputs': { 411 'output': { 412 'data': [ 413 -61.3144416809082, -138.35650634765625, 13.70072078704834, 414 60.996795654296875, -133.30337524414062, -57.08037567138672, 415 47.297691345214844, -144.51080322265625, -26.589828491210938, 416 31.235519409179688, 31.711524963378906, 86.4286117553711, 417 -93.55308532714844, -58.95903396606445, 4.348090171813965, 418 120.06570434570312, -10.67849349975586, -26.549598693847656, 419 9.73792839050293, -88.67774963378906, 39.89107894897461, 420 -45.74052047729492, -28.304336547851562, 0.6397457122802734 421 ], 422 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 423 } 424 } 425 } 426 }, 427 { 428 'name': 'add float32 broadcast 3D to 4D', 429 'graph': { 430 'inputs': { 431 'inputA': { 432 'data': [ 433 -43.333316802978516, -67.89795684814453, 26.462739944458008, 434 36.74276351928711, -65.1773910522461, -87.70664978027344, 435 65.27881622314453, -74.05226135253906, -13.827810287475586, 436 6.981486797332764, 99.83751678466797, 55.802337646484375, 437 -75.57196044921875, 11.499507904052734, 17.110109329223633, 438 95.81167602539062, 57.4474983215332, -57.175872802734375, 439 27.719053268432617, -18.219209671020508, 52.653099060058594, 440 -69.99455261230469, 39.8216552734375, -29.986528396606445 441 ], 442 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 443 }, 444 'inputB': { 445 'data': [ 446 -32.34067153930664, 43.12499237060547, 78.6887435913086, 447 -54.49899673461914 448 ], 449 'descriptor': {shape: [2, 2, 1], dataType: 'float32'} 450 } 451 }, 452 'operators': [{ 453 'name': 'add', 454 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 455 'outputs': 'output' 456 }], 457 'expectedOutputs': { 458 'output': { 459 'data': [ 460 -75.67398834228516, -100.23863220214844, -5.877931594848633, 461 79.86775207519531, -22.052398681640625, -44.58165740966797, 462 143.96755981445312, 4.636482238769531, 64.86093139648438, 463 -47.51750946044922, 45.33852005004883, 1.3033409118652344, 464 -107.91262817382812, -20.841163635253906, -15.230562210083008, 465 138.93667602539062, 100.57249450683594, -14.050880432128906, 466 106.40779876708984, 60.46953582763672, 131.3418426513672, 467 -124.49354553222656, -14.67734146118164, -84.48552703857422 468 ], 469 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 470 } 471 } 472 } 473 }, 474 { 475 'name': 'add float32 broadcast 4D to 4D', 476 'graph': { 477 'inputs': { 478 'inputA': { 479 'data': [-59.361572265625], 480 'descriptor': {shape: [1, 1, 1, 1], dataType: 'float32'} 481 }, 482 'inputB': { 483 'data': [ 484 -43.333316802978516, -67.89795684814453, 26.462739944458008, 485 36.74276351928711, -65.1773910522461, -87.70664978027344, 486 65.27881622314453, -74.05226135253906, -13.827810287475586, 487 6.981486797332764, 99.83751678466797, 55.802337646484375, 488 -75.57196044921875, 11.499507904052734, 17.110109329223633, 489 95.81167602539062, 57.4474983215332, -57.175872802734375, 490 27.719053268432617, -18.219209671020508, 52.653099060058594, 491 -69.99455261230469, 39.8216552734375, -29.986528396606445 492 ], 493 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 494 } 495 }, 496 'operators': [{ 497 'name': 'add', 498 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 499 'outputs': 'output' 500 }], 501 'expectedOutputs': { 502 'output': { 503 'data': [ 504 -102.69488525390625, -127.25952911376953, -32.898834228515625, 505 -22.61880874633789, -124.5389633178711, -147.06822204589844, 506 5.917243957519531, -133.41383361816406, -73.18938446044922, 507 -52.38008499145508, 40.47594451904297, -3.559234619140625, 508 -134.93353271484375, -47.862064361572266, -42.25146484375, 509 36.450103759765625, -1.9140739440917969, -116.53744506835938, 510 -31.642518997192383, -77.58078002929688, -6.708473205566406, 511 -129.3561248779297, -19.5399169921875, -89.34809875488281 512 ], 513 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 514 } 515 } 516 } 517 }, 518 { 519 'name': 'add float32 large inputs', 520 'graph': { 521 'inputs': { 522 'inputA': { 523 'data': 89.32998657226562, 524 'descriptor': {shape: [6000, 6000], dataType: 'float32'}, 525 'constant': true 526 }, 527 'inputB': { 528 'data': 77.24720764160156, 529 'descriptor': {shape: [6000, 6000], dataType: 'float32'} 530 } 531 }, 532 'operators': [{ 533 'name': 'add', 534 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 535 'outputs': 'output' 536 }], 537 'expectedOutputs': { 538 'output': { 539 'data': 166.5771942138672, 540 'descriptor': {shape: [6000, 6000], dataType: 'float32'} 541 } 542 } 543 } 544 }, 545 { 546 'name': 'add float32 with special character names', 547 'graph': { 548 'inputs': { 549 '12-L#!.☺': { 550 'data': [89.32998657226562], 551 'descriptor': {shape: [1], dataType: 'float32'}, 552 'constant': true 553 }, 554 '🤦🏼♂️124DS#!F': { 555 'data': [77.24720764160156], 556 'descriptor': {shape: [1], dataType: 'float32'} 557 } 558 }, 559 'operators': [{ 560 'name': 'add', 561 'arguments': [{'a': '12-L#!.☺'}, {'b': '🤦🏼♂️124DS#!F'}], 562 'outputs': 'output' 563 }], 564 'expectedOutputs': { 565 'output': { 566 'data': [166.5771942138672], 567 'descriptor': {shape: [1], dataType: 'float32'} 568 } 569 } 570 } 571 }, 572 573 // float16 tests 574 { 575 'name': 'add float16 1D constant tensors', 576 'graph': { 577 'inputs': { 578 'inputA': { 579 'data': [ 580 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 581 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 582 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 583 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 584 ], 585 'descriptor': {shape: [24], dataType: 'float16'}, 586 'constant': true 587 }, 588 'inputB': { 589 'data': [ 590 -59.75, -44.8125, -87.9375, 1.884765625, 84.875, 591 47.5625, 85.625, 43.03125, -60.25, 15.609375, 592 70.625, -7.453125, -30.203125, -97.6875, -0.0098419189453125, 593 -77.6875, 30.203125, -59.1875, 89.375, 28.6875, 594 -29.71875, -90.625, 28.28125, 27.65625 595 ], 596 'descriptor': {shape: [24], dataType: 'float16'}, 597 'constant': true 598 } 599 }, 600 'operators': [{ 601 'name': 'add', 602 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 603 'outputs': 'output' 604 }], 605 'expectedOutputs': { 606 'output': { 607 'data': [ 608 -103.125, -112.6875, -61.46875, 38.625, 19.6875, -40.125, 609 150.875, -31.03125, -74.0625, 22.59375, 170.5, 48.375, 610 -105.75, -86.1875, 17.09375, 18.125, 87.625, -116.375, 611 117.125, 10.46875, 22.9375, -160.625, 68.125, -2.328125 612 ], 613 'descriptor': {shape: [24], dataType: 'float16'} 614 } 615 } 616 } 617 }, 618 { 619 'name': 'add float16 1D tensors', 620 'graph': { 621 'inputs': { 622 'inputA': { 623 'data': [ 624 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 625 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 626 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 627 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 628 ], 629 'descriptor': {shape: [24], dataType: 'float16'} 630 }, 631 'inputB': { 632 'data': [ 633 -59.75, -44.8125, -87.9375, 1.884765625, 84.875, 634 47.5625, 85.625, 43.03125, -60.25, 15.609375, 635 70.625, -7.453125, -30.203125, -97.6875, -0.0098419189453125, 636 -77.6875, 30.203125, -59.1875, 89.375, 28.6875, 637 -29.71875, -90.625, 28.28125, 27.65625 638 ], 639 'descriptor': {shape: [24], dataType: 'float16'} 640 } 641 }, 642 'operators': [{ 643 'name': 'add', 644 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 645 'outputs': 'output' 646 }], 647 'expectedOutputs': { 648 'output': { 649 'data': [ 650 -103.125, -112.6875, -61.46875, 38.625, 19.6875, -40.125, 651 150.875, -31.03125, -74.0625, 22.59375, 170.5, 48.375, 652 -105.75, -86.1875, 17.09375, 18.125, 87.625, -116.375, 653 117.125, 10.46875, 22.9375, -160.625, 68.125, -2.328125 654 ], 655 'descriptor': {shape: [24], dataType: 'float16'} 656 } 657 } 658 } 659 }, 660 { 661 'name': 'add float16 2D tensors', 662 'graph': { 663 'inputs': { 664 'inputA': { 665 'data': [ 666 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 667 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 668 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 669 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 670 ], 671 'descriptor': {shape: [4, 6], dataType: 'float16'} 672 }, 673 'inputB': { 674 'data': [ 675 -59.75, -44.8125, -87.9375, 1.884765625, 84.875, 676 47.5625, 85.625, 43.03125, -60.25, 15.609375, 677 70.625, -7.453125, -30.203125, -97.6875, -0.0098419189453125, 678 -77.6875, 30.203125, -59.1875, 89.375, 28.6875, 679 -29.71875, -90.625, 28.28125, 27.65625 680 ], 681 'descriptor': {shape: [4, 6], dataType: 'float16'} 682 } 683 }, 684 'operators': [{ 685 'name': 'add', 686 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 687 'outputs': 'output' 688 }], 689 'expectedOutputs': { 690 'output': { 691 'data': [ 692 -103.125, -112.6875, -61.46875, 38.625, 19.6875, -40.125, 693 150.875, -31.03125, -74.0625, 22.59375, 170.5, 48.375, 694 -105.75, -86.1875, 17.09375, 18.125, 87.625, -116.375, 695 117.125, 10.46875, 22.9375, -160.625, 68.125, -2.328125 696 ], 697 'descriptor': {shape: [4, 6], dataType: 'float16'} 698 } 699 } 700 } 701 }, 702 { 703 'name': 'add float16 3D tensors', 704 'graph': { 705 'inputs': { 706 'inputA': { 707 'data': [ 708 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 709 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 710 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 711 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 712 ], 713 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 714 }, 715 'inputB': { 716 'data': [ 717 -59.75, -44.8125, -87.9375, 1.884765625, 84.875, 718 47.5625, 85.625, 43.03125, -60.25, 15.609375, 719 70.625, -7.453125, -30.203125, -97.6875, -0.0098419189453125, 720 -77.6875, 30.203125, -59.1875, 89.375, 28.6875, 721 -29.71875, -90.625, 28.28125, 27.65625 722 ], 723 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 724 } 725 }, 726 'operators': [{ 727 'name': 'add', 728 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 729 'outputs': 'output' 730 }], 731 'expectedOutputs': { 732 'output': { 733 'data': [ 734 -103.125, -112.6875, -61.46875, 38.625, 19.6875, -40.125, 735 150.875, -31.03125, -74.0625, 22.59375, 170.5, 48.375, 736 -105.75, -86.1875, 17.09375, 18.125, 87.625, -116.375, 737 117.125, 10.46875, 22.9375, -160.625, 68.125, -2.328125 738 ], 739 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 740 } 741 } 742 } 743 }, 744 { 745 'name': 'add float16 4D tensors', 746 'graph': { 747 'inputs': { 748 'inputA': { 749 'data': [ 750 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 751 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 752 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 753 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 754 ], 755 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 756 }, 757 'inputB': { 758 'data': [ 759 -59.75, -44.8125, -87.9375, 1.884765625, 84.875, 760 47.5625, 85.625, 43.03125, -60.25, 15.609375, 761 70.625, -7.453125, -30.203125, -97.6875, -0.0098419189453125, 762 -77.6875, 30.203125, -59.1875, 89.375, 28.6875, 763 -29.71875, -90.625, 28.28125, 27.65625 764 ], 765 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 766 } 767 }, 768 'operators': [{ 769 'name': 'add', 770 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 771 'outputs': 'output' 772 }], 773 'expectedOutputs': { 774 'output': { 775 'data': [ 776 -103.125, -112.6875, -61.46875, 38.625, 19.6875, -40.125, 777 150.875, -31.03125, -74.0625, 22.59375, 170.5, 48.375, 778 -105.75, -86.1875, 17.09375, 18.125, 87.625, -116.375, 779 117.125, 10.46875, 22.9375, -160.625, 68.125, -2.328125 780 ], 781 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 782 } 783 } 784 } 785 }, 786 { 787 'name': 'add float16 5D tensors', 788 'graph': { 789 'inputs': { 790 'inputA': { 791 'data': [ 792 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 793 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 794 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 795 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 796 ], 797 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 798 }, 799 'inputB': { 800 'data': [ 801 -59.75, -44.8125, -87.9375, 1.884765625, 84.875, 802 47.5625, 85.625, 43.03125, -60.25, 15.609375, 803 70.625, -7.453125, -30.203125, -97.6875, -0.0098419189453125, 804 -77.6875, 30.203125, -59.1875, 89.375, 28.6875, 805 -29.71875, -90.625, 28.28125, 27.65625 806 ], 807 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 808 } 809 }, 810 'operators': [{ 811 'name': 'add', 812 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 813 'outputs': 'output' 814 }], 815 'expectedOutputs': { 816 'output': { 817 'data': [ 818 -103.125, -112.6875, -61.46875, 38.625, 19.6875, -40.125, 819 150.875, -31.03125, -74.0625, 22.59375, 170.5, 48.375, 820 -105.75, -86.1875, 17.09375, 18.125, 87.625, -116.375, 821 117.125, 10.46875, 22.9375, -160.625, 68.125, -2.328125 822 ], 823 'descriptor': {shape: [2, 2, 1, 2, 3], dataType: 'float16'} 824 } 825 } 826 } 827 }, 828 { 829 'name': 'add float16 broadcast 1D to 4D', 830 'graph': { 831 'inputs': { 832 'inputA': { 833 'data': [-59.375], 834 'descriptor': {shape: [1], dataType: 'float16'} 835 }, 836 'inputB': { 837 'data': [ 838 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 839 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 840 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 841 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 842 ], 843 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 844 } 845 }, 846 'operators': [{ 847 'name': 'add', 848 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 849 'outputs': 'output' 850 }], 851 'expectedOutputs': { 852 'output': { 853 'data': [ 854 -102.75, -127.25, -32.90625, -22.625, -124.5625, -147, 855 5.875, -133.5, -73.1875, -52.40625, 40.4375, -3.5625, 856 -135, -47.875, -42.25, 36.4375, -1.9375, -116.5625, 857 -31.65625, -77.625, -6.71875, -129.375, -19.5625, -89.375 858 ], 859 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 860 } 861 } 862 } 863 }, 864 { 865 'name': 'add float16 broadcast 2D to 4D', 866 'graph': { 867 'inputs': { 868 'inputA': { 869 'data': [ 870 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 871 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 872 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 873 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 874 ], 875 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 876 }, 877 'inputB': { 878 'data': [-17.984375, -70.4375, -12.765625, 24.25, -68.125, 30.625], 879 'descriptor': {shape: [2, 3], dataType: 'float16'} 880 } 881 }, 882 'operators': [{ 883 'name': 'add', 884 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 885 'outputs': 'output' 886 }], 887 'expectedOutputs': { 888 'output': { 889 'data': [ 890 -61.3125, -138.25, 13.703125, 61, -133.25, -57.0625, 891 47.25, -144.5, -26.59375, 31.234375, 31.6875, 86.4375, 892 -93.5625, -58.9375, 4.34375, 120.0625, -10.6875, -26.5625, 893 9.734375, -88.625, 39.875, -45.75, -28.3125, 0.640625 894 ], 895 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 896 } 897 } 898 } 899 }, 900 { 901 'name': 'add float16 broadcast 3D to 4D', 902 'graph': { 903 'inputs': { 904 'inputA': { 905 'data': [ 906 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 907 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 908 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 909 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 910 ], 911 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 912 }, 913 'inputB': { 914 'data': [-32.34375, 43.125, 78.6875, -54.5], 915 'descriptor': {shape: [2, 2, 1], dataType: 'float16'} 916 } 917 }, 918 'operators': [{ 919 'name': 'add', 920 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 921 'outputs': 'output' 922 }], 923 'expectedOutputs': { 924 'output': { 925 'data': [ 926 -75.6875, -100.25, -5.875, 79.875, -22.0625, -44.5625, 927 144, 4.625, 64.875, -47.53125, 45.3125, 1.3125, 928 -107.875, -20.84375, -15.234375, 139, 100.5625, -14.0625, 929 106.375, 60.46875, 131.375, -124.5, -14.6875, -84.5 930 ], 931 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 932 } 933 } 934 } 935 }, 936 { 937 'name': 'add float16 broadcast 4D to 4D', 938 'graph': { 939 'inputs': { 940 'inputA': { 941 'data': [-59.375], 942 'descriptor': {shape: [1, 1, 1, 1], dataType: 'float16'} 943 }, 944 'inputB': { 945 'data': [ 946 -43.34375, -67.875, 26.46875, 36.75, -65.1875, -87.6875, 947 65.25, -74.0625, -13.828125, 6.98046875, 99.8125, 55.8125, 948 -75.5625, 11.5, 17.109375, 95.8125, 57.4375, -57.1875, 949 27.71875, -18.21875, 52.65625, -70, 39.8125, -29.984375 950 ], 951 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 952 } 953 }, 954 'operators': [{ 955 'name': 'add', 956 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 957 'outputs': 'output' 958 }], 959 'expectedOutputs': { 960 'output': { 961 'data': [ 962 -102.75, -127.25, -32.90625, -22.625, -124.5625, -147, 963 5.875, -133.5, -73.1875, -52.40625, 40.4375, -3.5625, 964 -135, -47.875, -42.25, 36.4375, -1.9375, -116.5625, 965 -31.65625, -77.625, -6.71875, -129.375, -19.5625, -89.375 966 ], 967 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 968 } 969 } 970 } 971 }, 972 { 973 'name': 'add float16 large inputs', 974 'graph': { 975 'inputs': { 976 'inputA': { 977 'data': 89.3125, 978 'descriptor': {shape: [6000, 6000], dataType: 'float16'}, 979 'constant': true 980 }, 981 'inputB': { 982 'data': 77.25, 983 'descriptor': {shape: [6000, 6000], dataType: 'float16'} 984 } 985 }, 986 'operators': [{ 987 'name': 'add', 988 'arguments': [{'a': 'inputA'}, {'b': 'inputB'}], 989 'outputs': 'output' 990 }], 991 'expectedOutputs': { 992 'output': { 993 'data': 166.5, 994 'descriptor': {shape: [6000, 6000], dataType: 'float16'} 995 } 996 } 997 } 998 } 999 ]; 1000 1001 webnn_conformance_test(addTests, buildAndExecuteGraph, getPrecisionTolerance);