Skip to content

Commit

Permalink
Remove MLTensorUsage
Browse files Browse the repository at this point in the history
  • Loading branch information
Honry committed Nov 14, 2024
1 parent 77a98b9 commit be33084
Show file tree
Hide file tree
Showing 39 changed files with 1 addition and 78 deletions.
1 change: 0 additions & 1 deletion code/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = {
'CodeMirror': 'readonly',
'executeCodeSnippet': 'readonly',
'sizeOfShape': 'readonly',
'MLTensorUsage': 'readonly',
},
ignorePatterns: ['libs/'],
};
3 changes: 0 additions & 3 deletions code/samples/matmul.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const graph = await builder.build({c});
// Step 3: Bind input and output buffers to the graph and execute.
const bufferA = new Float32Array(3*4).fill(1.0);
const bufferB = new Float32Array(4*3).fill(0.8);
descA.usage = MLTensorUsage.WRITE;
descA.writable = true;
descB.usage = MLTensorUsage.WRITE;
descB.writable = true;
const tensorA = await context.createTensor(descA);
const tensorB = await context.createTensor(descB);
Expand All @@ -24,7 +22,6 @@ const tensorC = await context.createTensor({
dataType: 'float32',
dimensions: [3, 3],
shape: [3, 3],
usage: MLTensorUsage.READ,
readable: true,
});
context.dispatch(graph, {a: tensorA, b: tensorB}, {c: tensorC});
Expand Down
2 changes: 0 additions & 2 deletions code/samples/mul_add.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ const graph = await builder.build({'C': C});
// 3. Bind inputs to the graph and execute for the result.
const bufferA = new Float32Array(4).fill(1.0);
const bufferB = new Float32Array(4).fill(0.8);
desc.usage = MLTensorUsage.WRITE;
desc.writable = true;
const tensorA = await context.createTensor(desc);
const tensorB = await context.createTensor(desc);
context.writeTensor(tensorA, bufferA);
context.writeTensor(tensorB, bufferB);
const tensorC = await context.createTensor({
...desc,
usage: MLTensorUsage.READ,
readable: true,
writable: false,
});
Expand Down
2 changes: 0 additions & 2 deletions code/samples/simple_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const graph = await builder.build({'output': output});
const inputBuffer1 = new Float32Array(TENSOR_SIZE).fill(1);
const inputBuffer2 = new Float32Array(TENSOR_SIZE).fill(1);

desc.usage = MLTensorUsage.WRITE;
desc.writable = true;
const inputTensor1 = await context.createTensor(desc);
const inputTensor2 = await context.createTensor(desc);
Expand All @@ -60,7 +59,6 @@ context.writeTensor(inputTensor2, inputBuffer2);

const outputTensor = await context.createTensor({
...desc,
usage: MLTensorUsage.READ,
readable: true,
writable: false,
});
Expand Down
1 change: 0 additions & 1 deletion face_recognition/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
globals: {
'MLGraphBuilder': 'readonly',
'MLTensorUsage': 'readonly',
'tf': 'readonly',
},
};
2 changes: 0 additions & 2 deletions face_recognition/facenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,12 @@ export class FaceNetNchw {
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});

Expand Down
2 changes: 0 additions & 2 deletions face_recognition/facenet_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,12 @@ export class FaceNetNhwc {
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});

Expand Down
1 change: 0 additions & 1 deletion facial_landmark_detection/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
globals: {
'MLGraphBuilder': 'readonly',
'MLTensorUsage': 'readonly',
'tf': 'readonly',
},
};
2 changes: 0 additions & 2 deletions facial_landmark_detection/face_landmark_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ export class FaceLandmarkNchw {
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});

Expand Down
2 changes: 0 additions & 2 deletions facial_landmark_detection/face_landmark_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,12 @@ export class FaceLandmarkNhwc {
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});

