xeus-cling icon indicating copy to clipboard operation
xeus-cling copied to clipboard

libtorch with xeus-cling results in "symbol '__emutls_v._ZSt11__once_call' unresolved while linking"

Open justinblaber opened this issue 4 years ago • 5 comments

image

Some functionality seems to work, like torch::zeros. However, if I try to use torch::from_blob I get the following errors:

IncrementalExecutor::executeFunction: symbol '__emutls_v._ZSt11__once_call' unresolved while linking [cling interface function]!
IncrementalExecutor::executeFunction: symbol '__emutls_v._ZSt15__once_callable' unresolved while linking [cling interface function]!

Any ideas how I can go about solving this? I'd really like to be able to use libtorch with xeus-cling... but its proving to be very difficult. I manually built this pytorch, but I've also tried downloading the pre-compiled nightly builts. I was even able to do some very hacky stuff to get libtorch.so to compile from the cling environment, but the above two errors still appear...

justinblaber avatar Oct 20 '20 15:10 justinblaber

You probably need to load the library (and tell xeus-cling where to find it). See here.

JohanMabille avatar Oct 20 '20 21:10 JohanMabille

@JohanMabille I've added all the relevant libtorch librarys (library/include paths and loaded the libtorch library) to my knowledge.

I checked and emutls is something inside libgcc or something? Which makes me think the problem is more deeply rooted.

There are some other similar issues:

https://root-forum.cern.ch/t/unresolved-symbol-emutls-v-zst11-once-call/30595/2 https://github.com/jupyter-xeus/xeus-cling/issues/262

I tried using pre-built binaries, recompiling from source, lots of stuff really. Nothing seems to work.

If libtorch works well with xeus-cling that would be pretty amazing for pytorch users that want to experiment with deploying in C++...

justinblaber avatar Oct 21 '20 15:10 justinblaber

It's a cling issue .

Possible solution https://github.com/llvm/llvm-project/commit/8eec91e96d4a03ee1a3287405dda53e60d0c9933

I don't use libtorch with xeus-cling, but it works fine. Only from_blob does not work (I think it works on OSX).

@justinblaber, correct me if I'm wrong, with from_blob you point the address (an OpenCV matrix, for example) instead of making a copy to initialize a Tensor? I don't know what your case is, but you can initialize a Tensor with std::vector, for example, and then reshape. In cell 7 and 8 of this notebook there is an example of how to do it.

cauachagas avatar Oct 27 '20 18:10 cauachagas

@cauachagas Do you know how I can use that solution you linked to fix the issue? I'm not familiar with llvm/cling so I don't know where to begin...

But, I'm basically using it because I have a memory buffer (i.e. just a pointer) that stores segmentation results from tensorrt. I wanna do an argmax operation on it, so I was just gonna from_blob() it then use libtorch to do the argmax.

I think this is pretty important functionality because I could see a lot of use cases where you have a memory buffer and want to use a libtorch operation on it without having to reallocate it or something.

justinblaber avatar Oct 28 '20 02:10 justinblaber

Cling uses LLVM5 with custom Clang. The possible solution uses version 6 of the LLVM. If this is the only solution, then, in theory, you can solve it using a more updated version of LLVM.

I may be talking nonsense, but I believe that this problem does not happen on OSX, because it natively uses Clang. For Linux, the build of the custom Clang is done with GCC.

I use Arch Linux and tried to compile Cling using LLVM5 and Clang5 from the arch4edu repository. I told Cmake the path of the variable LLVM_CONFIG among other things. He compiled everything, but at the end, the cling gives error 😢 . Apparently, Clang has to be provided here

git clone --depth=1 -b "cling-patches" http://root.cern.ch/git/clang.git

Update:

See this script from AUR

https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=cling

Do this

cd ~/
srcdir=$HOME
git clone --depth=1 -b "cling-patches" http://root.cern.ch/git/clang.git
git clone --depth=1 -b "cling-patches" http://root.cern.ch/git/llvm.git
git clone --depth=1 -b "v0.7" http://root.cern.ch/git/clang.git

and then follow as in the script and modify the necessary files https://github.com/llvm/llvm-project/commit/8eec91e96d4a03ee1a3287405dda53e60d0c9933

cauachagas avatar Oct 28 '20 17:10 cauachagas