From 9918dff0960d9aa6ddbf207a73fcd60c387f7e8c Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Wed, 21 Aug 2024 08:32:51 -0700 Subject: [PATCH] webnn: Set a max operand rank of 8 We likely eventually want this to be part of MLOpSupportsLimits, but for now this allows us to replace some checked-casts in favor of static-casts, and not need to worry about tensors with absurd ranks See https://github.com/webmachinelearning/webnn/issues/456 Bug: 329482489 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel,mac14-blink-rel,mac14.arm64-blink-rel Change-Id: I021d3b30ea1b8f5f3bef1725130fd2e4c569f494 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5639505 Reviewed-by: ningxin hu Reviewed-by: Phillis Tang Reviewed-by: Koji Ishii Commit-Queue: Austin Sullivan Cr-Commit-Position: refs/heads/main@{#1344800} --- webnn/validation_tests/invalid-rank.https.any.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 webnn/validation_tests/invalid-rank.https.any.js diff --git a/webnn/validation_tests/invalid-rank.https.any.js b/webnn/validation_tests/invalid-rank.https.any.js new file mode 100644 index 00000000000000..59f5ac52337533 --- /dev/null +++ b/webnn/validation_tests/invalid-rank.https.any.js @@ -0,0 +1,16 @@ +// META: title=ensure an MLOperand cannot be created with an invalid rank +// META: global=window,dedicatedworker +// META: variant=?cpu +// META: variant=?gpu +// META: variant=?npu +// META: script=../resources/utils_validation.js + +promise_test(async t => { + const builder = new MLGraphBuilder(context); + + const shapeWithLargeRank = Array(10).fill(2); + assert_throws_js( + TypeError, + () => builder.input( + 'a', {dataType: 'float32', dimensions: shapeWithLargeRank})); +}, 'Throw if rank is too large');