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 : Link vulkan-shaders-gen with pthreads #8835

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

Patater
Copy link
Contributor

@Patater Patater commented Aug 2, 2024

When using CMake to build with Vulkan support, compiling vulkan-shaders-gen fails due to missing a CMakeLists.txt specification to link vulkan-shaders-gen with the threading library, resulting in the following error.

    [5/172] Linking CXX executable bin/vulkan-shaders-gen
    FAILED: bin/vulkan-shaders-gen
    : && /usr/bin/c++ ggml/src/vulkan-shaders/CMakeFiles/vulkan-shaders-gen.dir/vulkan-shaders-gen.cpp.o -o bin/vulkan-shaders-gen   && :
    ld: error: undefined symbol: pthread_create
    >>> referenced by vulkan-shaders-gen.cpp
    >>>               ggml/src/vulkan-shaders/CMakeFiles/vulkan-shaders-gen.dir/vulkan-shaders-gen.cpp.o:(std::__1::__libcpp_thread_create[abi:se180100](pthread**,
    >>>               void* (*)(void*), void*))
    c++: error: linker command failed with exit code 1 (use -v to see invocation)
    [6/172] Generating build details from Git
    -- Found Git: /usr/local/bin/git (found version "2.45.2")
    ninja: build stopped: subcommand failed.

Add the CMakeLists.txt specification to link vulkan-shaders-gen with the threading library and fix the above error.

Fixes #8834

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
benelan Ben Elan
When using CMake to build with Vulkan support, compiling
vulkan-shaders-gen fails due to missing a CMakeLists.txt specification
to link vulkan-shaders-gen with the threading library, resulting in the
following error.

    [5/172] Linking CXX executable bin/vulkan-shaders-gen
    FAILED: bin/vulkan-shaders-gen
    : && /usr/bin/c++ ggml/src/vulkan-shaders/CMakeFiles/vulkan-shaders-gen.dir/vulkan-shaders-gen.cpp.o -o bin/vulkan-shaders-gen   && :
    ld: error: undefined symbol: pthread_create
    >>> referenced by vulkan-shaders-gen.cpp
    >>>               ggml/src/vulkan-shaders/CMakeFiles/vulkan-shaders-gen.dir/vulkan-shaders-gen.cpp.o:(std::__1::__libcpp_thread_create[abi:se180100](pthread**,
    >>>               void* (*)(void*), void*))
    c++: error: linker command failed with exit code 1 (use -v to see invocation)
    [6/172] Generating build details from Git
    -- Found Git: /usr/local/bin/git (found version "2.45.2")
    ninja: build stopped: subcommand failed.

Add the CMakeLists.txt specification to link vulkan-shaders-gen with the
threading library and fix the above error.

Fixes ggml-org#8834
@Patater Patater force-pushed the fix-vulkan-pthreads branch from c86f6a9 to 9cdd1df Compare August 2, 2024 18:05
@Patater Patater changed the title cmake: Link vulkan-shaders-gen with pthreads cmake : Link vulkan-shaders-gen with pthreads Aug 2, 2024
@0cc4m
Copy link
Collaborator

0cc4m commented Aug 4, 2024

Is it a specific OS/distro/compiler setup that causes this? I have been using CMake to build Vulkan without issues on Linux.

I'll test this later. Thank you for the submission.

@0cc4m 0cc4m self-assigned this Aug 4, 2024
@Patater
Copy link
Contributor Author

Patater commented Aug 5, 2024

Is it a specific OS/distro/compiler setup that causes this? I have been using CMake to build Vulkan without issues on Linux.

Yes, this is an issue on FreeBSD with clang. Here's the version which led me to discover the missing dependency:

