From 720c1e65b69994fd94dbccc0db73593ab22efbe6 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 13 Dec 2024 02:58:58 +0000 Subject: [PATCH] Bug 1934638 [wpt PR 49470] - WebNN: Support `AllowSharedBufferSource` for constant, a=testonly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic update from web-platform-tests WebNN: Support `AllowSharedBufferSource` for constant This CL implements the WebNN spec change proposal [1] that uses `AllowSharedBufferSource` for `MLGraphBuilder.constant()`. [1]: https://github.com/webmachinelearning/webnn/pull/790 Bug: 380896836 Change-Id: Ib8fc58daaabf7493b08f9634daa1eeb08a50ad35 Cq-Include-Trybots: luci.chromium.try​:win11-blink-rel, mac14.arm64-blink-rel, mac15.arm64-blink-rel, linux-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6050722 Reviewed-by: Austin Sullivan Reviewed-by: Weizhong Xia Commit-Queue: ningxin hu Cr-Commit-Position: refs/heads/main{#1390750} -- wpt-commits: 2643d924a518d89e3a8239ef92705bf1373504c9 wpt-pr: 49470 UltraBlame original commit: 25acfa3eb6954786eb5663d66876762a2a82eec9 --- .../shared_arraybuffer_constant.https.any.js | 516 ++++++++++++++++++ ..._arraybuffer_constant.https.any.js.headers | 22 + .../validation_tests/constant.https.any.js | 352 ++++++++++-- .../constant.https.any.js.headers | 22 + 4 files changed, 875 insertions(+), 37 deletions(-) create mode 100644 testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js create mode 100644 testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js.headers create mode 100644 testing/web-platform/tests/webnn/validation_tests/constant.https.any.js.headers diff --git a/testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js new file mode 100644 index 0000000000000..3519ce7b4dbd0 --- /dev/null +++ b/testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js @@ -0,0 +1,516 @@ +/ +/ +META +: +title += +test +WebNN +API +constant +with +shared +array +buffer +/ +/ +META +: +global += +window +dedicatedworker +/ +/ +META +: +variant += +? +cpu +/ +/ +META +: +variant += +? +gpu +/ +/ +META +: +variant += +? +npu +/ +/ +META +: +script += +. +. +/ +resources +/ +utils_validation +. +js +/ +/ +META +: +script += +. +. +/ +resources +/ +utils +. +js +/ +/ +META +: +timeout += +long +' +use +strict +' +; +/ +/ +Skip +tests +if +WebNN +is +unimplemented +. +promise_setup +( +async +( +) += +> +{ +assert_implements +( +navigator +. +ml +' +missing +navigator +. +ml +' +) +; +} +) +; +/ +/ +https +: +/ +/ +www +. +w3 +. +org +/ +TR +/ +webnn +/ +# +api +- +mlgraphbuilder +- +constant +- +buffer +const +testContents += +Int32Array +. +from +( +[ +0 +1 +2 +3 +4 +5 +6 +7 +] +) +; +const +sharedArrayBuffer += +new +SharedArrayBuffer +( +testContents +. +byteLength +) +; +const +typedArray += +new +Int32Array +( +sharedArrayBuffer +) +; +typedArray +. +set +( +testContents +) +; +let +mlContext +; +let +mlGraph +; +let +outputTensor +; +promise_setup +( +async +( +) += +> +{ +try +{ +mlContext += +await +navigator +. +ml +. +createContext +( +contextOptions +) +; +} +catch +( +e +) +{ +throw +new +AssertionError +( +Unable +to +create +mlContext +for +{ +variant +} +variant +. +{ +e +} +) +; +} +try +{ +outputTensor += +await +mlContext +. +createTensor +( +{ +dataType +: +' +int32 +' +shape +: +[ +8 +] +readable +: +true +} +) +; +} +catch +( +e +) +{ +throw +new +AssertionError +( +Unable +to +create +tensor +for +{ +variant +} +variant +. +{ +e +} +) +; +} +} +) +; +promise_test +( +async +( +) += +> +{ +const +builder += +new +MLGraphBuilder +( +mlContext +) +; +const +constant += +builder +. +constant +( +{ +dataType +: +' +int32 +' +shape +: +[ +8 +] +} +sharedArrayBuffer +) +; +const +output += +builder +. +identity +( +constant +) +; +const +mlGraph += +await +builder +. +build +( +{ +output +} +) +; +mlContext +. +dispatch +( +mlGraph +{ +} +{ +output +: +outputTensor +} +) +; +const +results += +new +Int32Array +( +await +mlContext +. +readTensor +( +outputTensor +) +) +; +assert_array_equals +( +results +testContents +) +; +} +constant +( +) +with +a +SharedArrayBuffer +) +; +promise_test +( +async +( +) += +> +{ +const +builder += +new +MLGraphBuilder +( +mlContext +) +; +const +constant += +builder +. +constant +( +{ +dataType +: +' +int32 +' +shape +: +[ +8 +] +} +typedArray +) +; +const +output += +builder +. +identity +( +constant +) +; +const +mlGraph += +await +builder +. +build +( +{ +output +} +) +; +mlContext +. +dispatch +( +mlGraph +{ +} +{ +output +: +outputTensor +} +) +; +const +results += +new +Int32Array +( +await +mlContext +. +readTensor +( +outputTensor +) +) +; +assert_array_equals +( +results +testContents +) +; +} +constant +( +) +with +a +typeArray +from +a +SharedArrayBuffer +) +; diff --git a/testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js.headers b/testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js.headers new file mode 100644 index 0000000000000..f649d4e944afb --- /dev/null +++ b/testing/web-platform/tests/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js.headers @@ -0,0 +1,22 @@ +Cross +- +Origin +- +Embedder +- +Policy +: +require +- +corp +Cross +- +Origin +- +Opener +- +Policy +: +same +- +origin diff --git a/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js b/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js index 7a427a64e2faf..4b4ffe1a9fdb8 100644 --- a/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js @@ -73,7 +73,7 @@ for constant ( descriptor -bufferView +buffer ) { name @@ -107,7 +107,7 @@ shape [ ] } -bufferView +buffer : { type @@ -164,7 +164,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -204,9 +204,8 @@ if byte length of -bufferView -for float32 +buffer doesn \ ' @@ -231,7 +230,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -247,7 +246,7 @@ byteLength / / The -bufferView +buffer ' s byte @@ -314,7 +313,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -354,9 +353,8 @@ if byte length of -bufferView -for int32 +buffer doesn \ ' @@ -381,7 +379,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -397,7 +395,7 @@ byteLength / / The -bufferView +buffer ' s byte @@ -445,7 +443,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -485,9 +483,8 @@ if byte length of -bufferView -for uint32 +buffer doesn \ ' @@ -512,7 +509,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -558,7 +555,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -598,9 +595,8 @@ if byte length of -bufferView -for int64 +buffer doesn \ ' @@ -625,7 +621,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -671,7 +667,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -711,9 +707,8 @@ if byte length of -bufferView -for uint64 +buffer doesn \ ' @@ -738,7 +733,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -784,7 +779,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -824,9 +819,8 @@ if byte length of -bufferView -for int8 +buffer doesn \ ' @@ -851,7 +845,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -897,7 +891,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -937,9 +931,8 @@ if byte length of -bufferView -for uint8 +buffer doesn \ ' @@ -964,7 +957,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -1008,7 +1001,7 @@ shape 0 ] } -bufferView +buffer : { type @@ -1030,7 +1023,11 @@ constant ] Throw if -bufferView +buffer +view +\ +' +s type doesn \ @@ -1057,7 +1054,7 @@ shape 3 ] } -bufferView +buffer : { type @@ -1069,6 +1066,9 @@ byteLength * 4 } +viewTestOnly +: +true } ] ; @@ -1103,7 +1103,7 @@ ArrayBuffer ( test . -bufferView +buffer . byteLength ) @@ -1114,13 +1114,216 @@ bufferView new test . -bufferView +buffer . type ( buffer ) ; +const +sharedBuffer += +new +SharedArrayBuffer +( +test +. +buffer +. +byteLength +) +; +const +sharedBufferView += +new +test +. +buffer +. +type +( +sharedBuffer +) +; +if +( +test +. +viewTestOnly += += += +undefined +| +| +test +. +viewTestOnly += += += +false +) +{ +/ +/ +Test +building +constant +from +ArrayBuffer +. +if +( +test +. +output +) +{ +const +constantOperand += +builder +. +constant +( +test +. +descriptor +buffer +) +; +assert_equals +( +constantOperand +. +dataType +test +. +output +. +dataType +) +; +assert_array_equals +( +constantOperand +. +shape +test +. +output +. +shape +) +; +} +else +{ +assert_throws_js +( +TypeError +( +) += +> +builder +. +constant +( +test +. +descriptor +buffer +) +) +; +} +/ +/ +Test +building +constant +from +SharedArrayBuffer +. +if +( +test +. +output +) +{ +const +constantOperand += +builder +. +constant +( +test +. +descriptor +sharedBuffer +) +; +assert_equals +( +constantOperand +. +dataType +test +. +output +. +dataType +) +; +assert_array_equals +( +constantOperand +. +shape +test +. +output +. +shape +) +; +} +else +{ +assert_throws_js +( +TypeError +( +) += +> +builder +. +constant +( +test +. +descriptor +sharedBuffer +) +) +; +} +} +/ +/ +Test +building +constant +from +ArrayBufferView +. if ( test @@ -1187,6 +1390,81 @@ bufferView ) ; } +/ +/ +Test +building +constant +from +shared +ArrayBufferView +. +if +( +test +. +output +) +{ +const +constantOperand += +builder +. +constant +( +test +. +descriptor +sharedBufferView +) +; +assert_equals +( +constantOperand +. +dataType +test +. +output +. +dataType +) +; +assert_array_equals +( +constantOperand +. +shape +test +. +output +. +shape +) +; +} +else +{ +assert_throws_js +( +TypeError +( +) += +> +builder +. +constant +( +test +. +descriptor +sharedBufferView +) +) +; +} } test . diff --git a/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js.headers b/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js.headers new file mode 100644 index 0000000000000..f649d4e944afb --- /dev/null +++ b/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js.headers @@ -0,0 +1,22 @@ +Cross +- +Origin +- +Embedder +- +Policy +: +require +- +corp +Cross +- +Origin +- +Opener +- +Policy +: +same +- +origin