Skip to content

Commit

Permalink
[webnn] Add float32 tests for WebNN API expand op (#43559)
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceDai authored Dec 13, 2023
1 parent c849fb6 commit b597a15
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
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 @@ -318,6 +318,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 @@ -661,10 +662,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);
// 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

0 comments on commit b597a15

Please sign in to comment.