[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpack input in TopK WebGL kernel #5286

Merged
merged 4 commits into from
Jul 2, 2021

Conversation

ahmedsabie
Copy link
Contributor
@ahmedsabie ahmedsabie commented Jul 1, 2021

This prevents each shader from having to unpack the input again due to lazy unpacking

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


This change is Reviewable

Copy link
Collaborator
@lina128 lina128 left a comment

Choose a reason for hiding this comment

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

I think the current mechanism can handle this case:

The GPGPUProgram defaults packedInputs and packedOutput to false: https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-webgl/src/gpgpu_math.ts#L31-L33
When an input is packed, and the program expects an unpacked input, it will do the unpacking here: https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-webgl/src/backend_webgl.ts#L823

Maybe I missed anything?

Reviewable status: 0 of 1 approvals obtained (waiting on @pyu10055)

@ahmedsabie
Copy link
Contributor Author

The issue isn't that its unpacking, it's that it unpacks for every shader so it's repeating computation

Copy link
Collaborator
@lina128 lina128 left a comment

Choose a reason for hiding this comment

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

Do you mean, because TopK call the shaders repeatedly in a loop, and so it is doing unpacking and packing in each iteration?

Reviewable status: 0 of 1 approvals obtained (waiting on @pyu10055)

@ahmedsabie
Copy link
Contributor Author

Yes, i think in other kernels shaders aren't usually repeated and if they are it will be on new input not the original input, so they don't have that issue

Copy link
Collaborator
@lina128 lina128 left a comment

Choose a reason for hiding this comment

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

Make sense. In that case, should we do the reshape after the unpack, because reshape of unpacked tensor is not expensive. Otherwise, LGTM. Also curious how much perf improvement with this change?

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @pyu10055)

Copy link
Collaborator
@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 2 of 1 approvals obtained

@ahmedsabie
Copy link
Contributor Author

Make sense. In that case, should we do the reshape after the unpack, because reshape of unpacked tensor is not expensive. Otherwise, LGTM. Also curious how much perf improvement with this change?

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @pyu10055)

Great catch, will swap the reshape. The change was about a ~20% improvement on packed inputs (0 for unpacked since there's no issues with packing there)

@ahmedsabie ahmedsabie merged commit ff04476 into tensorflow:master Jul 2, 2021
@ahmedsabie ahmedsabie deleted the packed-topk branch July 2, 2021 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants