Skip to content

cmake: simplify vulkan shader test logic #13263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 14, 2025

Conversation

bandoti
Copy link
Collaborator

@bandoti bandoti commented May 2, 2025

This PR adds a CMake function to simplify the shader feature-detection logic. In addition, the requisite preprocessor defines are shared with the vulkan-shaders-gen project through an auto-generated cmake file, preventing the need to pass them along manually.

@github-actions github-actions bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels May 2, 2025
@bandoti bandoti requested review from jeffbolznv and 0cc4m May 2, 2025 12:24
@bandoti
Copy link
Collaborator Author

bandoti commented May 2, 2025

@jeffbolznv I think you were right about using the external project add for vulkan-shaders-gen for both the cross-compile and the regular build. I am going to try that here now I guess the timing is right. 😊

@jeffbolznv
Copy link
Collaborator

Thanks for making these cleanups. The changes look reasonable to me, though I don't know if there are any weird consequences of passing cmake arguments via file.

@bandoti
Copy link
Collaborator Author

bandoti commented May 2, 2025

No problem. We'll see how the CI responds. I added a couple cross-compile builds there so at very least we have the basic compile-checks covered.

@0cc4m
Copy link
Collaborator

0cc4m commented May 4, 2025

Interesting. This doesn't seem much simpler, though. It's about as much code and going through an external file is slightly convoluted. But I don't know enough about cmake to judge that particularly well, so I'll leave it up to you to decide what is better.

@bandoti
Copy link
Collaborator Author

bandoti commented May 4, 2025

The primary motivation is to only change one place when new extension checks are added.

Because the Vulkan-shaders-gen project had several bugs associated with missing defines, this change would ensure that they will be present without having to duplicate flags within the sub project.

Also, the "subdirs" loading is replaced by unifying the cross-compile approach with a regular build, both using ExternalProject_Add now.

@bandoti
Copy link
Collaborator Author

bandoti commented May 6, 2025

The one issue with using the file copy, however, is that one cannot build the Vulkan-shaders-gen without building ggml-vulkan, and so it becomes an implementation detail despite being an external project.

I am happy to undo that change if this is not desirable. From my point of view this is the only way I've built the app, but perhaps there's a reason to decouple them.

The net effect is just that we need to update 3 spots instead of 1 when adding new extension capabilities.

@bandoti
Copy link
Collaborator Author

bandoti commented May 13, 2025

I went ahead and removed the auto-generated file, but as a compromise the set of extension arguments are appended to a list which gets expanded automatically when adding vulkan-shaders-gen project.

So, when adding new extension checks we just need to make two changes:

  1. In ggml/src/ggml-vulkan/CMakeLists.txt:
    test_shader_extension_support(
        "GL_KHR_cooperative_matrix"
        "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
        "GGML_VULKAN_COOPMAT_GLSLC_SUPPORT"
    )
  1. And ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt:
if (GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
    add_compile_definitions(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT)
    message(STATUS "Enabling coopmat glslc support")
endif()

Well, and of course the shader test itself... 😅

Copy link
Collaborator

@0cc4m 0cc4m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either is fine, you know a lot more than me about cmake. As long as it works and I can figure out where new extensions have to go, I'm happy. 😄

@bandoti bandoti merged commit 09d13d9 into ggml-org:master May 14, 2025
44 checks passed
Silver267 pushed a commit to Silver267/llama.cpp that referenced this pull request May 14, 2025
@bandoti
Copy link
Collaborator Author

bandoti commented May 15, 2025

@0cc4m glad I could be of help. Learning Vulkan is on my bucket list but I'm not there yet—maybe some day I'll be able to help you all with the actual work! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning Vulkan Issues specific to the Vulkan backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants