Commit Graph

934 Commits (main)

Author SHA1 Message Date
Stella Laurenzo 97d83f786a Bump submodule versions.
* llvm-project: b5924a8e27536d19dd5c4d302db29fb6163d5faa
* mhlo: 848ca244d20f045b7921da55a98a04d95ef94f0e
* Multiple breakages that need to be fixed.

Fixes:
* Refactor dialect registration
* Remove all kindof methods (Casting functionality has been added upstream and is implicitly
available, see https://llvm.discourse.group/t/removing-kinds-from-attributes-and-types/1547.)
* Update dialect registration to comply with https://reviews.llvm.org/D85495.
* Remove type kinds and update some changed dialect signatures.
* Upgrade ATen dialect to match upstream needs.
  * Move dialect registration to tablegen.
  * Register the ListType in tablegen.
  * Change dialect initialization signature.
* Use TypeSwitch in MlirIr location printer.
* Remove global registry depends from npcomp-opt.
* Change LowerToLLVM to pass an MLIRContext vs an LLVMDialect for type creation.
* Remove dep on MLIREDSCInterface that is removed upstream.
* Thread through the DialectRegistry for opt and python-like tools.
* Modernize pass registration (This was forced because the GEN_PASS_REGISTRATION code now generates inline functions vs literal pass registration statements)

Co-authored-by: Marius Brehler <marius.brehler@iml.fraunhofer.de>
2020-09-08 13:26:42 -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
stephenneuendorffer a5f3b16f92
Fix precommit workflow (#13) 2020-08-06 23:51:05 -07:00
stephenneuendorffer 44af7a6d30
[cmake] Updates for basic shared library support (#7)
Mostly this is CMake cleanup.  Several library dependencies are missing, which
is often revealed with shared library builds.  Also, it's generally bad to
link directly against LLVM libraries because it fails when using
LLVM_LINK_LLVM_DYLIB.  MLIR will pull in libLLVM.so, and there will be
duplicate linkage with the the explicit libraries.  There may need to be more
refactoring here.
2020-08-05 14:49:18 -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 3efbbe8735 Misc fixes to enable building/testing on manylinux2014 images.
* Since the manylinux images do not hard-link against python libs (resolving them at runtime), the module must be built without resolving undefined references.
* For some reason, builds on this platform are stricter, exposing dependency ordering issues.
* The CMake bits to build the extension are still somewhat of a mess. I have better versions both upstream and in IREE and will be reconciling. For now, don't look too closely.
2020-08-04 17:26:15 -07:00
Stella Laurenzo 38abe99805 Collapse python_native/ into python/.
* These were separated originally for layering reasons that no longer apply.
* Most of the python extension code is under lib/ with just the module setup in python/.
2020-08-03 17:46:34 -07:00
Stella Laurenzo 29da57e631 Update sample for refjit invocation. 2020-07-10 22:57:26 -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 2e40ce05ad Remove old sample 2020-07-08 23:06:39 -07:00
Stella Laurenzo 70595bd87e Add sample for exercising the compiler. 2020-07-08 22:58:20 -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 750541e9a9 Extend type inference so that it works across conditional boundaries.
* The implementation is still limited but gives something to build on.
2020-06-10 21:33:17 -07:00
Stella Laurenzo 917fd94f94 Add limited support for function arguments. 2020-06-10 19:17:29 -07:00
Stella Laurenzo e3fd22a035 Add a (very) basic type inference pass for basicpy.
For simple programs, this gets us enough typing to lower to real backends.
2020-06-10 19:04:05 -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 7b95d860e9 Add sample for ast extraction. 2020-06-06 21:29:20 -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 60f132b26f Add pass registrations and a simple compilation example from python.
* Got side-tracked hunting down a vague-linkage RTTI issue due to not anchoring key methods in PassOptions.h to a module.
* Took the path of least resistance and just added the option to build LLVM with RTTI. I know how to fix this but would like to do some broader upstream fixes versus just hunting/pecking/working around in this project.
2020-06-03 23:58:58 -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
Stella Laurenzo db0b0ef1b2 Switch sample tracer to emit builtin_ufunc globals instead of the impl versions. 2020-05-08 14:35:13 -07:00
Stella Laurenzo 0092b912ab Update all python imports to be absolute and use a .env file to set the path correctly.
This makes things just work for debugging in VSCode.
2020-05-06 23:25:04 -07:00
Stella Laurenzo 3611958b11 Move python native library to python_native/_npcomp...so.
This allows binary and source packages to exist at different physical paths.
2020-05-06 22:44:12 -07:00
Stella Laurenzo 680e11ae62 Rename basicpy_None_type to basicpy_NoneType to match native spelling.
* Also adds Basicpy.py to tests.
2020-05-06 19:07:50 -07:00
Stella Laurenzo 644d9fb0d3 Remove spammy warnings and filecheck info in run_tests.
* This suppresses a warning that arises from using "-m" to launch a module contained in a package that arranges modules via __init__.py. It seems irrelevant to the use case of running doctests.
2020-05-06 18:48:12 -07:00
Stella Laurenzo 6b7c913e0b Add DialectHelper for Basicpy dialect.
* Involved native code for the types and slot_object_get ops.
2020-05-06 18:26:03 -07:00
Stella Laurenzo 4ebf972503 Merge ir.Ops and ir.Types into ir.DialectHelper.
This will aid in managing hierarchies of custom dialect helpers.
2020-05-06 18:26:03 -07:00
Sean Silva aa9ffc3a11 Delete npcomp.edsc_test from python/run_tests.py 2020-05-06 18:24:44 -07:00
Stella Laurenzo 714bc01c02 Bump llvm version to 0c4aab27b3da05dd1b0c0c39472525325fda5e23.
* Fixes some api-change breakages.
* Deletes edsc module now that the IR bindings are working (and since it broke with this update).
2020-05-05 21:00:49 -07:00
Stella Laurenzo 502ef8f195 Create skeleton for 'Basicpy' dialect.
* It is time to start adding more python mechanisms.
* Running into this for materializing slice() objects.
2020-05-04 17:48:02 -07:00
Stella Laurenzo ebb5bcf6af Handle np.transpose() and ndarray.T shortcut.
* Just the form without explicit permutation for now.
2020-05-04 16:20:36 -07:00
Stella Laurenzo a5f755d406 Implement __array_func__ hook and use it to trace np.dot.
* Creates an abstraction/registry around emitters (intended to generalize to AST compilation as well).
* Reworks ufuncs to use the same mechanism as array funcs.
* Adds the numpy.dot op.
2020-05-04 15:47:01 -07:00
Stella Laurenzo 1f54838d2e Add hook for __array_function__ and (failing) np.dot sample. 2020-05-03 13:39:30 -07:00
Stella Laurenzo a38a1e2850 Cleanup python namespace a bit for standalone use. 2020-05-02 21:54:13 -07:00
Stella Laurenzo c89a35f97f Rework the poc tracer to be structured how intended. 2020-05-02 19:52:21 -07:00
Stella Laurenzo 0805013716 Rename ufunc_call op builder for consistency. 2020-05-01 19:06:10 -07:00
Stella Laurenzo 78a8e6ec9e Add enough python bindings to build functions and ufunc calls. 2020-05-01 18:44:06 -07:00
Stella Laurenzo ba0c96b51a Add python side Numpy dialect wrapper. 2020-05-01 10:38:52 -07:00
Stella Laurenzo 23a9ffaabe Add wrappers for block and operation iteration.
I don't technically need this now but adding while the train of thought is fresh.
2020-05-01 10:16:19 -07:00
Stella Laurenzo c8740fd866 Start splitting Py* types into a header so that further C++ interop can be built. 2020-04-30 19:23:18 -07:00
Stella Laurenzo ec0f6b4b22 Add MLIRContext and ModuleOp python bindings with asm parse/print and diagnostics. 2020-04-30 17:14:03 -07:00
Stella Laurenzo 67d38db1e2 Start defining new IR bindings and cleanup python init. 2020-04-30 16:00:00 -07:00
Stella Laurenzo d3b6e1767a Add stub numpy dialect. 2020-04-26 17:20:58 -07:00
Stella Laurenzo ac302ea916 Update readme with simple config 2020-04-26 16:32:10 -07:00
Stella Laurenzo 9ee2f6ff7f Initial commit of python boiler-plate. 2020-04-26 15:50:23 -07:00