Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions ggml/src/ggml-vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.19)
cmake_policy(SET CMP0114 NEW)
cmake_policy(SET CMP0116 NEW)

find_package(Vulkan COMPONENTS glslc REQUIRED)

Expand Down Expand Up @@ -54,25 +55,25 @@ if (Vulkan_FOUND)
# Test all shader extensions
test_shader_extension_support(
"GL_KHR_cooperative_matrix"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/coopmat.comp"
"GGML_VULKAN_COOPMAT_GLSLC_SUPPORT"
)

test_shader_extension_support(
"GL_NV_cooperative_matrix2"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat2_support.comp"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/coopmat2.comp"
"GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT"
)

test_shader_extension_support(
"GL_EXT_integer_dot_product"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_integer_dot_support.comp"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/integer_dot.comp"
"GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORT"
)

test_shader_extension_support(
"GL_EXT_bfloat16"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_bfloat16_support.comp"
"${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/feature-tests/bfloat16.comp"
"GGML_VULKAN_BFLOAT16_GLSLC_SUPPORT"
)

Expand Down Expand Up @@ -160,7 +161,6 @@ if (Vulkan_FOUND)
set (_ggml_vk_genshaders_dir "${CMAKE_BINARY_DIR}/$<CONFIG>")
set (_ggml_vk_genshaders_cmd "${_ggml_vk_genshaders_dir}/vulkan-shaders-gen${_ggml_vk_host_suffix}")
set (_ggml_vk_header "${CMAKE_CURRENT_BINARY_DIR}/ggml-vulkan-shaders.hpp")
set (_ggml_vk_source "${CMAKE_CURRENT_BINARY_DIR}/ggml-vulkan-shaders.cpp")
set (_ggml_vk_input_dir "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders")
set (_ggml_vk_output_dir "${CMAKE_CURRENT_BINARY_DIR}/vulkan-shaders.spv")

Expand All @@ -176,24 +176,35 @@ if (Vulkan_FOUND)

add_custom_command(
OUTPUT ${_ggml_vk_header}
${_ggml_vk_source}

COMMAND ${_ggml_vk_genshaders_cmd}
--glslc ${Vulkan_GLSLC_EXECUTABLE}
--input-dir ${_ggml_vk_input_dir}
--output-dir ${_ggml_vk_output_dir}
--target-hpp ${_ggml_vk_header}
--target-cpp ${_ggml_vk_source}
--no-clean

DEPENDS ${_ggml_vk_shader_files}
${_ggml_vk_shaders_gen_sources}
DEPENDS ${_ggml_vk_shaders_gen_sources}
vulkan-shaders-gen

COMMENT "Generate vulkan shaders"
COMMENT "Generate vulkan shaders header"
)

target_sources(ggml-vulkan PRIVATE ${_ggml_vk_source} ${_ggml_vk_header})
target_sources(ggml-vulkan PRIVATE ${_ggml_vk_header})

foreach (file_full ${_ggml_vk_shader_files})
get_filename_component(file ${file_full} NAME)
set (_ggml_vk_target_cpp "${CMAKE_CURRENT_BINARY_DIR}/${file}.cpp")

add_custom_command(
OUTPUT ${_ggml_vk_target_cpp}
DEPFILE ${_ggml_vk_target_cpp}.d
COMMAND ${_ggml_vk_genshaders_cmd}
--glslc ${Vulkan_GLSLC_EXECUTABLE}
--source ${file_full}
--output-dir ${_ggml_vk_output_dir}
--target-hpp ${_ggml_vk_header}
--target-cpp ${_ggml_vk_target_cpp}
DEPENDS ${file_full}
${_ggml_vk_shaders_gen_sources}
vulkan-shaders-gen
COMMENT "Generate vulkan shaders for ${file}"
)
target_sources(ggml-vulkan PRIVATE ${_ggml_vk_target_cpp})
endforeach()

else()
message(WARNING "Vulkan not found")
Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/acc.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "types.comp"
#include "generic_binary_head.comp"
#include "types.glsl"
#include "generic_binary_head.glsl"

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

Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/add.comp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#extension GL_KHR_shader_subgroup_basic : enable
#endif

#include "types.comp"
#include "generic_binary_head.comp"
#include "types.glsl"
#include "generic_binary_head.glsl"

const uint num_threads = 256;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/add_id.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#extension GL_EXT_control_flow_attributes : require

#include "types.comp"
#include "types.glsl"

