Skip to content

Commit

Permalink
cmake : add Vulkan build (#730)
Browse files Browse the repository at this point in the history
* Add vulkan shaders from llama.cpp

* Add vulkan build to cmake

* remove autogenerated shaders file

* Update sync scripts

* Remove stale vulkan shaders file

* Add up-to-date shaders file
  • Loading branch information
abetlen committed May 25, 2024
1 parent 8d6b703 commit a10a8b8
Show file tree
Hide file tree
Showing 5 changed files with 3,174 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ option(GGML_METAL_NDEBUG "ggml: disable Metal debugging" OF
option(GGML_METAL_SHADER_DEBUG "ggml: compile Metal with -fno-fast-math" OFF)
option(GGML_METAL_EMBED_LIBRARY "ggml: embed Metal library" OFF)
option(GGML_RPC "ggml: use RPC" OFF)
option(GGML_VULKAN "ggml: use Vulkan" OFF)

option(GGML_CUDA_FORCE_DMMV "ggml: use dmmv instead of mmvq CUDA kernels" OFF)
option(GGML_CUDA_FORCE_MMQ "ggml: use mmq kernels instead of cuBLAS" OFF)
Expand Down
1 change: 1 addition & 0 deletions scripts/sync-llama-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ if [ -f $SRC_GGML/llama-src.patch ]; then
-e 's/\/ggml-sycl\.h/\/src\/ggml-sycl.h/g' \
-e 's/\/ggml-vulkan\.cpp/\/src\/ggml-vulkan.cpp/g' \
-e 's/\/ggml-vulkan\.h/\/src\/ggml-vulkan.h/g' \
-e 's/\/ggml_vk_generate_shaders\.py/\/src\/ggml_vk_generate_shaders.py/g' \
-e 's/\/ggml\.h/\/include\/ggml\/ggml.h/g' \
-e 's/\/ggml-alloc\.h/\/include\/ggml\/ggml-alloc.h/g' \
-e 's/\/ggml-backend\.h/\/include\/ggml\/ggml-backend.h/g' \
Expand Down
1 change: 1 addition & 0 deletions scripts/sync-llama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cp -rpv ../llama.cpp/ggml-sycl.cpp src/ggml-sycl.cpp
cp -rpv ../llama.cpp/ggml-sycl.h src/ggml-sycl.h
cp -rpv ../llama.cpp/ggml-vulkan.cpp src/ggml-vulkan.cpp
cp -rpv ../llama.cpp/ggml-vulkan.h src/ggml-vulkan.h
cp -rpv ../llama.cpp/ggml_vk_generate_shaders.py src/ggml_vk_generate_shaders.py
cp -rpv ../llama.cpp/ggml.h include/ggml/ggml.h
cp -rpv ../llama.cpp/ggml-alloc.h include/ggml/ggml-alloc.h
cp -rpv ../llama.cpp/ggml-backend.h include/ggml/ggml-backend.h
Expand Down
22 changes: 22 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,28 @@ if (GGML_RPC)
set(GGML_RPC_SOURCES ggml-rpc.cpp)
endif()

if (GGML_VULKAN)
find_package(Vulkan)
if (Vulkan_FOUND)
message(STATUS "Vulkan found")

set(GGML_VULKAN_SOURCES ggml-vulkan.cpp ggml-vulkan.h)

add_library(ggml-vulkan OBJECT ggml-vulkan.cpp ggml-vulkan.h)
if (BUILD_SHARED_LIBS)
set_target_properties(ggml-vulkan PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(ggml-vulkan PRIVATE Vulkan::Vulkan)
target_include_directories(ggml-vulkan PRIVATE . ../include ../include/ggml)

add_compile_definitions(GGML_USE_VULKAN)

set(GGML_EXTRA_LIBS ${GGMl_EXTRA_LIBS} ggml-vulkan)
else()
message(WARNING "Vulkan not found")
endif()
endif()

if (GGML_PERF)
set(GGML_EXTRA_FLAGS ${GGML_EXTRA_FLAGS} -DGGML_PERF)
endif()
Expand Down
Loading

0 comments on commit a10a8b8

Please sign in to comment.