Skip to content
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

[webnn] Add float32 tests for WebNN API expand op #43559

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions webnn/expand.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=test WebNN API expand operation
// META: global=window,dedicatedworker
// META: script=./resources/utils.js
// META: timeout=long

'use strict';

// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-expand

// reuse buildReshape method
testWebNNOperation('expand', buildReshape);
11 changes: 11 additions & 0 deletions webnn/gpu/expand.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=test WebNN API expand operation
// META: global=window,dedicatedworker
// META: script=../resources/utils.js
// META: timeout=long

'use strict';

// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-expand

// reuse buildReshape method
testWebNNOperation('expand', buildReshape, 'gpu');
6 changes: 4 additions & 2 deletions webnn/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const PrecisionMetrics = {
tan: {ATOL: {float32: 1/1024, float16: 1/512}},
// End Element-wise unary operations
elu: {ULP: {float32: 18, float16: 18}},
expand: {ULP: {float32: 0, float16: 0}},
gemm: {ULP: {float32: getGemmPrecisionTolerance, float16: getGemmPrecisionTolerance}},
hardSigmoid: {ULP: {float32: 2, float16: 2}},
hardSwish: {ULP: {float32: 4, float16: 4}},
Expand Down Expand Up @@ -660,10 +661,11 @@ const buildPad = (operationName, builder, resources) => {
};

const buildReshape = (operationName, builder, resources) => {
// MLOperand reshape(MLOperand input, sequence<unsigned long?> newShape);
// MLOperand reshape(MLOperand input, sequence<unsigned long> newShape);
Copy link

@fdwr fdwr Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what does this commented line mean? Does it mean you're implementing that API function here? If so, suggest adding that to the comment:

// Implements:
// MLOperand reshape(MLOperand input, sequence<unsigned long> newShape);
// MLOperand reshape(MLOperand input, sequence<unsigned long> newShape);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed '?' character since Chromium CL#5060264 - Drop null value support in newShape parameter for reshape has already been merged, link to webmachinelearning/webnn#388.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha.

// MLOperand expand(MLOperand input, sequence<unsigned long> newShape);
const namedOutputOperand = {};
const inputOperand = createSingleInputOperand(builder, resources);
// invoke builder.reshape()
// invoke builder.reshape() or builder.expand()
namedOutputOperand[resources.expected.name] = builder[operationName](inputOperand, resources.newShape);
return namedOutputOperand;
};
Expand Down