accelerate-llvm icon indicating copy to clipboard operation
accelerate-llvm copied to clipboard

Add LLVM 13.0 Support.

Open noahmartinwilliams opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe. I can't get the llvm back-end to install because my Linux distro doesn't offer the right version of LLVM, and the haskell compiler is dependent on the latest version.

Describe the solution you'd like It would be nice if the back-end worked with LLVM 13.0, or if it was less picky about the exact version. I've distro hopped a few times now, and part of the reason for switching was to try and get this library to consistently work.

Describe alternatives you've considered I've written a library using accelerate, and I wanted to test it out, but I can't install this, so I tried using the built-in interpreter just for now, but that seems to have some kind of memory leak. I was going to issue a bug report, but I can't seem to reproduce the memory leak with anything other than the somewhat large library I've written.

I've also tried using the tensorflow back-end, but that also has problems with the version numbers since it doesn't seem to be compatible with CUDA 11.6, and if I recall correctly I couldn't get the right version of the CPU version of tensorflow to install either.

I've also considered switching to a debian based distro (I'm currently on the latest version of Manjaro), but I really don't want to switch distros again.

Additional context

noahmartinwilliams avatar Apr 25 '22 17:04 noahmartinwilliams

If you change the llvm-hs source repository stanza in cargo.project (or the Stack equivalent) to this then accelerate-llvm will work just fine with LLVM 13:

source-repository-package
    type: git
    location: https://github.com/llvm-hs/llvm-hs.git
    tag: 01c730750492be81311b4ef68b45e9a0642004fd
    subdir: llvm-hs llvm-hs-pure

Atleast, for now. LLVM 14 was released en February, and I don't think llvm-hs has been updated to support that yet (although I also don't know if it even needs any changes).

robbert-vdh avatar Apr 25 '22 17:04 robbert-vdh

Which file is that? I tried modifying both cabal.project, and stack.yaml in accelerate-llvm, and they still won't build. Here's the error I got:

llvm-hs                    > build
llvm-hs                    > Preprocessing library for llvm-hs-13.0.0..
llvm-hs                    > compiling .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/LLVM/Internal/FFI/LLVMCTypes_hsc_make.c failed (exit code 1)
llvm-hs                    > rsp file was: ".stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/LLVM/Internal/FFI/hsc2hscall179588-0.rsp"
llvm-hs                    > command was: /bin/gcc -c .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/LLVM/Internal/FFI/LLVMCTypes_hsc_make.c -o .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/LLVM/Internal/FFI/LLVMCTypes_hsc_make.o -fuse-ld=lld -D__GLASGOW_HASKELL__=900 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Isrc -I/usr/include -I.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/src -I/usr/include -Wno-variadic-macros -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/autogen -I.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/global-autogen -include .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/build/autogen/cabal_macros.h -I/home/noah/.stack/snapshots/x86_64-linux-tinfo6/5be43a6dd75b361cf7460737f492c2ec0b58ea433f5957145784bd5b98d8774f/9.0.2/lib/x86_64-linux-ghc-9.0.2/primitive-0.7.3.0-EikPDi9CXNiB9f5MDJybeY/include -I/home/noah/.stack/programs/x86_64-linux/ghc-tinfo6-9.0.2/lib/ghc-9.0.2/bytestring-0.10.12.1/include -I/home/noah/.stack/programs/x86_64-linux/ghc-tinfo6-9.0.2/lib/ghc-9.0.2/base-4.15.1.0/include -I/home/noah/.stack/programs/x86_64-linux/ghc-tinfo6-9.0.2/lib/ghc-9.0.2/ghc-bignum-1.1/include -I/home/noah/.stack/programs/x86_64-linux/ghc-tinfo6-9.0.2/lib/ghc-9.0.2/include -I/home/noah/.stack/programs/x86_64-linux/ghc-tinfo6-9.0.2/lib/ghc-9.0.2/include/
llvm-hs                    > error: In file included from LLVMCTypes.hsc:16:
llvm-hs                    > /usr/include/llvm-c/Orc.h:34:22: error: expected ‘;’ before ‘typedef’
llvm-hs                    >    34 | LLVM_C_EXTERN_C_BEGIN
llvm-hs                    >       |                      ^
llvm-hs                    >       |                      ;
llvm-hs                    > ......
llvm-hs                    >    39 | typedef uint64_t LLVMOrcJITTargetAddress;
llvm-hs                    >       | ~~~~~~~               
llvm-hs                    > /usr/include/llvm-c/Orc.h:1136:20: error: expected ‘;’ before ‘typedef’
llvm-hs                    >  1136 | LLVM_C_EXTERN_C_END
llvm-hs                    >       |                    ^
llvm-hs                    >       |                    ;
llvm-hs                    > 
Progress 73/76         

