Skip to content
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

fix: ggml: fix vulkan-shaders-gen build #10448

Merged
merged 11 commits into from
Jan 15, 2025
Merged

Conversation

sparkleholic
Copy link
Contributor

The vulkan-shaders-gen target was not being built correctly in case of cross-compilation.
Other outputs need to be built for the cross compile target, but vulkan-shaders-gen needs to be built for the host.

@sparkleholic
Copy link
Contributor Author

sparkleholic commented Nov 25, 2024

@jeffbolznv , @0cc4m
This fix is ​​needed for cross-compilation.
vulkan-shaders-gen is needed at build time, so arch should be the same as host pc, but other binaries (libggml, libllama, etc.) are needed at runtime.
Therefore, CMAKE compilation variables that apply when building the llama.cpp project should not apply when building vulkan-shaders-gen in case of cross-compilation.

@0cc4m
Copy link
Collaborator

0cc4m commented Nov 25, 2024

@sparkleholic @jeffbolznv I understand, I'm sorry that a few PRs are getting delayed because of me. I'm currently ill, but getting better and I should be able to catch up with all of them later this week.

Maybe you can resolve the merge conflict already?

@jeffbolznv
Copy link
Collaborator

No rush, get well!

I'm not an expert at cmake or cross compilation, so I don't think I should review the change.

@sparkleholic
Copy link
Contributor Author

@0cc4m
master rebased to resolve conflicts.
I didn't mean to rush you. I sincerely hope you feel better soon. :)

@0cc4m
Copy link
Collaborator

0cc4m commented Nov 27, 2024

I can confirm this still works as usual on my system, but I'm also not a CMake expert. Maybe @bandoti can take a look?

@bandoti
Copy link
Collaborator

bandoti commented Nov 27, 2024

I am happy to take a look. The one thing that comes to mind here after initial look through is being able to customize the compiler in this case. In particular, gcc and g++ are hardcoded.

It would be worthwhile to add a default toolchain file for the build and allow one to customize by passing -DGGML_SHADERS_GEN_CROSS_TOOLCHAIN=... (or similar)

This would allow one to use a desire toolchain—maybe clang, etc.

And a lot of those switches passed to ExternalProject_Add() can of course be moved to the toolchain file instead.

@sparkleholic
Copy link
Contributor Author

@bandoti
Thank you for the valuable feedback.

I have updated the code to handle the GGML_SHADERS_GEN_TOOLCHAIN variable. When this variable is provided, the specified file is used. If it is not set, the code generates a temporary host toolchain file by detecting the host environment's compiler.

Please review the updated code once again.

@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 Nov 28, 2024
@0cc4m
Copy link
Collaborator

0cc4m commented Dec 2, 2024

@bandoti Can you take another look?

ggml/src/ggml-vulkan/CMakeLists.txt Outdated Show resolved Hide resolved
ggml/src/ggml-vulkan/CMakeLists.txt Outdated Show resolved Hide resolved
@bandoti
Copy link
Collaborator

bandoti commented Dec 2, 2024

@sparkleholic Sorry for the delay! I had these review comments in but forgot to submit them. 🤦‍♂️

@bandoti
Copy link
Collaborator

bandoti commented Dec 15, 2024

@sparkleholic Just following up on this change. If you need further assistance please let me know I am happy to help.

@sparkleholic
Copy link
Contributor Author

sparkleholic commented Dec 24, 2024

@bandoti < Sorry for the late reply.
Thank you for the comments. I'll follow up this soon.

@sparkleholic
Copy link
Contributor Author

Rebased branch to latest master.

@bandoti
Copy link
Collaborator

bandoti commented Dec 28, 2024

@sparkleholic No worries on the delay! Your contribution is greatly appreciated :)

It appears as though the test failure is unrelated to this. I'm wondering if merging the latest and rerunning the tests will clear the status. I have only one minor question in the review.

@bandoti
Copy link
Collaborator

bandoti commented Jan 8, 2025

@sparkleholic I have submitted a pull request to your master_fix branch which updates to latest and resolves a minor merge conflict. Please merge it into your branch so we can get the CI fixed here and merge these changes in!

Here's the PR for reference: sparkleholic#2

@sparkleholic
Copy link
Contributor Author

