summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webnn/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /testing/web-platform/tests/webnn/resources
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webnn/resources')
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/arg_max.json2
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/arg_min.json2
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/matmul.json384
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/prelu.json28
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_max.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_min.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_product.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json8
-rw-r--r--testing/web-platform/tests/webnn/resources/test_data/softplus.json152
-rw-r--r--testing/web-platform/tests/webnn/resources/utils.js140
16 files changed, 206 insertions, 582 deletions
diff --git a/testing/web-platform/tests/webnn/resources/test_data/arg_max.json b/testing/web-platform/tests/webnn/resources/test_data/arg_max.json
index d2fe9e62ca..348a54dc24 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/arg_max.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/arg_max.json
@@ -460,7 +460,7 @@
}
},
"options": {
- "keepDimensions": true
+ "keepDimensions": false
},
"expected": {
"name": "output",
diff --git a/testing/web-platform/tests/webnn/resources/test_data/arg_min.json b/testing/web-platform/tests/webnn/resources/test_data/arg_min.json
index 132a2dc3e8..330afbc710 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/arg_min.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/arg_min.json
@@ -460,7 +460,7 @@
}
},
"options": {
- "keepDimensions": true
+ "keepDimensions": false
},
"expected": {
"name": "output",
diff --git a/testing/web-platform/tests/webnn/resources/test_data/matmul.json b/testing/web-platform/tests/webnn/resources/test_data/matmul.json
index f3a03e442e..cc1789ee25 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/matmul.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/matmul.json
@@ -1,332 +1,6 @@
{
"tests": [
{
- "name": "matmul float32 constant 1D and 1D tensors all positive produces a scalar",
- "inputs": {
- "a": {
- "shape": [4],
- "data": [
- 50.10142534731317,
- 22.2193058046253,
- 34.65448469299386,
- 36.35148095671881
- ],
- "type": "float32",
- "constant": true
- },
- "b": {
- "shape": [4],
- "data": [
- 27.829805134194842,
- 83.14548502311283,
- 34.4128942110155,
- 83.20379675185079
- ],
- "type": "float32",
- "constant": true
- }
- },
- "expected": {
- "name": "output",
- "data": 7458.89013671875,
- "type": "float32"
- }
- },
- {
- "name": "matmul float32 1D and 1D tensors all positive produces a scalar",
- "inputs": {
- "a": {
- "shape": [4],
- "data": [
- 50.10142534731317,
- 22.2193058046253,
- 34.65448469299386,
- 36.35148095671881
- ],
- "type": "float32"
- },
- "b": {
- "shape": [4],
- "data": [
- 27.829805134194842,
- 83.14548502311283,
- 34.4128942110155,
- 83.20379675185079
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "data": 7458.89013671875,
- "type": "float32"
- }
- },
- {
- "name": "matmul float32 1D and 1D tensors all negative produces a scalar",
- "inputs": {
- "a": {
- "shape": [4],
- "data": [
- -86.60583871803968,
- -94.74202421330796,
- -86.16720380573273,
- -76.0215630990851
- ],
- "type": "float32"
- },
- "b": {
- "shape": [4],
- "data": [
- -21.22328469397374,
- -56.66441199254357,
- -77.66753889428908,
- -56.55797454862353
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "data": 18198.58203125,
- "type": "float32"
- }
- },
- {
- "name": "matmul float32 positive 1D and negative 1D tensors produces a scalar",
- "inputs": {
- "a": {
- "shape": [4],
- "data": [
- 50.10142534731317,
- 22.2193058046253,
- 34.65448469299386,
- 36.35148095671881
- ],
- "type": "float32"
- },
- "b": {
- "shape": [4],
- "data": [
- -21.22328469397374,
- -56.66441199254357,
- -77.66753889428908,
- -56.55797454862353
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "data": -7069.85546875,
- "type": "float32"
- }
- },
- {
- "name": "matmul float32 negative 1D and positive 1D tensors produces a scalar",
- "inputs": {
- "a": {
- "shape": [4],
- "data": [
- -86.60583871803968,
- -94.74202421330796,
- -86.16720380573273,
- -76.0215630990851
- ],
- "type": "float32"
- },
- "b": {
- "shape": [4],
- "data": [
- 27.829805134194842,
- 83.14548502311283,
- 34.4128942110155,
- 83.20379675185079
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "data": -19578.140625,
- "type": "float32"
- }
- },
- {
- "name": "matmul float32 1D and 2D tensors",
- "inputs": {
- "a": {
- "shape": [4],
- "data": [
- 50.10142534731317,
- 22.2193058046253,
- 34.65448469299386,
- 36.35148095671881
- ],
- "type": "float32"
- },
- "b": {
- "shape": [4, 5],
- "data": [
- 88.17004408170853,
- 78.40126706348094,
- 14.819002753540623,
- 3.692303791736573,
- 45.9064286713635,
- 43.08391896733015,
- 47.19946845924572,
- 60.925216107016425,
- 8.162760351602216,
- 20.33326305093228,
- 20.438397895943282,
- 27.01940859922867,
- 15.601424432184263,
- 87.46969388883927,
- 65.79554455585657,
- 69.31696864490797,
- 31.984439910782992,
- 12.291812891860388,
- 13.304834654547172,
- 85.26705387930089
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "shape": [1, 5],
- "data": [
- 8602.796875,
- 7075.7802734375,
- 3083.654052734375,
- 3881.228271484375,
- 8131.462890625
- ],
- "type": "float32"
- }
- },
- {
- "name": "matmul float32 1D and 4D tensors",
- "inputs": {
- "a": {
- "shape": [4],
- "data": [
- 50.10142534731317,
- 22.2193058046253,
- 34.65448469299386,
- 36.35148095671881
- ],
- "type": "float32"
- },
- "b": {
- "shape": [2, 2, 4, 2],
- "data": [
- 71.54684436671175,
- 78.61926127874348,
- 2.246814764541316,
- 12.044773359659434,
- 1.8342867333124069,
- 82.09732511549477,
- 43.884761946067094,
- 5.616231825100204,
- 34.67424097413332,
- 49.152710076333506,
- 75.34904358690912,
- 84.74523302920429,
- 36.56497325521975,
- 22.89479672718755,
- 15.02636975800511,
- 66.49530785246675,
- 65.81345056776044,
- 26.749681209347376,
- 19.415639234175774,
- 98.60692665127114,
- 65.39448996549784,
- 56.47023672202065,
- 80.64523905250766,
- 82.20401464839868,
- 70.84606482516416,
- 50.27994995977012,
- 67.39406108056262,
- 75.35806805146241,
- 2.7487208784167327,
- 68.0645872775828,
- 70.73791158057968,
- 46.26436742398676
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "shape": [2, 2, 1, 2],
- "data": [
- 5293.36376953125,
- 7255.7626953125,
- 5224.80322265625,
- 7556.21142578125,
- 8926.5361328125,
- 8476.359375,
- 7713.62158203125,
- 8234.0224609375
- ],
- "type": "float32"
- }
- },
- {
- "name": "matmul float32 2D and 1D tensors",
- "inputs": {
- "a": {
- "shape": [5, 4],
- "data": [
- 88.17004408170853,
- 43.08391896733015,
- 20.438397895943282,
- 69.31696864490797,
- 78.40126706348094,
- 47.19946845924572,
- 27.01940859922867,
- 31.984439910782992,
- 14.819002753540623,
- 60.925216107016425,
- 15.601424432184263,
- 12.291812891860388,
- 3.692303791736573,
- 8.162760351602216,
- 87.46969388883927,
- 13.304834654547172,
- 45.9064286713635,
- 20.33326305093228,
- 65.79554455585657,
- 85.26705387930089
- ],
- "type": "float32"
- },
- "b": {
- "shape": [4],
- "data": [
- 50.10142534731317,
- 22.2193058046253,
- 34.65448469299386,
- 36.35148095671881
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "shape": [5, 1],
- "data": [
- 8602.796875,
- 7075.7802734375,
- 3083.654052734375,
- 3881.228271484375,
- 8131.462890625
- ],
- "type": "float32"
- }
- },
- {
"name": "matmul float32 2D and 2D tensors",
"inputs": {
"a": {
@@ -750,64 +424,6 @@
}
},
{
- "name": "matmul float32 3D and 1D tensors",
- "inputs": {
- "a": {
- "shape": [2, 3, 4],
- "data": [
- 56.46701250066562,
- 99.86045478237251,
- 71.05493372292567,
- 32.45438455331333,
- 17.310747999630017,
- 2.586275053048559,
- 92.31499166302054,
- 96.9758519231732,
- 26.4721315276526,
- 77.67031776320978,
- 29.278788710989147,
- 82.12142428847062,
- 89.89308471484885,
- 82.49795321217854,
- 64.36866008901963,
- 23.75928513568486,
- 6.67026681065197,
- 81.55583129445503,
- 16.142963270263433,
- 57.45134849716054,
- 26.82641739603182,
- 85.0296980735713,
- 36.198863464757956,
- 89.60960360138286
- ],
- "type": "float32"
- },
- "b": {
- "shape": [4],
- "data": [
- 27.829805134194842,
- 83.14548502311283,
- 34.4128942110155,
- 83.20379675185079
- ],
- "type": "float32"
- }
- },
- "expected": {
- "name": "output",
- "shape": [2, 3, 1],
- "data": [
- 15019.9462890625,
- 11942.376953125,
- 15035.0322265625,
- 13553.013671875,
- 12302.328125,
- 16517.9765625
- ],
- "type": "float32"
- }
- },
- {
"name": "matmul float32 4D and 4D (broadcast) tensors",
"inputs": {
"a": {
diff --git a/testing/web-platform/tests/webnn/resources/test_data/prelu.json b/testing/web-platform/tests/webnn/resources/test_data/prelu.json
index cf79bee7a9..14a7c412dd 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/prelu.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/prelu.json
@@ -1,6 +1,34 @@
{
"tests": [
{
+ "name": "prelu float32 0D scalar",
+ "inputs": {
+ "x": {
+ "shape": [],
+ "data": [
+ -4.794857500523286
+ ],
+ "type": "float32"
+ },
+ "slope": {
+ "shape": [],
+ "data": [
+ 1.1202747481570352
+ ],
+ "type": "float32",
+ "constant": true
+ }
+ },
+ "expected": {
+ "name": "output",
+ "shape": [],
+ "data": [
+ -5.371557712554932
+ ],
+ "type": "float32"
+ }
+ },
+ {
"name": "prelu float32 1D constant tensors",
"inputs": {
"x": {
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json
index 7cbc442511..c3f2b618e9 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_l1.json
@@ -676,7 +676,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -725,11 +726,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
108.43173217773438,
315.6007995605469,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json
index 7e59a45d5e..d83eea9dfb 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_l2.json
@@ -676,7 +676,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -725,11 +726,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
138.580078125,
166.67791748046875,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json
index 250398d227..061e12ad51 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum.json
@@ -596,7 +596,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -645,11 +646,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
5.7273993492126465,
5.64375114440918,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json
index b7f39abd52..3577d6aa9e 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_log_sum_exp.json
@@ -676,7 +676,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -725,11 +726,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
8.563796997070312,
5.500619411468506,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json
index 967aea8bf4..11ed0ed919 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_max.json
@@ -556,7 +556,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -605,11 +606,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
90.42288208007812,
94.99645233154297,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json
index 5a48952c06..8c26d0a562 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_mean.json
@@ -670,7 +670,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"shape": [2, 2],
@@ -718,10 +719,11 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
52.287559509277344,
45.10261917114258,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json
index 92de75e92a..6c26df5db1 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_min.json
@@ -556,7 +556,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -605,11 +606,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
-87.9623031616211,
-53.747413635253906,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json
index 691bf4da9b..d58af30ec1 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_product.json
@@ -556,7 +556,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -605,11 +606,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
-3638925568,
6523364352,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json
index df47a1a2b2..7027d38b67 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum.json
@@ -670,7 +670,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"shape": [2, 2],
@@ -718,10 +719,11 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
355.21942138671875,
185.98255920410156,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json
index 8ac373e4b3..bd2ebb341a 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/reduce_sum_square.json
@@ -676,7 +676,8 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": false
},
"expected": {
"name": "output",
@@ -725,11 +726,12 @@
}
},
"options": {
- "axes": [1, 3]
+ "axes": [1, 3],
+ "keepDimensions": true
},
"expected": {
"name": "output",
- "shape": [1, 2, 2, 1],
+ "shape": [2, 1, 2, 1],
"data": [
12302.474609375,
22772.77734375,
diff --git a/testing/web-platform/tests/webnn/resources/test_data/softplus.json b/testing/web-platform/tests/webnn/resources/test_data/softplus.json
index eb05b7b281..373612d5ca 100644
--- a/testing/web-platform/tests/webnn/resources/test_data/softplus.json
+++ b/testing/web-platform/tests/webnn/resources/test_data/softplus.json
@@ -1,7 +1,7 @@
-{ // softplus: The calculation follows the expression ln(1 + exp(steepness * x)) / steepness.
+{ // softplus: The calculation follows the expression ln(1 + exp(x)).
"tests": [
{
- "name": "softplus float32 1D constant tensor default options", // default options: {steepness: 1}
+ "name": "softplus float32 1D constant tensor",
"inputs": {
"x": {
"shape": [24],
@@ -68,7 +68,7 @@
}
},
{
- "name": "softplus float32 1D tensor default options", // default options: {steepness: 1}
+ "name": "softplus float32 1D tensor",
"inputs": {
"x": {
"shape": [24],
@@ -134,7 +134,7 @@
}
},
{
- "name": "softplus float32 2D tensor default options",
+ "name": "softplus float32 2D tensor",
"inputs": {
"x": {
"shape": [4, 6],
@@ -200,7 +200,7 @@
}
},
{
- "name": "softplus float32 3D tensor default options",
+ "name": "softplus float32 3D tensor",
"inputs": {
"x": {
"shape": [2, 3, 4],
@@ -266,7 +266,7 @@
}
},
{
- "name": "softplus float32 4D tensor default options",
+ "name": "softplus float32 4D tensor",
"inputs": {
"x": {
"shape": [1, 2, 3, 4],
@@ -332,7 +332,7 @@
}
},
{
- "name": "softplus float32 5D tensor default options",
+ "name": "softplus float32 5D tensor",
"inputs": {
"x": {
"shape": [1, 2, 1, 3, 4],
@@ -396,144 +396,6 @@
],
"type": "float32"
}
- },
- {
- "name": "softplus both positive float32 4D tensor and options.steepness",
- "inputs": {
- "x": {
- "shape": [1, 2, 3, 4],
- "data": [
- 5.626614582460632,
- 5.167487045486892,
- 4.0146356193402655,
- 9.48003299650489,
- 9.989938045769978,
- 7.0654412821434125,
- 2.132681001794825,
- 8.187151346059956,
- 5.169976220175496,
- 2.1044997879382077,
- 3.523329401138895,
- 4.136340646976668,
- 1.7418719794295656,
- 5.145224066290767,
- 5.015515309165462,
- 0.045903935074711466,
- 2.9570898924917377,
- 3.959244712098706,
- 5.517926978255181,
- 7.192322388417094,
- 8.76492480390928,
- 1.3734704039113388,
- 8.930669016709397,
- 8.660283210871246
- ],
- "type": "float32"
- }
- },
- "options": {
- "steepness": 1.5104469060897827
- },
- "expected": {
- "name": "output",
- "shape": [1, 2, 3, 4],
- "data": [
- 5.626749515533447,
- 5.167757034301758,
- 4.016173362731934,
- 9.480032920837402,
- 9.989937782287598,
- 7.065456390380859,
- 2.158585548400879,
- 8.187153816223145,
- 5.170245170593262,
- 2.1315081119537354,
- 3.526555061340332,
- 4.137620449066162,
- 1.7879058122634888,
- 5.145503044128418,
- 5.015854835510254,
- 0.4822517931461334,
- 2.964651584625244,
- 3.960916519165039,
- 5.518085956573486,
- 7.19233512878418,
- 8.764925956726074,
- 1.4518096446990967,
- 8.930669784545898,
- 8.660284042358398
- ],
- "type": "float32"
- }
- },
- {
- "name": "softplus both negative float32 4D tensor and options.steepness",
- "inputs": {
- "x": {
- "shape": [1, 2, 3, 4],
- "data": [
- -5.584833476104802,
- -8.188738740810354,
- -8.981280004134987,
- -1.7315531899284586,
- -0.7266543578958906,
- -0.0034800119290885334,
- -7.378389455552106,
- -8.907525953796949,
- -6.0483786568116304,
- -6.328561142365743,
- -2.6006513567654626,
- -5.02005264196455,
- -2.0647716093484414,
- -1.5499896740695434,
- -2.221591675966657,
- -1.1088025713211636,
- -2.7854626064634385,
- -2.105037489961294,
- -5.144277741727352,
- -5.081219916574497,
- -7.499426297617635,
- -2.4305558382286545,
- -8.390520024268328,
- -0.07117499202643174
- ],
- "type": "float32"
- }
- },
- "options": {
- "steepness": -1.2985155767552126
- },
- "expected": {
- "name": "output",
- "shape": [1, 2, 3, 4],
- "data": [
- -5.585379123687744,
- -8.188756942749023,
- -8.981287002563477,
- -1.8088372945785522,
- -0.9798305630683899,
- -0.5355416536331177,
- -7.378442287445068,
- -8.907533645629883,
- -6.048677444458008,
- -6.328769207000732,
- -2.626511573791504,
- -5.021188259124756,
- -2.1157851219177246,
- -1.6465802192687988,
- -2.2634570598602295,
- -1.2725814580917358,
- -2.805877923965454,
- -2.1535322666168213,
- -5.145244121551514,
- -5.082269191741943,
- -7.499471664428711,
- -2.4626762866973877,
- -8.390534400939941,
- -0.5702091455459595
- ],
- "type": "float32"
- }
}
]
} \ No newline at end of file
diff --git a/testing/web-platform/tests/webnn/resources/utils.js b/testing/web-platform/tests/webnn/resources/utils.js
index d1dc0675a7..e5b80ae9f7 100644
--- a/testing/web-platform/tests/webnn/resources/utils.js
+++ b/testing/web-platform/tests/webnn/resources/utils.js
@@ -13,6 +13,15 @@ const TypedArrayDict = {
int64: BigInt64Array,
};
+const kContextOptionsForVariant = {
+ cpu: {
+ deviceType: 'cpu',
+ },
+ gpu: {
+ deviceType: 'gpu',
+ }
+};
+
// The maximum index to validate for the output's expected value.
const kMaximumIndexToValidate = 1000;
@@ -867,17 +876,15 @@ const run = async (operationName, context, builder, resources, buildFunc) => {
checkResults(operationName, namedOutputOperands, result.outputs, resources);
};
+const variant = location.search.substring(1);
+const contextOptions = kContextOptionsForVariant[variant];
+
/**
* Run WebNN operation tests.
* @param {(String[]|String)} operationName - An operation name array or an operation name
* @param {Function} buildFunc - A build function for an operation
- * @param {String} deviceType - The execution device type for this test
*/
-const testWebNNOperation = (operationName, buildFunc, deviceType = 'cpu') => {
- test(() => assert_not_equals(navigator.ml, undefined, "ml property is defined on navigator"));
- if (navigator.ml === undefined) {
- return;
- }
+const testWebNNOperation = (operationName, buildFunc) => {
let operationNameArray;
if (typeof operationName === 'string') {
operationNameArray = [operationName];
@@ -890,7 +897,14 @@ const testWebNNOperation = (operationName, buildFunc, deviceType = 'cpu') => {
operationNameArray.forEach((subOperationName) => {
const tests = loadTests(subOperationName);
promise_setup(async () => {
- context = await navigator.ml.createContext({deviceType});
+ let supported = false;
+ try {
+ context = await navigator.ml.createContext(contextOptions);
+ supported = true;
+ } catch (e) {
+ }
+ assert_implements(
+ supported, `Unable to create context for ${variant} variant`);
builder = new MLGraphBuilder(context);
});
for (const subTest of tests) {
@@ -901,6 +915,65 @@ const testWebNNOperation = (operationName, buildFunc, deviceType = 'cpu') => {
});
};
+/**
+ * WebNN parallel compute operation test.
+ */
+const testParallelCompute = () => {
+ let ml_context;
+ let ml_graph;
+
+ promise_setup(async () => {
+ let supported = false;
+ try {
+ ml_context = await navigator.ml.createContext(contextOptions);
+ supported = true;
+ } catch (e) {
+ }
+ assert_implements(
+ supported, `Unable to create context for ${variant} variant`);
+ // Construct a simple graph: A = B * 2.
+ const builder = new MLGraphBuilder(ml_context);
+ const operandType = {dataType: 'float32', dimensions: [1]};
+ const input_operand = builder.input('input', operandType);
+ const const_operand = builder.constant(operandType, Float32Array.from([2]));
+ const output_operand = builder.mul(input_operand, const_operand);
+ ml_graph = await builder.build({'output': output_operand});
+ });
+
+ promise_test(async () => {
+ const test_inputs = [1, 2, 3, 4];
+
+ const actual_outputs = await Promise.all(test_inputs.map(async (input) => {
+ let inputs = {'input': Float32Array.from([input])};
+ let outputs = {'output': new Float32Array(1)};
+ ({inputs, outputs} = await ml_context.compute(ml_graph, inputs, outputs));
+ return outputs.output[0];
+ }));
+
+ const expected_outputs = [2, 4, 6, 8];
+ assert_array_equals(actual_outputs, expected_outputs);
+ });
+};
+
+/**
+ * Run WebNN conformance tests by specified operation.
+ * @param {(String[]|String)} operationName - An operation name array or an
+ * operation name
+ * @param {Function} buildFunc - A build function for an operation
+ */
+const runWebNNConformanceTests = (operationName, buildFunc) => {
+ // Link to https://github.com/web-platform-tests/wpt/pull/44883
+ // Check navigator.ml is defined before trying to run WebNN tests
+ if (navigator.ml) {
+ testWebNNOperation(operationName, buildFunc);
+ } else {
+ // Show indication to users why the test failed
+ test(
+ () => assert_not_equals(
+ navigator.ml, undefined, 'ml property is defined on navigator'));
+ }
+};
+
// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript
const toHalf = (value) => {
let floatView = new Float32Array(1);
@@ -970,13 +1043,19 @@ const createBuffer = (context, bufferSize) => {
/**
* WebNN destroy buffer twice test.
* @param {String} testName - The name of the test operation.
- * @param {String} deviceType - The execution device type for this test.
*/
-const testDestroyWebNNBuffer = (testName, deviceType = 'cpu') => {
+const testDestroyWebNNBuffer = (testName) => {
let context;
let buffer;
promise_setup(async () => {
- context = await navigator.ml.createContext({deviceType});
+ let supported = false;
+ try {
+ context = await navigator.ml.createContext(contextOptions);
+ supported = true;
+ } catch (e) {
+ }
+ assert_implements(
+ supported, `Unable to create context for ${variant} variant`);
buffer = createBuffer(context, 4);
});
promise_test(async () => {
@@ -993,12 +1072,19 @@ const testDestroyWebNNBuffer = (testName, deviceType = 'cpu') => {
* WebNN create buffer test.
* @param {String} testName - The name of the test operation.
* @param {Number} bufferSize - Size of the buffer to create, in bytes.
- * @param {String} deviceType - The execution device type for this test.
*/
-const testCreateWebNNBuffer = (testName, bufferSize, deviceType = 'cpu') => {
+const testCreateWebNNBuffer = (testName, bufferSize) => {
let context;
+
promise_setup(async () => {
- context = await navigator.ml.createContext({deviceType});
+ let supported = false;
+ try {
+ context = await navigator.ml.createContext(contextOptions);
+ supported = true;
+ } catch (e) {
+ }
+ assert_implements(
+ supported, `Unable to create context for ${variant} variant`);
});
promise_test(async () => {
createBuffer(context, bufferSize);
@@ -1021,12 +1107,18 @@ const assert_buffer_data_equals = async (ml_context, ml_buffer, expected) => {
/**
* WebNN write buffer operation test.
* @param {String} testName - The name of the test operation.
- * @param {String} deviceType - The execution device type for this test.
*/
-const testWriteWebNNBuffer = (testName, deviceType = 'cpu') => {
+const testWriteWebNNBuffer = (testName) => {
let ml_context;
promise_setup(async () => {
- ml_context = await navigator.ml.createContext({deviceType});
+ let supported = false;
+ try {
+ ml_context = await navigator.ml.createContext(contextOptions);
+ supported = true;
+ } catch (e) {
+ }
+ assert_implements(
+ supported, `Unable to create context for ${variant} variant`);
});
promise_test(async () => {
@@ -1117,7 +1209,7 @@ const testWriteWebNNBuffer = (testName, deviceType = 'cpu') => {
return;
}
- let another_ml_context = await navigator.ml.createContext({deviceType});
+ let another_ml_context = await navigator.ml.createContext(contextOptions);
let another_ml_buffer = createBuffer(another_ml_context, ml_buffer.size);
let input_data = new Uint8Array(ml_buffer.size).fill(0xAA);
@@ -1131,12 +1223,18 @@ const testWriteWebNNBuffer = (testName, deviceType = 'cpu') => {
/**
* WebNN read buffer operation test.
* @param {String} testName - The name of the test operation.
- * @param {String} deviceType - The execution device type for this test.
*/
-const testReadWebNNBuffer = (testName, deviceType = 'cpu') => {
+const testReadWebNNBuffer = (testName) => {
let ml_context;
promise_setup(async () => {
- ml_context = await navigator.ml.createContext({deviceType});
+ let supported = false;
+ try {
+ ml_context = await navigator.ml.createContext(contextOptions);
+ supported = true;
+ } catch (e) {
+ }
+ assert_implements(
+ supported, `Unable to create context for ${variant} variant`);
});
promise_test(async t => {
@@ -1277,7 +1375,7 @@ const testReadWebNNBuffer = (testName, deviceType = 'cpu') => {
return;
}
- let another_ml_context = await navigator.ml.createContext({deviceType});
+ let another_ml_context = await navigator.ml.createContext(contextOptions);
let another_ml_buffer = createBuffer(another_ml_context, ml_buffer.size);
await promise_rejects_js(