--  While building package llvm-hs-13.0.0 (scroll up to its section to see the error) using:
      /tmp/stack-6bb819a95bbfa8f5/llvm-hs-13.0.0/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/setup/setup --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

Adding the missing semicolon didn't work either. Then it just gives me compiler errors for llvm-hs itself.

llvm-hs               > [1 of 2] Compiling Main             ( /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/Setup.hs, /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/setup/Main.o )
llvm-hs               > [2 of 2] Compiling StackSetupShim   ( /home/noah/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/setup/StackSetupShim.o )
llvm-hs               > Linking /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/setup/setup ...
llvm-hs               > Configuring llvm-hs-13.0.0...
llvm-hs               > build
llvm-hs               > Preprocessing library for llvm-hs-13.0.0..
llvm-hs               > Building library for llvm-hs-13.0.0..
llvm-hs               > [  1 of 102] Compiling Control.Monad.Trans.AnyCont
llvm-hs               > 
llvm-hs               > /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/src/Control/Monad/Trans/AnyCont.hs:15:34: error:
llvm-hs               >     • Couldn't match type: forall r1. ContT r1 m a
llvm-hs               >                      with: ContT r m a
llvm-hs               >       Expected: AnyContT m a -> ContT r m a
llvm-hs               >         Actual: AnyContT m a -> forall r. ContT r m a
llvm-hs               >     • In the second argument of ‘(.)’, namely ‘unAnyContT’
llvm-hs               >       In the first argument of ‘($)’, namely ‘fmap f . unAnyContT’
llvm-hs               >       In the second argument of ‘($)’, namely ‘fmap f . unAnyContT $ p’
llvm-hs               >     • Relevant bindings include
llvm-hs               >         p :: AnyContT m a
llvm-hs               >           (bound at src/Control/Monad/Trans/AnyCont.hs:15:10)
llvm-hs               >         f :: a -> b (bound at src/Control/Monad/Trans/AnyCont.hs:15:8)
llvm-hs               >         fmap :: (a -> b) -> AnyContT m a -> AnyContT m b
llvm-hs               >           (bound at src/Control/Monad/Trans/AnyCont.hs:15:3)
llvm-hs               >    |
llvm-hs               > 15 |   fmap f p = AnyContT $ fmap f . unAnyContT $ p
llvm-hs               >    |                                  ^^^^^^^^^^
llvm-hs               > 
llvm-hs               > /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/src/Control/Monad/Trans/AnyCont.hs:22:39: error:
llvm-hs               >     • Couldn't match type: forall r1. ContT r1 m b
llvm-hs               >                      with: ContT r m b
llvm-hs               >       Expected: AnyContT m b -> ContT r m b
llvm-hs               >         Actual: AnyContT m b -> forall r. ContT r m b
llvm-hs               >     • In the first argument of ‘(.)’, namely ‘unAnyContT’
llvm-hs               >       In the second argument of ‘(>>=)’, namely ‘unAnyContT . k’
llvm-hs               >       In the second argument of ‘($)’, namely ‘f >>= unAnyContT . k’
llvm-hs               >     • Relevant bindings include
llvm-hs               >         k :: a -> AnyContT m b
llvm-hs               >           (bound at src/Control/Monad/Trans/AnyCont.hs:22:18)
llvm-hs               >         f :: forall r. ContT r m a
llvm-hs               >           (bound at src/Control/Monad/Trans/AnyCont.hs:22:12)
llvm-hs               >         (>>=) :: AnyContT m a -> (a -> AnyContT m b) -> AnyContT m b
llvm-hs               >           (bound at src/Control/Monad/Trans/AnyCont.hs:22:14)
llvm-hs               >    |
llvm-hs               > 22 |   AnyContT f >>= k = AnyContT $ f >>= unAnyContT . k
llvm-hs               >    |                                       ^^^^^^^^^^
llvm-hs               > 
llvm-hs               > /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/src/Control/Monad/Trans/AnyCont.hs:41:15: error:
llvm-hs               >     • Couldn't match type: (a0 -> m0 r0) -> m0 r0
llvm-hs               >                      with: forall r. (a -> m r) -> m r
llvm-hs               >       Expected: AnyContT m a -> forall r. (a -> m r) -> m r
llvm-hs               >         Actual: AnyContT m a -> (a0 -> m0 r0) -> m0 r0
llvm-hs               >     • In the expression: runContT . unAnyContT
llvm-hs               >       In an equation for ‘runAnyContT’:
llvm-hs               >           runAnyContT = runContT . unAnyContT
llvm-hs               >     • Relevant bindings include
llvm-hs               >         runAnyContT :: AnyContT m a -> forall r. (a -> m r) -> m r
llvm-hs               >           (bound at src/Control/Monad/Trans/AnyCont.hs:41:1)
llvm-hs               >    |
llvm-hs               > 41 | runAnyContT = runContT . unAnyContT
llvm-hs               >    |               ^^^^^^^^^^^^^^^^^^^^^
llvm-hs               > 
llvm-hs               > /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/src/Control/Monad/Trans/AnyCont.hs:41:26: error:
llvm-hs               >     • Couldn't match type: forall r. ContT r m a
llvm-hs               >                      with: ContT r0 m0 a0
llvm-hs               >       Expected: AnyContT m a -> ContT r0 m0 a0
llvm-hs               >         Actual: AnyContT m a -> forall r. ContT r m a
llvm-hs               >     • In the second argument of ‘(.)’, namely ‘unAnyContT’
llvm-hs               >       In the expression: runContT . unAnyContT
llvm-hs               >       In an equation for ‘runAnyContT’:
llvm-hs               >           runAnyContT = runContT . unAnyContT
llvm-hs               >     • Relevant bindings include
llvm-hs               >         runAnyContT :: AnyContT m a -> forall r. (a -> m r) -> m r
llvm-hs               >           (bound at src/Control/Monad/Trans/AnyCont.hs:41:1)
llvm-hs               >    |
llvm-hs               > 41 | runAnyContT = runContT . unAnyContT
llvm-hs               >    |                          ^^^^^^^^^^
Progress 1/4

--  While building package llvm-hs-13.0.0 (scroll up to its section to see the error) using:
      /tmp/stack-d631ba7c394f8c7b/llvm-hs-13.0.0/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0/setup/setup --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

noahmartinwilliams avatar Apr 25 '22 17:04 noahmartinwilliams

I was able to make llvm-hs compile with LLVM 12 by using the upstream llvm-12 branch of the project and manually adding it to stack's extra-deps. They were able to resolve that bug. The latest commit works.

I am not yet sure if one can make it work with LLVM 13, though.

karlfroldan avatar Jun 14 '22 13:06 karlfroldan

I've (finally) updated to work with LLVM-15 (and LLVM-12 if you are using an older version of ghc), so closing this one. If you specifically need llvm-13 for some reason, feel free to reopen.

tmcdonell avatar Aug 22 '23 11:08 tmcdonell