Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
egalli committed Dec 11, 2024
1 parent 18224f3 commit be01b60
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions js/web/lib/wasm/jsep/backend-webnn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class WebNNBackend {
/**
* Temporary tensors for the current session.
*/
private temporarySessionTensors: Map<number, TensorId[]> = new Map();
private temporarySessionTensorIds: Map<number, TensorId[]> = new Map();

constructor(env: Env) {
configureLogger(env.logLevel!, !!env.debug);
Expand All @@ -106,15 +106,15 @@ export class WebNNBackend {

public onRunEnd(sessionId: number): void {
LOG_DEBUG('verbose', () => `[WebNN] onRunEnd {sessionId: ${sessionId}}`);
const tensors = this.temporarySessionTensors.get(sessionId);
if (!tensors) {
const tensorIds = this.temporarySessionTensorIds.get(sessionId);
if (!tensorIds) {
return;
}
for (const tensor of tensors) {
LOG_DEBUG('verbose', () => `[WebNN] releasing temporary tensor {tensorId: ${tensor}}`);
this.tensorManager.releaseTensorId(tensor);
for (const tensorId of tensorIds) {
LOG_DEBUG('verbose', () => `[WebNN] releasing temporary tensor {tensorId: ${tensorId}}`);
this.tensorManager.releaseTensorId(tensorId);
}
this.temporarySessionTensors.delete(sessionId);
this.temporarySessionTensorIds.delete(sessionId);
}

public async createMLContext(optionsOrDevice?: MLContextOptions | GPUDevice): Promise<MLContext> {
Expand Down Expand Up @@ -229,9 +229,9 @@ export class WebNNBackend {
}
const tensorId = this.tensorManager.reserveTensorId();
await this.tensorManager.ensureTensor(tensorId, dataType, shape, false);
const tensors = this.temporarySessionTensors.get(this.currentSessionId);
const tensors = this.temporarySessionTensorIds.get(this.currentSessionId);
if (!tensors) {
this.temporarySessionTensors.set(this.currentSessionId, [tensorId]);
this.temporarySessionTensorIds.set(this.currentSessionId, [tensorId]);
} else {
tensors.push(tensorId);
}
Expand Down

0 comments on commit be01b60

Please sign in to comment.