nihui/vkpeak

vkpeak crashes at vkMapMemory() on APUs with large dedicated GPU memory allocations set in BIOS (>512MB)

Closed this issue · 3 comments

vkpeak tries to allocate 3 ncnn::VkMat instances here. The allocation size is derived from VulkanDevice::get_heap_budget().

VulkanDevice::get_heap_budget() returns memory budget from the first heap with VK_MEMORY_HEAP_DEVICE_LOCAL_BIT flag. In the case of AMD APUs, this returns the heap representing dedicated GPU memory allocated by the BIOS.

When ncnn::VkMat does the actual allocation however, it uses VkBlobAllocator::fastMalloc(). It handles integrated GPU devices in a special way, specifically requiring VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT and preferring VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT.

As a result, VkMat allocates memory from the 3rd heap with only 256MB of capacity. This causes allocation failures in VkAllocator::allocate_memory() and NULL being passed into vkMapMemory() in VkBlobAllocator::fastMalloc(), resulting 0xc0000005 in amdvlk64.dll.

There's also potential memory performance issue, as the 256MB (device local | host visible) memory on APUs is not cacheable.

hi
please test if this fix works for you Tencent/ncnn#4936

Tested. It allocated from the expected heap and no longer crashed. Thanks for the fix.