You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e94faaa
Browse filesBrowse the repository at this point in the historyBrowse files
[Vulkan] Let tensor wrap an external image with caller-supplied sizes (pytorch#21930)
## 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.h` — `external_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
0 commit comments