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

Build llama runner fail due to pthread #3617

Closed
CHNtentes opened this issue May 15, 2024 · 10 comments
Closed

Build llama runner fail due to pthread #3617

CHNtentes opened this issue May 15, 2024 · 10 comments

Comments

@CHNtentes
Copy link

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?

@mergennachin
Copy link
Contributor

Yeah, I think it happens on PC.

We added that as part of "Common Issues and Mitigations" section in https://github.com/pytorch/executorch/blob/main/examples/models/llama2/README.md#common-issues-and-mitigations

@mergennachin
Copy link
Contributor

Are there any further actionable things to do with this github issue?

@CHNtentes
Copy link
Author

Thanks for your reply. I'll close this issue.

@CHNtentes CHNtentes reopened this May 16, 2024
@CHNtentes
Copy link
Author

Are there any further actionable things to do with this github issue?

@mergennachin I built llama runner on pc successfully, but when I build it for android, it again gives me another similar error:

(executorch) v2x@v2x-OMEN-Desktop:/hdd_2/ltg/executorch$ cmake --build cmake-out-android/examples/models/llama2 -j16 --config Release                     [ 16%] Building CXX object runner/CMakeFiles/llama_runner.dir/runner.cpp.o
[ 16%] Building CXX object runner/CMakeFiles/llama_runner.dir/__/tokenizer/bpe_tokenizer.cpp.o
[ 25%] Building CXX object runner/CMakeFiles/llama_runner.dir/hdd_2/ltg/executorch/extension/evalue_util/print_evalue.cpp.o
[ 33%] Building CXX object runner/CMakeFiles/llama_runner.dir/hdd_2/ltg/executorch/kernels/optimized/blas/CPUBlas.cpp.o
[ 41%] Building CXX object runner/CMakeFiles/llama_runner.dir/__/sampler/sampler.cpp.o
[ 58%] Building CXX object custom_ops/CMakeFiles/custom_ops.dir/hdd_2/ltg/executorch/extension/parallel/thread_parallel.cpp.o
[ 58%] Building CXX object custom_ops/CMakeFiles/custom_ops.dir/op_sdpa.cpp.o
[ 66%] Linking CXX static library libllama_runner.a
[ 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
ld.lld: error: unable to find library -lpthread
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
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 already add pthread to target link libraries in examples/models/llama2/CMakeLists.txt, and I don't know what to do now...

@mcr229
Copy link
Contributor

mcr229 commented May 16, 2024

@kirklandsign

@CHNtentes
Copy link
Author

I actually found a temporary solution, just remove "-lpthread" from cmake-out-android/examples/models/llama2/CMakeFiles/llama_main.dir/link.txt and the build succeeded. It seems that the project does not require -lpthread after all, not sure why it was added though.

@kirklandsign
Copy link
Contributor

Hi @CHNtentes for this part, do you mean for Android or PC?

I actually found a temporary solution, just remove "-lpthread" from cmake-out-android/examples/models/llama2/CMakeFiles/llama_main.dir/link.txt and the build succeeded. It seems that the project does not require -lpthread after all, not sure why it was added though.

@CHNtentes
Copy link
Author

Hi @CHNtentes for this part, do you mean for Android or PC?

I actually found a temporary solution, just remove "-lpthread" from cmake-out-android/examples/models/llama2/CMakeFiles/llama_main.dir/link.txt and the build succeeded. It seems that the project does not require -lpthread after all, not sure why it was added though.

It is for Android. You can find it in filename.

@kirklandsign
Copy link
Contributor

It is for Android. You can find it in filename.

OK for android I didn't use -lpthread and it worked for me. Android has its own libc bionic so the behavior might be different.

@kirklandsign
Copy link
Contributor

All resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants