Skip to content

Commit ae4d3f9

Browse files
a-sullychromium-wpt-export-bot
authored andcommitted
Reland "webnn: Remove sync methods"
This is a reland of commit a3e84dde09e099bebbe4793ffaa70679168130d6 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} Bug: 40283536, 41481333 Change-Id: Iffcb922b8175a7181deba1f4c2faa953010ae5c0
1 parent 196f4a5 commit ae4d3f9

File tree

2 files changed

+28
-82
lines changed

2 files changed

+28
-82
lines changed

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
);

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
@@ -793,25 +791,7 @@ const buildGraph = (operationName, builder, resources, buildFunc) => {
793791
};
794792

795793
/**
796-
* Build a graph, synchronously compile graph and execute, then check computed results.
797-
* @param {String} operationName - An operation name
798-
* @param {MLContext} context - A ML context
799-
* @param {MLGraphBuilder} builder - A ML graph builder
800-
* @param {Object} resources - Resources used for building a graph
801-
* @param {Function} buildFunc - A build function for an operation
802-
*/
803-
const runSync = (operationName, context, builder, resources, buildFunc) => {
804-
// build a graph
805-
const [namedOutputOperands, inputs, outputs] = buildGraph(operationName, builder, resources, buildFunc);
806-
// synchronously compile the graph up to the output operand
807-
const graph = builder.buildSync(namedOutputOperands);
808-
// synchronously execute the compiled graph.
809-
context.computeSync(graph, inputs, outputs);
810-
checkResults(operationName, namedOutputOperands, outputs, resources);
811-
};
812-
813-
/**
814-
* Build a graph, asynchronously compile graph and execute, then check computed results.
794+
* Build a graph, compile graph and execute, then check computed results.
815795
* @param {String} operationName - An operation name
816796
* @param {MLContext} context - A ML context
817797
* @param {MLGraphBuilder} builder - A ML graph builder
@@ -821,9 +801,9 @@ const runSync = (operationName, context, builder, resources, buildFunc) => {
821801
const run = async (operationName, context, builder, resources, buildFunc) => {
822802
// build a graph
823803
const [namedOutputOperands, inputs, outputs] = buildGraph(operationName, builder, resources, buildFunc);
824-
// asynchronously compile the graph up to the output operand
804+
// compile the graph up to the output operand
825805
const graph = await builder.build(namedOutputOperands);
826-
// asynchronously execute the compiled graph
806+
// execute the compiled graph
827807
const result = await context.compute(graph, inputs, outputs);
828808
checkResults(operationName, namedOutputOperands, result.outputs, resources);
829809
};
@@ -842,41 +822,18 @@ const testWebNNOperation = (operationName, buildFunc, deviceType = 'cpu') => {
842822
operationNameArray = operationName;
843823
}
844824

845-
ExecutionArray.forEach(executionType => {
846-
const isSync = executionType === 'sync';
847-
if (self.GLOBAL.isWindow() && isSync) {
848-
return;
849-
}
850-
let context;
851-
let builder;
852-
if (isSync) {
853-
// test sync
854-
operationNameArray.forEach((subOperationName) => {
855-
const tests = loadTests(subOperationName);
856-
setup(() => {
857-
context = navigator.ml.createContextSync({deviceType});
858-
builder = new MLGraphBuilder(context);
859-
});
860-
for (const subTest of tests) {
861-
test(() => {
862-
runSync(subOperationName, context, builder, subTest, buildFunc);
863-
}, `${subTest.name} / ${executionType}`);
864-
}
865-
});
866-
} else {
867-
// test async
868-
operationNameArray.forEach((subOperationName) => {
869-
const tests = loadTests(subOperationName);
870-
promise_setup(async () => {
871-
context = await navigator.ml.createContext({deviceType});
872-
builder = new MLGraphBuilder(context);
873-
});
874-
for (const subTest of tests) {
875-
promise_test(async () => {
876-
await run(subOperationName, context, builder, subTest, buildFunc);
877-
}, `${subTest.name} / ${executionType}`);
878-
}
879-
});
825+
let context;
826+
let builder;
827+
operationNameArray.forEach((subOperationName) => {
828+
const tests = loadTests(subOperationName);
829+
promise_setup(async () => {
830+
context = await navigator.ml.createContext({deviceType});
831+
builder = new MLGraphBuilder(context);
832+
});
833+
for (const subTest of tests) {
834+
promise_test(async () => {
835+
await run(subOperationName, context, builder, subTest, buildFunc);
836+
}, `${subTest.name}`);
880837
}
881838
});
882839
};

0 commit comments

Comments
 (0)