-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webnn: Allow an MLGraphBuilder to build at most one MLGraph
See webmachinelearning/webnn#717 Bug: 354724062 Change-Id: I8ac2bf94b1f5a0db93a042babdc2556eab35034a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5684454 Reviewed-by: Reilly Grant <reillyg@chromium.org> Commit-Queue: Austin Sullivan <asully@chromium.org> Cr-Commit-Position: refs/heads/main@{#1332702}
- Loading branch information
1 parent
2f1700a
commit b7777fa
Showing
42 changed files
with
269 additions
and
104 deletions.
There are no files selected for viewing
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
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
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,85 @@ | ||
// META: title=ensure MLMLGraphBuilder may build at most one MLGraph | ||
// META: global=window,dedicatedworker | ||
// META: script=../resources/utils_validation.js | ||
|
||
const kExampleInputDescriptor = { | ||
dataType: 'float32', | ||
dimensions: [2] | ||
}; | ||
|
||
promise_test(async t => { | ||
const builder = new MLGraphBuilder(context); | ||
const a = builder.input('a', kExampleInputDescriptor); | ||
const b = builder.input('b', kExampleInputDescriptor); | ||
const c = builder.add(a, b); | ||
const graph = await builder.build({c}); | ||
|
||
await promise_rejects_dom(t, 'InvalidStateError', builder.build({c})); | ||
}, 'Throw if attempting to build a second graph with an MLGraphBuilder'); | ||
|
||
promise_test(async t => { | ||
const builder = new MLGraphBuilder(context); | ||
const a = builder.input('a', kExampleInputDescriptor); | ||
const b = builder.input('b', kExampleInputDescriptor); | ||
const c = builder.add(a, b); | ||
const graph = await builder.build({c}); | ||
|
||
assert_throws_dom('InvalidStateError', () => builder.sub(a, b)); | ||
}, 'Throw if an operand-yielding method is called on a built MLGraphBuilder'); | ||
|
||
promise_test(async t => { | ||
const builder = new MLGraphBuilder(context); | ||
const a = builder.input('a', kExampleInputDescriptor); | ||
const b = builder.input('b', kExampleInputDescriptor); | ||
const c = builder.add(a, b); | ||
const graph = await builder.build({c}); | ||
|
||
assert_throws_dom( | ||
'InvalidStateError', () => builder.input('d', kExampleInputDescriptor)); | ||
}, 'Throw if adding an input operand to a built MLGraphBuilder'); | ||
|
||
promise_test(async t => { | ||
const builder = new MLGraphBuilder(context); | ||
const a = builder.input('a', kExampleInputDescriptor); | ||
const b = builder.input('b', kExampleInputDescriptor); | ||
const c = builder.add(a, b); | ||
const graph = await builder.build({c}); | ||
|
||
const buffer = new ArrayBuffer(8); | ||
const bufferView = new Float32Array(buffer); | ||
|
||
assert_throws_dom( | ||
'InvalidStateError', | ||
() => builder.constant(kExampleInputDescriptor, bufferView)); | ||
}, 'Throw if adding a constant operand to a built MLGraphBuilder'); | ||
|
||
promise_test(async t => { | ||
const builder = new MLGraphBuilder(context); | ||
const a = builder.input('a', kExampleInputDescriptor); | ||
const b = builder.input('b', kExampleInputDescriptor); | ||
const c = builder.add(a, b); | ||
|
||
// Call build() with invalid parameters. | ||
await promise_rejects_js(t, TypeError, builder.build({a})); | ||
|
||
// Passing valid parameters successfully creates the graph... | ||
const graph = await builder.build({c}); | ||
|
||
// ...exactly once! | ||
await promise_rejects_dom(t, 'InvalidStateError', builder.build({c})); | ||
}, 'An MLGraphBuilder remains unbuilt if build() is called with invalid paramaters'); | ||
|
||
promise_test(async t => { | ||
const builder1 = new MLGraphBuilder(context); | ||
const builder2 = new MLGraphBuilder(context); | ||
|
||
const a1 = builder1.input('a', kExampleInputDescriptor); | ||
const b1 = builder1.input('b', kExampleInputDescriptor); | ||
const c1 = builder1.add(a1, b1); | ||
const graph1 = await builder1.build({c1}); | ||
|
||
const a2 = builder2.input('a', kExampleInputDescriptor); | ||
const b2 = builder2.input('b', kExampleInputDescriptor); | ||
const c2 = builder2.add(a2, b2); | ||
const graph2 = await builder2.build({c2}); | ||
}, 'Build two graphs with separate MLGraphBuilders'); |
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
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
Oops, something went wrong.