Skip to content

Commit 1595243

Browse files
Bug 1880651 [wpt PR 44626] - Reland "webnn: Remove sync methods", a=testonly
Automatic update from web-platform-tests Reland "webnn: Remove sync methods" (#44626) This is a reland of commit a3e84dde09e099bebbe4793ffaa70679168130d6 This CL contains a few additional changes: - Enables the async APIs on workers, which was causing bots to fail since workers could not call createContext() - Rebaselines WPTs accordingly - Updates the WPT expectations for the webnn-service-enabled virtual test suite Original change's description: > webnn: Remove sync methods > > See webmachinelearning/webnn#548 > > Deletes all sync methods and simplifies the names of all "Async" > methods - e.g. BuildAsync() -> Build() > > Bug: 40283536, 41481333 > Change-Id: I3b38d987cb4641ea41ab9a974c46dcba16d5c108 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5292884 > Commit-Queue: Austin Sullivan <[email protected]> > Reviewed-by: Reilly Grant <[email protected]> > Reviewed-by: ningxin hu <[email protected]> > Reviewed-by: Alex Gough <[email protected]> > Cr-Commit-Position: refs/heads/main@{#1261223} Cq-Include-Trybots: luci.chromium.try​:win11-x64-fyi-rel Bug: 40283536, 41481333, 41485898 Change-Id: Iffcb922b8175a7181deba1f4c2faa953010ae5c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5303774 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Austin Sullivan <[email protected]> Reviewed-by: Rafael Cintron <[email protected]> Reviewed-by: Alex Gough <[email protected]> Cr-Commit-Position: refs/heads/main@{#1262043} Co-authored-by: Austin Sullivan <[email protected]> -- wpt-commits: 0e308a624676bfea808af80e9a6378ec94dce931 wpt-pr: 44626
1 parent 043c946 commit 1595243

File tree

2 files changed

+28
-82
lines changed

2 files changed

+28
-82
lines changed

testing/web-platform/tests/webnn/idlharness.https.any.js

+13-24
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,18 @@ idl_test(
2828
MLGraph: ['graph']
2929
});
3030

31-
for (const executionType of ExecutionArray) {
32-
const isSync = executionType === 'sync';
33-
if (self.GLOBAL.isWindow() && isSync) {
34-
continue;
35-
}
36-
37-
if (isSync) {
38-
self.context = navigator.ml.createContextSync();
39-
} else {
40-
self.context = await navigator.ml.createContext();
41-
}
42-
43-
self.builder = new MLGraphBuilder(self.context);
44-
self.input = builder.input('input', {dataType: 'float32', dimensions: [1, 1, 5, 5]});
45-
self.filter = builder.constant({dataType: 'float32', dimensions: [1, 1, 3, 3]}, new Float32Array(9).fill(1));
46-
self.relu = builder.relu();
47-
self.output = builder.conv2d(input, filter, {activation: relu, inputLayout: "nchw"});
48-
49-
if (isSync) {
50-
self.graph = builder.buildSync({output});
51-
} else {
52-
self.graph = await builder.build({output});
53-
}
54-
}
31+
self.context = await navigator.ml.createContext();
32+
33+
self.builder = new MLGraphBuilder(self.context);
34+
self.input =
35+
builder.input('input', {dataType: 'float32', dimensions: [1, 1, 5, 5]});
36+
self.filter = builder.constant(
37+
{dataType: 'float32', dimensions: [1, 1, 3, 3]},
38+
new Float32Array(9).fill(1));
39+
self.relu = builder.relu();
40+
self.output =
41+
builder.conv2d(input, filter, {activation: relu, inputLayout: "nchw"});
42+
43+
self.graph = await builder.build({output});
5544
}
5645
);

testing/web-platform/tests/webnn/resources/utils.js

