Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vulkan : fix build failure caused by vulkan-shaders-gen install #14047

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

Conversation

AsbjornOlling
Copy link
Contributor

@AsbjornOlling AsbjornOlling commented Jun 6, 2025

The problem

It seems like the CMakelists.txt refactor in PR #13263 caused some build errors when compiling for vulkan.

This cmake issue also caused the llama-cpp-rs rust bindings to no longer compile for vulkan, see: utilityai/llama-cpp-rs#747

I found one other issue related to this problem: #13753

It's reproducible by running the nix build for the vulkan target: nix build '.#vulkan'

Or to run for a specific ref: nix build 'github:ggml-org/llama.cpp/b5600'

Somehow, for some build environments, that change caused the vulkan-shaders-gen executable to be placed in a wrong directory.

The fix

This small change to the cmake config fixes it. I'm not very familiar with the cmake setup in llama.cpp, or cmake in general, so it would be nice if someone more familiar with cmake than me would review this :)

It seems that this PR fixes compilation for vulkan in the utilityai rust bindings, in the nix flake, and in termux. I haven't tested the termux thing, but it had an identical symptom to the two other environments.

Testing

nix build '.#vulkan' now works again.

I also ran the CI suite, for CPU and vulkan targets:

bash ./ci/run.sh ./tmp/results ./tmp/mnt` # works
GG_BUILD_VULKAN=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt` # also works

I also tested that the vulkan docker build still works, like this:

docker build -t local/llama.cpp:full-vulkan --target full -f .devops/vulkan.Dockerfile

I also tested it on the unit and integration test suites of nobodywho.

I have only tested the build on x86_64-linux.

@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 Jun 6, 2025
@0cc4m 0cc4m requested a review from bandoti June 6, 2025 11:13
@AsbjornOlling
Copy link
Contributor Author

Uh, oh - build failure on windows.

  Performing install step for 'vulkan-shaders-gen'
  -- Install configuration: "Release"
  CMake Error at cmake_install.cmake:39 (file):
    file INSTALL cannot find
    "D:/a/llama.cpp/llama.cpp/build/ggml/src/ggml-vulkan/vulkan-shaders-gen-prefix/src/vulkan-shaders-gen-build/Release/vulkan-shaders-gen.exe":
    No error.

Seems like the new error on windows is exactly the error that I am trying to address on linux.

@bandoti
Copy link
Collaborator

bandoti commented Jun 6, 2025

It seems to me we need to keep the runtime output directory setting then in some cases but not others—or perhaps use some sort of generator expression. There can be issues with multi-configuration generators that we need to ensure work properly.

For example, the reason we set RUNTIME_OUTPUT_DIRECTORY is so the binaries get installed in the same location as the "parent" project.

I'd like to know though what is the difference between the nix builds and the regular Linux builds, and should we bring Nix in line with the Ubuntu builds?

@7c6f434c
Copy link

7c6f434c commented Jun 7, 2025

From my observations, the Nix-sandboxed build failure looks like compiler putting the compiled program where it needs to be; but later, when installing from this location to the same location, CMake starts by deleting the target file (equal to the source file) and cannot copy the now-freshly-deleted source file afterwards.

@bandoti
Copy link
Collaborator

bandoti commented Jun 7, 2025

Err hold on I'm going to take a closer look at what the Windows builds are doing. I am starting to see where there might be some problems with those directories.

@bandoti
Copy link
Collaborator

bandoti commented Jun 7, 2025

Okay sorry for the confusion. I think this is a simple issue where the Windows builds are creating a Release build for the Vulkan-shaders-gen and the debug build is expecting it to be in the debug location.

So your proposed change here should be good but it's only part of the picture. 😊

Perhaps:


set(VULKAN_SHADER_GEN_CMAKE_BUILD_ARGS "")
    if (CMAKE_BUILD_TYPE AND CMAKE_BUILD_TYPE MATCHES "Debug|Release|MinSizeRel|RelWithDebInfo")
        list(APPEND VULKAN_SHADER_GEN_CMAKE_BUILD_ARGS --config=${CMAKE_BUILD_TYPE})
    endif()

Is setting the build type but the install command is not using the --config=${CMAKE_BUILD_TYPE}. For multi-configuration generators it also needs to be specified at install time.

So we probably want to add a separate variable like VULKAN_SHADER_GEN_CMAKE_INSTALL_ARGS in similar fashion to the above.

@7c6f434c
Copy link

I can confirm that 7c6f434c@0c65422 works on Nixpkgs side, but I don't really use Windows. @AsbjornOlling will you update the PR? Or should I open another one myself to see if CI passes?

@AsbjornOlling
Copy link
Contributor Author

AsbjornOlling commented Jun 10, 2025

@7c6f434c I will update the PR and test if it compiles on windows

EDIT: it doesn't. Fails to compile for windows on both this repo's CI, and my downstream project's CI.

...actually, looks the CI job from this repo for windows/vulkan never ran. Seems like it might have been cancelled because of a failling unit test on another windows target?

