Skip to content

Commit 92adb94

Browse files
SS-JIAfacebook-github-bot
authored andcommitted
vTensor cleanup 2/N - remove discard_and_reallocate API (#5422)
Summary: Pull Request resolved: #5422 ## Context Remove the unused `discard_and_reallocate()` API. The purpose of this AP is to allow a `vTensor` instance to request a new memory allocation when being resized to a larger size than what the current memory allocation can support. This was originally intended to support unbounded dynamic shapes in the ExecuTorch Vulkan delegate, but it is unlikely that this functionality will ever be used. The reason is that re-allocating memory would require re-encoding the command buffer, which goes against the execution philosophy of the Vulkan delegate (encode command buffer once, submit repeatedly). ghstack-source-id: 243061031 exported-using-ghexport Reviewed By: jorgep31415 Differential Revision: D62878649 fbshipit-source-id: e293fe2dfcbbec8c615370a370db14424b971369
1 parent aaf73d8 commit 92adb94

File tree

3 files changed

+0
-104
lines changed

3 files changed

+0
-104
lines changed

backends/vulkan/runtime/api/containers/Tensor.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -396,30 +396,6 @@ bool vTensorStorage::is_copy_of(const vTensorStorage& other) const {
396396
return image_.is_copy_of(other.image_);
397397
}
398398

399-
void vTensorStorage::discard_and_reallocate(
400-
const std::vector<int64_t>& padded_sizes,
401-
const std::vector<int64_t>& axis_map,
402-
const utils::GPUMemoryLayout gpu_memory_layout,
403-
const vkapi::ScalarType dtype) {
404-
const bool image_owns_memory = image_.owns_memory();
405-
const bool buffer_owns_memory = buffer_.owns_memory();
406-
407-
flush();
408-
409-
image_extents_ =
410-
calculate_image_extents(padded_sizes, axis_map, gpu_memory_layout);
411-
image_ = allocate_image(
412-
context_,
413-
image_extents_,
414-
storage_type_,
415-
to_vkformat(dtype),
416-
image_owns_memory);
417-
418-
buffer_length_ = utils::multiply_integers(padded_sizes);
419-
buffer_ = allocate_buffer(
420-
context_, buffer_length_, storage_type_, dtype, buffer_owns_memory);
421-
}
422-
423399
//
424400
// vTensor
425401
//
@@ -805,15 +781,5 @@ void vTensor::virtual_transpose(const int64_t dim0, const int64_t dim1) {
805781
update_metadata();
806782
}
807783

808-
void vTensor::reallocate(const std::vector<int64_t>& new_sizes) {
809-
sizes_ = new_sizes;
810-
update_metadata();
811-
storage_.discard_and_reallocate(
812-
calculate_padded_sizes(new_sizes, memory_layout_),
813-
axis_map_,
814-
memory_layout_,
815-
dtype_);
816-
}
817-
818784
} // namespace api
819785
} // namespace vkcompute

backends/vulkan/runtime/api/containers/Tensor.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,6 @@ class vTensorStorage final {
157157
* Used for checking if this vTensorStorage is a copy of another instance
158158
*/
159159
bool is_copy_of(const vTensorStorage& other) const;
160-
161-
void discard_and_reallocate(
162-
const std::vector<int64_t>& padded_sizes,
163-
const std::vector<int64_t>& axis_map,
164-
const utils::GPUMemoryLayout gpu_memory_layout,
165-
const vkapi::ScalarType dtype);
166160
};
167161

168162
class vTensor final {
@@ -535,12 +529,6 @@ class vTensor final {
535529
*/
536530
void virtual_transpose(const int64_t dim0, const int64_t dim1);
537531

538-
/*
539-
* Discard the underlying VkImage or VkBuffer and re-allocate based on new
540-
* tensor sizes
541-
*/
542-
void reallocate(const std::vector<int64_t>& new_sizes);
543-
544532
/*
545533
* Check if this vTensor instance is a view of another vTensor instance
546534
*/

backends/vulkan/test/vulkan_compute_api_test.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -940,64 +940,6 @@ TEST_F(VulkanComputeAPITest, use_non_bound_textures_fails) {
940940
EXPECT_THROW(fill_vtensor(a, data_a), vkapi::Error);
941941
}
942942

943-
TEST_F(VulkanComputeAPITest, tensor_reallocation_test) {
944-
std::vector<int64_t> sizes = {4, 4, 1};
945-
vTensor a = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ true);
946-
vTensor b = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ true);
947-
vTensor c = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ true);
948-
949-
execute_and_check_add(a, b, c, 3.0f, 5.0f);
950-
951-
// Redo with new sizes
952-
std::vector<int64_t> new_sizes = {4, 6, 3};
953-
a.reallocate(new_sizes);
954-
b.reallocate(new_sizes);
955-
c.reallocate(new_sizes);
956-
957-
// Flush everything
958-
context()->flush();
959-
960-
execute_and_check_add(a, b, c, 12.0f, 10.0f);
961-
}
962-
963-
TEST_F(
964-
VulkanComputeAPITest,
965-
tensor_reallocation_with_deferred_allocation_test) {
966-
std::vector<int64_t> sizes = {8, 8, 8};
967-
vTensor a = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ false);
968-
vTensor b = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ false);
969-
vTensor c = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ false);
970-
971-
vkapi::Allocation a_mem = allocate_memory_for(a);
972-
a.image().bind_allocation(a_mem);
973-
vkapi::Allocation b_mem = allocate_memory_for(b);
974-
b.image().bind_allocation(b_mem);
975-
vkapi::Allocation c_mem = allocate_memory_for(c);
976-
c.image().bind_allocation(c_mem);
977-
978-
execute_and_check_add(a, b, c, 4.0f, 8.0f);
979-
980-
std::vector<std::vector<int64_t>> new_sizes_list = {
981-
{4, 3, 5}, {4, 1, 7}, {8, 3, 2}, {8, 7, 2}};
982-
983-
for (auto& new_sizes : new_sizes_list) {
984-
// Redo with new sizes
985-
a.reallocate(new_sizes);
986-
b.reallocate(new_sizes);
987-
c.reallocate(new_sizes);
988-
989-
// Flush everything
990-
context()->flush();
991-
992-
a.image().bind_allocation(a_mem);
993-
b.image().bind_allocation(b_mem);
994-
c.image().bind_allocation(c_mem);
995-
996-
execute_and_check_add(
997-
a, b, c, float(new_sizes[1] + 4.5f), float(new_sizes[2] + 13.0f));
998-
}
999-
}
1000-
1001943
TEST_F(VulkanComputeAPITest, texture_virtual_resize) {
1002944
context()->set_cmd(/*reusable = */ true);
1003945
std::vector<int64_t> sizes = {8, 12, 12};

0 commit comments

Comments
 (0)