forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo reuse code for WebNN op tests #442
Open
BruceDai
wants to merge
10
commits into
master
Choose a base branch
from
webnn_op_tests_reusable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
16985d3
[webnn] Add tests for concat operation.
BruceDai a34c3cd
[webnn] Updated concat tests to align with latest WebNN API Spec
BruceDai 5baff1e
[webnn] Optimize concat tests by addressing comments.
BruceDai 56bcecd
[webnn] Align the usage for sync and async functions.
BruceDai fe02442
[webnn] Optimize concat tests with renaming variables.
BruceDai 1836156
[webnn] Optimized concat tests by moving if condition checking out of…
BruceDai 9024b21
[webnn] Refined code to reuse for other operation tests.
BruceDai 32290b2
[webnn] Address comments to move nested functions outside.
BruceDai 15e7e8b
[webnn] More refined code to reuse for other operation tests.
BruceDai 3edeb4c
Demo reusable code
BruceDai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// META: title=test WebNN API clamp operation | ||
// META: global=window,dedicatedworker | ||
// META: script=./resources/utils.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-clamp | ||
|
||
const computeClamp = (builder, resources) => { | ||
// MLOperand clamp(MLOperand x, optional MLClampOptions options = {}); | ||
// use 'x' for input operand name | ||
const [inputOperand] = createInputOperands(builder, resources, ['x']); | ||
return builder.clamp(inputOperand, resources.options); | ||
}; | ||
|
||
testWebNNOperation('clamp', '/webnn/resources/test_data/clamp.json', computeClamp); | ||
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,19 @@ | ||
// META: title=test WebNN API concat operation | ||
// META: global=window,dedicatedworker | ||
// META: script=./resources/utils.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-concat | ||
|
||
const computeConcat = (builder, resources) => { | ||
// MLOperand concat(sequence<MLOperand> inputs, long axis); | ||
const inputOperands = []; | ||
for (let input of resources.inputs) { | ||
inputOperands.push(builder.input(input.name, {type: resources.type, dimensions: input.shape})); | ||
} | ||
return builder.concat(inputOperands, resources.axis); | ||
}; | ||
|
||
testWebNNOperation('concat', '/webnn/resources/test_data/concat.json', computeConcat); |
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,45 @@ | ||
// META: title=test WebNN API gemm operation | ||
// META: global=window,dedicatedworker | ||
// META: script=./resources/utils.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-gemm | ||
|
||
const computeGemm = (builder, resources) => { | ||
// MLOperand gemm(MLOperand a, MLOperand b, optional MLGemmOptions options = {}); | ||
// use 'a' and 'b' for input operands name | ||
const [inputOperandA, inputOperandB] = createInputOperands(builder, resources, ['a', 'b']); | ||
const operandType = resources.type; | ||
const TestTypedArray = TypedArrayDict[operandType]; | ||
const options = resources.options; | ||
const gemmOptions = {}; | ||
if (options !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to process options of test json file to pass to context = navigator.ml.createContextSync({deviceType});
// or
// context = await navigator.ml.createContext({deviceType});
builder = new MLGraphBuilder(context); |
||
if (options.c !== undefined) { | ||
if (typeof options.c === 'number') { | ||
// scalar | ||
gemmOptions.c = new TestTypedArray([options.c])[0]; | ||
} else { | ||
gemmOptions.c = builder.constant({type: operandType, dimensions: options.c.shape}, new TestTypedArray(options.c.data)); | ||
} | ||
} | ||
if (options.alpha !== undefined) { | ||
// scalar | ||
gemmOptions.alpha = new TestTypedArray([options.alpha])[0]; | ||
} | ||
if (options.beta !== undefined) { | ||
// scalar | ||
gemmOptions.beta = new TestTypedArray([options.beta])[0]; | ||
} | ||
if (options.aTranspose !== undefined) { | ||
gemmOptions.aTranspose = options.aTranspose; | ||
} | ||
if (options.bTranspose !== undefined) { | ||
gemmOptions.bTranspose = options.bTranspose; | ||
} | ||
} | ||
return builder.gemm(inputOperandA, inputOperandB, gemmOptions); | ||
}; | ||
|
||
testWebNNOperation('gemm', '/webnn/resources/test_data/gemm.json', computeGemm); |
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,17 @@ | ||
// META: title=test WebNN API matmul operation | ||
// META: global=window,dedicatedworker | ||
// META: script=./resources/utils.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-matmul | ||
|
||
const computeMatmul = (builder, resources) => { | ||
// MLOperand matmul(MLOperand a, MLOperand b); | ||
// use 'a' and 'b' for input operands name | ||
const [inputOperandA, inputOperandB] = createInputOperands(builder, resources, ['a', 'b']); | ||
return builder.matmul(inputOperandA, inputOperandB); | ||
}; | ||
|
||
testWebNNOperation('matmul', '/webnn/resources/test_data/matmul.json', computeMatmul); |
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,17 @@ | ||
// META: title=test WebNN API relu operation | ||
// META: global=window,dedicatedworker | ||
// META: script=./resources/utils.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-relu | ||
|
||
const computeRelu = (builder, resources) => { | ||
// MLOperand relu(MLOperand x); | ||
// use 'x' for input operand name | ||
const [inputOperand] = createInputOperands(builder, resources, ['x']); | ||
return builder.relu(inputOperand); | ||
}; | ||
|
||
testWebNNOperation('relu', '/webnn/resources/test_data/relu.json', computeRelu); |
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,18 @@ | ||
// META: title=test WebNN API reshape operation | ||
// META: global=window,dedicatedworker | ||
// META: script=./resources/utils.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-reshape | ||
|
||
const computeReshape = (builder, resources) => { | ||
// MLOperand reshape(MLOperand input, sequence<long> newShape); | ||
// use 'input' for input operand name | ||
const [inputOperand] = createInputOperands(builder, resources, ['input']); | ||
return builder.reshape(inputOperand, resources.newShape); | ||
}; | ||
|
||
testWebNNOperation('reshape', '/webnn/resources/test_data/reshape.json', computeReshape); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to use the following solution for next adding tests converted from native tests, like NNAPI, DML.
@huningxin, any suggestions, thanks.
Solution:
For tests of elementwise binary ops,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we merged later converted NNAPI/DML tests into <operation-name>.json, not sperate tests by files (disadvantage: the file size of all-in-one <operation-name>.json would be larger),we maybe optimize
testWebNNOperation()
to
testWebNNOperation([op-name1, op-name2...], func)
, liketestWebNNOperation(['add', 'sub', 'mul', 'div', 'max', 'min', 'pow'], computeBinary)
,any suggestions? Thanks.