From 3d7d8d00a4dc7d97d2ec703e4444f1732d914a10 Mon Sep 17 00:00:00 2001 From: Henri Vasserman Date: Tue, 4 Jul 2023 17:02:22 +0300 Subject: [PATCH 1/2] add cmake commands --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffda74a700bef..cfd24455450fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -313,6 +313,37 @@ if (LLAMA_CLBLAST) endif() endif() +if (LLAMA_VULKAN) + find_package(Vulkan COMPONENTS glslc) + if (Vulkan_FOUND) + message(STATUS "Vulkan found") + + add_library(ggml-vulkan STATIC ggml-vulkan.cpp ggml-vulkan.h) + target_link_libraries(ggml-vulkan PUBLIC Vulkan::Vulkan) + + set(GGML_VULKAN_SHADERS matmul_f32 matmul_f16 f16_to_f32 dequant_q4_0) + + foreach(s IN LISTS GGML_VULKAN_SHADERS) + add_custom_command( + OUTPUT "vk_shaders/${s}.spv" + COMMAND "${Vulkan_GLSLC_EXECUTABLE}" + -fshader-stage=compute + --target-env=vulkan1.2 + -O "${CMAKE_CURRENT_SOURCE_DIR}/vk_shaders/${s}.glsl" + -o "${CMAKE_CURRENT_BINARY_DIR}/vk_shaders/${s}.spv" + DEPENDS "vk_shaders/${s}.glsl" + ) + target_sources(ggml-vulkan PRIVATE "vk_shaders/${s}.spv") + endforeach() + + add_compile_definitions(GGML_USE_VULKAN) + + set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} ggml-vulkan) + else() + message(WARNING "Vulkan not found") + endif() +endif() + if (LLAMA_ALL_WARNINGS) if (NOT MSVC) set(c_flags From ea06a2c3210bac1f60934a521387b0aee27fcde4 Mon Sep 17 00:00:00 2001 From: 0cc4m Date: Fri, 7 Jul 2023 05:52:33 +0200 Subject: [PATCH 2/2] Disable glslc optimization for CMake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfd24455450fa..aa8f33b40f325 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,7 +329,7 @@ if (LLAMA_VULKAN) COMMAND "${Vulkan_GLSLC_EXECUTABLE}" -fshader-stage=compute --target-env=vulkan1.2 - -O "${CMAKE_CURRENT_SOURCE_DIR}/vk_shaders/${s}.glsl" + "${CMAKE_CURRENT_SOURCE_DIR}/vk_shaders/${s}.glsl" -o "${CMAKE_CURRENT_BINARY_DIR}/vk_shaders/${s}.spv" DEPENDS "vk_shaders/${s}.glsl" )