Expand Down
2 changes: 0 additions & 2 deletions facial_landmark_detection/ssd_mobilenetv2_face_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,13 @@ ${nameArray[1]}`;
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
for (const [key, value] of Object.entries(this.outputsInfo)) {
this.outputTensors_[key] = await this.context_.createTensor({
dataType: 'float32',
dimensions: value,
shape: value,
usage: MLTensorUsage.READ,
readable: true,
});
}
Expand Down
2 changes: 0 additions & 2 deletions facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,13 @@ ${nameArray[1]}`;
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
for (const [key, value] of Object.entries(this.outputsInfo)) {
this.outputTensors_[key] = await this.context_.createTensor({
dataType: 'float32',
dimensions: value,
shape: value,
usage: MLTensorUsage.READ,
readable: true,
});
}
Expand Down
1 change: 0 additions & 1 deletion image_classification/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
globals: {
'MLGraphBuilder': 'readonly',
'MLTensorUsage': 'readonly',
},
};
2 changes: 0 additions & 2 deletions image_classification/efficientnet_fp16_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,12 @@ export class EfficientNetFP16Nchw {
shape: this.inputOptions.inputShape,
};
let data = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
data = this.builder_.cast(data, 'float16');
Expand Down
2 changes: 0 additions & 2 deletions image_classification/mobilenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ export class MobileNetV2Nchw {
shape: this.inputOptions.inputShape,
};
let data = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
if (this.dataType_ === 'float16') {
Expand Down
2 changes: 0 additions & 2 deletions image_classification/mobilenet_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,12 @@ export class MobileNetV2Nhwc {
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
const conv0 = this.buildConv_(
Expand Down
2 changes: 0 additions & 2 deletions image_classification/resnet50v1_fp16_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ export class ResNet50V1FP16Nchw {
shape: this.inputOptions.inputShape,
};
let data = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
data = this.builder_.cast(data, 'float16');
Expand Down
2 changes: 0 additions & 2 deletions image_classification/resnet50v2_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ export class ResNet50V2Nchw {
shape: this.inputOptions.inputShape,
};
const data = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
const bn1 = this.buildBatchNorm_(data, '0', '', false);
Expand Down
2 changes: 0 additions & 2 deletions image_classification/resnet50v2_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ export class ResNet50V2Nhwc {
shape: this.inputOptions.inputShape,
};
const input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
const conv1 = await this.buildConv_(
Expand Down
2 changes: 0 additions & 2 deletions image_classification/squeezenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ export class SqueezeNetNchw {
shape: this.inputOptions.inputShape,
};
const data = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
const conv0 = this.buildConv_(data, 'conv0', {strides: [2, 2]});
Expand Down
2 changes: 0 additions & 2 deletions image_classification/squeezenet_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ export class SqueezeNetNhwc {
shape: this.inputOptions.inputShape,
};
const placeholder = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
const conv1 = this.buildConv_(
Expand Down
1 change: 0 additions & 1 deletion lenet/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
ignorePatterns: ['libs/'],
globals: {
'MLGraphBuilder': 'readonly',
'MLTensorUsage': 'readonly',
'BigInt64Array': 'readonly',
'mnist': 'readonly',
},
Expand Down
2 changes: 0 additions & 2 deletions lenet/lenet.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ export class LeNet {
shape: inputShape,
};
let input = this.builder_.input('input', inputDesc);
inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);
this.outputTensor_ = await this.context_.createTensor({
dataType: 'float32',
dimensions: this.outputShape_,
shape: this.outputShape_,
usage: MLTensorUsage.READ,
readable: true,
});
if (this.layout_ === 'nhwc') {
Expand Down
1 change: 0 additions & 1 deletion nnotepad/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
env: {'es6': true, 'browser': true, 'jquery': false, 'node': true},
parserOptions: {ecmaVersion: 2021, sourceType: 'module'},
globals: {'MLTensorUsage': 'readonly'},
};
3 changes: 1 addition & 2 deletions nnotepad/js/nnotepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class WebNNUtil {
const isShapeMethod = typeof operand.shape === 'function';
const operandShape = isShapeMethod ? operand.shape() : operand.shape;
const operandDataType = isShapeMethod ? operand.dataType() :
operand.dataType;
operand.dataType;
const size = [...operandShape].reduce((a, b) => a * b, 1);
const ctor = WebNNUtil.dataTypeToBufferType(operandDataType);
return Reflect.construct(ctor, [size]);
Expand All @@ -52,7 +52,6 @@ class WebNNUtil {
dataType: isShapeMethod ? operand.dataType() : operand.dataType,
dimensions: isShapeMethod ? operand.shape() : operand.shape,
shape: isShapeMethod ? operand.shape() : operand.shape,
usage: MLTensorUsage.READ,
readable: true,
};
const tensor = await context.createTensor(desc);
Expand Down
1 change: 0 additions & 1 deletion nsnet2/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
ignorePatterns: ['libs/'],
globals: {
'MLGraphBuilder': 'readonly',
'MLTensorUsage': 'readonly',
'tf': 'readonly',
},
};
4 changes: 0 additions & 4 deletions nsnet2/nsnet2.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class NSNet2 {
const inputDesc = {dataType: 'float32', dimensions: inputShape, shape: inputShape};
const input = this.builder_.input('input', inputDesc);

inputDesc.usage = MLTensorUsage.WRITE;
inputDesc.writable = true;
this.inputTensor_ = await this.context_.createTensor(inputDesc);

Expand All @@ -64,7 +63,6 @@ export class NSNet2 {
const squeeze95 = this.builder_.reshape(gru93, squeeze95Shape);
const initialState155 = this.builder_.input('initialState155', initialStateDesc);

initialStateDesc.usage = MLTensorUsage.WRITE;
initialStateDesc.writable = true;
this.initialState92Tensor_ = await this.context_.createTensor(initialStateDesc);
this.initialState155Tensor_ = await this.context_.createTensor(initialStateDesc);
Expand All @@ -73,15 +71,13 @@ export class NSNet2 {
dataType: 'float32',
dimensions: inputShape,
shape: inputShape, // Same as inputShape.
usage: MLTensorUsage.READ,
readable: true,
});
const gruOutputShape = [1, batchSize, this.hiddenSize];
const gruOutputDesc = {
dataType: 'float32',
dimensions: gruOutputShape,
shape: gruOutputShape,
usage: MLTensorUsage.READ,
readable: true,
};
this.gru94Tensor_ = await this.context_.createTensor(gruOutputDesc);
Expand Down
1 change: 0 additions & 1 deletion object_detection/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
globals: {
'MLGraphBuilder': 'readonly',
'MLTensorUsage': 'readonly',
},
};
Loading

0 comments on commit be33084

Please sign in to comment.