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