Skip to content

Commit 04ab3d3

Browse files
author
Sandro Hanea
committed
Fixed COOPMAT on Vulkan builds with CROSS_COMPILE ON
1 parent e27fd6f commit 04ab3d3

File tree

2 files changed

+58
-21
lines changed

2 files changed

+58
-21
lines changed

ggml/src/ggml-vulkan/CMakeLists.txt

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,54 @@ if (Vulkan_FOUND)
2222
ggml-vulkan.cpp
2323
../../include/ggml-vulkan.h
2424
)
25+
if (CMAKE_CROSSCOMPILING)
26+
# Make this configurable for cross builds
27+
option(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT "Enable coopmat shaders" OFF)
28+
option(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT "Enable coopmat2 shaders" OFF)
29+
else()
30+
# Compile a test shader to determine whether GL_KHR_cooperative_matrix is supported.
31+
# If it's not, there will be an error to stderr.
32+
# If it's supported, set a define to indicate that we should compile those shaders
33+
execute_process(COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
34+
OUTPUT_VARIABLE glslc_output
35+
ERROR_VARIABLE glslc_error)
36+
37+
if (${glslc_error} MATCHES ".*extension not supported: GL_KHR_cooperative_matrix.*")
38+
message(STATUS "GL_KHR_cooperative_matrix not supported by glslc")
39+
set(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT OFF CACHE INTERNAL "Not enable coopmat shaders")
40+
else()
41+
message(STATUS "GL_KHR_cooperative_matrix supported by glslc")
42+
set(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT ON CACHE INTERNAL "Enable coopmat shaders")
43+
endif()
2544

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)
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)
3251

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)
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 "Not enable coopmat2 shaders")
55+
else()
56+
message(STATUS "GL_NV_cooperative_matrix2 supported by glslc")
57+
set(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT ON CACHE INTERNAL "Enable coopmat2 shaders")
58+
endif()
3859
endif()
3960

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")
61+
if (GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
62+
message(STATUS "GGML_VULKAN_COOPMAT_GLSLC_SUPPORT enabled")
63+
add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
4964
else()
50-
message(STATUS "GL_NV_cooperative_matrix2 supported by glslc")
65+
message(STATUS "GGML_VULKAN_COOPMAT_GLSLC_SUPPORT disabled")
66+
endif()
67+
68+
if (GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
69+
message(STATUS "GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT enabled")
5170
add_compile_definitions(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
71+
else()
72+
message(STATUS "GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT disabled")
5273
endif()
5374

5475
target_link_libraries(ggml-vulkan PRIVATE Vulkan::Vulkan)
@@ -119,6 +140,8 @@ if (Vulkan_FOUND)
119140
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders
120141
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${HOST_CMAKE_TOOLCHAIN_FILE}
121142
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
143+
-DGGML_VULKAN_COOPMAT_GLSLC_SUPPORT=${GGML_VULKAN_COOPMAT_GLSLC_SUPPORT}
144+
-DGGML_VULKAN_COOPMAT2_GLSLC_SUPPORT=${GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT}
122145
BUILD_COMMAND ${CMAKE_COMMAND} --build .
123146
INSTALL_COMMAND ${CMAKE_COMMAND} --install .
124147
INSTALL_DIR ${CMAKE_BINARY_DIR}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@ if(NOT GLSLC_EXECUTABLE)
44
message(FATAL_ERROR "glslc not found.")
55
endif()
66

7+
option(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT "Enable coopmat shaders" OFF)
8+
option(GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT "Enable coopmat2 shaders" OFF)
9+
10+
message(STATUS "GGML_VULKAN_COOPMAT_GLSLC_SUPPORT: ${GGML_VULKAN_COOPMAT_GLSLC_SUPPORT}")
11+
message(STATUS "GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT: ${GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT}")
12+
713
set(TARGET vulkan-shaders-gen)
814
add_executable(${TARGET} vulkan-shaders-gen.cpp)
15+
if (GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
16+
target_compile_definitions(vulkan-shaders-gen PRIVATE GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
17+
endif()
18+
19+
if (GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
20+
target_compile_definitions(vulkan-shaders-gen PRIVATE GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT)
21+
endif()
22+
923
install(TARGETS ${TARGET} RUNTIME)
1024
target_compile_features(${TARGET} PRIVATE cxx_std_17)
1125
target_link_libraries(vulkan-shaders-gen PUBLIC Threads::Threads)

0 commit comments

Comments
 (0)