Skip to content

Commit 93bb926

Browse files
authored
vulkan: set all memory allocations to high priority (#17624)
* vulkan: set all memory allocations to high priority * gate by env var
1 parent 8160b38 commit 93bb926

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ struct vk_device_struct {
519519
bool fp16;
520520
bool bf16;
521521
bool pipeline_robustness;
522+
bool memory_priority;
522523
vk::Device device;
523524
uint32_t vendor_id;
524525
vk::DriverId driver_id;
@@ -2369,7 +2370,13 @@ static vk_buffer ggml_vk_create_buffer(vk_device& device, size_t size, const std
23692370

23702371
vk::PhysicalDeviceMemoryProperties mem_props = device->physical_device.getMemoryProperties();
23712372

2372-
const vk::MemoryAllocateFlagsInfo mem_flags_info { mem_flags };
2373+
const vk::MemoryPriorityAllocateInfoEXT mem_priority_info { 1.0f };
2374+
2375+
vk::MemoryAllocateFlagsInfo mem_flags_info { mem_flags };
2376+
2377+
if (device->memory_priority) {
2378+
mem_flags_info.setPNext(&mem_priority_info);
2379+
}
23732380

23742381
for (auto it = req_flags_list.begin(); it != req_flags_list.end(); it++) {
23752382
const auto & req_flags = *it;
@@ -4340,6 +4347,9 @@ static vk_device ggml_vk_get_device(size_t idx) {
43404347
#endif
43414348
} else if (strcmp("VK_KHR_pipeline_executable_properties", properties.extensionName) == 0) {
43424349
pipeline_executable_properties_support = true;
4350+
} else if (strcmp("VK_EXT_memory_priority", properties.extensionName) == 0 &&
4351+
getenv("GGML_VK_ENABLE_MEMORY_PRIORITY")) {
4352+
device->memory_priority = true;
43434353
}
43444354
}
43454355

@@ -4531,6 +4541,16 @@ static vk_device ggml_vk_get_device(size_t idx) {
45314541
device_extensions.push_back("VK_EXT_pipeline_robustness");
45324542
}
45334543

4544+
VkPhysicalDeviceMemoryPriorityFeaturesEXT memory_priority_features;
4545+
memory_priority_features.pNext = nullptr;
4546+
memory_priority_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT;
4547+
memory_priority_features.memoryPriority = VK_FALSE;
4548+
if (device->memory_priority) {
4549+
last_struct->pNext = (VkBaseOutStructure *)&memory_priority_features;
4550+
last_struct = (VkBaseOutStructure *)&memory_priority_features;
4551+
device_extensions.push_back("VK_EXT_memory_priority");
4552+
}
4553+
45344554
VkPhysicalDeviceSubgroupSizeControlFeaturesEXT subgroup_size_control_features;
45354555
subgroup_size_control_features.pNext = nullptr;
45364556
subgroup_size_control_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT;

0 commit comments

Comments
 (0)