+15-58
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const ExecutionArray = ['sync', 'async'];
4-
53
// https://webmachinelearning.github.io/webnn/#enumdef-mloperanddatatype
64
const TypedArrayDict = {
75
// workaround use Uint16 for Float16
@@ -803,25 +801,7 @@ const buildGraph = (operationName, builder, resources, buildFunc) => {
803801
};
804802

805803
/**
806-
* Build a graph, synchronously compile graph and execute, then check computed results.
807-
* @param {String} operationName - An operation name
808-
* @param {MLContext} context - A ML context
809-
* @param {MLGraphBuilder} builder - A ML graph builder
810-
* @param {Object} resources - Resources used for building a graph
811-
* @param {Function} buildFunc - A build function for an operation
812-
*/
813-
const runSync = (operationName, context, builder, resources, buildFunc) => {
814-
// build a graph
815-
const [namedOutputOperands, inputs, outputs] = buildGraph(operationName, builder, resources, buildFunc);
816-
// synchronously compile the graph up to the output operand
817-
const graph = builder.buildSync(namedOutputOperands);
818-
// synchronously execute the compiled graph.
819-
context.computeSync(graph, inputs, outputs);
820-
checkResults(operationName, namedOutputOperands, outputs, resources);
821-
};
822-
823-
/**
824-
* Build a graph, asynchronously compile graph and execute, then check computed results.
804+
* Build a graph, compile graph and execute, then check computed results.
825805
* @param {String} operationName - An operation name
826806
* @param {MLContext} context - A ML context
827807
* @param {MLGraphBuilder} builder - A ML graph builder
@@ -831,9 +811,9 @@ const runSync = (operationName, context, builder, resources, buildFunc) => {
831811
const run = async (operationName, context, builder, resources, buildFunc) => {
832812
// build a graph
833813
const [namedOutputOperands, inputs, outputs] = buildGraph(operationName, builder, resources, buildFunc);
834-
// asynchronously compile the graph up to the output operand
814+
// compile the graph up to the output operand
835815
const graph = await builder.build(namedOutputOperands);
836-
// asynchronously execute the compiled graph
816+
// execute the compiled graph
837817
const result = await context.compute(graph, inputs, outputs);
838818
checkResults(operationName, namedOutputOperands, result.outputs, resources);
839819
};
@@ -852,41 +832,18 @@ const testWebNNOperation = (operationName, buildFunc, deviceType = 'cpu') => {
852832
operationNameArray = operationName;
853833
}
854834

855-
ExecutionArray.forEach(executionType => {
856-
const isSync = executionType === 'sync';
857-
if (self.GLOBAL.isWindow() && isSync) {
858-
return;
859-
}
860-
let context;
861-
let builder;
862-
if (isSync) {
863-
// test sync
864-
operationNameArray.forEach((subOperationName) => {
865-
const tests = loadTests(subOperationName);
866-
setup(() => {
867-
context = navigator.ml.createContextSync({deviceType});
868-
builder = new MLGraphBuilder(context);
869-
});
870-
for (const subTest of tests) {
871-
test(() => {
872-
runSync(subOperationName, context, builder, subTest, buildFunc);
873-
}, `${subTest.name} / ${executionType}`);
874-
}
875-
});
876-
} else {
877-
// test async
878-
operationNameArray.forEach((subOperationName) => {
879-
const tests = loadTests(subOperationName);
880-
promise_setup(async () => {
881-
context = await navigator.ml.createContext({deviceType});
882-
builder = new MLGraphBuilder(context);
883-
});
884-
for (const subTest of tests) {
885-
promise_test(async () => {
886-
await run(subOperationName, context, builder, subTest, buildFunc);
887-
}, `${subTest.name} / ${executionType}`);
888-
}
889-
});
835+
let context;
836+
let builder;
837+
operationNameArray.forEach((subOperationName) => {
838+
const tests = loadTests(subOperationName);
839+
promise_setup(async () => {
840+
context = await navigator.ml.createContext({deviceType});
841+
builder = new MLGraphBuilder(context);
842+
});
843+
for (const subTest of tests) {
844+
promise_test(async () => {
845+
await run(subOperationName, context, builder, subTest, buildFunc);
846+
}, `${subTest.name}`);
890847
}
891848
});
892849
};

0 commit comments

Comments
 (0)