Commit Graph

73 Commits (59b7c559f4782be9e1ea5f5e9eb365cf47565426)

Author SHA1 Message Date
Stella Laurenzo 0d91885965
Add initial python bindings for c10 dispatcher internals. (#55)
* Exposes the op registry via a get_registered_ops method.
* Moves the aten dialect generation scripts in prep for integrating them with this facility.
2020-09-24 16:26:29 -07:00
Stella Laurenzo bc7c852379 Add more ops from the original integration.
* Still need to add a systematic mechanism for discovering gradient ops.
* Work needed on the various _ suffixed inplace ops.
* Other randoms still not mapped.
* Outside of this commit, I do have enough commented/reworked to roughly build but that will take another handful of commits to get going.
2020-09-18 19:11:18 -07:00
Stella Laurenzo a74a98094b
Add a new python script to auto-generate ATen op ODS definitions. (#43)
* Add a new python script to auto-generate ATen op ODS definitions.

* There is still some work on some of the ops to annotate correct types.
* The ODS is not actually included into the dialect yet, but I'd like to commit it so that we can track changes.
* Will reconcile this with the ops produced by the existing script in a followup. Still need to do some more iteration to reach parity.
2020-09-16 16:21:24 -07:00
Stella Laurenzo d1ed6d260e Initial work on a torch op registry.
* This extracts metadata from python invocations (nearly) sufficient to generate ODS and a Torch IR translation table for most of the ops.
* It also has the side effect of creating a data structure with meaningfully runnable examples suitable for an automated regression test.
* There are some ops that are sufficiently complex/weird (like _convolution) that we'll just manually handle those.
* See example output: https://gist.github.com/stellaraccident/60a58457b15e9184e224fa98a2658769
2020-08-28 15:20:55 -07:00
stephenneuendorffer 31b3041e88
Add pytorch interface to ATen Dialect (#30)
This patch adds a pytorch interface to npcomp.  This interface is modeled
after pytorch_xla and exposes the MLIR-based flow as a virtual device (similar
to a gpu device or the xla backend).  Usage is intended to be something like:

  dev = torch_mlir.mlir_device()
  t0 = torch.randn((4,4), device=dev)
  t1 = torch.randn((4,4), device=dev)
  t2 = t0 + t1
  t2_mlir = torch_mlir.get_mlir( t2 )
  t2_cpu = t2.to('cpu')

In this case t2_cpu would contain the result of the computation, and t2_mlir
contains the mlir description of the computation.  Note that this also
properly returns backward paths synthesized by pytorch.  There are several
parts of this:

1) A tensor type (implemented by tensor.* and tensor_impl.*)
2) The device modeling (aten_mlir_bridge.*, aten_mlir_device.*, aten_mlir_type*)
3) a temporary IR (implemented by ir.cpp)

There is also a reference lowering directly from the ATen dialect to C
function calls consisting of two parts:

1) The driver that uses the IR to generate MLIR, run Passes and compile the
result using mlir::ExecutionEngine (implemented by jit.cpp and
mlir_gen.cpp)
2) A runtime library implemented by lib/aten_ops.cpp.  Most of the operations
are implemented by callbacks into the torch C++ libraries.

Some aspects of this are known to be less than optimal, in particular:
1) There's some function definitions that don't live in the file corresponding
to their declaration.
2) More aspects of this (e.g. the IR) seem like they should be automatically
generated.
3) It's unclear to me how much of the 'IR' is actually necessary, or whether
MLIR could be created on the fly.

Note that this code is licensed in a way similar to pytorch, with the
intention that eventually (when npcomp reaches some maturity) it should be
pushed there.  (see frontends/pytorch/LICENSE)  The code is also structured
much closer to the pytorch coding style than the LLVM coding style.
2020-08-21 11:22:47 -07:00
Stella Laurenzo 186dfd39ea Remove use of namedtupled defaults kwarg.
* It is incompatible with python < 3.7.

