Skip to content

Commit

Permalink
[WebNN] Remove MLTensorUsage
Browse files Browse the repository at this point in the history
  • Loading branch information
Honry committed Nov 13, 2024
1 parent bc2b1b5 commit 230b2fa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
7 changes: 2 additions & 5 deletions js/web/lib/wasm/jsep/webnn/tensor-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ class TensorIdTracker {
}

// eslint-disable-next-line no-bitwise
const usage = MLTensorUsage.READ | MLTensorUsage.WRITE;
this.wrapper = await this.tensorManager.getCachedTensor(dataType, shape, usage, true, true);
this.wrapper = await this.tensorManager.getCachedTensor(dataType, shape, true, true);

if (copyOld && this.activeUpload) {
this.wrapper.write(this.activeUpload);
Expand Down Expand Up @@ -329,7 +328,7 @@ class TensorManagerImpl implements TensorManager {
shape: readonly number[],
): TensorId {
const tensorId = createNewTensorId();
// Defaulting to READ | WRITE if usage is not provided.
// Defaulting writable and readable to true if they are not provided.
// eslint-disable-next-line no-bitwise
const wrapper = new TensorWrapper({
sessionId: this.backend.currentSessionId,
Expand All @@ -349,7 +348,6 @@ class TensorManagerImpl implements TensorManager {
public async getCachedTensor(
dataType: MLOperandDataType,
shape: readonly number[],
usage: MLTensorUsageFlags,
writable: boolean,
readable: boolean,
): Promise<TensorWrapper> {
Expand All @@ -368,7 +366,6 @@ class TensorManagerImpl implements TensorManager {
dataType,
shape,
dimensions: shape,
usage,
writable,
readable,
});
Expand Down
10 changes: 0 additions & 10 deletions js/web/lib/wasm/jsep/webnn/webnn.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,7 @@ interface MLTensor {

type MLNamedTensor = Record<string, MLTensor>;

type MLTensorUsageFlags = number;

// TODO(@Honry): Remove this once it is deprecated in Chromium.
declare const MLTensorUsage: {
readonly WEBGPU_INTEROP: MLTensorUsageFlags;
readonly READ: MLTensorUsageFlags;
readonly WRITE: MLTensorUsageFlags;
};

interface MLTensorDescriptor extends MLOperandDescriptor {
usage: MLTensorUsageFlags;
importableToWebGPU?: boolean;
readable?: boolean;
writable?: boolean;
Expand Down
2 changes: 0 additions & 2 deletions js/web/test/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ async function createMLTensorForOutput(mlContext: MLContext, type: ort.Tensor.Ty
shape: dims as number[],
// Assign both shape and dimensions while transitioning to new API.
dimensions: dims as number[],
usage: MLTensorUsage.READ,
readable: true,
});

Expand All @@ -686,7 +685,6 @@ async function createMLTensorForInput(mlContext: MLContext, cpuTensor: ort.Tenso
shape: cpuTensor.dims as number[],
// Assign both shape and dimensions while transitioning to new API.
dimensions: cpuTensor.dims as number[],
usage: MLTensorUsage.WRITE,
writable: true,
});
mlContext.writeTensor(mlTensor, cpuTensor.data);
Expand Down

0 comments on commit 230b2fa

Please sign in to comment.