BERT-NER icon indicating copy to clipboard operation
BERT-NER copied to clipboard

Inference for C++ on macOS

Open loretoparisi opened this issue 6 years ago • 7 comments
trafficstars

I did some changes to make the inference to run in macOS:

  • I had to add the missing header stdc++.h, that ca be added in the unilib/ folder
  • I have downloaded libtorch for macos and put in ../darwin/libtorch
  • Then
cmake -DCMAKE_PREFIX_PATH=../darwin/libtorch .
make

the cmake is ok

-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found torch: /Users/loretoparisi/Documents/Projects/AI/BERT-NER/darwin/libtorch/lib/libtorch.dylib  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/loretoparisi/Documents/Projects/AI/BERT-NER/cpp-app
(.env) ip-192-168-23-184:cpp-app loretoparisi$ make

Unfortunately I'm stuck with this error during make:

Undefined symbols for architecture x86_64:
  "long* at::Tensor::data_ptr<long>() const", referenced from:
      long* at::Tensor::data<long>() const in app.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [app] Error 1
make[1]: *** [CMakeFiles/app.dir/all] Error 2
make: *** [all] Error 2

loretoparisi avatar Nov 18 '19 15:11 loretoparisi

Hi @loretoparisi, I didn't test the C++ inference on macOS. I will try running it with the above modification you suggested.

https://medium.com/@m.muizzsuddin_25037/error-ld-symbol-not-found-for-architecture-x86-64-a5e5b648ffc

kamalkraj avatar Nov 18 '19 15:11 kamalkraj

@kamalkraj I put the changes here: https://github.com/loretoparisi/BERT-NER and asked SF for that error as well: https://stackoverflow.com/questions/58918352/torch-error-on-macos-symbols-not-found-for-architecture-x86-64

loretoparisi avatar Nov 18 '19 15:11 loretoparisi

The problem is this line apparently

vector<long> out(output[0].data<long>(), output[0].data<long>() + output[0].numel());
Undefined symbols for architecture x86_64:
  "long* at::Tensor::data_ptr<long>() const", referenced from:
      long* at::Tensor::data<long>() const in app.cpp.o
ld: symbol(s) not found for architecture x86_64

loretoparisi avatar Nov 18 '19 15:11 loretoparisi

@loretoparisi , which version is libtorch are you using? I am using 1.2.0

kamalkraj avatar Nov 18 '19 16:11 kamalkraj

The latest available for macos, libtorch-macos-1.3.1.zip

loretoparisi avatar Nov 18 '19 16:11 loretoparisi

@loretoparisi, Try using https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.2.0.zip

kamalkraj avatar Nov 18 '19 16:11 kamalkraj

@kamalkraj thank you, got exactly the same error:

[100%] Linking CXX executable app
Undefined symbols for architecture x86_64:
  "long* at::Tensor::data<long>() const", referenced from:
      predict(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in app.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [app] Error 1
make[1]: *** [CMakeFiles/app.dir/all] Error 2
make: *** [all] Error 2

maybe we could find a different way to express this vector

vector<long> out(output[0].data<long>(), output[0].data<long>() + output[0].numel());

loretoparisi avatar Nov 18 '19 16:11 loretoparisi