From ba654bfb5d0fe5cd145bac02f63d67826d951d33 Mon Sep 17 00:00:00 2001 From: BruceDai Date: Wed, 13 Dec 2023 16:51:42 +0800 Subject: [PATCH] [webnn] Add float32 tests for WebNN API where op (#43558) --- webnn/gpu/where.https.any.js | 10 ++++++++++ webnn/resources/utils.js | 10 ++++++++++ webnn/where.https.any.js | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 webnn/gpu/where.https.any.js create mode 100644 webnn/where.https.any.js diff --git a/webnn/gpu/where.https.any.js b/webnn/gpu/where.https.any.js new file mode 100644 index 00000000000000..ec0c5530a044b4 --- /dev/null +++ b/webnn/gpu/where.https.any.js @@ -0,0 +1,10 @@ +// META: title=test WebNN API where operation +// META: global=window,dedicatedworker +// META: script=../resources/utils.js +// META: timeout=long + +'use strict'; + +// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-where + +testWebNNOperation('where', buildWhere, 'gpu'); \ No newline at end of file diff --git a/webnn/resources/utils.js b/webnn/resources/utils.js index 328b0bb8a5e1a9..c3b10a7020182f 100644 --- a/webnn/resources/utils.js +++ b/webnn/resources/utils.js @@ -354,6 +354,7 @@ const PrecisionMetrics = { squeeze: {ULP: {float32: 0, float16: 0}}, tanh: {ATOL: {float32: 1/1024, float16: 1/512}}, transpose: {ULP: {float32: 0, float16: 0}}, + where: {ULP: {float32: 0, float16: 0}}, }; /** @@ -694,6 +695,15 @@ const buildSplit = (operationName, builder, resources) => { return namedOutputOperand; }; +const buildWhere = (operationName, builder, resources) => { + // MLOperand where(MLOperand condition, MLOperand trueValues, MLOperand falseValues); + const namedOutputOperand = {}; + const [conditionOperand, trueValuesOperand, falseValuesOperand] = createMultiInputOperands(builder, resources); + // invoke builder.where() + namedOutputOperand[resources.expected.name] = builder[operationName](conditionOperand, trueValuesOperand, falseValuesOperand); + return namedOutputOperand; +}; + /** * Build a graph. * @param {String} operationName - An operation name diff --git a/webnn/where.https.any.js b/webnn/where.https.any.js new file mode 100644 index 00000000000000..306128a8142275 --- /dev/null +++ b/webnn/where.https.any.js @@ -0,0 +1,10 @@ +// META: title=test WebNN API where operation +// META: global=window,dedicatedworker +// META: script=./resources/utils.js +// META: timeout=long + +'use strict'; + +// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-where + +testWebNNOperation('where', buildWhere); \ No newline at end of file