Skip to content

[ET-VK][BE][ez] vTensor cleanup 2/N - remove discard_and_reallocate API #5422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions backends/vulkan/runtime/api/containers/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,30 +396,6 @@ bool vTensorStorage::is_copy_of(const vTensorStorage& other) const {
return image_.is_copy_of(other.image_);
}

void vTensorStorage::discard_and_reallocate(
const std::vector<int64_t>& padded_sizes,
const std::vector<int64_t>& axis_map,
const utils::GPUMemoryLayout gpu_memory_layout,
const vkapi::ScalarType dtype) {
const bool image_owns_memory = image_.owns_memory();
const bool buffer_owns_memory = buffer_.owns_memory();

flush();

image_extents_ =
calculate_image_extents(padded_sizes, axis_map, gpu_memory_layout);
image_ = allocate_image(
context_,
image_extents_,
storage_type_,
to_vkformat(dtype),
image_owns_memory);

buffer_length_ = utils::multiply_integers(padded_sizes);
buffer_ = allocate_buffer(
context_, buffer_length_, storage_type_, dtype, buffer_owns_memory);
}

//
// vTensor
//
Expand Down Expand Up @@ -805,15 +781,5 @@ void vTensor::virtual_transpose(const int64_t dim0, const int64_t dim1) {
update_metadata();
}

void vTensor::reallocate(const std::vector<int64_t>& new_sizes) {
sizes_ = new_sizes;
update_metadata();
storage_.discard_and_reallocate(
calculate_padded_sizes(new_sizes, memory_layout_),
axis_map_,
memory_layout_,
dtype_);
}

} // namespace api
} // namespace vkcompute
12 changes: 0 additions & 12 deletions backends/vulkan/runtime/api/containers/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,6 @@ class vTensorStorage final {
* Used for checking if this vTensorStorage is a copy of another instance
*/
bool is_copy_of(const vTensorStorage& other) const;

void discard_and_reallocate(
const std::vector<int64_t>& padded_sizes,
const std::vector<int64_t>& axis_map,
const utils::GPUMemoryLayout gpu_memory_layout,
const vkapi::ScalarType dtype);
};

class vTensor final {
Expand Down Expand Up @@ -535,12 +529,6 @@ class vTensor final {
*/
void virtual_transpose(const int64_t dim0, const int64_t dim1);

/*
* Discard the underlying VkImage or VkBuffer and re-allocate based on new
* tensor sizes
*/
void reallocate(const std::vector<int64_t>& new_sizes);

/*
* Check if this vTensor instance is a view of another vTensor instance
*/
Expand Down
58 changes: 0 additions & 58 deletions backends/vulkan/test/vulkan_compute_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,64 +940,6 @@ TEST_F(VulkanComputeAPITest, use_non_bound_textures_fails) {
EXPECT_THROW(fill_vtensor(a, data_a), vkapi::Error);
}

TEST_F(VulkanComputeAPITest, tensor_reallocation_test) {
std::vector<int64_t> sizes = {4, 4, 1};
vTensor a = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ true);
vTensor b = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ true);
vTensor c = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ true);

execute_and_check_add(a, b, c, 3.0f, 5.0f);

// Redo with new sizes
std::vector<int64_t> new_sizes = {4, 6, 3};
a.reallocate(new_sizes);
b.reallocate(new_sizes);
c.reallocate(new_sizes);

// Flush everything
context()->flush();

execute_and_check_add(a, b, c, 12.0f, 10.0f);
}

TEST_F(
VulkanComputeAPITest,
tensor_reallocation_with_deferred_allocation_test) {
std::vector<int64_t> sizes = {8, 8, 8};
vTensor a = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ false);
vTensor b = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ false);
vTensor c = CREATE_FLOAT_TEXTURE(sizes, /*allocate_memory = */ false);

vkapi::Allocation a_mem = allocate_memory_for(a);
a.image().bind_allocation(a_mem);
vkapi::Allocation b_mem = allocate_memory_for(b);
b.image().bind_allocation(b_mem);
vkapi::Allocation c_mem = allocate_memory_for(c);
c.image().bind_allocation(c_mem);

execute_and_check_add(a, b, c, 4.0f, 8.0f);

std::vector<std::vector<int64_t>> new_sizes_list = {
{4, 3, 5}, {4, 1, 7}, {8, 3, 2}, {8, 7, 2}};

for (auto& new_sizes : new_sizes_list) {
// Redo with new sizes
a.reallocate(new_sizes);
b.reallocate(new_sizes);
c.reallocate(new_sizes);

// Flush everything
context()->flush();

a.image().bind_allocation(a_mem);
b.image().bind_allocation(b_mem);
c.image().bind_allocation(c_mem);

execute_and_check_add(
a, b, c, float(new_sizes[1] + 4.5f), float(new_sizes[2] + 13.0f));
}
}

TEST_F(VulkanComputeAPITest, texture_virtual_resize) {
context()->set_cmd(/*reusable = */ true);
std::vector<int64_t> sizes = {8, 12, 12};
Expand Down
Loading