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

Run libtorch examples, export error "undefined reference to xxx" #73829

Open
TheGreatGalaxy opened this issue Mar 5, 2022 · 8 comments
Open
Labels
module: abi libtorch C++ ABI related problems module: binaries Anything related to official binaries that we release to users module: build Build system issues triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@TheGreatGalaxy
Copy link

TheGreatGalaxy commented Mar 5, 2022

🐛 Describe the bug

When run the pytorch example: https://pytorch.org/cppdocs/installing.html

CMakeLists.txt files:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)

find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# message("TORCH_CXX_FLAGS====: " ${TORCH_CXX_FLAGS})

# link_directories("/usr/local/cuda-11.2/targets/x86_64-linux/lib")

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
message("TORCH_LIBRARIES:" "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

if (MSVC)
  file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  add_custom_command(TARGET example-app
                     POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E copy_if_different
                     ${TORCH_DLLS}
                     $<TARGET_FILE_DIR:example-app>)
endif (MSVC)

cpp:

#include <torch/torch.h>
#include <iostream>

int main() {
  torch::Tensor tensor = torch::rand({2, 3});
  std::cout << tensor << std::endl;
}

cmake command:

cmake -DCMAKE_PREFIX_PATH=/home/guangtong/project/libtorch  ..

cmake --build . --config Release

will appears:

cmake --build . --config Release
[ 50%] Linking CXX executable example-app
/home/xxxxxx/project/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaStreamUpdateCaptureDependencies@libcudart.so.11.0'
/home/xxxxxx/project/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaStreamGetCaptureInfo_v2@libcudart.so.11.0'
/home/xxxxxx/project/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaGraphRetainUserObject@libcudart.so.11.0'
/home/xxxxxx/project/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaUserObjectCreate@libcudart.so.11.0'
collect2: error: ld returned 1 exit status
CMakeFiles/example-app.dir/build.make:110: recipe for target 'example-app' failed
make[2]: *** [example-app] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example-app.dir/all' failed
make[1]: *** [CMakeFiles/example-app.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

but seems the file dependencies is ok:

ldd -r  libtorch_cuda_cpp.so
	linux-vdso.so.1 (0x00007ffe39818000)
	libcudart-a7b20f20.so.11.0 (0x00007fba89fc1000)
	libc10_cuda.so (0x00007fba89d5b000)
	libnvToolsExt-24de1d56.so.1 (0x00007fba89b51000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fba89932000)
	libc10.so (0x00007fba896ba000)
	libtorch_cpu.so (0x00007fba726f1000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fba724ed000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fba722e5000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fba71f5c000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fba71bbe000)
	libgomp-52f2fd74.so.1 (0x00007fba7198b000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fba71773000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fba71382000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fbafb5a3000)

Versions

libtorch version:
https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.10.2%2Bcu113.zip

os: Ubuntu 18.04

cmake version: 3.10.2

cc @ezyang @seemethere @malfet

@TheGreatGalaxy TheGreatGalaxy changed the title Run examples: libtorch_cuda_cpp.so: undefined reference to `cudaStreamUpdateCaptureDependencies@libcudart.so.11.0' Run libtorch examples, export error "undefined reference to xxx" Mar 5, 2022
@mruberry mruberry added module: build Build system issues triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Mar 7, 2022
@adeilsonsilva
Copy link

adeilsonsilva commented Mar 17, 2022

Check your CUDA version using nvidia-smi, you probably have CUDA < 11.3. I was trying to use the same libtorch version as you with CUDA 11.2 and had the same errors. After I downloaded libtorch for cuda 11.1 I was able to compile succesfully.

@TheGreatGalaxy
Copy link
Author

Check your CUDA version using nvidia-smi, you probably have CUDA < 11.3. I was trying to use the same libtorch version as you with CUDA 11.2 and had the same errors. After I downloaded libtorch for cuda 11.1 I was able to compile succesfully.

My cuda is 11.4. I will try with cuda 11.1. Thanks!

@waldirfc
Copy link

I still had the same problem with libtorch cu113 and cuda 11.4.
Meanwhile, I am working on the CPU version.
If you have any news I would appreciate them.

@Fatichti
Copy link

I try to install pytorch from source.
i have CUDA 11.7 on my computer.

i have build successfully but i have an error when i try to import a module from d2go

Error initial :
Failed to load image Python extension: /home/kainoo/miniconda3/envs/Env4D2go/lib/python3.9/site-packages/torch/lib/libtorch_cuda_cpp.so: undefined symbol: _ZN5torch19kParamCommsCallNameE

Error detail :
image

Link lib detail:
image

Do you have any idea to solve it ?

@malfet malfet added module: binaries Anything related to official binaries that we release to users module: abi libtorch C++ ABI related problems labels Aug 25, 2022
@MrRace
Copy link

MrRace commented Nov 9, 2022

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0

Therefore I choose the https://download.pytorch.org/libtorch/cu117/libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcu117.zip
And follow the guideline in https://pytorch.org/cppdocs/installing.html and when run the ./example-app, but error comes:

./example-app: symbol lookup error: /share/tools/libtorch-cxx11-abi-shared-with-deps-1.13.0+cu117/lib/libtorch_cuda_cpp.so: undefined symbol: _ZTIN4c10d4WorkE

How to solve it ? Thanks a lot!

@Wentao795
Copy link

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0

因此我选择了https://download.pytorch.org/libtorch/cu117/libtorch-cxx11-abi-shared-with-deps-1.13.0%2Bcu117.zip And follow the guideline inhttps://pytorch.org/cppdocs/installing.html和 when run the ./example-app,但是错误来了:

./example-app: symbol lookup error: /share/tools/libtorch-cxx11-abi-shared-with-deps-1.13.0+cu117/lib/libtorch_cuda_cpp.so: undefined symbol: _ZTIN4c10d4WorkE

如何解决?非常感谢!

hi ~, i have the same problem,you have solved it?

@thiagocrepaldi
Copy link
Collaborator

same here, but the error only happens when I try to use torch::randn({1, 10, 12, 12}). If I use other torch APIs like torch::relu, there is no linking issue.

@puppy2333
Copy link

I think using matched cuda and libtorch versions solves this issue. Moreover maybe we should only use the listed versions of libtorch on the official website (currently 11.8, 12.1 and 12.4)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: abi libtorch C++ ABI related problems module: binaries Anything related to official binaries that we release to users module: build Build system issues triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

10 participants