From 7273c2bc85cdb8826733ee0de6d341629317c25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ingve=20Schj=C3=B8lberg?= Date: Fri, 24 Jul 2026 14:44:53 +0200 Subject: [PATCH] [vulkan] remove unused allocator release overload The Vulkan allocator as well as the region and block allocators all had a `int release(void *user_context)` overload in addition to the regular `int release(void *user_context, MemoryRegion *region)`. The single-argument overload is unused, and it is bug prone. It is easy to call the single-argument overload instead of the correct two-argument overload by forgetting to fill the user_context argument. This may not produce any compiler error because a pointer to a MemoryRegion converts implicitly to a `void *`. Since the overload is unused, this commit removes it from the three allocator classes. Also in the block allocator, a private helper `release_block_entry` is also removed. Its only reference was the single-argument `release`. --- src/runtime/internal/block_allocator.h | 27 ------------------------- src/runtime/internal/region_allocator.h | 18 ----------------- src/runtime/vulkan_memory.h | 18 ----------------- 3 files changed, 63 deletions(-) diff --git a/src/runtime/internal/block_allocator.h b/src/runtime/internal/block_allocator.h index 37cacce601e3..73e71080d139 100644 --- a/src/runtime/internal/block_allocator.h +++ b/src/runtime/internal/block_allocator.h @@ -60,7 +60,6 @@ class BlockAllocator { int reclaim(void *user_context, MemoryRegion *region); //< free the region and consolidate int retain(void *user_context, MemoryRegion *region); //< retain the region and increase the usage count bool collect(void *user_context); //< returns true if any blocks were removed - int release(void *user_context); int destroy(void *user_context); // Access methods @@ -95,9 +94,6 @@ class BlockAllocator { // Creates a new block entry and adds it tos the list BlockEntry *create_block_entry(void *user_context, const MemoryRequest &request); - // Releases the block entry from being used, and makes it available for further allocations - int release_block_entry(void *user_context, BlockEntry *block_entry); - // Destroys the block entry and removes it from the list int destroy_block_entry(void *user_context, BlockEntry *block_entry); @@ -265,16 +261,6 @@ bool BlockAllocator::collect(void *user_context) { return result; } -int BlockAllocator::release(void *user_context) { - BlockEntry *block_entry = block_list.back(); - while (block_entry != nullptr) { - BlockEntry *prev_entry = block_entry->prev_ptr; - release_block_entry(user_context, block_entry); - block_entry = prev_entry; - } - return 0; -} - int BlockAllocator::destroy(void *user_context) { BlockEntry *block_entry = block_list.back(); while (block_entry != nullptr) { @@ -504,19 +490,6 @@ BlockAllocator::create_block_entry(void *user_context, const MemoryRequest &requ return block_entry; } -int BlockAllocator::release_block_entry(void *user_context, BlockAllocator::BlockEntry *block_entry) { -#ifdef DEBUG_RUNTIME_INTERNAL - debug(user_context) << "BlockAllocator: Releasing block entry (" - << "block_entry=" << (void *)(block_entry) << " " - << "block=" << (void *)(block_entry->value) << ")..."; -#endif - BlockResource *block = static_cast(block_entry->value); - if (block->allocator) { - return block->allocator->release(user_context); - } - return 0; -} - int BlockAllocator::destroy_block_entry(void *user_context, BlockAllocator::BlockEntry *block_entry) { #ifdef DEBUG_RUNTIME_INTERNAL debug(user_context) << "BlockAllocator: Destroying block entry (" diff --git a/src/runtime/internal/region_allocator.h b/src/runtime/internal/region_allocator.h index 8c04116a3a65..ee17bc396a04 100644 --- a/src/runtime/internal/region_allocator.h +++ b/src/runtime/internal/region_allocator.h @@ -51,7 +51,6 @@ class RegionAllocator { int reclaim(void *user_context, MemoryRegion *memory_region); //< free the region and consolidate int retain(void *user_context, MemoryRegion *memory_region); //< retain the region and increase usage count bool collect(void *user_context); //< returns true if any blocks were removed - int release(void *user_context); int destroy(void *user_context); // Returns the currently managed block resource @@ -672,23 +671,6 @@ int RegionAllocator::free_block_region(void *user_context, BlockRegion *block_re return error_code; } -int RegionAllocator::release(void *user_context) { -#ifdef DEBUG_RUNTIME_INTERNAL - debug(user_context) << "RegionAllocator: Releasing all regions (" - << "user_context=" << (void *)(user_context) << ") ..."; -#endif - - BlockRegion *block_region = block->regions; - while (block_region != nullptr) { - release_block_region(user_context, block_region); - if (is_last_block_region(user_context, block_region)) { - break; - } - block_region = block_region->next_ptr; - } - return 0; -} - bool RegionAllocator::collect(void *user_context) { #ifdef DEBUG_RUNTIME_INTERNAL debug(user_context) << "RegionAllocator: Collecting free block regions (" diff --git a/src/runtime/vulkan_memory.h b/src/runtime/vulkan_memory.h index b21a2e476d86..f8cf751ba901 100644 --- a/src/runtime/vulkan_memory.h +++ b/src/runtime/vulkan_memory.h @@ -64,7 +64,6 @@ class VulkanMemoryAllocator { int reclaim(void *user_context, MemoryRegion *region); //< free the region and consolidate int retain(void *user_context, MemoryRegion *region); //< retain the region and increase its use count bool collect(void *user_context); //< returns true if any blocks were removed - int release(void *user_context); int destroy(void *user_context); void *map(void *user_context, MemoryRegion *region); @@ -504,23 +503,6 @@ bool VulkanMemoryAllocator::collect(void *user_context) { return block_allocator->collect(this); } -int VulkanMemoryAllocator::release(void *user_context) { -#if defined(HL_VK_DEBUG_MEM) - debug(nullptr) << "VulkanMemoryAllocator: Releasing block allocator (" - << "user_context=" << user_context << ") ... \n"; -#endif - if ((device == nullptr) || (physical_device == nullptr)) { - error(user_context) << "VulkanMemoryAllocator: Unable to release allocator! Invalid device handle!\n"; - return halide_error_code_generic_error; - } - if (block_allocator == nullptr) { - error(user_context) << "VulkanMemoryAllocator: Unable to release allocator! Invalid block allocator!\n"; - return halide_error_code_generic_error; - } - - return block_allocator->release(this); -} - int VulkanMemoryAllocator::destroy(void *user_context) { #if defined(HL_VK_DEBUG_MEM) debug(nullptr) << "VulkanMemoryAllocator: Destroying allocator ("