mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-29 08:41:22 +00:00 
			
		
		
		
	vulkan: fix coopmat shader generation when cross-compiling (#12272)
* vulkan: fix coopmat shader generation when cross-compiling
Previously the status of coopmat{,2} support isn't passed to the
vulkan-shaders-gen project building on the host, which leads to build
failure because of the cross-compiling code expecting coopmat{,2}
shaders that didn't get generated.
Fix this by passing the coopmat{,2} support status to vulkan-shaders
subproject.
Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
* Only call coop-mat shaders once
* Fix whitespace
---------
Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
Co-authored-by: bandoti <141645996+bandoti@users.noreply.github.com>
			
			
This commit is contained in:
		| @@ -23,32 +23,40 @@ if (Vulkan_FOUND) | |||||||
|                              ../../include/ggml-vulkan.h |                              ../../include/ggml-vulkan.h | ||||||
|                             ) |                             ) | ||||||
|  |  | ||||||
|     # Compile a test shader to determine whether GL_KHR_cooperative_matrix is supported. |     if(NOT DEFINED GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) | ||||||
|     # If it's not, there will be an error to stderr. |         # Compile a test shader to determine whether GL_KHR_cooperative_matrix is supported. | ||||||
|     # If it's supported, set a define to indicate that we should compile those shaders |         # If it's not, there will be an error to stderr. | ||||||
|     execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp" |         # If it's supported, set a define to indicate that we should compile those shaders | ||||||
|                     OUTPUT_VARIABLE glslc_output |         execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp" | ||||||
|                     ERROR_VARIABLE glslc_error) |                         OUTPUT_VARIABLE glslc_output | ||||||
|  |                         ERROR_VARIABLE glslc_error) | ||||||
|  |  | ||||||
|     if (${glslc_error} MATCHES ".*extension not supported: GL_KHR_cooperative_matrix.*") |         if (${glslc_error} MATCHES ".*extension not supported: GL_KHR_cooperative_matrix.*") | ||||||
|         message(STATUS "GL_KHR_cooperative_matrix not supported by glslc") |             message(STATUS "GL_KHR_cooperative_matrix not supported by glslc") | ||||||
|     else() |             set(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT OFF CACHE INTERNAL "Whether coopmat is supported by glslc") | ||||||
|         message(STATUS "GL_KHR_cooperative_matrix supported by glslc") |         else() | ||||||
|         add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) |             message(STATUS "GL_KHR_cooperative_matrix supported by glslc") | ||||||
|  |             add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) | ||||||
|  |             set(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT ON CACHE INTERNAL "Whether coopmat is supported by glslc") | ||||||
|  |         endif() | ||||||
|     endif() |     endif() | ||||||
|  |  | ||||||
|     # Compile a test shader to determine whether GL_NV_cooperative_matrix2 is supported. |     if(NOT DEFINED GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT) | ||||||
|     # If it's not, there will be an error to stderr. |         # Compile a test shader to determine whether GL_NV_cooperative_matrix2 is supported. | ||||||
|     # If it's supported, set a define to indicate that we should compile those shaders |         # If it's not, there will be an error to stderr. | ||||||
|     execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat2_support.comp" |         # If it's supported, set a define to indicate that we should compile those shaders | ||||||
|                     OUTPUT_VARIABLE glslc_output |         execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat2_support.comp" | ||||||
|                     ERROR_VARIABLE glslc_error) |                         OUTPUT_VARIABLE glslc_output | ||||||
|  |                         ERROR_VARIABLE glslc_error) | ||||||
|  |  | ||||||
|     if (${glslc_error} MATCHES ".*extension not supported: GL_NV_cooperative_matrix2.*") |         if (${glslc_error} MATCHES ".*extension not supported: GL_NV_cooperative_matrix2.*") | ||||||
|         message(STATUS "GL_NV_cooperative_matrix2 not supported by glslc") |             message(STATUS "GL_NV_cooperative_matrix2 not supported by glslc") | ||||||
|     else() |             set(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT OFF CACHE INTERNAL "Whether coopmat2 is supported by glslc") | ||||||
|         message(STATUS "GL_NV_cooperative_matrix2 supported by glslc") |         else() | ||||||
|         add_compile_definitions(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT) |             message(STATUS "GL_NV_cooperative_matrix2 supported by glslc") | ||||||
|  |             add_compile_definitions(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT) | ||||||
|  |             set(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT ON CACHE INTERNAL "Whether coopmat2 is supported by glslc") | ||||||
|  |         endif() | ||||||
|     endif() |     endif() | ||||||
|  |  | ||||||
|     target_link_libraries(ggml-vulkan PRIVATE Vulkan::Vulkan) |     target_link_libraries(ggml-vulkan PRIVATE Vulkan::Vulkan) | ||||||
| @@ -119,6 +127,8 @@ if (Vulkan_FOUND) | |||||||
|             SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders |             SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders | ||||||
|             CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${HOST_CMAKE_TOOLCHAIN_FILE} |             CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${HOST_CMAKE_TOOLCHAIN_FILE} | ||||||
|                     -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} |                     -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} | ||||||
|  |                     -DGGML_VULKAN_COOPMAT_GLSLC_SUPPORT=${GGML_VULKAN_COOPMAT_GLSLC_SUPPORT} | ||||||
|  |                     -DGGML_VULKAN_COOPMAT2_GLSLC_SUPPORT=${GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT} | ||||||
|             BUILD_COMMAND ${CMAKE_COMMAND} --build . |             BUILD_COMMAND ${CMAKE_COMMAND} --build . | ||||||
|             INSTALL_COMMAND ${CMAKE_COMMAND} --install . |             INSTALL_COMMAND ${CMAKE_COMMAND} --install . | ||||||
|             INSTALL_DIR ${CMAKE_BINARY_DIR} |             INSTALL_DIR ${CMAKE_BINARY_DIR} | ||||||
|   | |||||||
| @@ -1,5 +1,11 @@ | |||||||
| find_package (Threads REQUIRED) | find_package (Threads REQUIRED) | ||||||
|  |  | ||||||
|  | if (GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) | ||||||
|  |     add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) | ||||||
|  | endif() | ||||||
|  | if (GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT) | ||||||
|  |     add_compile_definitions(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT) | ||||||
|  | endif() | ||||||
| set(TARGET vulkan-shaders-gen) | set(TARGET vulkan-shaders-gen) | ||||||
| add_executable(${TARGET} vulkan-shaders-gen.cpp) | add_executable(${TARGET} vulkan-shaders-gen.cpp) | ||||||
| install(TARGETS ${TARGET} RUNTIME) | install(TARGETS ${TARGET} RUNTIME) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Icenowy Zheng
					Icenowy Zheng