Skip to content

Commit

Permalink
Merge pull request #2 from SlyEcho/vulkan
Browse files Browse the repository at this point in the history
add cmake commands
  • Loading branch information
0cc4m authored Jul 7, 2023
2 parents 869ae76 + ea06a2c commit 6d5a0ad
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"${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
Expand Down

0 comments on commit 6d5a0ad

Please sign in to comment.