@sparkleholic I have submitted a pull request to your master_fix branch which updates to latest and resolves a minor merge conflict. Please merge it into your branch so we can get the CI fixed here and merge these changes in!

Here's the PR for reference: sparkleholic#2

@bandoti < Thanks a lot!
I'l like to merge your PR into my branch first to proceed this PR.
image
Could you confirm which option should be selected for this?

@bandoti
Copy link
Collaborator

bandoti commented Jan 9, 2025

@sparkleholic A regular merge commit (the default) should be good. Our changes here will get squashed once they merge it into master. 😊

I just made one change, FYI, which adds NO_CMAKE_FIND_ROOT_PATH to the find_program calls. This will ensure that the cross-compile prefixes will be ignored when searching for the system compilers.

@sparkleholic sparkleholic requested a review from ngxson as a code owner January 10, 2025 05:00
@github-actions github-actions bot added documentation Improvements or additions to documentation testing Everything test related examples python python script changes labels Jan 10, 2025
Fix compile error not finding vulkan-shaders-gen
Fix build issues with vulkan-shaders-gen:
- Add target dependency for correct build order
- Use CMAKE_HOST_SYSTEM_NAME for executable suffix
- Fix MSVC output directory in host toolchain
- Normalize path handling for cross-compilation
fix: normalize vulkan-shaders-gen output path for MSVC
Improve host compiler detection for vulkan shader generation:
- Add NO_CMAKE_FIND_ROOT_PATH to all compiler searches
- Consolidate compiler detection logic
- Fix Windows-specific MSVC detection
- Ensure correct compiler search in cross-compilation
@sparkleholic sparkleholic requested a review from bandoti January 12, 2025 13:11
Copy link
Collaborator

@bandoti bandoti left a comment

Choose a reason for hiding this comment

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

Everything seems good to me except my one comment on detect_host_compiler. After that (whether the suggestion works or not and we keep it as-is) I am happy to move forward!

ggml/src/ggml-vulkan/CMakeLists.txt Show resolved Hide resolved
Simplified the CMake function to improve the process of detecting the host compiler.
@sparkleholic
Copy link
Contributor Author

sparkleholic commented Jan 13, 2025

Please hold on merging this patch for a moment. I'm checking my cross-compilation environment one last time.

Since `vulkan-shader-gen.cpp` only requires the `glslc` executable
and not the Vulkan headers or libraries, CMakeLists.txt needs to
be corrected.
(See: ecc93d0)
@sparkleholic
Copy link
Contributor Author

FYI: @jeffbolznv
Added a necessary change for cross-compiling environment.
37d0cb6

@sparkleholic
Copy link
Contributor Author

@bandoti <
Ready to merge.

@sparkleholic sparkleholic requested a review from bandoti January 13, 2025 07:20
@sparkleholic sparkleholic requested a review from bandoti January 13, 2025 14:45
Copy link
Collaborator

@bandoti bandoti left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@sparkleholic
Copy link
Contributor Author

sparkleholic commented Jan 14, 2025

@bandoti , @ngxson
This PR is still open...

@0cc4m
Copy link
Collaborator

0cc4m commented Jan 14, 2025

@bandoti , @ngxson This PR is still open...

It needs approval from a collaborator. I'll do a quick test that everything runs as intended on a regular setup later today and merge if it's fine.

@ngxson
Copy link
Collaborator

ngxson commented Jan 14, 2025

This change is not related to my part. I was added because you pushed a merge commit or rebase.

Please ask for people who maintains the vulkan backend.

@ngxson ngxson removed their request for review January 14, 2025 09:43
- Rename host_toolchain.cmake.in to cmake/host-toolchain.cmake.in
ggml/CMakeLists.txt Outdated Show resolved Hide resolved
Rename the macro GGML_SHADERS_GEN_TOOLCHAIN to GGML_VULKAN_SHADERS_GEN_TOOLCHAIN
@sparkleholic sparkleholic requested a review from 0cc4m January 15, 2025 10:51
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.

Thank you for your patience with all the feedback. I tested it and found no issues.

@0cc4m 0cc4m merged commit 1d85043 into ggerganov:master Jan 15, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation examples ggml changes relating to the ggml tensor library for machine learning python python script changes server testing Everything test related Vulkan Issues specific to the Vulkan backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants