Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

webnn: Deprecate MLOperand members in favor of readonly attributes #48877

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions webnn/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getSoftmaxPrecisionTolerance =
if (inputs[inputIndex]) {
inputShape = inputs[inputIndex].descriptor.shape;
} else {
inputShape = intermediateOperands[inputIndex].shape();
inputShape = intermediateOperands[inputIndex].shape;
}
const axis = args.length === 2 ? args[1][Object.keys(args[1])[0]] : 1;
const tolerance = inputShape[axis] * 3 + 3;
Expand Down Expand Up @@ -132,10 +132,10 @@ const assertDescriptorsEquals = (outputOperand, expected) => {
const dataType =
expected.castedType ? expected.castedType : expected.dataType;
assert_true(
outputOperand.dataType() === dataType,
outputOperand.dataType === dataType,
'actual output dataType should be equal to expected output dataType');
assert_array_equals(
outputOperand.shape(), expected.shape,
outputOperand.shape, expected.shape,
'actual output shape should be equal to expected output shape');
};

Expand Down Expand Up @@ -634,7 +634,7 @@ const getGemmPrecisionTolerance =
if (inputs[indexA]) {
ShapeA = inputs[indexA].descriptor.shape;
} else {
ShapeA = intermediateOperands[indexA].shape();
ShapeA = intermediateOperands[indexA].shape;
}
const options =
args.length === 3 ? {...args[2][Object.keys(args[2])[0]]} : {};
Expand Down Expand Up @@ -671,13 +671,13 @@ const getConv2dPrecisionTolerance =
if (inputs[inputIndex]) {
inputShape = inputs[inputIndex].descriptor.shape;
} else {
inputShape = intermediateOperands[inputIndex].shape();
inputShape = intermediateOperands[inputIndex].shape;
}
let filterShape;
if (inputs[filterIndex]) {
filterShape = inputs[filterIndex].descriptor.shape;
} else {
filterShape = intermediateOperands[filterIndex].shape();
filterShape = intermediateOperands[filterIndex].shape;
}
const options =
args.length === 3 ? {...args[2][Object.keys(args[2])[0]]} : {};
Expand Down
8 changes: 4 additions & 4 deletions webnn/resources/utils_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ function validateUnaryOperation(operationName, supportedDataTypes, label) {
const input = builder.input(`input`, {dataType, shape});
assert_equals(typeof builder[operationName], 'function');
const output = builder[operationName](input);
assert_equals(output.dataType(), dataType);
assert_array_equals(output.shape(), shape);
assert_equals(output.dataType, dataType);
assert_array_equals(output.shape, shape);
}
}
}, `[${operationName}] Test building an unary operator with supported type.`);
Expand Down Expand Up @@ -484,8 +484,8 @@ function validateSingleInputOperation(operationName, label) {
for (let shape of allWebNNShapesArray) {
const input = builder.input(`input`, {dataType, shape});
const output = builder[operationName](input);
assert_equals(output.dataType(), dataType);
assert_array_equals(output.shape(), shape);
assert_equals(output.dataType, dataType);
assert_array_equals(output.shape, shape);
}
}
}, `[${operationName}] Test building the operator with supported data type.`);
Expand Down
8 changes: 4 additions & 4 deletions webnn/validation_tests/argMinMax.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ function runTests(operatorName, tests) {
if (context.opSupportLimits()[operatorName].output.dataTypes.includes(
test.options.outputDataType)) {
const output = builder[operatorName](input, axis, test.options);
assert_equals(output.dataType(), test.options.outputDataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.options.outputDataType);
assert_array_equals(output.shape, test.output.shape);
} else {
assert_throws_js(
TypeError, () => builder[operatorName](input, axis, test.options));
Expand All @@ -84,8 +84,8 @@ function runTests(operatorName, tests) {
}
if (test.output) {
const output = builder[operatorName](input, axis, test.options);
assert_equals(output.dataType(), 'int32');
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, 'int32');
assert_array_equals(output.shape, test.output.shape);
} else {
const regrexp = /\[arg_min_max_1_\!\]/;
assert_throws_with_label(
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/batchNormalization.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ tests.forEach(
if (test.output) {
const output =
builder.batchNormalization(input, mean, variance, test.options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const regrexp = /\[batchNormalization_\?_123\]/;
assert_throws_with_label(
Expand Down
8 changes: 4 additions & 4 deletions webnn/validation_tests/clamp.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ promise_test(async t => {
const options = {minValue: 1.0, maxValue: 3.0};
const input = builder.input('input', {dataType: 'float32', shape: [1, 2, 3]});
const output = builder.clamp(input, options);
assert_equals(output.dataType(), 'float32');
assert_array_equals(output.shape(), [1, 2, 3]);
assert_equals(output.dataType, 'float32');
assert_array_equals(output.shape, [1, 2, 3]);
}, '[clamp] Build with options');

promise_test(async t => {
Expand All @@ -28,8 +28,8 @@ promise_test(async t => {
const input =
builder.input('input', {dataType: 'float32', shape: [1, 2, 3, 4]});
const output = builder.clamp(input, options);
assert_equals(output.dataType(), 'float32');
assert_array_equals(output.shape(), [1, 2, 3, 4]);
assert_equals(output.dataType, 'float32');
assert_array_equals(output.shape, [1, 2, 3, 4]);
}, '[clamp] Build with options.minValue == options.maxValue');

promise_test(async t => {
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/concat.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ tests.forEach(
}
if (test.output) {
const output = builder.concat(inputs, test.axis);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const options = {label};
const regrexp = new RegExp('\\[' + label + '\\]');
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/constant.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ tests.forEach(
const bufferView = new test.bufferView.type(buffer);
if (test.output) {
const constantOperand = builder.constant(test.descriptor, bufferView);
assert_equals(constantOperand.dataType(), test.output.dataType);
assert_array_equals(constantOperand.shape(), test.output.shape);
assert_equals(constantOperand.dataType, test.output.dataType);
assert_array_equals(constantOperand.shape, test.output.shape);
} else {
assert_throws_js(
TypeError, () => builder.constant(test.descriptor, bufferView));
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/conv2d.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ tests.forEach(
context.opSupportLimits().conv2d.input.dataTypes.includes(
test.input.dataType)) {
const output = builder.conv2d(input, filter, test.options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const regrexp = /\[conv_2d_\*\]/;
assert_throws_with_label(
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/convTranspose2d.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ tests.forEach(
context.opSupportLimits().convTranspose2d.input.dataTypes.includes(
test.input.dataType)) {
const output = builder.convTranspose2d(input, filter, test.options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const regrexp = new RegExp('\\[' + label + '\\]');
assert_throws_with_label(
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/cumulativeSum.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ tests.forEach(
}
if (test.output) {
const output = builder.cumulativeSum(input, test.axis, options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'cumulative_sum';
options.label = label;
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/dequantizeLinear.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ tests.forEach(
const zeroPoint = builder.input('zeroPoint', test.zeroPoint);
if (test.output) {
const output = builder.dequantizeLinear(input, scale, zeroPoint);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'dequantize_linear_123';
const options = {label};
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/elementwise-binary.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ function runElementWiseBinaryTests(operatorName, tests) {

if (test.output) {
const output = builder[operatorName](a, b);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const options = {label};
assert_throws_with_label(
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/elu.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ promise_test(async t => {
const options = {alpha: 1.0};
const input = builder.input('input', {dataType: 'float32', shape: [1, 2, 3]});
const output = builder.elu(input, options);
assert_equals(output.dataType(), 'float32');
assert_array_equals(output.shape(), [1, 2, 3]);
assert_equals(output.dataType, 'float32');
assert_array_equals(output.shape, [1, 2, 3]);
}, '[elu] Build with options');

promise_test(async t => {
Expand Down
8 changes: 4 additions & 4 deletions webnn/validation_tests/expand.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ tests.forEach(

if (test.output) {
const output = builder.expand(input, test.newShape);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const options = {...test.options};
if (options.label) {
Expand All @@ -97,8 +97,8 @@ promise_test(async t => {
const input = builder.input(`input`, {dataType, shape});
if (context.opSupportLimits().expand.input.dataTypes.includes(dataType)) {
const output = builder.expand(input, newShape);
assert_equals(output.dataType(), dataType);
assert_array_equals(output.shape(), newShape);
assert_equals(output.dataType, dataType);
assert_array_equals(output.shape, newShape);
} else {
assert_throws_js(TypeError, () => builder.expand(input, newShape));
}
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/gather.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ tests.forEach(

if (test.output) {
const output = builder.gather(input, indices, options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'gather_'
options.label = label;
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/gatherElements.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ tests.forEach(

if (test.output) {
const output = builder.gatherElements(input, indices, options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'gatherElements_'
options.label = label;
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/gatherND.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ tests.forEach(test => promise_test(async t => {
context.opSupportLimits().gatherND.input.dataTypes.includes(
test.input.dataType)) {
const output = builder.gatherND(input, indices);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'gatherND_';
const options = {label: label};
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/gemm.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ tests.forEach(
}
if (test.output) {
const output = builder.gemm(a, b, test.options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const regrexp = new RegExp('\\[' + label + '\\]');
assert_throws_with_label(
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/gru.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ tests.forEach(
options);
assert_equals(outputs.length, test.outputs.length);
for (let i = 0; i < outputs.length; ++i) {
assert_equals(outputs[i].dataType(), test.outputs[i].dataType);
assert_array_equals(outputs[i].shape(), test.outputs[i].shape);
assert_equals(outputs[i].dataType, test.outputs[i].dataType);
assert_array_equals(outputs[i].shape, test.outputs[i].shape);
}
} else {
const label = 'gru_xxx';
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/gruCell.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ tests.forEach(
const output = builder.gruCell(
input, weight, recurrentWeight, hiddenState, test.hiddenSize,
options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'gru_cell_xxx';
options.label = label;
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/hardSigmoid.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ promise_test(async t => {
const options = {alpha: 0.5, beta: 1.0};
const input = builder.input('input', {dataType: 'float16', shape: [1, 2, 3]});
const output = builder.hardSigmoid(input, options);
assert_equals(output.dataType(), 'float16');
assert_array_equals(output.shape(), [1, 2, 3]);
assert_equals(output.dataType, 'float16');
assert_array_equals(output.shape, [1, 2, 3]);
}, '[hardSigmoid] Test building with options');

promise_test(async t => {
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/input.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ tests.forEach(
const builder = new MLGraphBuilder(context);
if (test.output) {
const inputOperand = builder.input(test.name, test.descriptor);
assert_equals(inputOperand.dataType(), test.output.dataType);
assert_array_equals(inputOperand.shape(), test.output.shape);
assert_equals(inputOperand.dataType, test.output.dataType);
assert_array_equals(inputOperand.shape, test.output.shape);
} else {
assert_throws_js(
TypeError, () => builder.input(test.name, test.descriptor));
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/instanceNormalization.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ tests.forEach(
.instanceNormalization.input.dataTypes.includes(
test.input.dataType)) {
const output = builder.instanceNormalization(input, test.options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const regrexp = new RegExp('\\[' + label + '\\]');
assert_throws_with_label(
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/layerNormalization.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ tests.forEach(
context.opSupportLimits().layerNormalization.input.dataTypes.includes(
test.input.dataType)) {
const output = builder.layerNormalization(input, test.options);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const regrexp = new RegExp('\\[' + label + '\\]');
assert_throws_with_label(
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/leakyRelu.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ promise_test(async t => {
const options = {alpha: 0.02};
const input = builder.input('input', {dataType: 'float32', shape: [1, 2, 3]});
const output = builder.leakyRelu(input, options);
assert_equals(output.dataType(), 'float32');
assert_array_equals(output.shape(), [1, 2, 3]);
assert_equals(output.dataType, 'float32');
assert_array_equals(output.shape, [1, 2, 3]);
}, '[leakyRelu] Build with options');

promise_test(async t => {
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/linear.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ promise_test(async t => {
const options = {alpha: 1.5, beta: 0.3};
const input = builder.input('input', {dataType: 'float32', shape: [1, 2, 3]});
const output = builder.linear(input, options);
assert_equals(output.dataType(), 'float32');
assert_array_equals(output.shape(), [1, 2, 3]);
assert_equals(output.dataType, 'float32');
assert_array_equals(output.shape, [1, 2, 3]);
}, '[linear] Build with options');

promise_test(async t => {
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/lstm.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ tests.forEach(
options);
assert_equals(outputs.length, test.outputs.length);
for (let i = 0; i < outputs.length; ++i) {
assert_equals(outputs[i].dataType(), test.outputs[i].dataType);
assert_array_equals(outputs[i].shape(), test.outputs[i].shape);
assert_equals(outputs[i].dataType, test.outputs[i].dataType);
assert_array_equals(outputs[i].shape, test.outputs[i].shape);
}
} else {
const label = 'lstm_xxx';
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/lstmCell.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ tests.forEach(
test.hiddenSize, options);
assert_equals(outputs.length, test.outputs.length);
for (let i = 0; i < outputs.length; ++i) {
assert_equals(outputs[i].dataType(), test.outputs[i].dataType);
assert_array_equals(outputs[i].shape(), test.outputs[i].shape);
assert_equals(outputs[i].dataType, test.outputs[i].dataType);
assert_array_equals(outputs[i].shape, test.outputs[i].shape);
}
} else {
const label = 'lstm_cell_xxx';
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/matmul.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ tests.forEach(test => promise_test(async t => {
const inputB = builder.input('b', test.inputs.b);
if (test.output) {
const output = builder.matmul(inputA, inputB);
assert_equals(output.dataType(), test.output.dataType);
assert_array_equals(output.shape(), test.output.shape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'matmul_123';
const options = {label};
Expand Down
Loading