Skip to content

Commit 6c4720c

Browse files
committed
fix: ggml: make GGML compatible with vulkan v1.2.162
Add the option GGML_VULKAN_V1_2_162 to make GGML compatible with vulkan v1.2.162. This option is OFF by default. vulkan-header: v1.2.162 https://github.com/KhronosGroup/Vulkan-Headers/tree/v1.2.162
1 parent 755a9b2 commit 6c4720c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE})
7373
# 3rd party libs
7474
option(LLAMA_CURL "llama: use libcurl to download model from an URL" OFF)
7575

76+
option(GGML_VULKAN_V1_2_162 "llama: make GGML compatible with vulkan v1.2.162" OFF)
77+
if (GGML_VULKAN_V1_2_162 AND GGML_VULKAN)
78+
add_definitions(-DGGML_VULKAN_V1_2_162)
79+
endif()
80+
7681
# Required for relocatable CMake package
7782
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build-info.cmake)
7883

ggml/src/ggml-vulkan.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ static_assert(K_QUANTS_PER_ITERATION == 1 || K_QUANTS_PER_ITERATION == 2, "K_QUA
6565
#define VK_LOG_DEBUG(msg) ((void) 0)
6666
#endif // GGML_VULKAN_DEBUG
6767

68+
#ifdef GGML_VULKAN_V1_2_162
69+
#ifdef VK_NULL_HANDLE
70+
#undef VK_NULL_HANDLE
71+
#define VK_NULL_HANDLE nullptr
72+
#endif // VK_NULL_HANDLE
73+
#endif // GGML_VULKAN_V1_2_162
74+
6875
struct ggml_backend_vk_context;
6976

7077
struct vk_queue {
@@ -865,6 +872,16 @@ static void ggml_vk_submit(vk_context& ctx, vk::Fence fence) {
865872
tl_signal_vals[idx].push_back(submission.signal_semaphores[i].value);
866873
tl_signal_semaphores[idx].push_back(submission.signal_semaphores[i].s);
867874
}
875+
#if defined(GGML_VULKAN_V1_2_162)
876+
vk::TimelineSemaphoreSubmitInfo timeline_info(
877+
(uint32_t) submission.wait_semaphores.size(),
878+
tl_wait_vals[idx].data(),
879+
(uint32_t) submission.signal_semaphores.size(),
880+
tl_signal_vals[idx].data()
881+
);
882+
timeline_info.setPNext(nullptr);
883+
tl_submit_infos.push_back(timeline_info);
884+
#else
868885
tl_submit_infos.push_back({
869886
(uint32_t) submission.wait_semaphores.size(),
870887
tl_wait_vals[idx].data(),
@@ -873,6 +890,7 @@ static void ggml_vk_submit(vk_context& ctx, vk::Fence fence) {
873890
});
874891
tl_submit_infos[idx].sType = vk::StructureType::eTimelineSemaphoreSubmitInfo;
875892
tl_submit_infos[idx].pNext = nullptr;
893+
#endif
876894
vk::SubmitInfo si{
877895
(uint32_t) submission.wait_semaphores.size(),
878896
tl_wait_semaphores[idx].data(),
@@ -1846,22 +1864,28 @@ static vk_device ggml_vk_get_device(size_t idx) {
18461864

18471865
vk::PhysicalDeviceProperties2 props2;
18481866
vk::PhysicalDeviceMaintenance3Properties props3;
1867+
#ifndef GGML_VULKAN_V1_2_162
18491868
vk::PhysicalDeviceMaintenance4Properties props4;
1869+
#endif // GGML_VULKAN_V1_2_162
18501870
vk::PhysicalDeviceSubgroupProperties subgroup_props;
18511871
props2.pNext = &props3;
18521872
props3.pNext = &subgroup_props;
1873+
#ifndef GGML_VULKAN_V1_2_162
18531874
if (maintenance4_support) {
18541875
subgroup_props.pNext = &props4;
18551876
}
1877+
#endif // GGML_VULKAN_V1_2_162
18561878
device->physical_device.getProperties2(&props2);
18571879
device->properties = props2.properties;
18581880

18591881
const char* GGML_VK_FORCE_MAX_ALLOCATION_SIZE = getenv("GGML_VK_FORCE_MAX_ALLOCATION_SIZE");
18601882

18611883
if (GGML_VK_FORCE_MAX_ALLOCATION_SIZE != nullptr) {
18621884
device->max_memory_allocation_size = std::stoi(GGML_VK_FORCE_MAX_ALLOCATION_SIZE);
1885+
#ifndef GGML_VULKAN_V1_2_162
18631886
} else if (maintenance4_support) {
18641887
device->max_memory_allocation_size = std::min(props3.maxMemoryAllocationSize, props4.maxBufferSize);
1888+
#endif // GGML_VULKAN_V1_2_162
18651889
} else {
18661890
device->max_memory_allocation_size = props3.maxMemoryAllocationSize;
18671891
}

0 commit comments

Comments
 (0)