Skip to content

Enable Dynamic shape support via tensor virtual and physical resizing #2340

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

Closed
wants to merge 1 commit into from

Conversation

SS-JIA
Copy link
Contributor

@SS-JIA SS-JIA commented Mar 10, 2024

Summary:

Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

  1. Discarding underlying vkImage or vkBuffer and reallocating a new vkImage or vkBuffer with updated sizes. This method is intended to be used when the current vkImage or vkBuffer is not large enough to contain the new sizes.
  2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying vkImage or vkBuffer as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

Differential Revision: D54728401

Copy link

pytorch-bot bot commented Mar 10, 2024

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit 7be9040 with merge base e5ef31d (image):

NEW FAILURES - The following jobs have failed:

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 Mar 10, 2024
@facebook-github-bot
Copy link
Contributor

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

SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 10, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from e820fee to c3990de Compare March 10, 2024 19:49
@facebook-github-bot
Copy link
Contributor

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

SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 10, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from c3990de to c98c726 Compare March 10, 2024 19:51
@facebook-github-bot
Copy link
Contributor

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

SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 10, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from c98c726 to b0d5a6f Compare March 10, 2024 20:18
@facebook-github-bot
Copy link
Contributor

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

SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 10, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from b0d5a6f to 461bc8f Compare March 10, 2024 20:19
@facebook-github-bot
Copy link
Contributor

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

SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 11, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from 461bc8f to 375480b Compare March 11, 2024 16:00
SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 11, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

Reviewed By: jorgep31415

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from 375480b to 758449b Compare March 11, 2024 17:50
@facebook-github-bot
Copy link
Contributor

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

1 similar comment
@facebook-github-bot
Copy link
Contributor

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

jorgep31415 added a commit that referenced this pull request Mar 11, 2024
Before: Each node contains a `UniformParamsBuffer`.
After: Each node contains a `std::vector<std::shared_ptr<UniformParamsBuffer>>`.

In follow up changes, we will break up parameters to be passed via multiple UniformParamsBuffer, since
1. some are tensor-specific (e.g. image extents) and
2. others are operator-specific (e.g. alpha for binary ops).

Hence, we need **`std::vector`**.

We are adding the methods for #1 in #2340. Since #1 and #2 will be owned by different objects, we need **pointers**. Since #1 is owned by `vTensor` which is non-copyable, we can't use unique_ptr so we need **`std::shared_ptr`**.

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

[ghstack-poisoned]
jorgep31415 added a commit that referenced this pull request Mar 11, 2024
Before: Each node contains a `UniformParamsBuffer`.
After: Each node contains a `std::vector<std::shared_ptr<UniformParamsBuffer>>`.

In follow up changes, we will break up parameters to be passed via multiple UniformParamsBuffer, since
1. some are tensor-specific (e.g. image extents) and
2. others are operator-specific (e.g. alpha for binary ops).

Hence, we need **`std::vector`**.

We are adding the methods for #1 in #2340. Since #1 and #2 will be owned by different objects, we need **pointers**. Since #1 is owned by `vTensor` which is non-copyable, we can't use unique_ptr so we need **`std::shared_ptr`**.

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

ghstack-source-id: 218195447
Pull Request resolved: #2348
SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 11, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

bypass-github-export-checks

Reviewed By: jorgep31415

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from 758449b to a6a726e Compare March 11, 2024 19:47
@facebook-github-bot
Copy link
Contributor

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

SS-JIA added a commit to SS-JIA/pytorch that referenced this pull request Mar 11, 2024
…resizing (pytorch#121598)

Summary:

X-link: pytorch/executorch#2340

## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

bypass-github-export-checks

Test Plan: Check CI. Tests have also been added to `vulkan_compute_api_test` that test the two methods of tensor resizing.

Reviewed By: jorgep31415

Differential Revision: D54728401
SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 11, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

bypass-github-export-checks

Reviewed By: jorgep31415

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from a6a726e to ad3458c Compare March 11, 2024 19:47
@facebook-github-bot
Copy link
Contributor

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

facebook-github-bot pushed a commit that referenced this pull request Mar 11, 2024
Summary:
bypass-github-export-checks

Pull Request resolved: #2348

Before: Each node contains a `UniformParamsBuffer`.
After: Each node contains a `std::vector<std::shared_ptr<UniformParamsBuffer>>`.

In follow up changes, we will break up parameters to be passed via multiple UniformParamsBuffer, since
1. some are tensor-specific (e.g. image extents) and
2. others are operator-specific (e.g. alpha for binary ops).

Hence, we need **`std::vector`**.

We are adding the methods for #1 in #2340. Since #1 and #2 will be owned by different objects, we need **pointers**. Since #1 is owned by `vTensor` which is non-copyable, we can't use unique_ptr so we need **`std::shared_ptr`**.
ghstack-source-id: 218195447
exported-using-ghexport

Reviewed By: SS-JIA

Differential Revision: D54691831

fbshipit-source-id: 84ab9f777e247fd56234290ed7f7343b9701c73f
SS-JIA added a commit to SS-JIA/executorch-1 that referenced this pull request Mar 12, 2024
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

bypass-github-pytorch-ci-checks
bypass-github-executorch-ci-checks
bypass-github-export-checks

Reviewed By: jorgep31415

Differential Revision: D54728401
@SS-JIA SS-JIA force-pushed the export-D54728401 branch from ad3458c to ff1fa4f Compare March 12, 2024 04:37
…pytorch#2340)

Summary:
X-link: pytorch/pytorch#121598


## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

bypass-github-pytorch-ci-checks
bypass-github-executorch-ci-checks
bypass-github-export-checks

Reviewed By: jorgep31415

Differential Revision: D54728401
@facebook-github-bot
Copy link
Contributor

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

@SS-JIA SS-JIA force-pushed the export-D54728401 branch from ff1fa4f to 7be9040 Compare March 12, 2024 04:38
@facebook-github-bot
Copy link
Contributor

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

SS-JIA added a commit to SS-JIA/pytorch that referenced this pull request Mar 12, 2024
…resizing (pytorch#121598)

Summary:

X-link: pytorch/executorch#2340

## Context

This changeset lays the foundations for supporting dynamic shapes in the ExecuTorch Vulkan delegate via allowing Tensors to be resized in one of two ways:

1. Discarding underlying `vkImage` or `vkBuffer` and reallocating a new `vkImage` or `vkBuffer` with updated sizes. This method is intended to be used when the current `vkImage` or `vkBuffer` is not large enough to contain the new sizes.
2. Update the tensor's size metadata without reallocating any new resources. This allows shaders to interpret the underlying `vkImage` or `vkBuffer` as if it were smaller than it actually is, and allows command buffers to be preserved when sizes are changed.

bypass-github-pytorch-ci-checks
bypass-github-executorch-ci-checks
bypass-github-export-checks

Test Plan: Check CI. Tests have also been added to `vulkan_compute_api_test` that test the two methods of tensor resizing.

Reviewed By: jorgep31415

Differential Revision: D54728401
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 4dfb637.

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 Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants