Skip to content

Commit

Permalink
webgpu: Move the readSync warning position (tensorflow#7724)
Browse files Browse the repository at this point in the history
The warning should only happen when there is real data reading from 
gpu to cpu.
  • Loading branch information
qjia7 authored May 30, 2023
1 parent 428e55b commit dc65451
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tfjs-backend-webgpu/src/backend_webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,6 @@ export class WebGPUBackend extends KernelBackend {
}

override readSync(dataId: object): BackendValues {
if (!this.hasReadSyncWarned) {
this.hasReadSyncWarned = true;
console.warn(
`The performance of synchronously reading data from GPU to CPU is ` +
`poor on the webgpu backend, please use asynchronous APIs instead.`);
}

const tensorData = this.tensorMap.get(dataId);
const {values, complexTensorInfos} = tensorData;

Expand All @@ -403,6 +396,13 @@ export class WebGPUBackend extends KernelBackend {
return complexVals;
}

if (!this.hasReadSyncWarned) {
this.hasReadSyncWarned = true;
console.warn(
`The performance of synchronously reading data from GPU to CPU is ` +
`poor on the webgpu backend, please use asynchronous APIs instead.`);
}

const alphaModes: GPUCanvasAlphaMode[] = ['opaque', 'premultiplied'];

const buffer = tensorData.resource as GPUBuffer;
Expand Down

0 comments on commit dc65451

Please sign in to comment.