exp.https.any.js (22035B)
1 // META: title=test WebNN API element-wise exp 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 exponential of the input tensor, element-wise. 13 // 14 // MLOperand exp(MLOperand input); 15 16 17 const getExpPrecisionTolerance = (graphResources) => { 18 const toleranceValueDict = {float32: 32, float16: 1}; 19 const expectedDataType = 20 getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs); 21 return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]}; 22 }; 23 24 const expTests = [ 25 { 26 'name': 'exp float32 0D scalar', 27 'graph': { 28 'inputs': { 29 'expInput': { 30 'data': [0.3421436548233032], 31 'descriptor': {shape: [], dataType: 'float32'} 32 } 33 }, 34 'operators': [{ 35 'name': 'exp', 36 'arguments': [{'input': 'expInput'}], 37 'outputs': 'expOutput' 38 }], 39 'expectedOutputs': { 40 'expOutput': { 41 'data': [1.4079625606536865], 42 'descriptor': {shape: [], dataType: 'float32'} 43 } 44 } 45 } 46 }, 47 { 48 'name': 'exp float32 1D constant tensor', 49 'graph': { 50 'inputs': { 51 'expInput': { 52 'data': [ 53 0.3421436548233032, -3.310965061187744, -3.6967575550079346, 54 -5.105378150939941, 5.47104024887085, -0.06790750473737717, 55 2.7373435497283936, -3.5470757484436035, 5.339224815368652, 56 -1.2636781930923462, -0.9162953495979309, -9.088432312011719, 57 -4.016050815582275, 4.670352935791016, 7.326992034912109, 58 8.294342994689941, -7.345414161682129, -0.9275799989700317, 59 -1.7085379362106323, -9.73737907409668, -1.9747875928878784, 60 8.203149795532227, -7.267597675323486, -3.5890684127807617 61 ], 62 'descriptor': {shape: [24], dataType: 'float32'}, 63 'constant': true 64 } 65 }, 66 'operators': [{ 67 'name': 'exp', 68 'arguments': [{'input': 'expInput'}], 69 'outputs': 'expOutput' 70 }], 71 'expectedOutputs': { 72 'expOutput': { 73 'data': [ 74 1.4079625606536865, 0.03648095205426216, 0.024803820997476578, 75 0.006064045242965221, 237.70733642578125, 0.9343469142913818, 76 15.44589900970459, 0.02880876138806343, 208.35113525390625, 77 0.2826126217842102, 0.39999815821647644, 0.00011296502634650096, 78 0.018024004995822906, 106.73540496826172, 1520.8004150390625, 79 4001.173583984375, 0.0006455459515564144, 0.3955096900463104, 80 0.18113042414188385, 0.0000590350573475007, 0.1387907862663269, 81 3652.4365234375, 0.0006977862794883549, 0.02762405201792717 82 ], 83 'descriptor': {shape: [24], dataType: 'float32'} 84 } 85 } 86 } 87 }, 88 { 89 'name': 'exp float32 1D tensor', 90 'graph': { 91 'inputs': { 92 'expInput': { 93 'data': [ 94 0.3421436548233032, -3.310965061187744, -3.6967575550079346, 95 -5.105378150939941, 5.47104024887085, -0.06790750473737717, 96 2.7373435497283936, -3.5470757484436035, 5.339224815368652, 97 -1.2636781930923462, -0.9162953495979309, -9.088432312011719, 98 -4.016050815582275, 4.670352935791016, 7.326992034912109, 99 8.294342994689941, -7.345414161682129, -0.9275799989700317, 100 -1.7085379362106323, -9.73737907409668, -1.9747875928878784, 101 8.203149795532227, -7.267597675323486, -3.5890684127807617 102 ], 103 'descriptor': {shape: [24], dataType: 'float32'} 104 } 105 }, 106 'operators': [{ 107 'name': 'exp', 108 'arguments': [{'input': 'expInput'}], 109 'outputs': 'expOutput' 110 }], 111 'expectedOutputs': { 112 'expOutput': { 113 'data': [ 114 1.4079625606536865, 0.03648095205426216, 0.024803820997476578, 115 0.006064045242965221, 237.70733642578125, 0.9343469142913818, 116 15.44589900970459, 0.02880876138806343, 208.35113525390625, 117 0.2826126217842102, 0.39999815821647644, 0.00011296502634650096, 118 0.018024004995822906, 106.73540496826172, 1520.8004150390625, 119 4001.173583984375, 0.0006455459515564144, 0.3955096900463104, 120 0.18113042414188385, 0.0000590350573475007, 0.1387907862663269, 121 3652.4365234375, 0.0006977862794883549, 0.02762405201792717 122 ], 123 'descriptor': {shape: [24], dataType: 'float32'} 124 } 125 } 126 } 127 }, 128 { 129 'name': 'exp float32 2D tensor', 130 'graph': { 131 'inputs': { 132 'expInput': { 133 'data': [ 134 0.3421436548233032, -3.310965061187744, -3.6967575550079346, 135 -5.105378150939941, 5.47104024887085, -0.06790750473737717, 136 2.7373435497283936, -3.5470757484436035, 5.339224815368652, 137 -1.2636781930923462, -0.9162953495979309, -9.088432312011719, 138 -4.016050815582275, 4.670352935791016, 7.326992034912109, 139 8.294342994689941, -7.345414161682129, -0.9275799989700317, 140 -1.7085379362106323, -9.73737907409668, -1.9747875928878784, 141 8.203149795532227, -7.267597675323486, -3.5890684127807617 142 ], 143 'descriptor': {shape: [4, 6], dataType: 'float32'} 144 } 145 }, 146 'operators': [{ 147 'name': 'exp', 148 'arguments': [{'input': 'expInput'}], 149 'outputs': 'expOutput' 150 }], 151 'expectedOutputs': { 152 'expOutput': { 153 'data': [ 154 1.4079625606536865, 0.03648095205426216, 0.024803820997476578, 155 0.006064045242965221, 237.70733642578125, 0.9343469142913818, 156 15.44589900970459, 0.02880876138806343, 208.35113525390625, 157 0.2826126217842102, 0.39999815821647644, 0.00011296502634650096, 158 0.018024004995822906, 106.73540496826172, 1520.8004150390625, 159 4001.173583984375, 0.0006455459515564144, 0.3955096900463104, 160 0.18113042414188385, 0.0000590350573475007, 0.1387907862663269, 161 3652.4365234375, 0.0006977862794883549, 0.02762405201792717 162 ], 163 'descriptor': {shape: [4, 6], dataType: 'float32'} 164 } 165 } 166 } 167 }, 168 { 169 'name': 'exp float32 3D tensor', 170 'graph': { 171 'inputs': { 172 'expInput': { 173 'data': [ 174 0.3421436548233032, -3.310965061187744, -3.6967575550079346, 175 -5.105378150939941, 5.47104024887085, -0.06790750473737717, 176 2.7373435497283936, -3.5470757484436035, 5.339224815368652, 177 -1.2636781930923462, -0.9162953495979309, -9.088432312011719, 178 -4.016050815582275, 4.670352935791016, 7.326992034912109, 179 8.294342994689941, -7.345414161682129, -0.9275799989700317, 180 -1.7085379362106323, -9.73737907409668, -1.9747875928878784, 181 8.203149795532227, -7.267597675323486, -3.5890684127807617 182 ], 183 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 184 } 185 }, 186 'operators': [{ 187 'name': 'exp', 188 'arguments': [{'input': 'expInput'}], 189 'outputs': 'expOutput' 190 }], 191 'expectedOutputs': { 192 'expOutput': { 193 'data': [ 194 1.4079625606536865, 0.03648095205426216, 0.024803820997476578, 195 0.006064045242965221, 237.70733642578125, 0.9343469142913818, 196 15.44589900970459, 0.02880876138806343, 208.35113525390625, 197 0.2826126217842102, 0.39999815821647644, 0.00011296502634650096, 198 0.018024004995822906, 106.73540496826172, 1520.8004150390625, 199 4001.173583984375, 0.0006455459515564144, 0.3955096900463104, 200 0.18113042414188385, 0.0000590350573475007, 0.1387907862663269, 201 3652.4365234375, 0.0006977862794883549, 0.02762405201792717 202 ], 203 'descriptor': {shape: [2, 3, 4], dataType: 'float32'} 204 } 205 } 206 } 207 }, 208 { 209 'name': 'exp float32 4D tensor', 210 'graph': { 211 'inputs': { 212 'expInput': { 213 'data': [ 214 0.3421436548233032, -3.310965061187744, -3.6967575550079346, 215 -5.105378150939941, 5.47104024887085, -0.06790750473737717, 216 2.7373435497283936, -3.5470757484436035, 5.339224815368652, 217 -1.2636781930923462, -0.9162953495979309, -9.088432312011719, 218 -4.016050815582275, 4.670352935791016, 7.326992034912109, 219 8.294342994689941, -7.345414161682129, -0.9275799989700317, 220 -1.7085379362106323, -9.73737907409668, -1.9747875928878784, 221 8.203149795532227, -7.267597675323486, -3.5890684127807617 222 ], 223 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 224 } 225 }, 226 'operators': [{ 227 'name': 'exp', 228 'arguments': [{'input': 'expInput'}], 229 'outputs': 'expOutput' 230 }], 231 'expectedOutputs': { 232 'expOutput': { 233 'data': [ 234 1.4079625606536865, 0.03648095205426216, 0.024803820997476578, 235 0.006064045242965221, 237.70733642578125, 0.9343469142913818, 236 15.44589900970459, 0.02880876138806343, 208.35113525390625, 237 0.2826126217842102, 0.39999815821647644, 0.00011296502634650096, 238 0.018024004995822906, 106.73540496826172, 1520.8004150390625, 239 4001.173583984375, 0.0006455459515564144, 0.3955096900463104, 240 0.18113042414188385, 0.0000590350573475007, 0.1387907862663269, 241 3652.4365234375, 0.0006977862794883549, 0.02762405201792717 242 ], 243 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float32'} 244 } 245 } 246 } 247 }, 248 { 249 'name': 'exp float32 5D tensor', 250 'graph': { 251 'inputs': { 252 'expInput': { 253 'data': [ 254 0.3421436548233032, -3.310965061187744, -3.6967575550079346, 255 -5.105378150939941, 5.47104024887085, -0.06790750473737717, 256 2.7373435497283936, -3.5470757484436035, 5.339224815368652, 257 -1.2636781930923462, -0.9162953495979309, -9.088432312011719, 258 -4.016050815582275, 4.670352935791016, 7.326992034912109, 259 8.294342994689941, -7.345414161682129, -0.9275799989700317, 260 -1.7085379362106323, -9.73737907409668, -1.9747875928878784, 261 8.203149795532227, -7.267597675323486, -3.5890684127807617 262 ], 263 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 264 } 265 }, 266 'operators': [{ 267 'name': 'exp', 268 'arguments': [{'input': 'expInput'}], 269 'outputs': 'expOutput' 270 }], 271 'expectedOutputs': { 272 'expOutput': { 273 'data': [ 274 1.4079625606536865, 0.03648095205426216, 0.024803820997476578, 275 0.006064045242965221, 237.70733642578125, 0.9343469142913818, 276 15.44589900970459, 0.02880876138806343, 208.35113525390625, 277 0.2826126217842102, 0.39999815821647644, 0.00011296502634650096, 278 0.018024004995822906, 106.73540496826172, 1520.8004150390625, 279 4001.173583984375, 0.0006455459515564144, 0.3955096900463104, 280 0.18113042414188385, 0.0000590350573475007, 0.1387907862663269, 281 3652.4365234375, 0.0006977862794883549, 0.02762405201792717 282 ], 283 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float32'} 284 } 285 } 286 } 287 }, 288 289 // float16 tests 290 { 291 'name': 'exp float16 0D scalar', 292 'graph': { 293 'inputs': { 294 'expInput': { 295 'data': [0.342041015625], 296 'descriptor': {shape: [], dataType: 'float16'} 297 } 298 }, 299 'operators': [{ 300 'name': 'exp', 301 'arguments': [{'input': 'expInput'}], 302 'outputs': 'expOutput' 303 }], 304 'expectedOutputs': { 305 'expOutput': { 306 'data': [1.408203125], 307 'descriptor': {shape: [], dataType: 'float16'} 308 } 309 } 310 } 311 }, 312 { 313 'name': 'exp float16 1D constant tensor', 314 'graph': { 315 'inputs': { 316 'expInput': { 317 'data': [ 318 0.342041015625, -3.310546875, -3.697265625, -5.10546875, 319 5.47265625, -0.06793212890625, 2.73828125, -3.546875, 320 5.33984375, -1.263671875, -0.91650390625, -9.0859375, 321 -4.015625, 4.671875, 7.328125, 8.296875, 322 -7.34375, -0.927734375, -1.708984375, -9.734375, 323 -1.974609375, 8.203125, -7.26953125, -3.58984375 324 ], 325 'descriptor': {shape: [24], dataType: 'float16'}, 326 'constant': true 327 } 328 }, 329 'operators': [{ 330 'name': 'exp', 331 'arguments': [{'input': 'expInput'}], 332 'outputs': 'expOutput' 333 }], 334 'expectedOutputs': { 335 'expOutput': { 336 'data': [ 337 1.408203125, 338 0.0364990234375, 339 0.0247955322265625, 340 0.00606536865234375, 341 238.125, 342 0.93408203125, 343 15.4609375, 344 0.02880859375, 345 208.5, 346 0.28271484375, 347 0.39990234375, 348 0.00011324882507324219, 349 0.018035888671875, 350 106.875, 351 1523, 352 4012, 353 0.0006465911865234375, 354 0.3955078125, 355 0.1810302734375, 356 0.00005918741226196289, 357 0.1387939453125, 358 3652, 359 0.0006966590881347656, 360 0.0276031494140625 361 ], 362 'descriptor': {shape: [24], dataType: 'float16'} 363 } 364 } 365 } 366 }, 367 { 368 'name': 'exp float16 1D tensor', 369 'graph': { 370 'inputs': { 371 'expInput': { 372 'data': [ 373 0.342041015625, -3.310546875, -3.697265625, -5.10546875, 374 5.47265625, -0.06793212890625, 2.73828125, -3.546875, 375 5.33984375, -1.263671875, -0.91650390625, -9.0859375, 376 -4.015625, 4.671875, 7.328125, 8.296875, 377 -7.34375, -0.927734375, -1.708984375, -9.734375, 378 -1.974609375, 8.203125, -7.26953125, -3.58984375 379 ], 380 'descriptor': {shape: [24], dataType: 'float16'} 381 } 382 }, 383 'operators': [{ 384 'name': 'exp', 385 'arguments': [{'input': 'expInput'}], 386 'outputs': 'expOutput' 387 }], 388 'expectedOutputs': { 389 'expOutput': { 390 'data': [ 391 1.408203125, 392 0.0364990234375, 393 0.0247955322265625, 394 0.00606536865234375, 395 238.125, 396 0.93408203125, 397 15.4609375, 398 0.02880859375, 399 208.5, 400 0.28271484375, 401 0.39990234375, 402 0.00011324882507324219, 403 0.018035888671875, 404 106.875, 405 1523, 406 4012, 407 0.0006465911865234375, 408 0.3955078125, 409 0.1810302734375, 410 0.00005918741226196289, 411 0.1387939453125, 412 3652, 413 0.0006966590881347656, 414 0.0276031494140625 415 ], 416 'descriptor': {shape: [24], dataType: 'float16'} 417 } 418 } 419 } 420 }, 421 { 422 'name': 'exp float16 2D tensor', 423 'graph': { 424 'inputs': { 425 'expInput': { 426 'data': [ 427 0.342041015625, -3.310546875, -3.697265625, -5.10546875, 428 5.47265625, -0.06793212890625, 2.73828125, -3.546875, 429 5.33984375, -1.263671875, -0.91650390625, -9.0859375, 430 -4.015625, 4.671875, 7.328125, 8.296875, 431 -7.34375, -0.927734375, -1.708984375, -9.734375, 432 -1.974609375, 8.203125, -7.26953125, -3.58984375 433 ], 434 'descriptor': {shape: [4, 6], dataType: 'float16'} 435 } 436 }, 437 'operators': [{ 438 'name': 'exp', 439 'arguments': [{'input': 'expInput'}], 440 'outputs': 'expOutput' 441 }], 442 'expectedOutputs': { 443 'expOutput': { 444 'data': [ 445 1.408203125, 446 0.0364990234375, 447 0.0247955322265625, 448 0.00606536865234375, 449 238.125, 450 0.93408203125, 451 15.4609375, 452 0.02880859375, 453 208.5, 454 0.28271484375, 455 0.39990234375, 456 0.00011324882507324219, 457 0.018035888671875, 458 106.875, 459 1523, 460 4012, 461 0.0006465911865234375, 462 0.3955078125, 463 0.1810302734375, 464 0.00005918741226196289, 465 0.1387939453125, 466 3652, 467 0.0006966590881347656, 468 0.0276031494140625 469 ], 470 'descriptor': {shape: [4, 6], dataType: 'float16'} 471 } 472 } 473 } 474 }, 475 { 476 'name': 'exp float16 3D tensor', 477 'graph': { 478 'inputs': { 479 'expInput': { 480 'data': [ 481 0.342041015625, -3.310546875, -3.697265625, -5.10546875, 482 5.47265625, -0.06793212890625, 2.73828125, -3.546875, 483 5.33984375, -1.263671875, -0.91650390625, -9.0859375, 484 -4.015625, 4.671875, 7.328125, 8.296875, 485 -7.34375, -0.927734375, -1.708984375, -9.734375, 486 -1.974609375, 8.203125, -7.26953125, -3.58984375 487 ], 488 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 489 } 490 }, 491 'operators': [{ 492 'name': 'exp', 493 'arguments': [{'input': 'expInput'}], 494 'outputs': 'expOutput' 495 }], 496 'expectedOutputs': { 497 'expOutput': { 498 'data': [ 499 1.408203125, 500 0.0364990234375, 501 0.0247955322265625, 502 0.00606536865234375, 503 238.125, 504 0.93408203125, 505 15.4609375, 506 0.02880859375, 507 208.5, 508 0.28271484375, 509 0.39990234375, 510 0.00011324882507324219, 511 0.018035888671875, 512 106.875, 513 1523, 514 4012, 515 0.0006465911865234375, 516 0.3955078125, 517 0.1810302734375, 518 0.00005918741226196289, 519 0.1387939453125, 520 3652, 521 0.0006966590881347656, 522 0.0276031494140625 523 ], 524 'descriptor': {shape: [2, 3, 4], dataType: 'float16'} 525 } 526 } 527 } 528 }, 529 { 530 'name': 'exp float16 4D tensor', 531 'graph': { 532 'inputs': { 533 'expInput': { 534 'data': [ 535 0.342041015625, -3.310546875, -3.697265625, -5.10546875, 536 5.47265625, -0.06793212890625, 2.73828125, -3.546875, 537 5.33984375, -1.263671875, -0.91650390625, -9.0859375, 538 -4.015625, 4.671875, 7.328125, 8.296875, 539 -7.34375, -0.927734375, -1.708984375, -9.734375, 540 -1.974609375, 8.203125, -7.26953125, -3.58984375 541 ], 542 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 543 } 544 }, 545 'operators': [{ 546 'name': 'exp', 547 'arguments': [{'input': 'expInput'}], 548 'outputs': 'expOutput' 549 }], 550 'expectedOutputs': { 551 'expOutput': { 552 'data': [ 553 1.408203125, 554 0.0364990234375, 555 0.0247955322265625, 556 0.00606536865234375, 557 238.125, 558 0.93408203125, 559 15.4609375, 560 0.02880859375, 561 208.5, 562 0.28271484375, 563 0.39990234375, 564 0.00011324882507324219, 565 0.018035888671875, 566 106.875, 567 1523, 568 4012, 569 0.0006465911865234375, 570 0.3955078125, 571 0.1810302734375, 572 0.00005918741226196289, 573 0.1387939453125, 574 3652, 575 0.0006966590881347656, 576 0.0276031494140625 577 ], 578 'descriptor': {shape: [2, 2, 2, 3], dataType: 'float16'} 579 } 580 } 581 } 582 }, 583 { 584 'name': 'exp float16 5D tensor', 585 'graph': { 586 'inputs': { 587 'expInput': { 588 'data': [ 589 0.342041015625, -3.310546875, -3.697265625, -5.10546875, 590 5.47265625, -0.06793212890625, 2.73828125, -3.546875, 591 5.33984375, -1.263671875, -0.91650390625, -9.0859375, 592 -4.015625, 4.671875, 7.328125, 8.296875, 593 -7.34375, -0.927734375, -1.708984375, -9.734375, 594 -1.974609375, 8.203125, -7.26953125, -3.58984375 595 ], 596 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 597 } 598 }, 599 'operators': [{ 600 'name': 'exp', 601 'arguments': [{'input': 'expInput'}], 602 'outputs': 'expOutput' 603 }], 604 'expectedOutputs': { 605 'expOutput': { 606 'data': [ 607 1.408203125, 608 0.0364990234375, 609 0.0247955322265625, 610 0.00606536865234375, 611 238.125, 612 0.93408203125, 613 15.4609375, 614 0.02880859375, 615 208.5, 616 0.28271484375, 617 0.39990234375, 618 0.00011324882507324219, 619 0.018035888671875, 620 106.875, 621 1523, 622 4012, 623 0.0006465911865234375, 624 0.3955078125, 625 0.1810302734375, 626 0.00005918741226196289, 627 0.1387939453125, 628 3652, 629 0.0006966590881347656, 630 0.0276031494140625 631 ], 632 'descriptor': {shape: [2, 1, 4, 1, 3], dataType: 'float16'} 633 } 634 } 635 } 636 } 637 ]; 638 639 webnn_conformance_test( 640 expTests, buildAndExecuteGraph, getExpPrecisionTolerance);