Fixes #6
2020-08-04 18:41:22 -07:00
Stella Laurenzo 0356f65dcd Wire through codegen and runtime dependencies.
* Enables e2e test.
* With what I've learned in upstream about test directory layout, I can consolidate most of the separate directories we have for these things. Will do that in a followup.
* Not pleased with the LLVM global initialization depends but serviceable for now.
2020-07-10 22:57:26 -07:00
Stella Laurenzo 9e4a62fc71 Allow JITModule passes to be built separately.
* Re-introduces frontent/backend split.
* Adds a (very) trivial shape refinement pass.
2020-07-10 22:57:26 -07:00
Stella Laurenzo aea05d68d7 Initial python plumbing to interface with the refjit backend. 2020-07-10 22:57:26 -07:00
Stella Laurenzo aeb422b030 Some fixes to get npcomp building and passing on windows.
There is more that can be done here, but this gets it minimally working.
2020-07-01 21:28:04 -07:00
Stella Laurenzo 2d4b0843c1 Fix evaluation message reporting and add checks to tests. 2020-06-29 17:48:17 -07:00
Stella Laurenzo 046751254f Refactor old tracing tests and remove deprecated ops.
* Old doctests to run under lit.
* Old custom filecheck tests -> pytest directory (under lit).
* Rename some old ufunc ops in the tracer.
2020-06-29 16:19:03 -07:00
Stella Laurenzo 7ca292ade5 Add partial evaluator for explicit numpy ufuncs.
* This enables emission of "numpy.add(a, b)" and several dozen others.
* Will deprecate original ufunc infra in a follow-on.
2020-06-29 15:27:39 -07:00
Stella Laurenzo 1024c508f8 Move numpy compiler support to new directory. 2020-06-29 13:02:34 -07:00
Stella Laurenzo a4f3ce1ed3 Add value coding for ndarray.
* This lets us import arrays from the outer environment, which is the first step to actually handling numpy ops.
2020-06-28 18:42:08 -07:00
Stella Laurenzo bccfd5f6fc Refactor environment.py into components.
* Creates a new top level Configuration class
* Adds a module for creating test configs, getting some hard coding out of core classes
2020-06-28 16:52:25 -07:00
Stella Laurenzo 7bd5733d38 Add "template function" ops and importer code.
* This starts to lay down the infra for reasoning about calls
* Adds the importer code to generate IR for function calls of compiler recognized static functions.
2020-06-26 18:36:36 -07:00
Stella Laurenzo e45287d83e Rename 'macro' nomenclature to 'partial eval'. 2020-06-26 13:50:51 -07:00
Stella Laurenzo dd6a4e638b Add macro facility and use it to enable module and namedtuple attribute resolution. 2020-06-25 23:11:32 -07:00
Stella Laurenzo e5958d820f Add constant resolution from globals and builtins. 2020-06-22 18:42:32 -07:00
Stella Laurenzo f791909a25 Factor name resolution and constant creation to a new environment facility. 2020-06-22 18:15:56 -07:00
Stella Laurenzo b3ecd57b29 Add a sample test that exercises short circuit control flow. 2020-06-19 17:25:18 -07:00
Stella Laurenzo b811db4b76 Wrap the IREE compiler flow in a one stop API. 2020-06-19 17:17:22 -07:00
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
Stella Laurenzo b21b5322f6 Basicpy conversion to IREE+std skeleton and first conversions.
* Conversions to std for numeric binary expressions, numeric to_boolean, and numeric comparisons.
* Added folders to constant ops to comply with requirements of the pass system.
* Extended the frontend with parameter/result annotation processing for primitives (can specify types for function arguments).
* Added (empty) directory/sources for IREEVM conversions. These are only enabled if IREE is enabled.
2020-06-13 23:45:43 -07:00
Stella Laurenzo 2ba8296151 Add script tools/format_source.sh and run it on all python and c++ sources. 2020-06-13 14:53:54 -07:00
Stella Laurenzo c3d4436397 Introduce a Target class and use it to define generic 32 and 64bit variants. 2020-06-13 14:43:10 -07:00
Stella Laurenzo 917fd94f94 Add limited support for function arguments. 2020-06-10 19:17:29 -07:00
Stella Laurenzo 6728503fcf Remove unused assignment 2020-06-09 18:35:21 -07:00
Stella Laurenzo 340f109742 Add implicit return and expression statements where the value id discarded. 2020-06-09 18:34:07 -07:00
Stella Laurenzo 2bb4cdf4e7 Split frontent.py into importer.py. 2020-06-09 17:16:36 -07:00
Stella Laurenzo 22cbe044c2 Add IfExp emission. 2020-06-09 17:10:52 -07:00
Stella Laurenzo e18e8e0a96 Add boolean/logical operations (and, or, not).
* Adds a new to_boolean op to evaluate a value as a truthy i1
* Uses cascading scf.if ops to properly evaluate and/or sequences (short-circuit and original value returning)
* Adds a helper to construct select ops and uses it to implement 'not'
2020-06-09 00:01:21 -07:00
Stella Laurenzo 44f7e22f4d Remove 2-arg compare special case and use common utility to do sub evaluation. 2020-06-08 17:54:14 -07:00
Stella Laurenzo 1ef3614682 Add support for short-circuit comparisons with scf.if. 2020-06-08 17:52:07 -07:00
Stella Laurenzo a32219c3bb Refactor things so that an SCF mixin dialect helper can be used.
* Makes the OpBuilder an input to the DialectHelper.
* The containment hierarchy can be simplified further.
* There are still only a few places this is instantiated, so opting for working over great.
2020-06-08 16:10:51 -07:00
Stella Laurenzo 85b724e70c Adds ODS and import support for binary_expr and binary_compare ops.
* Currently only supports non-short-circuit comparisons.
2020-06-08 13:46:06 -07:00
Stella Laurenzo 7c176ed872 Add None constants. 2020-06-07 16:21:00 -07:00
Stella Laurenzo 4cd604f2a2 Fix AST constant handling to be compatible with 3.8 (the right way). 2020-06-07 16:16:19 -07:00
Stella Laurenzo 72499e0319 Add bytes constants. 2020-06-07 16:00:29 -07:00
Stella Laurenzo a1e6ff4ab7 Add ellipsis constants. 2020-06-07 15:49:39 -07:00
Stella Laurenzo f3829b1d4f Add string constants. 2020-06-07 15:46:28 -07:00
Stella Laurenzo 869228e316 Add bool constants. 2020-06-07 15:15:19 -07:00
Stella Laurenzo af4466197e Add lit test suite for python compiler.
* Adds a test for simple constants and fixes issues.
2020-06-07 14:29:39 -07:00
Stella Laurenzo 28048337ae Fix issue with float_attr. 2020-06-06 22:01:38 -07:00
Stella Laurenzo 0cc0a7165e Add basic AST -> basicpy dialect function extraction.
* Extends the bindings to support locations.
* Various other things necessary to extract a function with simple numeric expressions.
2020-06-06 21:24:28 -07:00
Stella Laurenzo fddf41ca92 Add python binding for running passes. 2020-06-03 01:29:59 -07:00
Stella Laurenzo f2985e0901 Add implicit constant capture.
We want more sophisticated capture later, but this allows basics to function.
2020-05-08 17:55:02 -07:00
Stella Laurenzo 8ae71a9551 Add MLIRContext.dense_elements_attr to create an attribute from a python buffer/array. 2020-05-08 17:36:07 -07:00
Stella Laurenzo a91b0bfbe1 Add numpy.get_slice op and wire it up to the tracer. 2020-05-08 16:04:58 -07:00