$ cc --version
FreeBSD clang version 18.1.5 (https://github.com/llvm/llvm-project.git llvmorg-18.1.5-0-g617a15a9eac9)
Target: x86_64-unknown-freebsd14.1
Thread model: posix
InstalledDir: /usr/bin

Other toolchains may include the threading library by default, but the robust thing to do is to be explicit about what we depend on. In this case, vulkan-shaders-gen requires threads, so we should tell CMake we require threads and let it take care of doing whatever necessary to build with the target toolchain.

@0cc4m
Copy link
Collaborator

0cc4m commented Aug 5, 2024

You're right. Do you know if the same issue exists on FreeBSD with the Makefile?

@mofosyne mofosyne added the Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix label Aug 5, 2024
@Patater
Copy link
Contributor Author

Patater commented Aug 5, 2024

Do you know if the same issue exists on FreeBSD with the Makefile?

The issue does not exist with the Makefile. The Makefile correctly uses -pthread during the build. As you can see, the vulkan-shaders-gen binary builds fine and runs as part of the build when we use make.

$ GGML_VULKAN=1 GGML_CURL=1 gmake -j
...
/usr/local/bin/ccache c++ -std=c++11 -fPIC -O3 -g -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wmissing-declarations -Wmissing-noreturn -pthread -f
openmp  -march=native -mtune=native -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi -Iggml/include -Iggml/src -Iinclude -Isr
c -Icommon -D_XOPEN_SOURCE=600 -D__BSD_VISIBLE -DNDEBUG -DGGML_USE_OPENMP -DGGML_USE_LLAMAFILE -DGGML_USE_VULKAN  -o vulkan-shaders-gen -L/usr/local/lib -lvulkan
  ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp
...
/usr/local/bin/ccache c++ -std=c++11 -fPIC -O3 -g -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wmissing-declarations -Wmissing-noreturn -pthread -f
openmp  -march=native -mtune=native -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi -Iggml/include -Iggml/src -Iinclude -Isr
c -Icommon -D_XOPEN_SOURCE=600 -D__BSD_VISIBLE -DNDEBUG -DGGML_USE_OPENMP -DGGML_USE_LLAMAFILE -DGGML_USE_VULKAN  -c common/build-info.cpp -o common/build-info.o
/code/github.com/ggerganov/llama.cpp/vulkan-shaders-gen \                                                                                                        
        --glslc      glslc \                                                                                                                                     
        --input-dir  ggml/src/vulkan-shaders \                                                                                                                   
        --target-hpp ggml/src/ggml-vulkan-shaders.hpp \                                                                                                          
        --target-cpp ggml/src/ggml-vulkan-shaders.cpp                                                                                                            
ggml_vulkan: Generating and compiling shaders to SPIR-V
...

@0cc4m
Copy link
Collaborator

0cc4m commented Aug 6, 2024

Thank you.

@0cc4m 0cc4m merged commit db20f50 into ggml-org:master Aug 6, 2024
53 checks passed
@Patater Patater deleted the fix-vulkan-pthreads branch August 6, 2024 14:02
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Aug 7, 2024

Verified

This commit was signed with the committer’s verified signature.
benelan Ben Elan
When using CMake to build with Vulkan support, compiling
vulkan-shaders-gen fails due to missing a CMakeLists.txt specification
to link vulkan-shaders-gen with the threading library, resulting in the
following error.

    [5/172] Linking CXX executable bin/vulkan-shaders-gen
    FAILED: bin/vulkan-shaders-gen
    : && /usr/bin/c++ ggml/src/vulkan-shaders/CMakeFiles/vulkan-shaders-gen.dir/vulkan-shaders-gen.cpp.o -o bin/vulkan-shaders-gen   && :
    ld: error: undefined symbol: pthread_create
    >>> referenced by vulkan-shaders-gen.cpp
    >>>               ggml/src/vulkan-shaders/CMakeFiles/vulkan-shaders-gen.dir/vulkan-shaders-gen.cpp.o:(std::__1::__libcpp_thread_create[abi:se180100](pthread**,
    >>>               void* (*)(void*), void*))
    c++: error: linker command failed with exit code 1 (use -v to see invocation)
    [6/172] Generating build details from Git
    -- Found Git: /usr/local/bin/git (found version "2.45.2")
    ninja: build stopped: subcommand failed.

Add the CMakeLists.txt specification to link vulkan-shaders-gen with the
threading library and fix the above error.

Fixes ggml-org#8834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Failure to build vulkan-shaders-gen on FreeBSD with CMake
3 participants