Skip to content

Latest commit

 

History

History

codegen

hasktorch-codegen

Parse source files from the TH library and generate low-level bindings in Haskell.

Warning - parsers are only "good enough" to process their intended C source inputs. They are not intended for general purpose use.

Code Generation

The [ffi/][ffi] modules are generated using the scripts in codegen/. Since the outputs are already part of the repo, you should not need to run codegen/ programs to use hasktorch.

However, if you are contributing to hasktorch itself, you may want to modify/re-generate the code generation processes. Currently there are three main operations:

  • cabal new-run hasktorch-codegen:ht-codegen -- --lib TH --type generic - Builds generic modules (one version per tensor type).
  • cabal new-run hasktorch-codegen:ht-codegen -- --lib TH --type concrete - Builds non-generic modules.

All of these programs write .hs files into the output/ directory as a staging area (rather than overwriting [ffi/][ffi] directly).

For details on the TH library's pseudo-templating preprocessor mechanism for underlying the generic modules, see Adam Paszke's writeup.