accelerate-llvm for Apple Silicon

35 views
Skip to first unread message

Tymur Lysenko

unread,
Dec 8, 2021, 7:11:18 AM12/8/21
to Accelerate
Hello!

I am trying to use Accelerate on M1 (also known as Apple Silicon) Macbook with this stack snapshot. I see on hackage that the current version of llvm-hs is 9.0.1, which accelerate-llvm depends on. In turn, llvm-hs needs an actual LLVM library. It means, that I have to build LLVM 9 from sources (since it is not available in brew for M1) targeting x86 architecture, because when llvm-hs will be built for x86 (there is no support for M1 in GHC 8.10.7) it needs to be linked against LLVM 9 dynamic library and this can be done only when the shared library is built for x86 (otherwise, the linker will issue a warning). So I use the following command to build LLVM 9 from sources:

cmake -G 'Ninja' ../llvm \
-DCMAKE_BUILD_TYPE='Release' \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON \
-DCMAKE_C_FLAGS='-arch x86_64' \
-DCMAKE_CXX_FLAGS='-arch x86_64'

And `sudo cmake --build . --target install` to install.

Also, following accelerate-llvm readme I run these commands:

export INSTALL_PREFIX=/usr/local
cd $INSTALL_PREFIX/lib
sudo ln -s libLLVM.dylib libLLVM-9.dylib
sudo install_name_tool -id $PWD/libLTO.dylib libLTO.dylib
sudo install_name_tool -id $PWD/libLLVM.dylib libLLVM.dylib
sudo install_name_tool -change '@rpath/libLLVM.dylib' $PWD/libLLVM.dylib libLTO.dylib

After running the commands I go to my project and run `stack build`. Project's stack.yml is:


resolver:

packages:
- .

extra-deps:
- accelerate-1.3.0.0
- accelerate-llvm-1.3.0.0
- accelerate-llvm-native-1.3.0.0
- llvm-hs-9.0.1

flags:
  llvm-hs:
    shared-llvm: true

ghc-options:
  "$everything": -haddock
  "$locals": -Wall -Werror
  llvm-hs: -optcxx=-std=c++11


It results in a successful build of llvm-hs, but then accelerate-llvm fails to build with error:

<command line>: dlopen(/Users/user/.stack/snapshots/x86_64-osx/aa871c0d39823e39cd95f72eca98ef70c02ddfb7560544d56e9e7b145b40f449/8.10.7/lib/x86_64-osx-ghc-8.10.7/libHSllvm-hs-9.0.1-5INivu5SR3W8mSsWX7hrNz-ghc8.10.7.dylib, 0x0005): symbol not found in flat namespace '__ZTIN4llvm13ErrorInfoBaseE'

I tried to figure out how to fix this, but did not succeed on my own. Can anyone, please, tell me what is this error related to and how it can be fixed?

Thank you in advance,
Tymur Lysenko

Reply all
Reply to author
Forward
0 new messages