Skip to content

[Vulkan] Let tensor adopt an image with caller-supplied sizes - #21930

Open
kiymetakdemir wants to merge 1 commit into
pytorch:mainfrom
kiymetakdemir:vulkan-tensor-adopt-image
Open

[Vulkan] Let tensor adopt an image with caller-supplied sizes#21930
kiymetakdemir wants to merge 1 commit into
pytorch:mainfrom
kiymetakdemir:vulkan-tensor-adopt-image

Conversation

@kiymetakdemir

@kiymetakdemir kiymetakdemir commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

vTensor(context, image) infers the tensor's shape from the image's extents, and a VkImage has three: width, height and depth, so that inference always yields a rank-3 shape. A logical shape such as [B, S, H, D] is unreachable, which blocks wrapping an externally owned image as a tensor whose axes the shaders can index.

This lets the caller pass the image to the main vTensor constructor instead, so the sizes, dtype and layout come from the caller and only the storage comes from the image. A ComputeGraph::add_tensor overload reaches it. The image is held as a VulkanImage copy, which aliases the handle with is_copy_ set, so the adopted view never destroys memory. An extent check rejects an image whose size disagrees with the requested sizes.

The allocating path is untouched. The parameter defaults to nullptr and construction only diverges when it is set, so logical_limits still seeds from the physical extents as before.

Files

  • backends/vulkan/runtime/api/containers/Tensor.hadopt_image on the vTensor constructor.
  • backends/vulkan/runtime/api/containers/Tensor.cpp — storage selection between the adopting and allocating vTensorStorage, and the extent check.
  • backends/vulkan/runtime/graph/ComputeGraph.h, .cpp — an add_tensor overload taking sizes, dtype, memory layout and an image.
  • backends/vulkan/test/vulkan_compute_api_test.cpp — 3 new tests.

Testing

vulkan_compute_api_test New coverage: adopting at [1, 37, 8, 64] and keeping all four sizes, asserted against the inferring constructor collapsing the same image to rank 3; rejecting an image whose extents disagree with the requested sizes; and an adopted view reporting is_copy_of the source and leaving the source image live after the view is destroyed and deferred cleanup has run.

cc @SS-JIA @manuelcandales @digantdesai @cbilgin

@kiymetakdemir kiymetakdemir self-assigned this Aug 19, 2026
@kiymetakdemir
kiymetakdemir requested a review from SS-JIA as a code owner August 19, 2026 00:45
@pytorch-bot pytorch-bot Bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Aug 19, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 Unclassified Failure

As of commit 47404f6 with merge base 14326d9 (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • pull / test-arduino-library / run / arduino-library (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    RuntimeError: Command docker exec -t 61d4318a65b614a179cec53d26a7b67968da936582d8df742b72f2cee6938d08 /exec failed with exit code 2

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

@meta-cla meta-cla 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 Aug 19, 2026
@github-actions

Copy link
Copy Markdown

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.

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. module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant