Skip to content
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

Throw errors on allocation failures #5166

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions src/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "gpu.h"
#include "pipeline.h"
#include <stdexcept>

#if __ANDROID_API__ >= 26
#include <android/hardware_buffer.h>
Expand Down Expand Up @@ -448,6 +449,7 @@ VkBuffer VkAllocator::create_buffer(size_t size, VkBufferUsageFlags usage)
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkCreateBuffer failed %d", ret);
throw std::runtime_error("vkCreateBuffer failed");
return 0;
}

Expand All @@ -467,6 +469,7 @@ VkDeviceMemory VkAllocator::allocate_memory(size_t size, uint32_t memory_type_in
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkAllocateMemory failed %d", ret);
throw std::runtime_error("vkAllocateMemory failed");
return 0;
}

Expand All @@ -493,6 +496,7 @@ VkDeviceMemory VkAllocator::allocate_dedicated_memory(size_t size, uint32_t memo
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkAllocateMemory failed %d", ret);
throw std::runtime_error("vkAllocateMemory failed");
return 0;
}

Expand Down Expand Up @@ -2039,6 +2043,7 @@ VkImageMemory* VkAndroidHardwareBufferImageAllocator::fastMalloc(int /*w*/, int
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkAllocateMemory failed %d", ret);
throw std::runtime_error("vkAllocateMemory failed");
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "option.h"
#include "pipeline.h"
#include <stdexcept>

namespace ncnn {

Expand Down Expand Up @@ -2420,6 +2421,7 @@ int VkCompute::submit_and_wait()
{
NCNN_LOGE("vkQueueSubmit failed %d", ret);
vkdev->reclaim_queue(vkdev->info.compute_queue_family_index(), compute_queue);
throw std::runtime_error("vkQueueSubmit failed");
return -1;
}
}
Expand All @@ -2432,6 +2434,7 @@ int VkCompute::submit_and_wait()
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkWaitForFences failed %d", ret);
throw std::runtime_error("vkWaitForFences failed");
return -1;
}
}
Expand Down Expand Up @@ -3403,6 +3406,7 @@ int VkTransfer::submit_and_wait()
{
NCNN_LOGE("vkQueueSubmit failed %d", ret);
vkdev->reclaim_queue(vkdev->info.compute_queue_family_index(), compute_queue);
throw std::runtime_error("vkQueueSubmit failed");
return -1;
}
}
Expand Down Expand Up @@ -3436,6 +3440,7 @@ int VkTransfer::submit_and_wait()
NCNN_LOGE("vkQueueSubmit failed %d", ret);
vkdev->reclaim_queue(vkdev->info.transfer_queue_family_index(), transfer_queue);
vkdev->reclaim_queue(vkdev->info.compute_queue_family_index(), compute_queue);
throw std::runtime_error("vkQueueSubmit failed");
return -1;
}
}
Expand All @@ -3459,6 +3464,7 @@ int VkTransfer::submit_and_wait()
NCNN_LOGE("vkQueueSubmit failed %d", ret);
vkdev->reclaim_queue(vkdev->info.transfer_queue_family_index(), transfer_queue);
vkdev->reclaim_queue(vkdev->info.compute_queue_family_index(), compute_queue);
throw std::runtime_error("vkQueueSubmit failed");
return -1;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "layer_type.h"
#include "mat.h"
#include "pipelinecache.h"
#include <stdexcept>

// There is known issue that vkDestroyDebugUtilsMessengerEXT crash on exit when vulkan validation layer enabled
// upstream fix https://github.com/KhronosGroup/Vulkan-Loader/pull/539
Expand Down Expand Up @@ -3276,6 +3277,7 @@ void VulkanDevice::reclaim_blob_allocator(VkAllocator* allocator) const
}

NCNN_LOGE("FATAL ERROR! reclaim_blob_allocator get wild allocator %p", allocator);
throw std::runtime_error("FATAL ERROR! reclaim_blob_allocator get wild allocator");
}

VkAllocator* VulkanDevice::acquire_staging_allocator() const
Expand Down Expand Up @@ -3313,6 +3315,7 @@ void VulkanDevice::reclaim_staging_allocator(VkAllocator* allocator) const
}

NCNN_LOGE("FATAL ERROR! reclaim_staging_allocator get wild allocator %p", allocator);
throw std::runtime_error("FATAL ERROR! reclaim_staging_allocator get wild allocator");
}

const VkSampler* VulkanDevice::immutable_texelfetch_sampler() const
Expand Down