diff --git a/interfaces/webnn.idl b/interfaces/webnn.idl index 63554edbffd491..5dd81fc29f30c5 100644 --- a/interfaces/webnn.idl +++ b/interfaces/webnn.idl @@ -19,8 +19,7 @@ dictionary MLContextOptions { MLPowerPreference powerPreference = "default"; }; -[SecureContext, Exposed=(Window, DedicatedWorker)] -interface ML { +[SecureContext, Exposed = (Window, Worker)] interface ML { Promise createContext(optional MLContextOptions options = {}); Promise createContext(GPUDevice gpuDevice); }; @@ -31,8 +30,7 @@ dictionary MLContextLostInfo { DOMString message; }; -[SecureContext, Exposed=(Window, DedicatedWorker)] -interface MLContext { +[SecureContext, Exposed = (Window, Worker)] interface MLContext { undefined dispatch(MLGraph graph, MLNamedTensors inputs, MLNamedTensors outputs); Promise createTensor(MLTensorDescriptor descriptor); @@ -71,7 +69,7 @@ dictionary MLSingleInputSupportLimits { MLSupportLimits output; }; -[SecureContext, Exposed=(Window, DedicatedWorker)] +[SecureContext, Exposed=(Window, Worker)] interface MLGraph { undefined destroy(); }; @@ -97,7 +95,7 @@ dictionary MLOperandDescriptor { required sequence<[EnforceRange] unsigned long> shape; }; -[SecureContext, Exposed=(Window, DedicatedWorker)] +[SecureContext, Exposed=(Window, Worker)] interface MLOperand { readonly attribute MLOperandDataType dataType; readonly attribute FrozenArray shape; @@ -114,7 +112,7 @@ dictionary MLTensorDescriptor : MLOperandDescriptor { boolean writable = false; }; -[SecureContext, Exposed=(Window, DedicatedWorker)] +[SecureContext, Exposed=(Window, Worker)] interface MLTensor { readonly attribute MLOperandDataType dataType; readonly attribute FrozenArray shape; @@ -126,7 +124,7 @@ interface MLTensor { typedef record MLNamedOperands; -[SecureContext, Exposed=(Window, DedicatedWorker)] +[SecureContext, Exposed=(Window, Worker)] interface MLGraphBuilder { // Construct the graph builder from the context. constructor(MLContext context); diff --git a/webnn/conformance_tests/byob_readtensor.https.any.js b/webnn/conformance_tests/byob_readtensor.https.any.js index 97bd666fa2cbf1..5cbadb3c611765 100644 --- a/webnn/conformance_tests/byob_readtensor.https.any.js +++ b/webnn/conformance_tests/byob_readtensor.https.any.js @@ -1,5 +1,5 @@ // META: title=test WebNN API tensor operations -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu @@ -94,22 +94,24 @@ promise_test(async () => { assert_array_equals(new Uint32Array(arrayBuffer), testContents); }, `readTensor() with an ArrayBuffer`); -promise_test(async () => { - const sharedArrayBuffer = new SharedArrayBuffer(testContents.byteLength); +if ('SharedArrayBuffer' in globalThis) { + promise_test(async () => { + const sharedArrayBuffer = new SharedArrayBuffer(testContents.byteLength); - await mlContext.readTensor(mlTensor, sharedArrayBuffer); + await mlContext.readTensor(mlTensor, sharedArrayBuffer); - assert_array_equals(new Uint32Array(sharedArrayBuffer), testContents); -}, `readTensor() with a SharedArrayBuffer`); + assert_array_equals(new Uint32Array(sharedArrayBuffer), testContents); + }, `readTensor() with a SharedArrayBuffer`); -promise_test(async () => { - const sharedArrayBuffer = new SharedArrayBuffer(testContents.byteLength); - const typedArray = new Uint32Array(sharedArrayBuffer); + promise_test(async () => { + const sharedArrayBuffer = new SharedArrayBuffer(testContents.byteLength); + const typedArray = new Uint32Array(sharedArrayBuffer); - await mlContext.readTensor(mlTensor, typedArray); + await mlContext.readTensor(mlTensor, typedArray); - assert_array_equals(typedArray, testContents); -}, `readTensor() with a typeArray from a SharedArrayBuffer`); + assert_array_equals(typedArray, testContents); + }, `readTensor() with a typeArray from a SharedArrayBuffer`); +} promise_test(async () => { // Create a slightly larger ArrayBuffer and set up the TypedArray at an diff --git a/webnn/conformance_tests/identity.https.any.js b/webnn/conformance_tests/identity.https.any.js index 05fee94f71ddd1..214d16e396465b 100644 --- a/webnn/conformance_tests/identity.https.any.js +++ b/webnn/conformance_tests/identity.https.any.js @@ -1,5 +1,5 @@ // META: title=test WebNN API element-wise identity operation -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/conformance_tests/inputs-are-not-modified.https.any.js b/webnn/conformance_tests/inputs-are-not-modified.https.any.js index 730941fbd8b6ec..0ea7a08c87b13f 100644 --- a/webnn/conformance_tests/inputs-are-not-modified.https.any.js +++ b/webnn/conformance_tests/inputs-are-not-modified.https.any.js @@ -1,5 +1,5 @@ // META: title=test that input tensors are not modified during a call to dispatch() -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/conformance_tests/parallel-dispatch.https.any.js b/webnn/conformance_tests/parallel-dispatch.https.any.js index 4051645771fa0c..6ad4cd93d65d05 100644 --- a/webnn/conformance_tests/parallel-dispatch.https.any.js +++ b/webnn/conformance_tests/parallel-dispatch.https.any.js @@ -1,5 +1,5 @@ // META: title=test parallel WebNN API dispatch calls -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/conformance_tests/scalars.https.any.js b/webnn/conformance_tests/scalars.https.any.js index 7cb3ceeff7f997..095d96c519e99e 100644 --- a/webnn/conformance_tests/scalars.https.any.js +++ b/webnn/conformance_tests/scalars.https.any.js @@ -1,5 +1,5 @@ // META: title=test that scalar values work as expected -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js b/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js index 8bf7212feaf99e..8f0d5e2eda3f7f 100644 --- a/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js +++ b/webnn/conformance_tests/shared_arraybuffer_constant.https.any.js @@ -1,5 +1,5 @@ // META: title=test WebNN API constant with shared array buffer -// META: global=window,dedicatedworker +// META: global=window,dedicatedworker,serviceworker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/conformance_tests/subgraph.https.any.js b/webnn/conformance_tests/subgraph.https.any.js index ed35637b43c98f..9b21d6e4f9453f 100644 --- a/webnn/conformance_tests/subgraph.https.any.js +++ b/webnn/conformance_tests/subgraph.https.any.js @@ -1,5 +1,5 @@ // META: title=test WebNN API subgraph with multiple operations -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/conformance_tests/tensor.https.any.js b/webnn/conformance_tests/tensor.https.any.js index 0906ae96ba2c6a..1a46c35b320e97 100644 --- a/webnn/conformance_tests/tensor.https.any.js +++ b/webnn/conformance_tests/tensor.https.any.js @@ -1,5 +1,5 @@ // META: title=test WebNN API tensor operations -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu @@ -175,44 +175,46 @@ const testWriteTensor = (testName) => { } }); - promise_test(async () => { - const tensorDescriptor = { - dataType: 'int32', - shape: [4], - readable: true, - writable: true, - }; - const tensorByteLength = sizeOfDescriptor(tensorDescriptor); - - // Required to use SharedArrayBuffer. - assert_true( - self.crossOriginIsolated, - 'The page is served with COOP and COEP, it should be cross-origin-isolated.'); - - let arrayBuffer = new ArrayBuffer(tensorByteLength); - let arrayBufferView = new Int32Array(arrayBuffer); - arrayBufferView.fill(7); - - let sharedArrayBuffer = new SharedArrayBuffer(tensorByteLength); - let sharedArrayBufferView = new Int32Array(sharedArrayBuffer); - sharedArrayBufferView.fill(7); - - const tensors = await Promise.all([ - mlContext.createTensor(tensorDescriptor), - mlContext.createTensor(tensorDescriptor), - mlContext.createTensor(tensorDescriptor), - mlContext.createTensor(tensorDescriptor) - ]); - - mlContext.writeTensor(tensors[0], arrayBuffer); - mlContext.writeTensor(tensors[2], arrayBufferView); - mlContext.writeTensor(tensors[1], sharedArrayBuffer); - mlContext.writeTensor(tensors[3], sharedArrayBufferView); - - await Promise.all(tensors.map(async (tensor) => { - assert_tensor_data_equals(mlContext, tensor, arrayBufferView); - })); - }, `${testName} / write with different kinds of buffers`); + if ('SharedArrayBuffer' in globalThis) { + promise_test(async () => { + const tensorDescriptor = { + dataType: 'int32', + shape: [4], + readable: true, + writable: true, + }; + const tensorByteLength = sizeOfDescriptor(tensorDescriptor); + + // Required to use SharedArrayBuffer. + assert_true( + self.crossOriginIsolated, + 'The page is served with COOP and COEP, it should be cross-origin-isolated.'); + + let arrayBuffer = new ArrayBuffer(tensorByteLength); + let arrayBufferView = new Int32Array(arrayBuffer); + arrayBufferView.fill(7); + + let sharedArrayBuffer = new SharedArrayBuffer(tensorByteLength); + let sharedArrayBufferView = new Int32Array(sharedArrayBuffer); + sharedArrayBufferView.fill(7); + + const tensors = await Promise.all([ + mlContext.createTensor(tensorDescriptor), + mlContext.createTensor(tensorDescriptor), + mlContext.createTensor(tensorDescriptor), + mlContext.createTensor(tensorDescriptor) + ]); + + mlContext.writeTensor(tensors[0], arrayBuffer); + mlContext.writeTensor(tensors[2], arrayBufferView); + mlContext.writeTensor(tensors[1], sharedArrayBuffer); + mlContext.writeTensor(tensors[3], sharedArrayBufferView); + + await Promise.all(tensors.map(async (tensor) => { + assert_tensor_data_equals(mlContext, tensor, arrayBufferView); + })); + }, `${testName} / write with different kinds of buffers`); + } promise_test(async () => { const tensorDescriptor = { diff --git a/webnn/idlharness.https.any.js b/webnn/idlharness.https.any.js index 905744ffea6127..feb9d09f1a86ea 100644 --- a/webnn/idlharness.https.any.js +++ b/webnn/idlharness.https.any.js @@ -1,4 +1,4 @@ -// META: global=window,dedicatedworker +// META: global=window,worker // META: script=/resources/WebIDLParser.js // META: script=/resources/idlharness.js // META: script=./resources/utils.js diff --git a/webnn/validation_tests/build-more-than-once.https.any.js b/webnn/validation_tests/build-more-than-once.https.any.js index 3d648c9b0191f1..405a9acf27f8db 100644 --- a/webnn/validation_tests/build-more-than-once.https.any.js +++ b/webnn/validation_tests/build-more-than-once.https.any.js @@ -1,5 +1,5 @@ // META: title=ensure MLMLGraphBuilder may build at most one MLGraph -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/constant-changed-buffer.https.any.js b/webnn/validation_tests/constant-changed-buffer.https.any.js index b3c8e56046a141..d5a827aae75236 100644 --- a/webnn/validation_tests/constant-changed-buffer.https.any.js +++ b/webnn/validation_tests/constant-changed-buffer.https.any.js @@ -1,5 +1,5 @@ // META: title=ensure MLGraphBuilder.constant() handles buffers which change -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/constant.https.any.js b/webnn/validation_tests/constant.https.any.js index 31a7a676a6baf9..de72662ff69222 100644 --- a/webnn/validation_tests/constant.https.any.js +++ b/webnn/validation_tests/constant.https.any.js @@ -1,5 +1,5 @@ // META: title=validation tests for WebNN API constant interface -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu @@ -128,8 +128,6 @@ tests.forEach( const builder = new MLGraphBuilder(context); const buffer = new ArrayBuffer(test.buffer.byteLength); const bufferView = new test.buffer.type(buffer); - const sharedBuffer = new SharedArrayBuffer(test.buffer.byteLength); - const sharedBufferView = new test.buffer.type(sharedBuffer); if (test.viewTestOnly === undefined || test.viewTestOnly === false) { // Test building constant from ArrayBuffer. @@ -141,15 +139,19 @@ tests.forEach( assert_throws_js( TypeError, () => builder.constant(test.descriptor, buffer)); } - // Test building constant from SharedArrayBuffer. - if (test.output) { - const constantOperand = - builder.constant(test.descriptor, sharedBuffer); - assert_equals(constantOperand.dataType, test.output.dataType); - assert_array_equals(constantOperand.shape, test.output.shape); - } else { - assert_throws_js( - TypeError, () => builder.constant(test.descriptor, sharedBuffer)); + if ('SharedArrayBuffer' in globalThis) { + // Test building constant from SharedArrayBuffer. + const sharedBuffer = new SharedArrayBuffer(test.buffer.byteLength); + if (test.output) { + const constantOperand = + builder.constant(test.descriptor, sharedBuffer); + assert_equals(constantOperand.dataType, test.output.dataType); + assert_array_equals(constantOperand.shape, test.output.shape); + } else { + assert_throws_js( + TypeError, + () => builder.constant(test.descriptor, sharedBuffer)); + } } } @@ -162,15 +164,19 @@ tests.forEach( assert_throws_js( TypeError, () => builder.constant(test.descriptor, bufferView)); } - // Test building constant from shared ArrayBufferView. - if (test.output) { - const constantOperand = - builder.constant(test.descriptor, sharedBufferView); - assert_equals(constantOperand.dataType, test.output.dataType); - assert_array_equals(constantOperand.shape, test.output.shape); - } else { - assert_throws_js( - TypeError, - () => builder.constant(test.descriptor, sharedBufferView)); + if ('SharedArrayBuffer' in globalThis) { + // Test building constant from shared ArrayBufferView. + const sharedBuffer = new SharedArrayBuffer(test.buffer.byteLength); + const sharedBufferView = new test.buffer.type(sharedBuffer); + if (test.output) { + const constantOperand = + builder.constant(test.descriptor, sharedBufferView); + assert_equals(constantOperand.dataType, test.output.dataType); + assert_array_equals(constantOperand.shape, test.output.shape); + } else { + assert_throws_js( + TypeError, + () => builder.constant(test.descriptor, sharedBufferView)); + } } }, test.name)); diff --git a/webnn/validation_tests/createContext.https.any.js b/webnn/validation_tests/createContext.https.any.js index 0357c88335ff01..314f7e3e3c65ec 100644 --- a/webnn/validation_tests/createContext.https.any.js +++ b/webnn/validation_tests/createContext.https.any.js @@ -1,5 +1,5 @@ // META: title=validation tests for WebNN API createContext() -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/destroyContext.https.any.js b/webnn/validation_tests/destroyContext.https.any.js index ba11362564d5dd..03ce62e69965e8 100644 --- a/webnn/validation_tests/destroyContext.https.any.js +++ b/webnn/validation_tests/destroyContext.https.any.js @@ -1,6 +1,6 @@ // META: timeout=long // META: title=validation tests for WebNN API MLContext::destroy() -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/destroyGraph.https.any.js b/webnn/validation_tests/destroyGraph.https.any.js index b77b2ad4e6e1d6..472ffce8c13777 100644 --- a/webnn/validation_tests/destroyGraph.https.any.js +++ b/webnn/validation_tests/destroyGraph.https.any.js @@ -1,6 +1,6 @@ // META: timeout=long // META: title=validation tests for WebNN API MLContext::destroy() -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/input.https.any.js b/webnn/validation_tests/input.https.any.js index 54f50b146cb33d..ed30548f9bd010 100644 --- a/webnn/validation_tests/input.https.any.js +++ b/webnn/validation_tests/input.https.any.js @@ -1,5 +1,5 @@ // META: title=validation tests for WebNN API input interface -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/invalid-rank.https.any.js b/webnn/validation_tests/invalid-rank.https.any.js index 93dfa105c6bd04..c1f96f99cc0f68 100644 --- a/webnn/validation_tests/invalid-rank.https.any.js +++ b/webnn/validation_tests/invalid-rank.https.any.js @@ -1,5 +1,5 @@ // META: title=ensure an MLOperand cannot be created with an invalid rank -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/pooling-and-reduction-keep-dims.https.any.js b/webnn/validation_tests/pooling-and-reduction-keep-dims.https.any.js index f2264e468d4228..da7afc9bce9e3e 100644 --- a/webnn/validation_tests/pooling-and-reduction-keep-dims.https.any.js +++ b/webnn/validation_tests/pooling-and-reduction-keep-dims.https.any.js @@ -1,5 +1,5 @@ // META: title=validation tests for pooling and reduction operators keep dimensions -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu diff --git a/webnn/validation_tests/unprintableNames.https.any.js b/webnn/validation_tests/unprintableNames.https.any.js index b954f361c0e58d..c3847d68e3ee35 100644 --- a/webnn/validation_tests/unprintableNames.https.any.js +++ b/webnn/validation_tests/unprintableNames.https.any.js @@ -1,5 +1,5 @@ // META: title=test graph inputs/outputs with unprintable names -// META: global=window,dedicatedworker +// META: global=window,worker // META: variant=?cpu // META: variant=?gpu // META: variant=?npu