Commit Graph

304 Commits

Author SHA1 Message Date
Tian Jin a7781791e9
[NFC] Fix comment style, shorten file names. (#169)
* Fix comment style, shorten file names.

* Update CMakeLists.txt

* Rename ONNXRewrite.td to Rewrite.td
2020-06-15 11:49:09 +08:00
Tung D. Le 60c648ae39
Avoid hardcoding ops with shape inference in ShapeInferencePass (#165)
* Avoid hardcoding ops with shape inference in ShapeInferencePass

* Minimize the changes

* Clang-format

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-06-12 15:42:05 +08:00
Tian Jin e0ae583da0
Compiling Models with Large Constant Arrays (#146)
* PoC works.

* MNist works.

* Clean up.

* Fix test.

* Make Linux work.

* Use consistent symbol name.

* Fix variable name.

* Fix array addr access.

* Bug fix.

* Bug fix.

* install before running e2e tests.

* Fix build config.

* Use sudo when installing.

* Make embeddedDataLoader position independent.

* Enable ResNet50.

* Format code.

* Format MainUtil.

* Try not using sudo to install.

* Supply runtime dir via environment variable.

* Dump problematic operation.

* Dump entire function.

* Debug.

* Dump input.

* Dump constant op.

* Debug.

* Debug.

* Debug.

* Print to stderr.

* take care of endianness.

* Use endianness-aware execution session.

* Fix ZLinux error.

* Include warning when desired output endianness can't be deduced.

* Remove debug code.

* Remove debug code in shape inference.

* Support binary-decoder for testing constants packing.

* Support filename, move-to-file, elision-threshold configurations in constant packing pass for easy testing.

* Add lit test, fix lit test type mismatch.

* Add more consts packing tests.

* Ensure intermediate files are properly cleaned up.

* No need for constant elimination.

* Link with threading libraries.

* Remove debug code.

* Format code.

* More tests.

* test nit.

* Remove debug code.

* Reduce hard-coded constants.

* Use temporary and unique working directory for hosting model parameters.

* Test if it works.

* Try to find objcopy.

* Rename symbols using objcopy.

* Move sanitized name to linux section.

* Use verbose mode for debugging.

* Disambiguate pass constructor.

* Fix symbol name.

* Use Command API to build and execute commands.

* Move linux to use Command API.

* Fix reset args.

* Execute redefine sym.

* Format code.

* Do not use verbose mode for CircleCI.

* Remove debug code.

* Prettify code, add comments.

* getSegmentData -> getEmbeddedConstPool

* vector -> std::vector.

* Make sure we properly clean up intermediate files.

* Fix test cases.

* Add runtime directory.

* Trigger rebuild.

* [Merge with master] fix debug script.

* Diable affine fusion pass for now.

* Support generic fallback const packing mechanism.

* Remove debug code.

* Handle the case where objcopy is not available.

* Fix Windows missing types.

* Support int64.

* Copy packed constant to a local directory for non-Linux/Mac platforms.

* Nit: remove debug code, refactor const pack preprocessing out as a separate function.

* Cannot make preprocessConstPack a standalone function because file removers are stack-allocated, and they are deallocated prematurely when function stack gets popped, deleteing intermediate files too early.

* Don't require executable filename.

* Import ONNX data types directly.

* Fix LIT test.

* Bug fix, use moved string value.

* Remove redundant filenames.

* Fix CMake script.

* Embed endianness information as a symbol, and check during runtime.

* More comments, update lit tests.

* Fix lit test on BE machine.

* Copyright notices.
2020-06-12 10:27:05 +08:00
Tung D. Le 8c4d527eea
Lower SplitOp to Krnl dialect (#155)
* Fix importing variadic output

* Lower splitop

* Support unknown dimension and add lit tests

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-06-11 10:57:20 +08:00
Gheorghe-Teodor Bercea 4ab96fbc6c
Add basic support for memory pool (#161)
* Reorganize main function.

* Follow review comments.

* Emit constants are globals in Krnl and LLVM dialects.

* Replace internal malloc with memory pool and getref instruction.

* Lower krnl.getref to LLVM.

* Fix formatting issues.

* Add tests.

* Add missing dependency.

* Improve LLVM lowering.

* Add test to show getref is generic.
2020-06-09 16:48:33 -04:00
Aman LaChapelle ca185002f2
Add shape inference for several ops (#163)
* 1. Add shape inference for the following ops:
 - Atan
 - Tan
 - Sin
 - Cast
 - ConvTranspose
 - Flatten
 - DynamicQuantizeLinear
 - QuantizeLinear
 - DequantizeLinear
 - ConvInteger

2. Import attributes for generic nodes
3. Fixes for cases where .cast<> should be .isa<> (ONNXConcat::inferShapes)

* Fix foormatting issues

* Address comments:
 - SmallVector<> * -> SmallVectorImpl<> &
 - switch-case -> helper function
   - Inside helper function, preserve signed-ness
 - add TODOs

* Can't use signed integers yet in convertONNXTypeToMLIRType, add TODO

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-06-09 14:55:49 +08:00
gongsu832 43dc1a1e01
Fix header dep (#150)
* Detect llvm-project commit change in utils/clone-mlir.sh and rebuild llvm-project
for zLinux Jenkins build bot

* Since many headers are generated and included indirectly through
other headers, there are often missing dependencies that break
parallel build. So we add header targets for KrnlOps, ONNXOps, and
MLONNXOps, and add explicit dependencies for all the relevant headers.

* fix copy-and-paste bug

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-06-09 10:38:32 +08:00
Alexandre Eichenberger e2af505746
Constprop (#162)
* initial const prop attempt

* added support for broadcast ops

* adde all binary broadcast ops into custom builders with precise type

* added test example

* working

* format

* fixed suggestion by Tung, start woring on unary

* added subtraction and neg the right way, and added elementwise mul too

* formatting changes

* format

* format

* added instructions to add new optimizations
2020-06-08 15:45:32 -04:00
Tian Jin dedd5f4a12
Minor bugfix. (#166) 2020-06-08 14:03:35 -04:00
Tung D. Le bb17fa965f
Add AffineScope trait to KrnlIterateOp and enable affine-loop-fusion pass (#140)
* Make KrnlIterate's IVs valid to AffineLoad/AffineStore

* [Unary elementwise op] Load/Store -> AffineLoad/AffineStore

* [Conv] Load/Store -> AffineLoad/AffineStore

* Add affine-loop-fusion pass

* typos

* Mistake when merging branch master

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-06-08 15:36:27 +08:00
Tian Jin cde1157d62
Rapid check test (#141)
* Call llc, ld from within onnx-mlir.

* Rename EmitLLVMBC -> EmitLib., reorder header files

* Edit comment.

* Checkpoint, debug.py works.

* Automatically generate inputs in debug.py.

* Use float.

* initial support for rapidcheck tests.

* Convolution test case works.

* Format code.

* Link library with MainUtils.

* Fix CMake script error.

* Fast implementation of array assertion, more detailed error analysis.

* More utility for DynMemRef.

* Fix linking issue.

* Uncomment unit test.

* Refactor to separate C++/Python ExecutionSession, enable unit test.

* format code.

* Verbose build.

* Enable PIC option for ExecusionSession.

* Fix cmake error.

* Build all targets.

* Fix doc to build all targets.

* Clean up.

* Clean up, debug.

* Use type alias consistently.

* Move definitions to DynMemRef.cpp.

* include algorithm.

* pyruntime -> PyRuntime

* Format code.

* Free memory.

* Add comments.

* Copyright notice.

* Improve stylistic consistency.

* Add comment.

* Revert irrelevant changes.

* Disambiguate.

* Refator test case generator out from test case implementation, implement example exhaustive test driver.

* Add documentation for testing.
2020-06-08 10:18:55 +08:00
Tung D. Le e2e1fbfd3b
Add type inference for CastOp (#156)
* Add type inference for CastOp

* Share type translation between op builder and onnx importer

* clang-format

* Format emitted code

* Remove unnecessary dependencies
2020-06-04 09:05:04 -04:00
Alexandre Eichenberger 2a1fe9e1e7
Believe all errors now results in meaningful actions (#153)
* removed warning missing return, dangling else

* fixed errors, made sure to return false in all shape inference failures

* shape inference use LogicalResults as return value

* format fixed

* format error

* additional error correction

* handle errors properly for all former emitError site, using either emitError, assert, or llvm_unreachable

* help added

* fixes

* edit of doc

* doc edit
2020-06-01 13:55:19 -04:00
Alexandre Eichenberger 20dd6544aa
conv bug fix (#154) 2020-05-28 07:34:58 +08:00
Tung D. Le 2b6befce87
Fix importing variadic output (#152)
* Fix importing variadic output

* clang-format
2020-05-27 09:33:53 -04:00
Alexandre Eichenberger 4f8fd9d1bf
Error fix3 (#145)
* removed warning missing return, dangling else

* fixed errors, made sure to return false in all shape inference failures

* shape inference use LogicalResults as return value

* format fixed

* format error

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-05-27 10:09:28 +08:00
Tung D. Le 028276ac0e
Fix cruntime not existed (#149)
Co-authored-by: Tung D. Le <tung@jp.ibm.com>
Co-authored-by: Tian Jin <tjingrant@gmail.com>

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-05-26 16:05:00 +08:00
chentong319 5a542e78a0
fix type inference (#144)
* fix type inference for ConstantOp and MaxPoolSingleOut

* modify interface

* use OpInterface

* change name to OpInterface

* Builder dependence

* Update CMakeLists.txt

* Update CMakeLists.txt

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-05-26 09:54:19 +08:00
chentong319 6099efd91b
Express some basic features of an Operation in TableGen file (#103)
* change operation definition

* change importer

* default type inference

* file format

* generate types for input/output

* generate the mapping for operation output type

* remove debug message for gen_doc.py

* update the dialect doc

* add support Complex

* format

* update document

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-21 22:03:16 -04:00
Tian Jin a270af5ce0
Support model debugging (#138)
* Call llc, ld from within onnx-mlir.

* Rename EmitLLVMBC -> EmitLib., reorder header files

* Checkpoint, debug.py works.

* Automatically generate inputs in debug.py.

* Use float.

* Fix merge conflict, remove RapidCheck from this patch.

* Remove submodule rapidcheck properly.

* Reformat code.

* More comments.

* Add documentation.

* Add documentation to navigation.

* Account for the fact that some initializers may also appear as input.
2020-05-21 13:02:48 +08:00
Tian Jin be62d85a32
Support onnx-mlir installation. (#139) 2020-05-21 11:03:06 +08:00
chentong319 a98c723b11
save and check the version of ONNX operation (#125)
* add version control

* fix the comments

* response to review and add onnx_ml

* update document

* add target and rename gen_doc.py

* small fix
2020-05-20 13:48:45 -04:00
Tung D. Le ad61eee908
Move to more recent LLVM commit ID (#131)
* Move to more recent LLVM ID (May 15)

* clang-format

* Bump cache version up

* Update readme

* Fix doc check

* Move to a newer commit id

* Update LoopToStandard -> SCFToStandard

* Change MLIRSideEffects to MLIRSideEffectInterfaces

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-05-20 15:45:42 +08:00
Gheorghe-Teodor Bercea c476f05a45
Fix comment [NFC] (#134)
* Reorganize main function.

* Follow review comments.

* Emit constants are globals in Krnl and LLVM dialects.

* Fix comment.
2020-05-19 14:21:59 -04:00
Gheorghe-Teodor Bercea 463efb736d
Fix name of intermediate file (#133)
* Reorganize main function.

* Follow review comments.

* Emit constants are globals in Krnl and LLVM dialects.

* Change extensions of intermediate file.
2020-05-19 12:28:09 -04:00
Tian Jin 4cdc0873ca
Call llc, ld from within onnx-mlir. (#127)
* Call llc, ld from within onnx-mlir.

* Rename EmitLLVMBC -> EmitLib., reorder header files

* Edit comment.

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-19 10:15:48 +08:00
chentong319 23bea50404
Implement PadOp based on attribute promotion (#71)
* enable promote attr for pad

* use optional arguments for pad

* shape infereance for pad

* Lowering Pad

* format file

* use DenseTensor for the attribute

* use Pad in ONNXRewrite

* fix the merge conflict

* fix the attr given to constantOp

* handle ONNXConstantOp in attribute promotion

* Fix bug when AttributePromotion is called more than once

* update ONNXOps.td.inc with correct version of onnx

* update onnx.md

* responses to review

* fix the build error

* change the implementation of Pad

* delete commented out code

* clang format

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-05-15 13:19:28 +08:00
Gheorghe-Teodor Bercea 4a68597417
Fix elision error (#121)
* Reorganize main function.

* Follow review comments.

* Emit constants are globals in Krnl and LLVM dialects.

* Add missing dependencies.

* Add dependency on ONNXOps.
2020-05-15 07:45:15 +08:00
Tung D. Le 4d8b855c17
Unify codes in shape inference and conversion (#98)
* Use AffineMap

* Shared AffineMap

* AffineMap for Conv/Pooling

* Create helper files

* Remove changes for Relu

* Remove redundant includes

* Use AffineMap for AveragePool's shape inference

* Add MLIR tests for unknown dimension case

* Extract a method AffineMapIntConstant

* Comment stylist and include path

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-14 17:31:33 +08:00
Tung D. Le d65a6e72dd
Specialize the op lowering logic for element-wise operations (#118)
* Specialize the op lowering logic for elementwise operations

* Fix clang-format error.

* Update tests for LSTM since LSTM uses element-wise ops

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-05-14 13:00:15 +08:00
Tian Jin 4dd3c809c7
Support importing tensor proto. (#116)
* Support importing tensor proto.

* Use signed types, use template.

* Resotre using signless integer types because Reshape faults with integer signs; using traits to declare/define attribute types.

* Simplify attribute importing logic.

* Use existing code to import TensorProto.

* nit.
2020-05-14 11:05:02 +08:00
Tian Jin adc08fb93e
Specify in linking stage, where runtime shared library is located. (#120)
* Specify in linking stage, where runtime shared library is located.

* Cite & make comment a full sentence.

* Fix error communicating runtime dir to ld.
2020-05-14 09:04:16 +08:00
Tian Jin 7f2bffb27d
[NFC] Set up clang-format Github Action (#119)
* Run clang-format on all source code.

* Add Clang-Format Github Action.

* Apply patch produced by Clang-Format Bot.

* nit.

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-13 22:37:51 +08:00
Tung D. Le 24343177b8
Lower LSTMOp to Krnl dialect (#73)
* Support dilations and enable e2e tests

* Fix allocating memory for dynamic shape

* Edit comments

* Do dilation by computing an offset from kernel index

* Correct dilation formula, add an example of out-of-bound, and add a test for dilation

* Import optional outputs as NoneType

* Shape inference for ONNXLSTM

* Edit ONNXLSTM::inferShape()

* Shape inference for ONNXLSTMOp

* Create a common function for inferring shape for RNN ops

* CheckInsertDeallocation for a specific result

* Allocate memory for LSTM

* First round of lowering

* Allocate memory for hidden and cell states

* Test with custom Tanh

* Fix an error in Ct's formula

* Add E2E tests

* Return outputs

* Refactor the code

* Enable E2E tests

* Support reverse and bidirectional directions

* Minor revision

* Return all intermediate hidden states

* Call existing activation functions

* Structs for activation functions

* Call existing activations in ONNX

* Minor revision

* Compare strings ignoring case

* Use memreftype of rank 0 for calling activation functions

* Fix getActivationPack()

* Revise the code

* Add one MLIR test

* Add MLIR tests for reverse and bidirectional modes

* Make the order of emiting instructions deterministic

* Use OperandAdaptor instead of directly use an operand index

* Use literal assignments

* Change some variable names

* Use literal assignments

* Use literal assignments

* Format the code

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-13 21:08:06 +08:00
Tung D. Le 9a874007ce
Implement shape inference for SplitOp (#95)
* Implement shape inference for SplitOp

* Change spitOpt to SplitAttribute and check the axis range before updating the axis attribute

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-13 18:07:27 +08:00
chentong319 7c29da191e
import onnx ml operations as a separate dialect (#97)
* generate MLONNX dialect

* Add MLONNX to Builder

* add MLONNX dialect operation document

* fix the format issues

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-12 18:43:44 -04:00
Chun-Wei Chen 41b595fc1e
Enable Build on Windows again and Update CI badge (#115)
* Use && instead of and for Windows

* Simulate fork on Windows by redirecting stderr

* Use exisiting onnx-mlir instead of cloning from master
2020-05-12 23:00:19 +08:00
Kevin Wu 2625e178df
Fix garbled filename output (#114) 2020-05-07 14:07:47 -04:00
David Byrd de9e9edc4d
implement shape inference for negate (#108)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-05-07 11:42:43 +08:00
Tian Jin 922b6b6c91
Fix Transform cmake (#111)
* target_link_libraries(OMElideKrnlGlobalConstants ...) adds duplicated
../lib/libOMKrnlOps.a ../lib/libOMONNXOps.a at end of linkage for onnx-mlir
and breaks shared library build

* Fix .buildbot/z13.sh to prepare for zLinux Jenkins build bot

Co-authored-by: Gong Su <gong_su@hotmail.com>
2020-05-07 00:11:04 +08:00
Miguel de Icaza e785a75705
Makes the DynMemRef.h usable from C (#101) 2020-04-30 14:54:19 +08:00
Tung D. Le 64ed03295f
Fix converting type for functions with no argument (#96)
* Fix converting type for functions with no argument

* Add two tests

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-04-27 11:01:51 -04:00
Tian Jin fad2ad7d03
Make onnx-mlir work with latest mlir. (#93)
* Make onnx-mlir work with latest mlir.

* Bump CircleCI cache version.

* Fix missing passes in onnx-mlir-opt.

* Fix backend test failure.

* Fix doc.

* Fix doc and exclude the generated _site directory from DocCheck.

* Remove debug code.

* Do not hard code target name, on Mac shared lib can end with .dylib.

* FunctionPass -> PassWrapper.
2020-04-27 17:03:56 +08:00
Gheorghe-Teodor Bercea 137ce767e6
Rework output to improve readability of intermediate MLIR code. (#87)
* Reorganize main function.

* Follow review comments.

* Emit constants are globals in Krnl and LLVM dialects.

* Output of non-value constants. Write full source to file.

* Fix e2e tests.

* Output constant free and full code in separate files.

* Emit separate files.

* Move file output management to utils.

* Elide the values of glotbal krnl constants.

* Add dual file output for Basic flag.

* Add tests.

* Add passes to cmake file.
2020-04-24 16:15:36 -04:00
Byron Changuion c567781fa3
Add support for Windows using Visual Studio Compiler (#86)
* Move to more recent LLVM commit ID

* Update LLVM cache version from V9 to V10

* Update to latest LLVM commit id from master, roll back conditions in util scripts

* Update circlci LLVM cache tag to ensure ci updates builds with latest LLVM commit id

* Update README.md to have matching LLVM commit id

* Update doc/Dialtects/onnx.md

* Enable onnx-mlir for VS builds on Windows

* Update README to include lit

* Update build command for Windows to include config

* Update build instructions, add cmd files for windows, enable single source of truth for MLIR commit-id (clone-mlir.sh)

* Add Visual Studio workload info

* Update ONNX op definitions

* Revert onnx submodule back to previous commit, disable warnings in CMakeLists to work around build issues with MSVC

* Update environment for path to PDcurses on Windows

* Fix directory strings to be compatible with Windows or Linux style slashes

* Fix install-mlir.sh so it works when sourced

* Ensure README and cmd files match and have correct paths

* Properly quote ONNX_MLIR_SRC_DIR

* Address PR feedback: Use llvm_unreachable to indicate failure to convert attribute proto to name/value pair

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-04-19 22:11:24 +08:00
Tung D. Le eac2297624
Lower MaxPooling and AveragePool to Krnl dialect using AffineMap (#38)
* Create a template for pooling and add support for AveragePool

* Edit MLIR tests for MaxPool according to the new lowering template for pooling

* Dealloc temporary variables

* Support count_include_pad for AveragePool

* Add MLIR tests for AveragePool lowering

* Make changes according to Tian's comments

* Push AffineMap as upper bound for KrnlIterateOp

* Test AffineMap to use in Pooling

* Replace the old implementaion by a new one using AffineMap

* Fix the computation when dilations are non-unit

* Clean up the old code

* Remove AveragePool from Canonicalization pass

* Fix computing the end indices of a filter window

* Refactor the code for pooling

* Revise pushAffineMapBound

* Add MLIR tests

* Remove unused functions

* Fix check-onnx-backend build on x86 Linux. (#91)

* Add the split marker to test files (#90)

Co-authored-by: Tian Jin <tjingrant@gmail.com>

Co-authored-by: gongsu832 <gong_su@hotmail.com>
Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-04-19 21:39:34 +08:00
gongsu832 72de6eb004
Fix check-onnx-backend build on x86 Linux. (#91) 2020-04-16 14:38:52 +08:00
Tian Jin d06dbfefdd
Specify each lib only once; allow llvm build in shared libs mode. (#77)
* Specify each lib only once; allow llvm build in shared libs mode.

* Remove debug code.

* For library targets, retain dependency information using add_dependencies, but do not link using taget_link_libraries.

* Do not set LD_PRELOAD by default.

Co-authored-by: Gong Su <gongsu@us.ibm.com>
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-04-14 17:40:05 +08:00
Alexandre Eichenberger fa8962753c
Concat lower (#82)
* implement shape inference for concat

* better checking of axis being concatenated: constant values only

* lowering of Concat with lit and backend tests

* fixes

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-04-13 11:40:39 -04:00
Tian Jin caeaa390e2
Bug fix, ensure krnl.iterate can lower in the degenerate case. (#78)
* Bug fix, ensure krnl.iterate can lower in the degenerate case.

* Fix parser issue with degenerate iterate op.

* Add a test case.

* Remove dead code.

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-04-10 23:27:00 +08:00
Tian Jin 7dba324404
Setup Documentation Page using Github Pages (#76)
* Setup documentation server, move doc files from /doc to /docs as per Github Pages convention.

* Include deleted files in patch.

* /doc -> /docs

* /doc -> /docs

* Update documentation on importing ONNX spec into ONNX Dialect; provide documentation on how to add new documentation pages.
2020-04-09 23:37:04 +08:00
Tung D. Le 4e66488ad3
Change the name and signature of mapToLowerScalarOp (#67)
* Revise mapToLowerScalarOp()

* Update TanhOp

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-04-09 16:06:56 +08:00
Tung D. Le f4fefcf713
Re-add tanh lowering (#75)
* Re-add tanh lowering

* Make the emission deterministic
2020-04-09 14:22:36 +08:00
Tian Jin c9199c9061
Programmatically ensure ONNX Dialect related generated files are up-to-date. (#58)
* Generate ONNX Dialect TableGen Inc files & operation importing inc files when necessary.

* Ensure TableGen inc file is generated before TableGen is invoked.

* Nit: capitalize builder -> Builder.

* Use file-same-as-stdout directive to ensure generated files are always up-to-date in our codebase.

* Use more up-to-date version of ONNXOps.td.inc.

* Do not automatically invoke gen_doc.py.

* Support dry run in gen_doc.py.

* Fix case.

* Remove debug code.

* Add test for new doc_check primitive.

* Add documentation for file-same-as-stdout.

* Provide more comments.

* Add DocCheck to DocCheck README.

* Nit: format CMake script.

* Update comments.

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
2020-04-08 15:00:34 +08:00
Alexandre Eichenberger f5bed72e13
implement shape inference for concat (#74)
* implement shape inference for concat

* better checking of axis being concatenated: constant values only
2020-04-07 16:13:41 -04:00
Gheorghe-Teodor Bercea 8532a10614
Fix input argument indexing error (#69)
* Reorganize main function.

* Follow review comments.

* Emit constants are globals in Krnl and LLVM dialects.

* Fixes. Emit error before return in shape inference.

* Fix description.

* Fix emitted error message.

* Fix index name.
2020-04-06 11:35:17 -04:00
Tung D. Le 83eb15bfae
Fix src/Dialect/ONNX/ONNXOps.td.inc (#68) 2020-04-03 18:18:35 +08:00
Gheorghe-Teodor Bercea f16e79d744
Emit constant tensors as global constants (#66)
* Reorganize main function.

* Follow review comments.

* Emit constants are globals in Krnl and LLVM dialects.

* Enable unique constant variable names.

* Emit alloca for local array. Add tests.

* Comment clean-up.

* Simplify MemRef construction.

* Fix output type.
2020-04-01 13:51:06 -04:00
Byron Changuion b65e77305c
Move to more recent LLVM commit ID (#64)
* Move to more recent LLVM commit ID

* Update LLVM cache version from V9 to V10

* Update to latest LLVM commit id from master, roll back conditions in util scripts

* Update circlci LLVM cache tag to ensure ci updates builds with latest LLVM commit id

* Update README.md to have matching LLVM commit id

* Update doc/Dialtects/onnx.md
2020-04-01 12:38:34 -04:00
Alexandre Eichenberger b422116f12
clean operands using names provided by operandAdaptors (#56)
* clean operands using names provided by operandAdaptors

* reverted changes that were erronerous, from Tung's comment

* clang format issues
2020-03-31 11:55:27 -04:00
Tung D. Le c8758545e7
Import optional outputs as NoneType (#57)
* Import optional outputs as NoneType

* Allow NoneType results after the shape inference

* Use empty() to check an empty string
2020-03-30 21:21:18 -04:00
chentong319 55cbe316fd
Handle error shape inference (#47)
* add return to inferShape

* ran clang-format

* minor changes according to review

* fix format
2020-03-30 11:22:55 -04:00
Tung D. Le 867406191f
Replace SplitConvOpPattern by a declarative rewriting rule (#46) 2020-03-30 14:23:14 +08:00
Alexandre Eichenberger 653fa69102
Unify Conv implementation (#54)
* fixed readme for new git repo

* conv with bias as an optional input
2020-03-26 11:03:19 -04:00
Gheorghe-Teodor Bercea 1777c07b1e
[NFC] Reorganize main function. (#44)
* Reorganize main function.

* Follow review comments.

* Use new file names.
2020-03-24 13:48:54 -04:00
Tung D. Le ddff0f1256
Fix a bug in createArrayAttribute (#43)
* Fix a bug in createArrayAttribute

* Use size_t

* Use const auto&
2020-03-24 14:04:23 +08:00
Gheorghe-Teodor Bercea b3719d486b
Make path relative to onnx-mlir project only (#40)
* Make path relative to onnx-mlir project.

* Use binary root folder path for onnx-mlir.
2020-03-20 12:04:22 -04:00
Tian Jin febee542ee
[NFC] Breakdown CMake Build Scripts to Smaller Parts (#39)
* 1.Break down CMake scripts to smaller libraries per-directory.
2. Move some transformations and interfaces to the right folder.
3. Fix minor merge failure of the patch renaming files to use LLVM convention.

* Link OMBuilder with OMONNXOps.

* 1. Update the src location of generated ONNX dialect definition.
2. Link OMONNXRewrite with OMONNXOps.

* Fix path to tablegen for add_onnx_mlir_dialect_doc.

* Update build script for onnx_mlir_transform.

* 1. Remove comment code.
2. onnx_mlir_attribute_promotion -> OMAttributePromotion.

* Name tablegen generated files with LLVM convention.

* Nit: reorder libraries to link against.

* Nit: Link against MLIR first.
2020-03-20 22:40:51 +08:00
Tian Jin 0aafb3e72f
[WIP][NFC]Rename files to llvm style (#35)
* Change naming style for builder directory.

* Change naming style for conversion folder.

* Fix case sensitivity issue.

* Fix missing onnx header onnx_pb.h issue.

* Rename files in Conversion to llvm style.

* Rename files in Dialect to llvm style.

* Path fix.

* Rename files in Pass to llvm style.

* Rename files in Runtime to llvm style.

* Rename files in Tool to llvm style.

* Rename files in Transform to llvm style.

* Change comments about filenames.

* Fix case.

* Rename interface directory to use llvm file naming convention.
2020-03-19 16:48:09 +08:00
Tian Jin 549af8f0b2
Support attribute promotion. (#34)
* Support attribute promotion.

* Simplify op interface name.

* 1. Add more comments to Attribute Promotion Pass.
2. Move Promotable Const Operand Interface to src/interface, and link against it.

* Complete NFC change onnx -> onnx-mlir.

* Move attribute_promotion pass to src/transform.

* Nit: reword comment.

* Support Attribute Promotion in gen_doc.py.

* Add test.

* Update ONNX doc.

* Add negative test.

* Rename onnxop.inc -> onnx_ops.td.inc.

* Include onnx_ops.td.inc.

* Nit: better comments.

* Prettify CMake.

* Remove original attribute_promotion code, improve comments.

* Append '_op_interface' to op interface decl/defs.

* Namespace cmake targets using onnx_mlir_ prefix.

* Use updated header name.

* Use new body file name.

* Fix dependency.

* Use new CMake target name.

* Make attribute promotion self-contained by removing redundant constant operaions inside the pass execution.

* Remove canonicalization pass.

* Increase comments.

* Use stricter checks.

* Add one more test case.

* Remove %arg1 as it's never used.
2020-03-19 15:03:37 +08:00
Tung D. Le 2814ea3898
Support dilations and enable the remaining e2e tests for MaxPoolSingleOut (#31)
* Support dilations and enable e2e tests

* Fix allocating memory for dynamic shape

* Edit comments

* Do dilation by computing an offset from kernel index

* Correct dilation formula, add an example of out-of-bound, and add a test for dilation

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-18 09:55:50 -04:00
Tung D. Le 4763e8a8bc
Lower ONNXAbsOp to Krnl dialect and enable e2e tests for ONNXReduceL1 (#18)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-17 11:12:45 -04:00
Gheorghe-Teodor Bercea 1622b9f161
[NFC] Change ONNF based names to ONNX-MLIR (#32)
* Rename onnf to onnx-mlir.

* Change workspace name.
2020-03-17 09:16:33 -04:00
Tian Jin c25831094e Revert "Support attribute promotion."
This reverts commit 955968b750.
2020-03-17 17:41:59 +08:00
Tian Jin 955968b750 Support attribute promotion. 2020-03-17 17:39:34 +08:00
Tung D. Le d86591d61a
Import all initialized tensors as dense constants (#30)
* Import initialized tensor as dense attribute

* Import all initialize tensors as dense constants

* Remove unintentional code

* Fix value attribute format in shape inference tests of reshape

* Readd rank check for reshape's shape inference

* Remove a redundant variable

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-16 11:17:28 -04:00
Gheorghe-Teodor Bercea c46880d5c6
Fix reshape output shape inference when a single dynamic shape is given (#22)
* Fix reshape when a dynamic shape is given.

* Fix default attributes for ConvNoBias.

* Fix comment.

* Resolve comment.

* Improve checks.

* Handle zero dim case.

* Add helper to fetch constants. Add test for dynamic reshape.

* Add test for zero.

* Use shortcut method for size.
2020-03-13 17:18:46 -04:00
chentong319 6137fc7c17
Fix issues #15 and #16 (#29)
* fix issue #15 and #16

* fix format

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-13 10:19:27 -04:00
Tung D. Le 362491553c
Shape inference for ONNXAveragePool (#21)
* Shape inference for ONNXAveragePool

* Edit comments and puts helper function on top of the file

* Fix template
2020-03-13 09:59:16 -04:00
Tung D. Le a65820940c
Lower ConstantOp (#28)
* Lower ConstantOp

* Refactor the code

* Edit error messages

* Check whether attribute is sparse or dense during shape inference
2020-03-12 10:58:42 -04:00
Tung D. Le 162ac1bc32
Pad value for MaxPool must be negative infinity instead of zero (#20)
Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
2020-03-12 09:30:02 -04:00
Alexandre Eichenberger 811b63e031
Inter common pad (#26)
* common pad handling in shape inference for conv and maxpool

* common pads

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-11 18:36:02 -04:00
chentong319 391f565a66
Lower constant padding operation to KRNL dialect (#27) 2020-03-11 16:54:07 -04:00
Gheorghe-Teodor Bercea e8a0b47e10
Fix case for upper and lower padding when strides are present. (#11)
* Fix case for upper and lower padding when strides are present.

* Address comments.

* Code clean-up.

* Fix tests.
2020-03-10 16:58:05 -04:00
Gheorghe-Teodor Bercea fe3279e721
Initialize operation arguments with ONNX model constants (#8)
* Save current state.

* Include constant arguments in source.

* Emit constants for Reshape second argument.

* Clean-up code.

* Add changes to gen_doc.py file.

* Propagate constant tensor to Reshape second arg to infer shape.

* Update documentation.

* Eliminate constant tensor operations when lowering to KRNL dialect.

* Replace ConstantTensorOp with ConstantOp.

* Add comment to remove temporary Constant lowering code.

* Remove unused shape inference for Constant.

* Remove comment.

* Remove explicit constant elimination.

* Refactor code.
2020-03-10 14:46:35 -04:00
Gheorghe-Teodor Bercea ba02b90e0b
Enable inference for arbitrary number of instructions (#12)
* Fix shape inference.

* Remove comment.

* Remove worklist since it is not needed.
2020-03-10 14:16:03 -04:00
Tung D. Le 1882059ac9
Support Pads for MaxPoolSingleOut (#14)
* Support Pads for MaxPoolSingleOut

* Regenerate onnx.md to include the new op

* Edit comments

* Undo redundant parts that were unintentionally changed

* Move declarative rewriting rules into canonicalize to avoid creating a new op

* Reformat the rewriting rule pattern of MaxPoolSingleOut

* Put ONNXPadConstantValuePadOp's build method into a .cpp file instead of a tablegen file

* Use the same helper function as the one in inferShape for the ONNXPadConstantValuePadOp's build method

* Change function names and fix padding for the spatial dimensions

* Call shape-inference again after canonicalization to infer shape for newly added ops during canonicalization.

* Fix typos
2020-03-09 20:15:58 -04:00
Gheorghe-Teodor Bercea 8a992b619f
Create some helper functions to emit constant op for a specific type (#7)
* emitConstantOp with a given type

* Helper functions to create infinity constants

* Use new constant helper functions for MaxPoolSingleOut

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-05 14:21:00 -05:00
Gheorghe-Teodor Bercea 8e1b30e133
Check channel dimension mismatch only for known dimensions (#2)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-04 14:34:08 -05:00
Gheorghe-Teodor Bercea e4c23da4fd
Lower MaxPoolSingleOutOp to Krnl dialect (#1)
* Lower MaxPoolSingleOutOp to Krnl dialect

* Edit comments

* Update changes according to the new folder structure

* Add MLIR tests

* Support ceil_mode

* Merge the first two krnl loops into one krnl loop; remove attribute checks

* Dynamically allocate memory for the result if the result has unknown dimensions

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-03-04 14:27:21 -05:00
Tung D. Le e97df0b343
Add a pass to decompose ONNX operations (#9) 2020-03-04 10:53:59 -05:00
Tung D. Le 5357fc1421
Use SqrtOp in Standard dialect (#108)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-02-26 12:03:24 -05:00
Tung D. Le 0c4a010283
Remove rank constraints in gemm fusion (#101)
* Remove rank constraints in gemm fusion

* Add an MLIR test

Co-authored-by: Tian Jin <tjingrant@gmail.com>
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-02-26 11:40:52 -05:00
Tung D. Le 24d89625e3
Remove redundant lower_frontend_to_krnl since we reorganized it (#99)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-02-26 16:32:06 +08:00
chentong 3abbf1c0e9 put the common code into a helper function 2020-02-25 17:43:49 -05:00
chentong 4079ee1f26 Merge remote-tracking branch 'upstream/master' into shapeinference-pad 2020-02-25 15:54:18 -05:00
Alexandre Eichenberger 3a88361b17
use input/output operation names, use helper for attribute function and int values (#106) 2020-02-25 15:46:11 -05:00
Alexandre Eichenberger 3b1c29c078
Using attribute setters for maxpool (#105)
* using attribute setters for maxpool

* fix typos, added handling of storage order, simplified code
2020-02-25 14:33:48 -05:00
Gheorghe-Teodor Bercea ee3e140ddb
[NFC] Change structure of conversion folder. (#96)
* Change structure of conversion folder.

* Fix comments.

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-02-25 10:38:08 -05:00
Gheorghe-Teodor Bercea 32f08bcf0c
Clean-up code. (#98) 2020-02-25 09:54:29 -05:00