From 6102da54b560dbf954868026f1072f1006d5873d Mon Sep 17 00:00:00 2001 From: Qin Jiajia Date: Tue, 30 May 2023 09:22:06 +0800 Subject: [PATCH] webgpu: Move the readSync warning position The warning should only happen when there is really data reading back from gpu to cpu. --- tfjs-backend-webgpu/src/backend_webgpu.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tfjs-backend-webgpu/src/backend_webgpu.ts b/tfjs-backend-webgpu/src/backend_webgpu.ts index b21c9be1030..9b5faa9f345 100644 --- a/tfjs-backend-webgpu/src/backend_webgpu.ts +++ b/tfjs-backend-webgpu/src/backend_webgpu.ts @@ -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; @@ -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;