Skip to content

[ET-VK] Clean up vTensor member variables and expose dim order UBO and push constant #11599

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

Merged
merged 3 commits into from
Jun 12, 2025

Conversation

SS-JIA
Copy link
Contributor

@SS-JIA SS-JIA commented Jun 12, 2025

Stack from ghstack (oldest at bottom):

Changes

  • Add dim order to the list of tensor metadata that can be ingested by compute shaders
  • Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in uniform_data_ and use uniform_data_ as the source of truth

Motivation

Add dim order to the list of tensor metadata that can be ingested by compute shaders

Knowing the dim order is necessary to convert between a linear buffer index to N-dimensional tensor index using a tensor's strides. Technically, the dim order can be inferred from the strides by performing an index sort on the strides array; however to prevent compute shaders from having to do this operation frequently, it is more efficient to pass in the dim order directly to the compute shader.

Currently, ET-VK compute shaders make strong assumptions about the dim order of buffer backed tensors so as to avoid having to dynamically generate the dim order from the strides array. However, these assumptions are not enforced and it is more correct to just account for the dim order rather than make assumptions. This will be addressed in the next diff.

Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in uniform_data_ and use uniform_data_ as the source of truth

I realized that the purpose of these "derived metadata" is to simply convert default tensor metadata such sizes, strides, etc. to a form where they can be used in a compute shader. There is no need to store these derived metadata persistently, since they are pretty much only useful in the final ivec4 form they exist as inside UniformData. So to simplify vTensor and to reduce the size of the class, I elected to remove these superfluous data members.

Performance Impact

  • Potential memory footprint improvement from reducing the size of vTensor.

Differential Revision: D76393427

…O and push constant

## Changes

* Add dim order to the list of tensor metadata that can be ingested by compute shaders
* Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in `uniform_data_` and use `uniform_data_` as the source of truth

## Motivation

> Add dim order to the list of tensor metadata that can be ingested by compute shaders

Knowing the dim order is necessary to convert between a linear buffer index to N-dimensional tensor index using a tensor's strides. Technically, the dim order can be inferred from the strides by performing an index sort on the strides array; however to prevent compute shaders from having to do this operation frequently, it is more efficient to pass in the dim order directly to the compute shader.

Currently, ET-VK compute shaders make strong assumptions about the dim order of buffer backed tensors so as to avoid having to dynamically generate the dim order from the strides array. However, these assumptions are not enforced and it is more correct to just account for the dim order rather than make assumptions. This will be addressed in the next diff.

> Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in `uniform_data_` and use `uniform_data_` as the source of truth

I realized that the purpose of these "derived metadata" is to simply convert default tensor metadata such sizes, strides, etc. to a form where they can be used in a compute shader. There is no need to store these derived metadata persistently, since they are pretty much only useful in the final `ivec4` form they exist as inside `UniformData`. So to simplify `vTensor` and to reduce the size of the class, I elected to remove these superfluous data members.

## Performance Impact

* Potential memory footprint improvement from reducing the size of `vTensor`.

Differential Revision: [D76393427](https://our.internmc.facebook.com/intern/diff/D76393427/)

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Jun 12, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/11599

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures

As of commit f3d245f with merge base 4a14fdd (image):

NEW FAILURES - The following jobs have failed:

  • pull / unittest / linux / linux-job (gh)
    /pytorch/executorch/backends/vulkan/runtime/api/containers/Tensor.cpp:651:17: error: no matching constructor for initialization of 'vkcompute::api::vTensor::TextureLimits'
  • pull / unittest-editable / linux / linux-job (gh)
    /pytorch/executorch/backends/vulkan/runtime/api/containers/Tensor.cpp:651:17: error: no matching constructor for initialization of 'vkcompute::api::vTensor::TextureLimits'

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 12, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76393427

Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

…m order` UBO and push constant"

## Changes

* Add dim order to the list of tensor metadata that can be ingested by compute shaders
* Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in `uniform_data_` and use `uniform_data_` as the source of truth

## Motivation

> Add dim order to the list of tensor metadata that can be ingested by compute shaders

Knowing the dim order is necessary to convert between a linear buffer index to N-dimensional tensor index using a tensor's strides. Technically, the dim order can be inferred from the strides by performing an index sort on the strides array; however to prevent compute shaders from having to do this operation frequently, it is more efficient to pass in the dim order directly to the compute shader.

Currently, ET-VK compute shaders make strong assumptions about the dim order of buffer backed tensors so as to avoid having to dynamically generate the dim order from the strides array. However, these assumptions are not enforced and it is more correct to just account for the dim order rather than make assumptions. This will be addressed in the next diff.

> Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in `uniform_data_` and use `uniform_data_` as the source of truth

I realized that the purpose of these "derived metadata" is to simply convert default tensor metadata such sizes, strides, etc. to a form where they can be used in a compute shader. There is no need to store these derived metadata persistently, since they are pretty much only useful in the final `ivec4` form they exist as inside `UniformData`. So to simplify `vTensor` and to reduce the size of the class, I elected to remove these superfluous data members.

## Performance Impact

* Potential memory footprint improvement from reducing the size of `vTensor`.

Differential Revision: [D76393427](https://our.internmc.facebook.com/intern/diff/D76393427/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76393427

…m order` UBO and push constant"

## Changes

* Add dim order to the list of tensor metadata that can be ingested by compute shaders
* Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in `uniform_data_` and use `uniform_data_` as the source of truth

## Motivation

> Add dim order to the list of tensor metadata that can be ingested by compute shaders

Knowing the dim order is necessary to convert between a linear buffer index to N-dimensional tensor index using a tensor's strides. Technically, the dim order can be inferred from the strides by performing an index sort on the strides array; however to prevent compute shaders from having to do this operation frequently, it is more efficient to pass in the dim order directly to the compute shader.

Currently, ET-VK compute shaders make strong assumptions about the dim order of buffer backed tensors so as to avoid having to dynamically generate the dim order from the strides array. However, these assumptions are not enforced and it is more correct to just account for the dim order rather than make assumptions. This will be addressed in the next diff.

> Do not persistently store derivative metadata (i.e. padded sizes, padded numel, unsqueezed strides, etc.) as members of vTensor; instead store these in `uniform_data_` and use `uniform_data_` as the source of truth

I realized that the purpose of these "derived metadata" is to simply convert default tensor metadata such sizes, strides, etc. to a form where they can be used in a compute shader. There is no need to store these derived metadata persistently, since they are pretty much only useful in the final `ivec4` form they exist as inside `UniformData`. So to simplify `vTensor` and to reduce the size of the class, I elected to remove these superfluous data members.

## Performance Impact

* Potential memory footprint improvement from reducing the size of `vTensor`.

Differential Revision: [D76393427](https://our.internmc.facebook.com/intern/diff/D76393427/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76393427

@facebook-github-bot facebook-github-bot merged commit d0c9233 into gh/SS-JIA/240/base Jun 12, 2025
94 of 98 checks passed
@facebook-github-bot facebook-github-bot deleted the gh/SS-JIA/240/head branch June 12, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants