Skip to content

Conversation

@SS-JIA
Copy link
Contributor

@SS-JIA SS-JIA commented Oct 2, 2024

Stack from ghstack (oldest at bottom):

Context

Fix one (hopefully) final kink with tensor views.

The issue

When creating a tensor view of a tensor that uses deferred memory allocation, at the time the view is created, it will copy the handle of the original tensor's VkImage. However, since the VkImage is not yet bounded to memory, it will have have a VkImageView associated with it, and the tensor view will copy the VkImageView handle and VK_NULL_HANDLE.

Later, the original tensor is expected to be bound to an allocation, at which point it will create an image view and bind the VkImage to memory. However, this does not update its views, which will still have a null VkImageView.

If the tensor view is also bound to the allocation, then the same VkImage will be bound to the same memory multiple times which is against the Vulkan spec.

The fix

Allow binding of VulkanImage and VulkanBuffer copies to only call the binding function if it is not a copy; assume that the original tensor is responsible for binding to memory.

In ComputeGraph, when adding a tensor view, add the created Value as a user of any SharedObject of which the original tensor is also a user.

Differential Revision: D63790718

…tion

## Context

Fix one (hopefully) final kink with tensor views.

### The issue

When creating a tensor view of a tensor that uses deferred memory allocation, at the time the view is created, it will copy the handle of the original tensor's `VkImage`. However, since the `VkImage` is not yet bounded to memory, it will have have a `VkImageView` associated with it, and the tensor view will copy the `VkImageView` handle and `VK_NULL_HANDLE`.

Later, the original tensor is expected to be bound to an allocation, at which point it will create an image view and bind the `VkImage` to memory. However, this does not update its views, which will still have a null `VkImageView`.

If the tensor view is also bound to the allocation, then the same `VkImage` will be bound to the same memory multiple times which is against the Vulkan spec.

### The fix

Allow binding of `VulkanImage` and `VulkanBuffer` copies to only call the binding function if it is not  a copy; assume that the original tensor is responsible for binding to memory.

In `ComputeGraph`, when adding a tensor view, add the created `Value` as a user of any `SharedObject` of which the original tensor is also a user.

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

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 2, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 5aecf69 with merge base 3aa6b14 (image):
💚 Looks good so far! There are no failures yet. 💚

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

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

…mory allocation"

## Context

Fix one (hopefully) final kink with tensor views.

### The issue

When creating a tensor view of a tensor that uses deferred memory allocation, at the time the view is created, it will copy the handle of the original tensor's `VkImage`. However, since the `VkImage` is not yet bounded to memory, it will have have a `VkImageView` associated with it, and the tensor view will copy the `VkImageView` handle and `VK_NULL_HANDLE`.

Later, the original tensor is expected to be bound to an allocation, at which point it will create an image view and bind the `VkImage` to memory. However, this does not update its views, which will still have a null `VkImageView`.

If the tensor view is also bound to the allocation, then the same `VkImage` will be bound to the same memory multiple times which is against the Vulkan spec.

### The fix

Allow binding of `VulkanImage` and `VulkanBuffer` copies to only call the binding function if it is not  a copy; assume that the original tensor is responsible for binding to memory.

In `ComputeGraph`, when adding a tensor view, add the created `Value` as a user of any `SharedObject` of which the original tensor is also a user.

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

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

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

…mory allocation"

## Context

Fix one (hopefully) final kink with tensor views.

### The issue

When creating a tensor view of a tensor that uses deferred memory allocation, at the time the view is created, it will copy the handle of the original tensor's `VkImage`. However, since the `VkImage` is not yet bounded to memory, it will have have a `VkImageView` associated with it, and the tensor view will copy the `VkImageView` handle and `VK_NULL_HANDLE`.

Later, the original tensor is expected to be bound to an allocation, at which point it will create an image view and bind the `VkImage` to memory. However, this does not update its views, which will still have a null `VkImageView`.

If the tensor view is also bound to the allocation, then the same `VkImage` will be bound to the same memory multiple times which is against the Vulkan spec.

### The fix

Allow binding of `VulkanImage` and `VulkanBuffer` copies to only call the binding function if it is not  a copy; assume that the original tensor is responsible for binding to memory.

In `ComputeGraph`, when adding a tensor view, add the created `Value` as a user of any `SharedObject` of which the original tensor is also a user.

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

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

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

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 7559ddd.

@SS-JIA SS-JIA deleted the gh/SS-JIA/101/head branch January 24, 2025 19:44
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.

4 participants