@AsbjornOlling AsbjornOlling force-pushed the fix-vulkan-build-failure-again branch from 0ca6e8d to cb3bf57 Compare June 10, 2025 09:03
@AsbjornOlling AsbjornOlling requested a review from bandoti June 10, 2025 09:34
@bandoti

This comment has been minimized.

@bandoti

This comment has been minimized.

@bandoti

This comment has been minimized.

@slaren

This comment has been minimized.

@bandoti

This comment has been minimized.

@bandoti
Copy link
Collaborator

bandoti commented Jun 12, 2025

@AsbjornOlling The fix has been merged into master—whenever you're ready, merging master into this branch should properly run the changes here. Thanks.

bandoti

This comment was marked as outdated.

@AsbjornOlling
Copy link
Contributor Author

AsbjornOlling commented Jun 12, 2025

Seems like it's showing the same issue on windows as before.
#14047 (comment)

 Performing install step for 'vulkan-shaders-gen'
  -- Install configuration: "Release"
  CMake Error at cmake_install.cmake:39 (file):
    file INSTALL cannot find
    "C:/a/llama.cpp/llama.cpp/build/ggml/src/ggml-vulkan/vulkan-shaders-gen-prefix/src/vulkan-shaders-gen-build/Release/vulkan-shaders-gen.exe":
    No error.

I wonder how the windows build is different from linux and macos. Could it be something to do with file extensions?
EDIT: nah file extensions seem to be handled by ${_ggml_vk_host_suffix}

@bandoti
Copy link
Collaborator

bandoti commented Jun 12, 2025

@AsbjornOlling I just realized the issue might be with the CMake command-line on the GitHub workflow. The install is specifying a Release build explicitly, but the generation step doesn't specify at all.

For this, I think we need to add -DCMAKE_BUILD_TYPE=Release to the command-line. Otherwise it seems to be defaulting to debug on the generate step (which is where the external project set up).

@bandoti
Copy link
Collaborator

bandoti commented Jun 13, 2025

Okay, sorry for the whirlwind here. In order to properly get this working, I want to restate the issue:

  1. When a multi-configuration generator is used, any of the supported configurations may be built (Debug, Release, etc.)—so at generation-time, it cannot assume one. At the moment, this is why the vulkan-shaders/CMakeLists.txt copies all configurations into the same CMAKE_RUNTIME_OUTPUT_DIRECTORY, so no matter which configuration is chosen, the vulkan-shaders-gen.exe will be available.
  2. When a single-configuration generator is used, the generate step (using -DCMAKE_BUILD_TYPE=Release) must match the build step (--config Release), which must also match the install step (if it is run).

We are seeing a couple problems with this: (a) the CI job is not specifying the proper generate flags; (b) in order to apply the Nix package fix (removing -DCMAKE_RUNTIME_OUTPUT_DIRECTORY) we need a way to handle case 1 above—and this seems to be simply forwarding the configurations along for gen., build, and install.

ExternalProject_Add(
    vulkan-shaders-gen
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders
    CMAKE_ARGS 
        ${VULKAN_SHADER_GEN_CMAKE_ARGS}
        -DCMAKE_BUILD_TYPE=$<CONFIG>  # Pass current config
    BUILD_COMMAND 
        ${CMAKE_COMMAND} --build . --config $<CONFIG> ${VULKAN_SHADER_GEN_CMAKE_BUILD_ARGS}
    INSTALL_COMMAND 
        ${CMAKE_COMMAND} --install . --config $<CONFIG>
    INSTALL_DIR ${CMAKE_BINARY_DIR}/$<CONFIG>
)

And we can probably just remove this code because it is encoded in $<CONFIG> now:

    set(VULKAN_SHADER_GEN_CMAKE_BUILD_ARGS "")
    set(VULKAN_SHADER_GEN_CMAKE_INSTALL_ARGS "")
    if (CMAKE_BUILD_TYPE AND CMAKE_BUILD_TYPE MATCHES "Debug|Release|MinSizeRel|RelWithDebInfo")
        list(APPEND VULKAN_SHADER_GEN_CMAKE_BUILD_ARGS --config=${CMAKE_BUILD_TYPE})
        list(APPEND VULKAN_SHADER_GEN_CMAKE_INSTALL_ARGS --config=${CMAKE_BUILD_TYPE})
    endif()

@bandoti
Copy link
Collaborator

bandoti commented Jun 13, 2025

@AsbjornOlling Because this issue seems to extend far beyond the original fix for Nix, I took the liberty to make the batch of Windows changes. Please see #14179 .

@AsbjornOlling
Copy link
Contributor Author

To be clear: the main motivation for this PR wasn't to fix nix builds, but to fix vulkan builds of the utilityai/llama-cpp-rs rust bindings. The issue is just most easily reproducible with nix.

@bandoti
Copy link
Collaborator

bandoti commented Jun 14, 2025

Ah—sorry for the confusion. I will update the note on the PR. If you are able to test that one and it fixes the bindings, that would be great! It now passes all the CI checks, but as these things go perhaps the rust bindings do not compile. 😅

Thank you!

@bandoti
Copy link
Collaborator

bandoti commented Jun 16, 2025

Closing as fixed in #14179

@bandoti bandoti closed this Jun 16, 2025
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.

4 participants