Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.
/ ffi-experimental Public archive

(DEPRECATED, migrated to main repo - hasktorch/hasktorch) Research code generation / FFI binding using libtorch 1.x for the next Hasktorch release

License

Notifications You must be signed in to change notification settings

hasktorch/ffi-experimental

Repository files navigation

(ARCHIVED) Hasktorch 0.2 Libtorch FFI

This repository contains all of the work leading up to Haskell support of PyTorch's C++ API (part of PyTorch's 1.0 release). It is now merged into hasktorch, where development on this work continues.

Work on ffi bindings into the c++ libtorch library in preparation for 0.2 which targets the pytorch's post 1.0libtorch backend.

General approach is to use generated Declarations.yaml spec instead of header parsing for code generation.

Project Structure

  • codegen/ - code generation, parses Declarations.yaml spec from pytorch and produces ffi/ contents
  • deps/ - submodules for dependencies - libtorch, mklml, pytorch
  • examples/ - high level example models (xor mlp, typed cnn)
  • ffi/- low level FFI bindings to libtorch
  • hasktorch/ - higher level user-facing library, calls into ffi/, used by examples/
  • inline-c/ - submodule to inline-cpp fork used for C++ FFI
  • spec/ - specification files used for codegen/

Getting dependencies

deps/ holds several external dependencies that are retrieved using the deps/get-deps.sh script.

This should be run prior to building

XOR MLP Example

The following steps should run the xor mlp example:

# Download libtorch-binary and other shared library dependencies
pushd deps
# For CPU
./get-deps.sh
# For CUDA-9
# ./get-deps.sh -a cu90
# For CUDA-10
# ./get-deps.sh -a cu100
popd

# Set shared library environment variables
source setenv

stack build examples

stack exec xor_mlp

Running code generation

Code generation is used to build low-level FFI functions.

Note that the code is already generated in this repo under ffi, running this is only needed if changes are being made to the code generation process.

To run:

stack build codegen
stack exec codegen-exe

To get CLI options:

stack exec codegen-exe -- --help

Additional Information

See the wiki for developer information.

Contributions

Contributions/PRs are welcome.

About

(DEPRECATED, migrated to main repo - hasktorch/hasktorch) Research code generation / FFI binding using libtorch 1.x for the next Hasktorch release

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published