From fd8577578dc11eced7abd32b4b66f5ae78b8aa6d Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Fri, 18 Oct 2024 21:27:38 +0000 Subject: [PATCH] Bug 1925437 [wpt PR 48690] - webnn: Deprecate MLTensorUsage in favor of boolean flags, a=testonly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic update from web-platform-tests webnn: Deprecate MLTensorUsage in favor of boolean flags As per the feedback on this thread on the MLTensor explainer PR: https://github.com/webmachinelearning/webnn/pull/754#discussion_r1772300523 This CL includes logic to still support specifying the deprecated MLTensorUsage flags for now, though this logic will only exist for about a milestone to give callers the opportunity to migrate their existing code Bug: 343638938 Change-Id: I56209e68fde3920b8d6c781c8f804ac6fcd35c9a Cq-Include-Trybots: luci.chromium.try​:mac14.arm64-blink-rel,win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5933323 Reviewed-by: ningxin hu Auto-Submit: Austin Sullivan Commit-Queue: ningxin hu Cr-Commit-Position: refs/heads/main@{#1370419} -- wpt-commits: ab3cd3a3748943c7ec96b7fdcc7b8e3acebe1396 wpt-pr: 48690 --- .../byob_readtensor.https.any.js | 7 +-- .../inputs-are-not-modified.https.any.js | 12 ++--- .../parallel-dispatch.https.any.js | 27 +++++++---- .../conformance_tests/tensor.https.any.js | 46 ++++++++++++------- .../destroyContext.https.any.js | 6 +-- .../destroyGraph.https.any.js | 6 +-- 6 files changed, 64 insertions(+), 40 deletions(-) diff --git a/testing/web-platform/tests/webnn/conformance_tests/byob_readtensor.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/byob_readtensor.https.any.js index b99c8704d236c..f43cca0ea4eb7 100644 --- a/testing/web-platform/tests/webnn/conformance_tests/byob_readtensor.https.any.js +++ b/testing/web-platform/tests/webnn/conformance_tests/byob_readtensor.https.any.js @@ -32,7 +32,8 @@ promise_setup(async () => { mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [2, 4], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }); } catch (e) { throw new AssertionError( @@ -141,7 +142,7 @@ promise_test(async (t) => { const tensor = await mlContext.createTensor({ dataType: 'int32', shape: [2, 2], - usage: MLTensorUsage.READ, + readable: true, }); const arrayBufferView = new Int32Array(2 * 2); const arrayBuffer = arrayBufferView.buffer; @@ -159,7 +160,7 @@ promise_test(async (t) => { const tensor = await mlContext.createTensor({ dataType: 'int32', shape: [2, 2], - usage: MLTensorUsage.READ, + readable: true, }); const arrayBufferView = new Int32Array(2 * 2); const arrayBuffer = arrayBufferView.buffer; diff --git a/testing/web-platform/tests/webnn/conformance_tests/inputs-are-not-modified.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/inputs-are-not-modified.https.any.js index ffd2d93a557f6..730941fbd8b6e 100644 --- a/testing/web-platform/tests/webnn/conformance_tests/inputs-are-not-modified.https.any.js +++ b/testing/web-platform/tests/webnn/conformance_tests/inputs-are-not-modified.https.any.js @@ -31,10 +31,10 @@ promise_test(async () => { mlContext.createTensor({ dataType: 'float32', shape: [4], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ + readable: true, + writable: true, }), - mlContext.createTensor( - {dataType: 'float32', shape: [4], usage: MLTensorUsage.READ}), + mlContext.createTensor({dataType: 'float32', shape: [4], readable: true}), builder.build({'output': outputOperand}) ]); @@ -66,10 +66,10 @@ promise_test(async () => { mlContext.createTensor({ dataType: 'float32', shape: [4], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ + readable: true, + writable: true, }), - mlContext.createTensor( - {dataType: 'float32', shape: [4], usage: MLTensorUsage.READ}), + mlContext.createTensor({dataType: 'float32', shape: [4], readable: true}), builder.build({'output': outputOperand}) ]); diff --git a/testing/web-platform/tests/webnn/conformance_tests/parallel-dispatch.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/parallel-dispatch.https.any.js index dfdf70a6aa46f..4051645771fa0 100644 --- a/testing/web-platform/tests/webnn/conformance_tests/parallel-dispatch.https.any.js +++ b/testing/web-platform/tests/webnn/conformance_tests/parallel-dispatch.https.any.js @@ -33,7 +33,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const [mlGraph, inputTensor1, inputTensor2, outputTensor] = @@ -73,7 +74,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const mlGraph = await buildMulGraph(mlContext, operandDescriptor, 3); @@ -101,7 +103,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const mlGraph = await buildMulGraph(mlContext, operandDescriptor, 10); @@ -140,7 +143,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const mlGraph = await buildMulGraph(mlContext, operandDescriptor, 9); @@ -178,7 +182,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const mlGraph = await buildMulGraph(mlContext, operandDescriptor, 2); @@ -211,7 +216,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; // write/write... @@ -250,7 +256,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; // write/write... @@ -288,7 +295,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const graphs = await Promise.all([3, 2].map(async (multiplier) => { @@ -324,7 +332,8 @@ promise_test(async () => { const operandDescriptor = { dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const graphs = await Promise.all([2, 3].map(async (multiplier) => { diff --git a/testing/web-platform/tests/webnn/conformance_tests/tensor.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/tensor.https.any.js index 51905bbaf3c59..0bc51614608f5 100644 --- a/testing/web-platform/tests/webnn/conformance_tests/tensor.https.any.js +++ b/testing/web-platform/tests/webnn/conformance_tests/tensor.https.any.js @@ -33,7 +33,13 @@ const sizeOfDescriptor = (descriptor) => { }; const getDescriptorFromTensor = (tensor) => { - return {dataType: tensor.dataType, shape: tensor.shape, usage: tensor.usage}; + return { + dataType: tensor.dataType, + shape: tensor.shape, + readable: tensor.readable, + writable: tensor.writable, + importableToWebGPU: tensor.importableToWebGPU, + }; }; @@ -162,7 +168,7 @@ const testWriteTensor = (testName) => { const tensorDescriptor = { dataType: 'int32', shape: [1], - usage: MLTensorUsage.WRITE, + writable: true, }; let mlTensor = await mlContext.createTensor(tensorDescriptor); @@ -211,7 +217,7 @@ const testWriteTensor = (testName) => { const tensorDescriptor = { dataType: 'int32', shape: [2, 2], - usage: MLTensorUsage.WRITE, + writable: true, }; let mlTensor = await mlContext.createTensor(tensorDescriptor); @@ -228,7 +234,7 @@ const testWriteTensor = (testName) => { const tensorDescriptor = { dataType: 'int32', shape: [2, 3], - usage: MLTensorUsage.WRITE, + writable: true, }; let mlTensor = await mlContext.createTensor(tensorDescriptor); @@ -247,7 +253,8 @@ const testWriteTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }); // Initialize the tensor. @@ -270,7 +277,8 @@ const testWriteTensor = (testName) => { const tensorDescriptor = { dataType: 'int32', shape: [2, 2], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; let mlTensor = await mlContext.createTensor(tensorDescriptor); @@ -321,7 +329,7 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [2, 2], - usage: MLTensorUsage.READ, + readable: true, }); // Reading a destroyed MLTensor should reject. @@ -335,7 +343,7 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [2, 3], - usage: MLTensorUsage.READ, + readable: true, }); let promise = mlContext.readTensor(mlTensor); @@ -351,7 +359,7 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [1024], - usage: MLTensorUsage.READ, + readable: true, }); await assert_tensor_data_equals(mlContext, mlTensor, new Uint32Array(1024)); @@ -361,7 +369,8 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [1], - usage: MLTensorUsage.READ | MLTensorUsage.WRITE, + readable: true, + writable: true, }); // Initialize the tensor. @@ -377,7 +386,8 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }); // Initialize the tensor. @@ -395,7 +405,8 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }); // Initialize the tensor. @@ -413,7 +424,8 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }); // Initialize the tensor. @@ -431,7 +443,8 @@ const testReadTensor = (testName) => { let mlTensor = await mlContext.createTensor({ dataType: 'int32', shape: [1], - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }); const inputData = [0xAA, 0xAA, 0xAA, 0xAA]; @@ -448,7 +461,7 @@ const testReadTensor = (testName) => { const tensorDescriptor = { dataType: 'int32', shape: [2, 3], - usage: MLTensorUsage.READ, + readable: true, }; let mlTensor = await mlContext.createTensor(tensorDescriptor); @@ -484,7 +497,8 @@ const testDispatchTensor = (testName) => { const tensorDescriptor = { dataType: 'float32', shape: shape, - usage: MLTensorUsage.WRITE | MLTensorUsage.READ, + readable: true, + writable: true, }; const lhsOperand = builder.input('lhs', tensorDescriptor); const rhsOperand = builder.input('rhs', tensorDescriptor); diff --git a/testing/web-platform/tests/webnn/validation_tests/destroyContext.https.any.js b/testing/web-platform/tests/webnn/validation_tests/destroyContext.https.any.js index b4027e23dba0f..abed6b09bde43 100644 --- a/testing/web-platform/tests/webnn/validation_tests/destroyContext.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/destroyContext.https.any.js @@ -135,7 +135,7 @@ promise_test(async t => { const tensor = await context.createTensor({ dataType: 'float32', shape: [1], - usage: MLTensorUsage.READ, + readable: true, }); context.destroy(); promise_rejects_dom(t, 'InvalidStateError', context.readTensor(tensor)); @@ -146,7 +146,7 @@ promise_test(async t => { const tensor = await context.createTensor({ dataType: 'float32', shape: [1], - usage: MLTensorUsage.READ, + readable: true, }); let promise = context.readTensor(tensor); context.destroy(); @@ -161,7 +161,7 @@ promise_test(async t => { const tensor = await context.createTensor({ dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE, + writable: true, }); let arrayBuffer = new ArrayBuffer(4); context.destroy(); diff --git a/testing/web-platform/tests/webnn/validation_tests/destroyGraph.https.any.js b/testing/web-platform/tests/webnn/validation_tests/destroyGraph.https.any.js index f7eb01eafef7e..4d883e9f3c3ea 100644 --- a/testing/web-platform/tests/webnn/validation_tests/destroyGraph.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/destroyGraph.https.any.js @@ -110,17 +110,17 @@ promise_test(async t => { const lhsTensor = await context.createTensor({ dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE, + writable: true, }); const rhsTensor = await context.createTensor({ dataType: 'float32', shape: [1], - usage: MLTensorUsage.WRITE, + writable: true, }); const outputTensor = await context.createTensor({ dataType: 'float32', shape: [1], - usage: MLTensorUsage.READ, + readable: true, }); // Initialize inputs const inputData = new Float32Array(1).fill(2.0);