Skip to content
Merged
Changes from 3 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
29 changes: 26 additions & 3 deletions ggml/src/ggml-vulkan/ggml-vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11443,13 +11443,36 @@ void ggml_backend_vk_get_device_memory(int device, size_t * free, size_t * total
GGML_ASSERT(device < (int) vk_instance.device_indices.size());

vk::PhysicalDevice vkdev = vk_instance.instance.enumeratePhysicalDevices()[vk_instance.device_indices[device]];

vk::PhysicalDeviceMemoryProperties memprops = vkdev.getMemoryProperties();

for (const vk::MemoryHeap& heap : memprops.memoryHeaps) {
std::vector<vk::ExtensionProperties> extensionprops = vkdev.enumerateDeviceExtensionProperties();
vk::PhysicalDeviceMemoryBudgetPropertiesEXT budgetprops;
vk::PhysicalDeviceMemoryProperties2 memprops2 = {};
bool membudget_extension_supported = false;

for (const auto & ext : extensionprops) {
if (std::string(ext.extensionName.data()) == VK_EXT_MEMORY_BUDGET_EXTENSION_NAME) {
membudget_extension_supported = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list can include hundreds of extensions, I think you should precompute this when the instance is created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I've moved the support detection to ggml_vk_instance_init

break;
}
}

if (membudget_extension_supported) {
memprops2.pNext = &budgetprops;
vkdev.getMemoryProperties2(&memprops2);
}

for (uint32_t i = 0; i < memprops.memoryHeapCount; ++i) {
const vk::MemoryHeap & heap = memprops.memoryHeaps[i];

if (heap.flags & vk::MemoryHeapFlagBits::eDeviceLocal) {
*total = heap.size;
*free = heap.size;

if (membudget_extension_supported && i < budgetprops.heapUsage.size()) {
*free = *total - budgetprops.heapUsage[i];
} else {
*free = heap.size;
}
break;
}
}
Expand Down
Loading