The Torch-MLIR project aims to provide first class support from the PyTorch ecosystem to the MLIR ecosystem.
 
 
 
 
 
 
Go to file
Stella Laurenzo 529873d13c Wire up IREE compilation and runtime in a new backend test.
* Adds python bindings for invoking flow, HAL, and VM lowering pipelines.
* Adds pythong bindings for translating to VM module flatbuffer.
* Adds a new backend_test/iree directory and configure lit to find the IREE python rt bindings.
* Open code a simple_invoke.py that exercises the whole pipeline (need real APIs for a lot of this).
* Fails when invoking the function because I never implemented argument marshaling for scalars :(
* Plenty of stuff to do tomorrow.
2020-06-19 00:30:34 -07:00
backend_test/iree Wire up IREE compilation and runtime in a new backend test. 2020-06-19 00:30:34 -07:00
include/npcomp Wire up IREE compilation and runtime in a new backend test. 2020-06-19 00:30:34 -07:00
lib Wire up IREE compilation and runtime in a new backend test. 2020-06-19 00:30:34 -07:00
pytest Basicpy conversion to IREE+std skeleton and first conversions. 2020-06-13 23:45:43 -07:00
python Wire up IREE compilation and runtime in a new backend test. 2020-06-19 00:30:34 -07:00
python_native Add _npcomp.backend.iree module. 2020-06-18 23:28:30 -07:00
runtime Add bare-bones npcomp-run-mlir. 2020-05-28 18:37:11 -07:00
test Wire up IREE compilation and runtime in a new backend test. 2020-06-19 00:30:34 -07:00
tools Add script tools/format_source.sh and run it on all python and c++ sources. 2020-06-13 14:53:54 -07:00
.clang-format Add stub numpy dialect. 2020-04-26 17:20:58 -07:00
.gitignore Add MLIRContext.dense_elements_attr to create an attribute from a python buffer/array. 2020-05-08 17:36:07 -07:00
.style.yapf Introduce a Target class and use it to define generic 32 and 64bit variants. 2020-06-13 14:43:10 -07:00
CMakeLists.txt Wire up IREE compilation and runtime in a new backend test. 2020-06-19 00:30:34 -07:00
LICENSE Add license 2020-04-26 20:10:24 -07:00
README.md Bump llvm-project to 52cae05e087b3d4fd02849fc37c387c720055ffb (2020/6/10). 2020-06-11 16:10:05 -07:00
contributing.md Add contributing.md 2020-04-26 20:17:16 -07:00

README.md

npcomp - An aspirational MLIR based numpy compiler

This is a research prototype of MLIR dialects for representing numpy programs, and a set of reference tracing/compiler tools. The primary purpose at this point is to establish a solid modeling of restricted Python programs and Numpy based computations in MLIR. While this project will provide some reference implementations to prove the design, the intention is to align this with the broader set of tools that exist at this level of abstraction.

Design Notes

As I work through things, I've been jotting down some design notes:

Quick start

LLVM_VERSION=10
export CC=clang-$LLVM_VERSION
export CXX=clang++-$LLVM_VERSION
export LDFLAGS=-fuse-ld=$(which ld.lld-$LLVM_VERSION)
export LLVM_SRC_DIR=/path/to/llvm-project

# Check out last known good commit.
(cd $LLVM_SRC_DIR && git checkout 52cae05e087b3d4fd02849fc37c387c720055ffb)

./tools/install_mlir.sh
./tools/cmake_configure.sh


# ./tools/test_all.sh runs all of these commands.
cd build
ninja
ninja check-npcomp
# Note: currently, python tests run separately
./python/run_tests.py

Interactive Use

The cmake configuration populates symlinks in the build/python directory mirroring the source layout. This allows edit-run without rebuilding (unless if files are added/removed).

Configuring the PYTHONPATH should be sufficient to run any interactive tooling (python3, Jupyter/Colab, etc).

export PYTHONPATH="$(realpath build/python):$(realpath build/python_native)"

The run_tests.py script is special in that it sets up the PYTHONPATH correctly when run.

Note that running the cmake_configure.sh script will also output a .env file in the workspace folder with the correct PYTHONPATH set. This allows tools like VSCode to work by default for debugging.

Things to look at:

  • python/npcomp/tracing/mlir_trace_test.py : Simple test case of tracing a function to an MLIR module.

Notes:

  • Python sources are symlinked to the output directory at configure time. Adding sources will require a reconfigure. Editing should not.
  • It is a very common issue to have both python 2.7 (aka. "python") and python 3.x (aka. "python3") on a system at a time (and we can only hope that one day this ends). Since the native library at development time binds to a specific version, if you try to run with a different python, you will get an error about the "native" module not being found.

Compiler development

For bash users, adding the following to your .bashrc defines some aliases that are useful during compiler development, such as shortcuts for builing and running npcomp-opt.

source $WHERE_YOU_CHECKED_OUT_NPCOMP/tools/bash_helpers.sh