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 2c88f57
Browse filesBrowse the repository at this point in the historyBrowse files
[Vulkan] Let tensor wrap an external buffer with caller-supplied sizes (pytorch#22031)
Follow-up to pytorch#21930, which added external-image storage.
`vTensorStorage` had no buffer equivalent, so a tensor could only be
built over externally owned storage if that storage was a `VulkanImage`.
This adds an `external_buffer` parameter beside `external_image`, along
with a `vTensorStorage` constructor and a
`ComputeGraph::add_tensor` overload taking a `VulkanBuffer`. The buffer
is held as a `VulkanBuffer` copy, which aliases the handle with
`is_copy_` set, so the view never frees memory it does not own. At most
one of the two may be set.
## Files
- `backends/vulkan/runtime/api/containers/Tensor.h` — `external_buffer`
on the `vTensor` constructor, and the `vTensorStorage` buffer
constructor.
- `backends/vulkan/runtime/api/containers/Tensor.cpp` — the buffer
storage constructor, external-storage selection, and the size check.
- `backends/vulkan/runtime/graph/ComputeGraph.h`, `.cpp` — an
`add_tensor` overload taking sizes, dtype, memory layout and a buffer.
- `backends/vulkan/test/vulkan_compute_api_test.cpp` — 3 new tests.
## Testing
`vulkan_compute_api_test` New coverage: wrapping a buffer at `[1, 37, 8,
64]` and keeping the sizes and buffer storage type; rejecting sizes
larger than the buffer; and a view reporting `is_copy_of` the source,
with the source buffer still live after the view is destroyed and
deferred cleanup has run.
cc @SS-JIA@manuelcandales@digantdesai@cbilgin
0 commit comments