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

Issue while compiling for Apple M1 #631

Closed
pgwadapool opened this issue Dec 27, 2021 · 11 comments
Closed

Issue while compiling for Apple M1 #631

pgwadapool opened this issue Dec 27, 2021 · 11 comments

Comments

@pgwadapool
Copy link

I am trying to compile this with ghc 8.10.7 and I get the below error with warnings of stdc++.dylib not found on Apple M1

libHSlibtorch-ffi-1.9.0.0-inplace-ghc8.10.7.dylib, 0x0005): symbol not found in flat namespace '__ZN2at10__lshift__ERKNS_6TensorERKN3c106ScalarE'

Looks like ghc 9.2.1 is not supported.
Any plans to support Apple M1?

@junjihashimoto
Copy link
Member

pytorch/pytorch#63558
In addition to upgrading ghc, we need universal binary of libtorch.

@austinvhuang
Copy link
Member

@pgwadapool thanks for checking. As @junjihashimoto mentions there's two requirements - upgrading the libtorch binary and GHC.

From past experience, we've tended to be on the conservative side with GHC upgrades (probably lagging ~ 6 months post release) as the heavy use of type-level functions unearths bugs that haven't been caught elsewhere and it's painful if we're one of a few that encounters it.

We'll get there with PT 1.10 and GHC 9.2, but it may be a few months to make sure the latter is stable. Happy to take PRs if it's something you want to explore.

@Bodigrim
Copy link

@austinvhuang any chance for GHC 9.2 support please? It's sufficiently mature now.

@junjihashimoto
Copy link
Member

GHC 9.2 is already supported.

@Bodigrim
Copy link

@junjihashimoto The build fails for me with

Failed to build tokenizers-0.1.0.0. The failure occurred during the configure
step.
Build log ( /Users/andrew/.cabal/logs/ghc-9.2.7/tknzrs-0.1.0.0-aa19ac03.log ):
Warning: tokenizers.cabal:16:3: The field "autogen-modules" is available only
since the Cabal specification version 2.0. This field will be ignored.
Configuring library for tokenizers-0.1.0.0..
Error: cabal-3.10.1.0: Missing dependency on a foreign library:
* Missing (or bad) C library: tokenizers_haskell
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

Error: cabal: Failed to build tokenizers-0.1.0.0 (which is required by
hasktorch-gradually-typed-0.2.0.0). See the build log above for details.

I assume tokenizers.cabal can use a bump of cabal-version to get autogen-modules accounted for.

@junjihashimoto
Copy link
Member

You should install the c library of tokenizers_haskell.

@Bodigrim
Copy link

Thanks @junjihashimoto!

@junjihashimoto
Copy link
Member

$ uname -a
Darwin xxx 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020 arm64 arm Darwin

% nix-shell -p haskell.compiler.ghc928

$ cat Makefile
all:
	ghc -o a.out test.hs main.cpp -optl='-Wl,-keep_dwarf_unwind' -lc++
	./a.out

$ cat test.hs
{-# LANGUAGE ForeignFunctionInterface #-}

import Foreign.C.Types (CInt(..))


foreign import ccall unsafe "hs_exception"
    c_hs_exception :: CInt

main = do
  print 12
  print c_hs_exception


$ cat main.cpp
# include <exception>
# include <stdexcept>

extern "C" int hs_exception() try
{
  throw std::logic_error("THIS FAILS!");
} catch(...) {
  return 0;
}

$ make
ghc -o a.out test.hs main.cpp -optl='-Wl,-keep_dwarf_unwind' -lc++
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking a.out ...
./a.out
12
libc++abi: terminating with uncaught exception of type std::logic_error: THIS FAILS!
make: *** [Makefile:3: all] Abort trap: 6

$
exit
% nix-shell -p haskell.compiler.ghc946

$ make
ghc -o a.out test.hs main.cpp -optl='-Wl,-keep_dwarf_unwind' -lc++
[1 of 2] Compiling Main             ( test.hs, test.o )
[2 of 2] Linking a.out [Objects changed]
./a.out
12
0

@junjihashimoto
Copy link
Member

I tried Apple M2 with ghc928. Catching a exception of c++ does not work.
In case of ghc946, it works.
I do not find out the reason.

@junjihashimoto
Copy link
Member

Now, the master branch supports ghc964, so the above issue of exception is fixed.
This release was made on Apple Silicon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants