Skip to content

Commit

Permalink
WebNN: Define mojo and IDL for constant (fillSequence) operator
Browse files Browse the repository at this point in the history
According to the WebNN spec[1], this CL defines mojo and extends the IDL
definition of constant MLOperand which can be created with the specified
data type and shape that contains the data as specified by the range.
Some related WPT tests and services unit tests are also added.

Since "bigint" currently has extremely limited use in Chromium, binding
code generation cannot yet handle unions with it[2]. We currently
support all data types supported by WebNN except int64 and uint64.

[1]: https://www.w3.org/TR/webnn/#api-mlgraphbuilder-constant-range
[2]: whatwg/webidl#1388

Bug: 40206287, 328109810
Change-Id: Iae0212071fc3567cebeeb8abb306b1d3b81ca462
  • Loading branch information
miaobin authored and chromium-wpt-export-bot committed Mar 22, 2024
1 parent f369f5f commit 1701d5b
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions webnn/validation_tests/fill_sequence.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// META: title=validation tests for WebNN API gru operation
// META: global=window,dedicatedworker
// META: script=../resources/utils_validation.js
// META: timeout=long

'use strict';

const tests = [
{
name: '[constant] Test building a constant MLOperand of the float32 data type',
desc: { dataType: 'float32', dimensions: [3] },
start: 0.1,
step: 0.1,
output: { dataType: 'float32', dimensions: [3] }
},
{
name: '[constant] Test building a constant MLOperand of the float16 data type',
desc: { dataType: 'float16', dimensions: [3] },
start: 0.1,
step: -0.2,
output: { dataType: 'float16', dimensions: [3] }
},
{
name: '[constant] Test building a constant MLOperand of the int8 data type',
desc: { dataType: 'int8', dimensions: [3] },
start: 3,
step: -2,
output: { dataType: 'int8', dimensions: [3] }
},
{
name: '[constant] Test building a constant MLOperand with output_shape = {}',
desc: { dataType: 'float32', dimensions: [] },
start: 0.1,
step: 0.2,
output: { dataType: 'float32', dimensions: [] }
},
{
name: '[constant] Test building a constant MLOperand with step = 0}',
desc: { dataType: 'float32', dimensions: [5] },
start: 0.1,
step: 0,
output: { dataType: 'float32', dimensions: [5] }
},
{
name: '[constant] Test building a constant MLOperand with start = infinity, step = -infinity}',
desc: { dataType: 'float16', dimensions: [5] },
start: Infinity,
step: -Infinity,
output: { dataType: 'float16', dimensions: [5] }
},
{
name: '[constant] TypeError is expected if the values of start or step are not within the range of int8',
desc: { dataType: 'int8', dimensions: [5] },
start: 200,
step: 2
},
{
name: '[constant] TypeError is expected if the values of start or step are not within the range of float16',
desc: { dataType: 'float16', dimensions: [5] },
start: 65535,
step: 2.2
},
{
name: '[constant] TypeError is expected if the endpoint value is not within the range of int8',
desc: { dataType: 'int8', dimensions: [5] },
start: 126,
step: 2
},
{
name: '[constant] TypeError is expected if the endpoint value is not within the range of float16',
desc: { dataType: 'float16', dimensions: [5] },
start: 65533,
step: 2.8
}
]

tests.forEach(
test => promise_test(async t => {
if (test.output) {
const output = builder.constant(
test.desc, test.start, test.step);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.dimensions);
} else {
assert_throws_js(
TypeError, () => builder.constant(
test.desc, test.start, test.step));
}
}, test.name));

0 comments on commit 1701d5b

Please sign in to comment.