forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebNN: Support
AllowSharedBufferSource
for constant
This CL implements the WebNN spec change proposal [1] that uses `AllowSharedBufferSource` for `MLGraphBuilder.constant()`. [1]: webmachinelearning/webnn#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 <asully@chromium.org> Reviewed-by: Weizhong Xia <weizhong@google.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Cr-Commit-Position: refs/heads/main@{#1390750}
- Loading branch information
1 parent
6a83407
commit 2643d92
Showing
4 changed files
with
143 additions
and
30 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
webnn/conformance_tests/shared_arraybuffer_constant.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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`); |
2 changes: 2 additions & 0 deletions
2
webnn/conformance_tests/shared_arraybuffer_constant.https.any.js.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Cross-Origin-Opener-Policy: same-origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Cross-Origin-Opener-Policy: same-origin |