Skip to content

Build llama runner fail due to pthread #3617

@CHNtentes

Description

@CHNtentes

Hi,
When I follow the insrtuction here to build llama runner on pc, it throws an error:

(executorch) v2x@v2x-OMEN-Desktop:/hdd_2/ltg/executorch$ cmake --build cmake-out/examples/models/llama2 -j8 --config Release                              [  8%] Building CXX object custom_ops/CMakeFiles/custom_ops.dir/hdd_2/ltg/executorch/extension/parallel/thread_parallel.cpp.o
[ 16%] Building CXX object runner/CMakeFiles/llama_runner.dir/__/tokenizer/bpe_tokenizer.cpp.o
[ 25%] Building CXX object custom_ops/CMakeFiles/custom_ops.dir/op_sdpa.cpp.o
[ 41%] Building CXX object runner/CMakeFiles/llama_runner.dir/runner.cpp.o
[ 41%] Building CXX object runner/CMakeFiles/llama_runner.dir/__/sampler/sampler.cpp.o
[ 58%] Building CXX object runner/CMakeFiles/llama_runner.dir/hdd_2/ltg/executorch/kernels/optimized/blas/CPUBlas.cpp.o
[ 58%] Building CXX object runner/CMakeFiles/llama_runner.dir/hdd_2/ltg/executorch/extension/evalue_util/print_evalue.cpp.o
/hdd_2/ltg/executorch/examples/models/llama2/custom_ops/op_sdpa.cpp: In lambda function:
/hdd_2/ltg/executorch/examples/models/llama2/custom_ops/op_sdpa.cpp:420:17: note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
  420 |                 [scaling_factor](Vec x, Vec y) {
      |                 ^
[ 66%] Linking CXX shared library libllama_runner.so
[ 66%] Built target llama_runner
[ 75%] Linking CXX static library libcustom_ops.a
[ 75%] Built target custom_ops
[ 83%] Building CXX object CMakeFiles/llama_main.dir/main.cpp.o
[ 91%] Building CXX object CMakeFiles/llama_main.dir/hdd_2/ltg/executorch/backends/xnnpack/threadpool/cpuinfo_utils.cpp.o
[100%] Linking CXX executable llama_main
/usr/bin/ld: CMakeFiles/llama_main.dir/hdd_2/ltg/executorch/backends/xnnpack/threadpool/cpuinfo_utils.cpp.o: in function `torch::executorch::cpuinfo::get_num_performant_cores()':
cpuinfo_utils.cpp:(.text+0x909): undefined reference to `pthread_once'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libxnnpack_backend.a(threadpool.cpp.o): in function `torch::executorch::threadpool::get_threadpool()':
threadpool.cpp:(.text._ZN5torch10executorch10threadpool14get_threadpoolEv+0x98): undefined reference to `pthread_once'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libpthreadpool.a(pthreads.c.o): in function `pthreadpool_create':
pthreads.c:(.text+0x32d): undefined reference to `pthread_create'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libpthreadpool.a(pthreads.c.o): in function `pthreadpool_destroy':
pthreads.c:(.text+0x67e): undefined reference to `pthread_join'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libcpuinfo.a(init.c.o): in function `cpuinfo_initialize':
init.c:(.text+0x17): undefined reference to `pthread_once'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libXNNPACK.a(init.c.o): in function `xnn_initialize':
init.c:(.text+0x61): undefined reference to `pthread_once'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libXNNPACK.a(hardware-config.c.o): in function `xnn_init_hardware_config':
hardware-config.c:(.text+0xf6): undefined reference to `pthread_once'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libXNNPACK.a(argmaxpool-config.c.o): in function `xnn_init_f32_argmaxpool_config':
argmaxpool-config.c:(.text+0x87): undefined reference to `pthread_once'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libXNNPACK.a(avgpool-config.c.o): in function `xnn_init_f16_avgpool_config':
avgpool-config.c:(.text+0xe0): undefined reference to `pthread_once'
/usr/bin/ld: /hdd_2/ltg/executorch/cmake-out/lib/libXNNPACK.a(avgpool-config.c.o):avgpool-config.c:(.text+0x111): more undefined references to `pthread_once' follow
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/llama_main.dir/build.make:133: llama_main] Error 1
make[1]: *** [CMakeFiles/Makefile2:119: CMakeFiles/llama_main.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

I ask ChatGPT and it tells me to add 'pthread' to target_link_libraries in examples/models/llama2/CMakeLists.txt, and it solves the issue effectively. I just wonder if this issue is only happening on my pc?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions