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

cmake: add ggml find package #11369

Merged
merged 14 commits into from
Jan 26, 2025
Merged

Conversation

bandoti
Copy link
Collaborator

@bandoti bandoti commented Jan 23, 2025

This change adds a cmake find package to the ggml library. It is responsible for providing link targets (of the form ggml::<backend>) for each backend. In addition, there is a ggml::all target which will link all backends.

Example usage:

find_package(ggml)
# ...
add_executable(myapp myapp.cpp)
target_link_libraries(myapp ggml::vulkan)

This change also now requires users of the llama find-package to explicitly request the backends:

find_package(Llama)  # will automatically call find_package(ggml)
# ...
add_executable(myapp myapp.cpp)
target_link_libraries(myapp llama ggml::all) # or some other backend

Work progress:

  • Implement general ggml find-package
  • Create new example application which does not depend on common (replacing main-cmake-pkg)

@github-actions github-actions bot added build Compilation issues ggml changes relating to the ggml tensor library for machine learning labels Jan 23, 2025
@github-actions github-actions bot added the devops improvements to build systems and github actions label Jan 23, 2025
@ggerganov
Copy link
Owner

@bandoti Thank you for helping out. Do you plan to finish the rest of the check items within this PR?

@bandoti
Copy link
Collaborator Author

bandoti commented Jan 24, 2025

@bandoti Thank you for helping out. Do you plan to finish the rest of the check items within this PR?

I need to at very least complete the second item as I haven't tested a link against it yet. Since the other examples depend on common I can't use them and need something very minimal, preferably in C to ensure the APIs are clean. If you happen to have such a simple example kicking around the office I could copy and paste it. 😉 Otherwise I am happy to work through it.

I am thinking of deferring the CI change however as there's a couple ways I can wire it into the general build. It would be nice to have it tested on all the existing builds (instead of adding new jobs) since they have various backends already and we don't want to stress the CI unnecessarily with more redundant builds.

@ggerganov
Copy link
Owner

The simple example does not depend on libcommon.

@bandoti
Copy link
Collaborator Author

bandoti commented Jan 24, 2025

The simple example does not depend on libcommon.

Perfect! Thank you. I will use that as a basis then.

@bandoti
Copy link
Collaborator Author

bandoti commented Jan 24, 2025

I have finished this change and tested with CPU/Vulkan builds to ensure multiple backends works okay. Although I was careful to ensure the other transient dependencies are roped in for the other backends, I expect some issues will come up and can be fixed in later PRs. In addition, both with/without shared libraries has been tested.

My plan is to follow up with some CI related changes to add regression tests here. As of now, none of this is being tested by the CI, so at the very least I will add one in the coming week to test CPU + Vulkan to ensure nothing breaks the transient dependencies. This would ensure that should issues arise it is likely due only to a specific dependency not being met as opposed to a broken cmake package (hopefully)!

@slaren, @ggerganov
If you're free to test this whenever time permits (or have someone else in mind), I recommend following the new README in examples/simple-cmake-pkg, adding or removing whatever flags for the appropriate backends that you like to use. 😊

Copy link
Owner

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

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

Tested on macOS and it works as expected:

 otool -L ./examples/simple-cmake-pkg/build/llama-simple-cmake-pkg 
./examples/simple-cmake-pkg/build/llama-simple-cmake-pkg:
	@rpath/libllama.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libggml-cpu.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libggml-blas.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libggml-metal.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libggml.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libggml-base.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1800.105.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)

examples/simple-cmake-pkg/README.md Outdated Show resolved Hide resolved
examples/simple-cmake-pkg/README.md Outdated Show resolved Hide resolved
@ggerganov
Copy link
Owner

My plan is to follow up with some CI related changes to add regression tests here. As of now, none of this is being tested by the CI, so at the very least I will add one in the coming week to test CPU + Vulkan to ensure nothing breaks the transient dependencies. This would ensure that should issues arise it is likely due only to a specific dependency not being met as opposed to a broken cmake package (hopefully)!

@bandoti Sounds great, help is appreciated. Sent you a collaborator invite.

bandoti and others added 2 commits January 26, 2025 09:09
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
@bandoti
Copy link
Collaborator Author

bandoti commented Jan 26, 2025

@ggerganov Thank you for the vote of confidence! I am excited to be part of such an interesting project and look forward to adding more value over time.

Should I merge this one in once the CI finishes? 😅

@bandoti bandoti merged commit 19f6518 into ggerganov:master Jan 26, 2025
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Compilation issues devops improvements to build systems and github actions examples ggml changes relating to the ggml tensor library for machine learning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants