Skip to content

Commit 1b81415

Browse files
Icenowybandoti
authored andcommitted
vulkan: fix coopmat shader generation when cross-compiling (llama/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 <[email protected]> * Only call coop-mat shaders once * Fix whitespace --------- Signed-off-by: Icenowy Zheng <[email protected]> Co-authored-by: bandoti <[email protected]>
1 parent 0001ec0 commit 1b81415

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

ggml/src/ggml-vulkan/CMakeLists.txt

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,40 @@ if (Vulkan_FOUND)
2323
../../include/ggml-vulkan.h
2424
)
2525

26-
# Compile a test shader to determine whether GL_KHR_cooperative_matrix is supported.
27-
# If it's not, there will be an error to stderr.
28-
# If it's supported, set a define to indicate that we should compile those shaders
29-
execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
30-
OUTPUT_VARIABLE glslc_output
31-
ERROR_VARIABLE glslc_error)
32-
33-
if (${glslc_error} MATCHES ".*extension not supported: GL_KHR_cooperative_matrix.*")
34-
message(STATUS "GL_KHR_cooperative_matrix not supported by glslc")
35-
else()
36-
message(STATUS "GL_KHR_cooperative_matrix supported by glslc")
37-
add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
26+
if(NOT DEFINED GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
27+
# Compile a test shader to determine whether GL_KHR_cooperative_matrix is supported.
28+
# If it's not, there will be an error to stderr.
29+
# If it's supported, set a define to indicate that we should compile those shaders
30+
execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
31+
OUTPUT_VARIABLE glslc_output
32+
ERROR_VARIABLE glslc_error)
33+
34+
if (${glslc_error} MATCHES ".*extension not supported: GL_KHR_cooperative_matrix.*")
35+
message(STATUS "GL_KHR_cooperative_matrix not supported by glslc")
36+
set(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT OFF CACHE INTERNAL "Whether coopmat is supported by glslc")
37+
else()
38+
message(STATUS "GL_KHR_cooperative_matrix supported by glslc")
39+
add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
40+
set(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT ON CACHE INTERNAL "Whether coopmat is supported by glslc")
41+
endif()
3842
endif()
3943

40-
# Compile a test shader to determine whether GL_NV_cooperative_matrix2 is supported.
41-
# If it's not, there will be an error to stderr.
42-
# If it's supported, set a define to indicate that we should compile those shaders
43-
execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat2_support.comp"
44-
OUTPUT_VARIABLE glslc_output
45-
ERROR_VARIABLE glslc_error)
46-
47-
if (${glslc_error} MATCHES ".*extension not supported: GL_NV_cooperative_matrix2.*")
48-
message(STATUS "GL_NV_cooperative_matrix2 not supported by glslc")
49-
else()
50-
message(STATUS "GL_NV_cooperative_matrix2 supported by glslc")
51-
add_compile_definitions(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
44+
if(NOT DEFINED GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
45+
# Compile a test shader to determine whether GL_NV_cooperative_matrix2 is supported.
46+
# If it's not, there will be an error to stderr.
47+
# If it's supported, set a define to indicate that we should compile those shaders
48+
execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat2_support.comp"
49+
OUTPUT_VARIABLE glslc_output
50+
ERROR_VARIABLE glslc_error)
51+
52+
if (${glslc_error} MATCHES ".*extension not supported: GL_NV_cooperative_matrix2.*")
53+
message(STATUS "GL_NV_cooperative_matrix2 not supported by glslc")
54+
set(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT OFF CACHE INTERNAL "Whether coopmat2 is supported by glslc")
55+
else()
56+
message(STATUS "GL_NV_cooperative_matrix2 supported by glslc")
57+
add_compile_definitions(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
58+
set(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT ON CACHE INTERNAL "Whether coopmat2 is supported by glslc")
59+
endif()
5260
endif()
5361

5462
target_link_libraries(ggml-vulkan PRIVATE Vulkan::Vulkan)
@@ -119,6 +127,8 @@ if (Vulkan_FOUND)
119127
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders
120128
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${HOST_CMAKE_TOOLCHAIN_FILE}
121129
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
130+
-DGGML_VULKAN_COOPMAT_GLSLC_SUPPORT=${GGML_VULKAN_COOPMAT_GLSLC_SUPPORT}
131+
-DGGML_VULKAN_COOPMAT2_GLSLC_SUPPORT=${GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT}
122132
BUILD_COMMAND ${CMAKE_COMMAND} --build .
123133
INSTALL_COMMAND ${CMAKE_COMMAND} --install .
124134
INSTALL_DIR ${CMAKE_BINARY_DIR}

ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
find_package (Threads REQUIRED)
22

3+
if (GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
4+
add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
5+
endif()
6+
if (GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
7+
add_compile_definitions(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
8+
endif()
39
set(TARGET vulkan-shaders-gen)
410
add_executable(${TARGET} vulkan-shaders-gen.cpp)
511
install(TARGETS ${TARGET} RUNTIME)

0 commit comments

Comments
 (0)