layout (push_constant) uniform parameter
{
Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/argmax.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "generic_head.comp"
#include "types.comp"
#include "generic_head.glsl"
#include "types.glsl"

#extension GL_EXT_control_flow_attributes : enable

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/argsort.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450
#extension GL_EXT_control_flow_attributes : enable

#include "types.comp"
#include "types.glsl"

layout(constant_id = 0) const int BLOCK_SIZE = 1024;
layout(constant_id = 1) const int BLOCK_SIZE_LOG2 = 10;
Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/clamp.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "types.comp"
#include "generic_unary_head.comp"
#include "types.glsl"
#include "generic_unary_head.glsl"

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

Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/concat.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "types.comp"
#include "generic_binary_head.comp"
#include "types.glsl"
#include "generic_binary_head.glsl"

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

Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/contig_copy.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "types.comp"
#include "generic_unary_head.comp"
#include "types.glsl"
#include "generic_unary_head.glsl"

#extension GL_EXT_control_flow_attributes : require

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/conv2d_dw.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "types.comp"
#include "types.glsl"

layout (push_constant) uniform parameter
{
Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/conv2d_mm.comp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# extension GL_KHR_shader_subgroup_shuffle : enable
#endif

#include "types.comp"
#include "types.glsl"

// shape notation: [dim(N), ..., dim(0)] -- stride(dim(j)) >= stride(dim(i)) if i > j
layout(binding = 0) readonly buffer A {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "types.comp"
#include "types.glsl"

layout (binding = 0) readonly buffer A {A_TYPE data_a[];}; // src0 - kernel: [K, Cout, Cin]
layout (binding = 1) readonly buffer B {B_TYPE data_b[];}; // src1 - input: [L, Cin]
Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/copy.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "types.comp"
#include "generic_unary_head.comp"
#include "types.glsl"
#include "generic_unary_head.glsl"

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

Expand Down
6 changes: 3 additions & 3 deletions ggml/src/ggml-vulkan/vulkan-shaders/copy_from_quant.comp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#version 450

#include "types.comp"
#include "generic_unary_head.comp"
#include "dequant_funcs.comp"
#include "types.glsl"
#include "generic_unary_head.glsl"
#include "dequant_funcs.glsl"

#if defined(DATA_A_IQ4_NL) || defined(DATA_A_MXFP4)
// 16 invocations needed for init_iq_shmem
Expand Down
8 changes: 4 additions & 4 deletions ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "rte.comp"
#include "types.comp"
#include "rte.glsl"
#include "types.glsl"

#if defined(SET_ROWS) && QUANT_K == 1
layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in;
Expand All @@ -14,7 +14,7 @@ const uint BLOCK_SIZE = 32;
layout (binding = 0) readonly buffer S {float data_s[];};

#if defined(SET_ROWS)
#include "generic_binary_head.comp"
#include "generic_binary_head.glsl"
layout (binding = 1) readonly buffer C {B_TYPE data_i[];};
layout (binding = 2) writeonly buffer Q {A_TYPE data_q[];};

Expand All @@ -25,7 +25,7 @@ layout (binding = 2) writeonly buffer Q {A_TYPE data_q[];};
#endif

#else
#include "generic_unary_head.comp"
#include "generic_unary_head.glsl"
layout (binding = 1) writeonly buffer Q {A_TYPE data_q[];};
#endif

Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/cos.comp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 450

#include "types.comp"
#include "generic_unary_head.comp"
#include "types.glsl"
#include "generic_unary_head.glsl"

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

Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-vulkan/vulkan-shaders/count_equal.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#extension GL_EXT_control_flow_attributes : enable

#include "types.comp"
#include "generic_head.comp"
#include "types.glsl"
#include "generic_head.glsl"

layout(local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_f32.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require
#endif

#include "types.comp"
#include "types.glsl"

#if defined(A_TYPE_PACKED16)
layout (binding = 0) readonly buffer A_PACKED16 {A_TYPE_PACKED16 data_a_packed16[];};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "types.comp"
#include "types.glsl"

layout(buffer_reference, std430, buffer_reference_align = 2) buffer decodeBufQ4_0 {
block_q4_0_packed16 block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ layout (push_constant) uniform parameter
uint nel;
} p;

#include "types.comp"
#include "types.glsl"
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_m.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq1_s.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_s.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xs.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq2_xxs.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_s.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq3_xxs.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_nl.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_iq4_xs.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_mxfp4.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_q2_k.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;

Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-vulkan/vulkan-shaders/dequant_q3_k.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

#include "dequant_head.comp"
#include "dequant_head.glsl"

layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;

Expand Down
Loading
Loading