VK_ERROR_OUT_OF_DEVICE_MEMORY but have 2G GPU free memory

Win7 1050Ti drive 471.272.0 vulkan version 1.2.175

When i call vkAllocateMemory, memory flag is VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
it failed, but i use gpu-z to check the free gpu memory, it have about 2G free GPU memory.

I also use cudaMemGetInfo() (I use both cuda and vulkan in same application) to get the free gpu memory size, it also report 2G free GPU memory.

Why? Did have some method to debug the reason?

Thanks.

I’d read all of the article linked below. But in particular, notice the mentions of “Windows 7” and “maxMemoryAllocationCount”.

As I recall, maxMemoryAllocationCount is the limit that, while it’s 4 billion on Linux, is annoyingly a mere 4,096 on Windows graphics drivers due to a Windows OS limitation (and applies to both Vulkan and OpenGL apps). Both results are with NVIDIA GPUs and drivers.

1 Like

Check Validation Layers message, also I agree with Dark_Photon, check
VkPhysicalDeviceLimits::maxMemoryAllocationCount

1 Like

Thanks for the reply.
I check the [VkPhysicalDeviceLimits::maxMemoryAllocationCount], the value is 4096.
And i use a global value to check the current alloc count, when call vkAllocateMemory, the global value + 1. When the vkAllocateMemory failed, the gloabl value is 10.
Validation Layers also don’t report any error info about vkAllocateMemory.

Any more details on the memory allocation that fails? The “free memory” info from gpu-z may not be the actual free memory your app is actually allowed to allocate, and large allocations may fail due to hardware limitations.

If your implementation supports https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_EXT_memory_budget.html you can check upfront if the heap you want to allocate from has enough free space for the allocation.

1 Like

Unfortunately it didn’t supoort this extensions.
The alloc size is 16M, i try to alloc a small size, yeah, it success.
So win7 don’t allow to alloc a 16M gpu memory, don’t make sense, how to get the max alloc size?
Thanks.

Allocating 16M shouldn’t be a problem. Can you post the code that fails?

I found the problem, because of i want to use these memory in cuda, i give some flags.
If i don’t use these flags, alloc success.
But the code works on win10.
When i create the buffer:

VkBufferCreateInfo BufferCreate;
VkExternalMemoryBufferCreateInfo ExInfo;
memset(&ExInfo, 0, sizeof(VkExternalMemoryBufferCreateInfo));
ExInfo.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO;
ExInfo.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT;
BufferCreate.pNext = &ExInfo;

When i call vkAllocateMemory:

VkMemoryAllocateInfo MemoryAllocate;

WindowsSecurityAttributes *pWinSecurity = new WindowsSecurityAttributes();
VkExportMemoryWin32HandleInfoKHR *pExportWin = new VkExportMemoryWin32HandleInfoKHR();
memset(pExportWin, 0, sizeof(VkExportMemoryWin32HandleInfoKHR));
pExportWin->sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR;
pExportWin->pAttributes = pWinSecurity->GetAttribute();
pExportWin->dwAccess = DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;

VkExportMemoryAllocateInfoKHR *pExport = new VkExportMemoryAllocateInfoKHR();
memset(pExport, 0, sizeof(VkExportMemoryAllocateInfoKHR));
pExport->sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO;
pExport->pNext = pExportWin;
pExport->handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT;
MemoryAllocate->pNext = pExport;

Finally i fix this problem.
On win7, if you want export vulkan memory to cuda, you should use VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, not
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT.

The Vulkan document is so …