Skip to content

Commit

Permalink
WebNN: Add IDL and mojo definitions for cumulativeSum operator
Browse files Browse the repository at this point in the history
This CL adds IDL and mojo definitions for `cumulativeSum` operator which
is proposed by WebML WG [1].

This CL also implements data type limits, inputs validation and adds
validation tests for `cumulativeSum` operator.

[1]:
    webmachinelearning/webnn#375 (comment)

Bug: 363677531
Change-Id: I5d10918598a7f1331c7281b2e3533c63448ffc30
Cq-Include-Trybots: luci.chromium.try:win11-blink-rel, mac14.arm64-blink-rel, mac14-blink-rel, mac15.arm64-blink-rel, mac15-blink-rel, linux-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5845069
Reviewed-by: Weizhong Xia <[email protected]>
Reviewed-by: ningxin hu <[email protected]>
Reviewed-by: Alex Gough <[email protected]>
Commit-Queue: Bin Miao <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1355527}
  • Loading branch information
miaobin authored and chromium-wpt-export-bot committed Sep 14, 2024
1 parent 8b875c4 commit da855e6
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions webnn/validation_tests/cumulativeSum.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// META: title=validation tests for WebNN API relu operation
// META: global=window,dedicatedworker
// META: variant=?cpu
// META: variant=?gpu
// META: variant=?npu
// META: script=../resources/utils_validation.js

'use strict';

const tests = [
{
name: '[cumulativeSum] Test with default options',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
axis: 0,
output: {dataType: 'float32', dimensions: [3, 2, 5]}
},
{
name: '[cumulativeSum] Test with axis=1',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
axis: 1,
output: {dataType: 'float32', dimensions: [3, 2, 5]}
},
{
name: '[cumulativeSum] Test with exclusive=true',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
axis: 1,
options: {exclusive: true},
output: {dataType: 'float32', dimensions: [3, 2, 5]}
},
{
name: '[cumulativeSum] Test with reversed=true',
input: {dataType: 'float32', dimensions: [3, 2, 5]},
axis: 1,
options: {reversed: true},
output: {dataType: 'float32', dimensions: [3, 2, 5]}
},
{
name: '[cumulativeSum] Throw if input is a scalar',
input: {dataType: 'float32', dimensions: []},
axis: 0
},
{
name: '[cumulativeSum] Throw if axis is invalid',
input: {dataType: 'float32', dimensions: [1, 2, 3]},
axis: 3
},
]

tests.forEach(
test => promise_test(async t => {
const builder = new MLGraphBuilder(context);
const input = builder.input('input', test.input);

const options = {};
if (test.options) {
if (test.options.exclusive) {
options.exclusive = test.options.exclusive;
}
if (test.options.reversed) {
options.reversed = test.options.reversed;
}
}
if (test.output) {
const output = builder.cumulativeSum(input, test.axis, options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.dimensions);
} else {
const label = 'cumulative_sum';
options.label = label;
const regexp = new RegExp('\\[' + label + '\\]');
assert_throws_with_label(
() => builder.cumulativeSum(input, test.axis, options), regexp);
}
}, test.name));

multi_builder_test(async (t, builder, otherBuilder) => {
const inputFromOtherBuilder =
otherBuilder.input('input', {dataType: 'float32', dimensions: [3, 2, 5]});
assert_throws_js(
TypeError, () => builder.cumulativeSum(inputFromOtherBuilder, 0));
}, '[cumulativeSum] throw if input is from another builder');

0 comments on commit da855e6

Please sign in to comment.