Skip to content

Conversation

@gyagp
Copy link

@gyagp gyagp commented Jun 17, 2022

This is to unify the implementation of fromPixels with other ops for better maintenance.

Close #5536

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@gyagp gyagp requested a review from qjia7 June 17, 2022 09:04
@gyagp gyagp changed the title webgpu: Make fromPixels a plain op webgpu: Make fromPixels not so special Jun 18, 2022
@gyagp gyagp force-pushed the frompixels2 branch 2 times, most recently from dc53dc9 to ee3cb16 Compare June 18, 2022 11:37
@gyagp
Copy link
Author

gyagp commented Jun 18, 2022

@qjia7 @axinging @xhcao PTAL!

Copy link
Contributor

@qjia7 qjia7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

// Short-circuit the computation since the result is empty (has 0 in its
// shape).
const outData = this.tensorMap.get(output.dataId);
outData.values =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a situation that output is not null, but output.shape is 0, output is not recorded in tensorMap? if so, outData is null.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tensor should be recorded in tensorMap. If output is not null, then it's already recorded.

this.device, program, pipelineLayout, inputsData, output);
});
const pipeline = key in this.pipelineCache ?
this.pipelineCache[key] :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the place to add elements into pipelineCache?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will fix in next update.

@gyagp
Copy link
Author

gyagp commented Jun 22, 2022

@qjia7 @axinging @xhcao I did further refactoring to unify the texture and buffer. Please review this again.

Copy link
Contributor

@qjia7 qjia7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check whether all fromPixels cases pass if set WEBGPU_USE_IMPORT to true.

const tensorData = this.tensorMap.get(tensor.dataId);

if (tensorData.textureInfo) {
return (tensorData.textureInfo.texture as GPUTexture).createView();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget the situation that tensorData.textureInfo.texture may be a GPUExternalTexture?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const externalTextureDescriptor = {source: pixels as HTMLVideoElement};
texture = backend.device.importExternalTexture(externalTextureDescriptor);
textureInfo = {
width: pixels.width,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you directly use the width height variables? pixels.width and pixels.height may not equal to width height in outputShape (see L57).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

format: textureFormat,
usage: textureUsage,
return {
width: externalImage.width,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful that externalImage.width may be not equal to outShape[1]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
this.uniformDisposalQueue.forEach(
d => this.bufferManager.releaseBuffer(d.buffer, d.byteSize, d.usage));
d => this.bufferManager.releaseBuffer(d.buffer, d.size, d.usage));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Maybe we can merge releaseResource and releaseBuffer in the next change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

releaseResource includes the buffer and texture management, so they don't need to be merged.

@gyagp
Copy link
Author

gyagp commented Jun 23, 2022

@qjia7 I enabled the fromPixels tests with both WEBGPU_USE_IMPORT true and false, and make sure the video is correctly loaded. Please take another look. Thanks!

Copy link
Contributor

@qjia7 qjia7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@gyagp
Copy link
Author

gyagp commented Jun 23, 2022

@xhcao Will you take another look at this PR?

Copy link
Contributor

@xhcao xhcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@gyagp gyagp merged commit c4c1e18 into tensorflow:master Jun 24, 2022
@gyagp gyagp deleted the frompixels2 branch June 24, 2022 07:31
@hujiajie
Copy link
Contributor

Has anyone encountered this error after the change?

Chrome 105.0.0.0 (Windows 10) webgpu backend webgpu webgpu {"WEBGPU_CPU_FORWARD":false} should behave well if WEBGPU_USER_IMPORT is true or false FAILED
 Error: The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.
     at fromPixels_ (tfjs-core/src/ops/browser.ts:115:13 <- tfjs/tfjs-backend-webgpu/src/tfjs-backend-webgpu_test_bundle.js:5941:15)
     at Object.<anonymous> (tfjs-core/src/ops/browser.ts:279:10 <- tfjs/tfjs-backend-webgpu/src/tfjs-backend-webgpu_test_bundle.js:6021:14)
     at <Jasmine>
     at tfjs/tfjs-backend-webgpu/src/tfjs-backend-webgpu_test_bundle.js:52:64
     at <Jasmine>
     at __async (tfjs-backend-webgpu/src/tfjs-backend-webgpu_test_bundle.js:36:12)
     at Object.fromPixelsAsync (tfjs-backend-webgpu/src/tfjs-backend-webgpu_test_bundle.js:6004:12)
     at ../../tfjs-backend-webgpu/src/backend_webgpu_test.ts:248:36 <- tfjs/tfjs-backend-webgpu/src/tfjs-backend-webgpu_test_bundle.js:84990:47
     at <Jasmine>
     at fulfilled (tfjs-backend-webgpu/src/tfjs-backend-webgpu_test_bundle.js:39:27)

@hujiajie
Copy link
Contributor

I did more tests today:

  1. the issue seems to be reproducible every time on UHD 620
  2. the issue happens occasionally (maybe <10%) on UHD 630
  3. the issue was not reproduced if I disabled hardware video decoding on UHD 620

@gyagp
Copy link
Author

gyagp commented Jun 29, 2022

I suggest to open a separate issue for this. Like we discussed in the meeting, can you report the readyState? The Error triggered in TFJS is not necessary and wrong, maybe we can simply remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

webgpu: fromPixels for HTMLVideoElement related cases fail to execute 'importExternalTexture'

5 participants