Skip to content

Commit e29acf7

Browse files
Aclyjeffbolznv
andauthored
vulkan : incremental shader builds (#16341)
* vulkan (DRAFT): split shader generation by GLSL source file, to improve incremental build times * support dep-files so shaders are recompiled if their included files change * rename shader files which are used as "headers" to use .glsl extension * move glslc extension detection shaders to separate folders * the above is to prevent them from getting glob'd with the actual compute shaders that need to be compiled * vulkan : only write embedded shader .hpp/.cpp when they change * avoid recompiling ggml-vulkan.cpp when editing shaders * pass single --source argument instead of --input-dir & --filter to shader gen * check for source file match earlier * fix hang in vulkan-shaders-gen when there are compilation errors * early out did not decrement compile_count * clean up * fix glslc integer dot product test * unconditionally write the embedded shader cpp output * replace output filepath in generated dep-files to match output in CMakeLists --------- Co-authored-by: Jeff Bolz <[email protected]>
1 parent 128d522 commit e29acf7

File tree

133 files changed

+405
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+405
-316
lines changed

ggml/src/ggml-vulkan/CMakeLists.txt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake_minimum_required(VERSION 3.19)
22
cmake_policy(SET CMP0114 NEW)
3+
cmake_policy(SET CMP0116 NEW)
34

45
find_package(Vulkan COMPONENTS glslc REQUIRED)
56

@@ -54,25 +55,25 @@ if (Vulkan_FOUND)
5455
# Test all shader extensions
5556
test_shader_extension_support(
5657
"GL_KHR_cooperative_matrix"
57-
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
58+
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/coopmat.comp"
5859
"GGML_VULKAN_COOPMAT_GLSLC_SUPPORT"
5960
)
6061

6162
test_shader_extension_support(
6263
"GL_NV_cooperative_matrix2"
63-
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat2_support.comp"
64+
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/coopmat2.comp"
6465
"GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT"
6566
)
6667

6768
test_shader_extension_support(
6869
"GL_EXT_integer_dot_product"
69-
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_integer_dot_support.comp"
70+
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/integer_dot.comp"
7071
"GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORT"
7172
)
7273

7374
test_shader_extension_support(
7475
"GL_EXT_bfloat16"
75-
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_bfloat16_support.comp"
76+
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/bfloat16.comp"
7677
"GGML_VULKAN_BFLOAT16_GLSLC_SUPPORT"
7778
)
7879

@@ -160,7 +161,6 @@ if (Vulkan_FOUND)
160161
set (_ggml_vk_genshaders_dir "${CMAKE_BINARY_DIR}/$<CONFIG>")
161162
set (_ggml_vk_genshaders_cmd "${_ggml_vk_genshaders_dir}/vulkan-shaders-gen${_ggml_vk_host_suffix}")
162163
set (_ggml_vk_header "${CMAKE_CURRENT_BINARY_DIR}/ggml-vulkan-shaders.hpp")
163-
set (_ggml_vk_source "${CMAKE_CURRENT_BINARY_DIR}/ggml-vulkan-shaders.cpp")
164164
set (_ggml_vk_input_dir "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders")
165165
set (_ggml_vk_output_dir "${CMAKE_CURRENT_BINARY_DIR}/vulkan-shaders.spv")
166166

@@ -176,24 +176,35 @@ if (Vulkan_FOUND)
176176

177177
add_custom_command(
178178
OUTPUT ${_ggml_vk_header}
179-
${_ggml_vk_source}
180-
181179
COMMAND ${_ggml_vk_genshaders_cmd}
182-
--glslc ${Vulkan_GLSLC_EXECUTABLE}
183-
--input-dir ${_ggml_vk_input_dir}
184180
--output-dir ${_ggml_vk_output_dir}
185181
--target-hpp ${_ggml_vk_header}
186-
--target-cpp ${_ggml_vk_source}
187-
--no-clean
188-
189-
DEPENDS ${_ggml_vk_shader_files}
190-
${_ggml_vk_shaders_gen_sources}
182+
DEPENDS ${_ggml_vk_shaders_gen_sources}
191183
vulkan-shaders-gen
192-
193-
COMMENT "Generate vulkan shaders"
184+
COMMENT "Generate vulkan shaders header"
194185
)
195-
196-
target_sources(ggml-vulkan PRIVATE ${_ggml_vk_source} ${_ggml_vk_header})
186+
target_sources(ggml-vulkan PRIVATE ${_ggml_vk_header})
187+
188+
foreach (file_full ${_ggml_vk_shader_files})
189+
get_filename_component(file ${file_full} NAME)
190+
set (_ggml_vk_target_cpp "${CMAKE_CURRENT_BINARY_DIR}/${file}.cpp")
191+
192+
add_custom_command(
193+
OUTPUT ${_ggml_vk_target_cpp}
194+
DEPFILE ${_ggml_vk_target_cpp}.d
195+
COMMAND ${_ggml_vk_genshaders_cmd}
196+
--glslc ${Vulkan_GLSLC_EXECUTABLE}
197+
--source ${file_full}
198+
--output-dir ${_ggml_vk_output_dir}
199+
--target-hpp ${_ggml_vk_header}
200+
--target-cpp ${_ggml_vk_target_cpp}
201+
DEPENDS ${file_full}
202+
${_ggml_vk_shaders_gen_sources}
203+
vulkan-shaders-gen
204+
COMMENT "Generate vulkan shaders for ${file}"
205+
)
206+
target_sources(ggml-vulkan PRIVATE ${_ggml_vk_target_cpp})
207+
endforeach()
197208

198209
else()
199210
message(WARNING "Vulkan not found")

ggml/src/ggml-vulkan/vulkan-shaders/acc.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 450
22

3-
#include "types.comp"
4-
#include "generic_binary_head.comp"
3+
#include "types.glsl"
4+
#include "generic_binary_head.glsl"
55

66
layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in;
77

ggml/src/ggml-vulkan/vulkan-shaders/add.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#extension GL_KHR_shader_subgroup_basic : enable
77
#endif
88

9-
#include "types.comp"
10-
#include "generic_binary_head.comp"
9+
#include "types.glsl"
10+
#include "generic_binary_head.glsl"
1111

1212
const uint num_threads = 256;
1313

ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#extension GL_EXT_control_flow_attributes : require
44

5-
#include "types.comp"
5+
#include "types.glsl"
66

77
layout (push_constant) uniform parameter
88
{

ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 450
22

3-
#include "generic_head.comp"
4-
#include "types.comp"
3+
#include "generic_head.glsl"
4+
#include "types.glsl"
55

66
#extension GL_EXT_control_flow_attributes : enable
77

ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 450
22
#extension GL_EXT_control_flow_attributes : enable
33

4-
#include "types.comp"
4+
#include "types.glsl"
55

66
layout(constant_id = 0) const int BLOCK_SIZE = 1024;
77
layout(constant_id = 1) const int BLOCK_SIZE_LOG2 = 10;

ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 450
22

3-
#include "types.comp"
4-
#include "generic_unary_head.comp"
3+
#include "types.glsl"
4+
#include "generic_unary_head.glsl"
55

66
layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in;
77

ggml/src/ggml-vulkan/vulkan-shaders/concat.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 450
22

3-
#include "types.comp"
4-
#include "generic_binary_head.comp"
3+
#include "types.glsl"
4+
#include "generic_binary_head.glsl"
55

66
layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in;
77

ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 450
22

3-
#include "types.comp"
4-
#include "generic_unary_head.comp"
3+
#include "types.glsl"
4+
#include "generic_unary_head.glsl"
55

66
#extension GL_EXT_control_flow_attributes : require
77

ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#version 450
22

3-
#include "types.comp"
3+
#include "types.glsl"
44

55
layout (push_constant) uniform parameter
66
{

0 commit comments

Comments
 (0)