Open maichmueller opened 8 months ago
If I add the conan package folder for tbb to LD_LIBRARY_PATH
it does find tbbmalloc
as well
LD_LIBRARY_PATH=/u/michael.aichmueller/.conan2/p/onetb75ff22d6ae745/p/lib/:$LD_LIBRARY_PATH ldd train
...
libtbbmalloc_proxy.so.2 => /u/michael.aichmueller/.conan2/p/onetb75ff22d6ae745/p/lib/libtbbmalloc_proxy.so.2 (0x00007efd7b721000)
libtbb.so.12 => /u/michael.aichmueller/.conan2/p/onetb75ff22d6ae745/p/lib/libtbb.so.12 (0x00007efd7b6ca000)
libtbbmalloc.so.2 => /u/michael.aichmueller/.conan2/p/onetb75ff22d6ae745/p/lib/libtbbmalloc.so.2 (0x00007efd7b10d000)
Oddly enough, it seems that tbbmalloc
is not mentioned in the dynamic section of the executable for some reason:
readelf -d ./train | grep 'NEEDED'
0x0000000000000001 (NEEDED) Shared library: [libtorch_cpu.so]
0x0000000000000001 (NEEDED) Shared library: [libc10.so]
0x0000000000000001 (NEEDED) Shared library: [libtorch.so]
0x0000000000000001 (NEEDED) Shared library: [libtbbmalloc_proxy.so.2]
0x0000000000000001 (NEEDED) Shared library: [libtbb.so.12]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
The ninja build file segement pertaining to the train
executable does list all tbb libs to link against with the correct paths:
If I remember correctly, tbbmalloc is not linked directly, and would be brought in by tbbmalloc_proxy instead.
I can find some evidence here:
I'd have thought that its use was opt-in as well, rather than by default - ie, I dont think your executable should link against tbbmalloc_proxy either.
hi @jcar87 ,
thanks for looking into this.
The behaviour of find_package(TBB REQUIRED)
without specifying components is to select all components tbb
, tbbmalloc
, tbbmalloc_proxy
according to the official README.
The conan package mimics this behaviour from what I can tell and also links all three components into onetbb::onetbb
:
########## AGGREGATED GLOBAL TARGET WITH THE COMPONENTS #####################
set_property(TARGET onetbb::onetbb PROPERTY INTERFACE_LINK_LIBRARIES TBB::tbbmalloc_proxy APPEND)
set_property(TARGET onetbb::onetbb PROPERTY INTERFACE_LINK_LIBRARIES TBB::tbbmalloc APPEND)
set_property(TARGET onetbb::onetbb PROPERTY INTERFACE_LINK_LIBRARIES TBB::tbb APPEND)
This means that target_link_libraries(train PRIVATE onetbb::onetbb)
brings in all components.
To be fair, I do not know what exactly I needed from TBB to use parallel std algorithms with GCC so I went with the default. But even if only e.g. tbb
was needed, I would expect that the linkage provided by the conan-package for onetbb works for all components. I do not quite understand why building and linking against all 3 components works as expected, but only tbbmalloc
is not found at runtime (despite residing in the same folder as the other tbb libs). Is this an RPATH issue?
Hi @maichmueller - I see, thanks for linking to the documentation.
the behaviour of find_package(TBB REQUIRED)
is to find all components, but you still need to choose which targets to link against. From what I can see, the onetbb::onetbb
target is generated by Conan's CMakeDeps
generator but has no equivalent in the TBB documentation. We do have targets for the ones mentioned by the TBB documentation.
I think your problem has to do with linking against the conan-only onetbb::onetbb
, when you should link against TBB::tbb
, and only if you know you need the malloc_proxy, link against that one too.
find_package(TBB REQUIRED)
...
target_link_libraries(
train
PRIVATE
onetbb::onetbb
)
should be:
find_package(TBB REQUIRED)
...
target_link_libraries(
train
PRIVATE
TBB::tbb
)
I do not quite understand why building and linking against all 3 components works as expected, but only tbbmalloc is not found at runtime (despite residing in the same folder as the other tbb libs). Is this an RPATH issue?
I suspect that the way tbbmalloc
is loaded at runtime is different than regular libraries. I can see some evidence here: https://github.com/oneapi-src/oneTBB/blob/9e401d119c9422775b2267cbf133f0446493ddf7/src/tbbmalloc/tbbmalloc.cpp#L27 , where dlopen()
is used. dlopen
may (or may not) follow slightly different rules or nuances than regular library loading. We could have a look, however I suspect in your case the solution is as above and only link against TBB::tbb
Hi @jcar87 ,
thanks for your help on this. I linked as you said now only to TBB::tbb which works out of the box. I am happy to leave it at that for my use case, but think that any user wishing to link against tbbmalloc
would run into this problem again.
For completeness sake, I installed TBB via apt
for some tests and noticed that my package would compensate for the missing libtbbmalloc
by simply picking it up from the system-wide installation while libtbb
would still be selected from the conan folder. Not sure which extra settings allow finding it in the system-wide install though and whether they are set by the package or whether using standard ubuntu search paths is already enough.
Description
EDIT: Linking onetbb fails for libtbbmalloc. My CMake configuration reads:
Running the executable throws the following error:
and
respectively depending on the config.
CMake-Conan handles the conan installation via the provided
conan_provider.cmake
. Myconandata.yml
includes the aforementioned package among others andconanfile.py
is defaulted.Checking the executable in debug and release with
ldd
shows the following:and
But all the libs are available in
/u/michael.aichmueller/.conan2/p/onetb75ff22d6ae745/p/lib
(release) and/u/michael.aichmueller/.conan2/p/b/onetb22d5b511a1c11/p/lib
(debug):I don't understand how linking
tbbmalloc
can succeed, but running the executable fails to find this lib in the same folder as the other tbb libs.Package and Environment Details
Conan profile
conan profile show Host profile: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 os=Linux
Build profile: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 os=Linux
Steps to reproduce
conandata.yml
conanfile.py
Run:
path/to/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -G Ninja -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCONAN_COMMAND=path/to/conan
Logs
Click to expand log
``` /u/michael.aichmueller/cmake-3.26.5-linux-x86_64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -G Ninja -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCONAN_COMMAND=/work/rleap1/michael.aichmueller/miniconda/bin/conan -S /work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network -B /work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network/cmake-build-debug-gcc-lactose -- CPM: Adding package microtar@27076 (27076e1) -- CMake-Conan: first find_package() found. Installing dependencies with Conan -- CMake-Conan: Checking if a default profile exists /u/michael.aichmueller/.conan2/profiles/default -- CMake-Conan: cmake_system_name=Linux -- CMake-Conan: cmake_system_processor=x86_64 -- CMake-Conan: CMake compiler=GNU -- CMake-Conan: CMake compiler version=11.4.0 -- CMake-Conan: [settings] compiler=gcc -- CMake-Conan: [settings] compiler.version=11 -- CMake-Conan: Creating profile /work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network/cmake-build-debug-gcc-lactose/conan_host_profile -- CMake-Conan: Profile: [settings] arch=x86_64 os=Linux compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 build_type=Debug [conf] tools.cmake.cmaketoolchain:generator=Ninja tools.build:compiler_executables={"c":"/usr/bin/gcc","cpp":"/usr/bin/g++"} -- CMake-Conan: Installing single configuration Debug -- CMake-Conan: conan install /work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network -of=/work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network/cmake-build-debug-gcc-lactose/conan --profile:host=default;--profile:host=/work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network/cmake-build-debug-gcc-lactose/conan_host_profile;--profile:build=default;--build=missing;-g;CMakeDeps ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Debug compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 os=Linux [conf] tools.cmake.cmaketoolchain:generator=Ninja tools.build:compiler_executables={'c': '/usr/bin/gcc', 'cpp': '/usr/bin/g++'} Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 os=Linux ======== Computing dependency graph ======== Graph root conanfile.py: /work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network/conanfile.py Requirements ... hwloc/2.9.3#7b004fab2336e27d686e9ae08dcf4b0d - Cache ... onetbb/2021.10.0#159e2dde755615b9f4d43b6868cdd1d2 - Cache ... Build requirements b2/4.10.1#1b290403d8648c79f468f5a6496f829a - Cache meson/1.2.2#aace9dcc1db58fa42ecb5292f724092d - Cache ninja/1.11.1#77587f8c8318662ac8e5a7867eb4be21 - Cache pkgconf/2.1.0#27f44583701117b571307cf5b5fe5605 - Cache Resolved version ranges ... ======== Computing necessary packages ======== Requirements ... c2a87ebbbc9c1 - Cache hwloc/2.9.3#7b004fab2336e27d686e9ae08dcf4b0d:56fabb2f37a6bb653f7e6dace9a7d53edb7ea31a#0498c2022f27709979bbe5847e6e7080 - Cache ... onetbb/2021.10.0#159e2dde755615b9f4d43b6868cdd1d2:8b2b2c1c14c6fcd8e1404345bdd476ed368ce915#8e82421c33b31696d7be11226265eaa5 - Cache ... Build requirements Skipped binaries b2/4.10.1, meson/1.2.2, ninja/1.11.1, pkgconf/2.1.0 ======== Installing packages ======== ... hwloc/2.9.3: Already installed! (3 of 11) ... onetbb/2021.10.0: Already installed! (11 of 11) ======== Finalizing install (deploy, generators) ======== conanfile.py: Writing generators to /work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network/cmake-build-debug-gcc-lactose/conan/build/Debug/generators conanfile.py: Generator 'CMakeDeps' calling 'generate()' conanfile.py: Calling generate() conanfile.py: Generators folder: /work/rleap1/michael.aichmueller/projects/hpl/Relational-Neural-Network/cmake-build-debug-gcc-lactose/conan/build/Debug/generators conanfile.py: CMakeToolchain generated: conan_toolchain.cmake conanfile.py: Preset 'conan-debug' added to CMakePresets.json. Invoke it manually using 'cmake --preset conan-debug' if using CMake>=3.23 conanfile.py: If your CMake version is not compatible with CMakePresets (<3.23) call cmake like: 'cmake