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

Can't build hasktorch-0.2.0.0 into external cabal project (linux, cuda) #591

Open
melendezd opened this issue Jul 27, 2021 · 3 comments
Open

Comments

@melendezd
Copy link

melendezd commented Jul 27, 2021

I was able to get the examples to work just fine (static typed MNIST CNN), but I'm having trouble building hasktorch-0.2.0.0 into a separate cabal project.
Steps:

  • Clone hasktorch
  • Run get-deps.h in hasktorch/deps/
  • Copy hasktorch/deps/libtorch/include/* into /usr/include
  • Copy hasktorch/deps/libtorch/lib/* into /lib (not sure if this is necessary with the setenv script)
  • Source setenv in hasktorch
  • Run hasktorch/setup-cabal.sh in hasktorch
  • cabal build hasktorch
    Hasktorch builds successfully on its own.

I then create a new cabal project called ml in a separate folder. Here's my ml.cabal file:

cabal-version:      2.4  
name:               ml  
version:            0.1.0.0  
executable ml  
    main-is:          Main.hs  
    build-depends:    base ^>=4.14.2.0, hasktorch==0.2.0.0  
    hs-source-dirs:   app  
    default-language: Haskell2010

I also create a cabal.project file:

packages: .
          /home/mapa/git/hasktorch/libtorch-ffi-helper
          /home/mapa/git/hasktorch/libtorch-ffi
          /home/mapa/git/hasktorch/hasktorch

Then, I run cabal build and get the following error:

Resolving dependencies...
Build profile: -w ghc-8.10.5 -O1
In order, the following will be built (use -v for more details):
 - libtorch-ffi-1.9.0.0 (lib) (first run)
 - hasktorch-0.2.0.0 (lib:hasktorch) (first run)
 - ml-0.1.0.0 (exe:ml) (first run)
Preprocessing library for libtorch-ffi-1.9.0.0..
Building library for libtorch-ffi-1.9.0.0..
[ 45 of 105] Compiling Torch.Internal.Unmanaged.Optim ( src/Torch/Internal/Unmanaged/Optim.hs, /home/mapa/projects/ml/dist-newstyle/build/x86_64-linux/ghc-8.10.5/libtorch-ffi-1.9.0.0/build/Torch/Internal/Unmanaged/Optim.o, /home/mapa/projects/ml/dist-newstyle/build/x86_64-linux/ghc-8.10.5/libtorch-ffi-1.9.0.0/build/Torch/Internal/Unmanaged/Optim.dyn_o )

/tmp/ghc6075_0/ghc_5.cpp:4:10: error:
     fatal error: torch/types.h: No such file or directory
        4 | #include <torch/types.h>
          |          ^~~~~~~~~~~~~~~
  |
4 | #include <torch/types.h>
  |          ^
compilation terminated.
`gcc' failed in phase `C Compiler'. (Exit code: 1)
cabal: Failed to build libtorch-ffi-1.9.0.0 (which is required by exe:ml from
ml-0.1.0.0).

Am I approaching this wrong?

@austinvhuang
Copy link
Member

@melendezd Is stack an option? If so the template here https://github.com/hasktorch/hasktorch-stack-skeleton takes care of the hasktorch git dependency using stack.yaml.

We'd like to have a cabal skeleton as well, but nobody has gotten to it yet (there's a nix one as well https://github.com/hasktorch/hasktorch-skeleton). If you need cabal maybe the troubleshooting here could be the basis for one.

@junjihashimoto
Copy link
Member

junjihashimoto commented Jul 27, 2021

In your use case, include path is not enough.
libtorch needs two include paths.
One is libtorch/include. Another is libtorch/include/torch/csrc/api/include.
This command may be helpful.
https://github.com/hasktorch/libtorch-binary-for-ci/blob/master/Makefile#L40

I recommend to use above skeltons.

@Reep236
Copy link
Contributor

Reep236 commented Jul 27, 2021

Heads up for hasktorch-skeleton, not sure why this is yet, but (in my experience) the .cabal file must be named hasktorch-skeleton.cabal or cabal will fail to locate it (even if the glob *.cabal is used). I haven't had the chance to figure out why this is yet. Also watch out for using Cuda 11, as the libtorch nix overlay has the incorrect version 11.0 instead of 11.1. I fixed the second issue in my local copy but never got to submitting a PR for it. Will do ASAP.

I'm really not sure about the first one. Maybe someone else has some more insight, but I'll hopefully have time to look at it some more later today.

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