Commit Graph

116 Commits

Author SHA1 Message Date
Tian Jin 9c398c0121
Support Optional Inputs (#94)
* 1. Combine variadicIn/Out with expectedNumOperands/Results to simplify import function arguments.
2. Generic improvements to code readability in gen_doc.py.

* Update ONNX Dialect doc.

* Remove redundant code in ImportNode.

* Prettify op_build_table.inc.

* 1. Remove irrelevant code in gen_doc.py

* Refactor code to be more readable.

* Further refactoring for readability improvements.

* Allow gemm to have an optional operand (bias term), and include an example of declarative optimization pattern targeting gemm with bias term ommitted.

* Make shape inference/lowering of gemm op compatible with optional operand declaration.

* Apply canonicalization again after lowering from onnx -> std dialects.

* Make hasBias compatible with the situation of GemmNoBias op.

* Update doc.

* Add a canonicalization test.

* Remove special handler for importing Gemm op, as it's redundant now.
2020-02-24 23:46:48 +08:00
chentong 2281cc060f Merge branch 'master' of github.com:clang-ykt/ONNF into shapeinference-pad
Conflicts:
	src/pass/shape_inference_pass.cpp
2020-02-21 09:30:40 -05:00
Tung D. Le aea6479ad3
Lower BatchNormalization (test mode) to Krnl dialect (#70)
* Add ONNXBatchNormalizationTestModeOp and its shape inference

* Lower batchnormalization test mode

* re-use scale, bias, mean, and variance

* Add MLIR tests

* Add e2e tests

* fix typos

* Fix a bug in MLIR tests

* Change type from int to int64_t for indices

* Uncomment e2e tests due to segmentation fault

* Uncomment e2e tests due to segmentation fault

* Revise the code

* [Tian] Fix segmentation fault in e2e tests

* Re-generate onnx.md to include BatchNormalizationTestModeOp

* Reverse an unintentional change

* Fix some typos in comments

* Use convertToMemRefType from the master branch

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-02-20 11:45:40 -05:00
Tung D. Le f1d20e368f
Add support of GemmNoBias (#91)
* Add support of GemmNoBias

* Fix a wrong indentation
2020-02-20 10:55:24 -05:00
chentong c11f97f1b5 fix test case for changes in Op definition 2020-02-17 09:07:58 -05:00
chentong ec43fadc3b Merge remote-tracking branch 'upstream/master' into shapeinference-pad 2020-02-17 08:27:43 -05:00
Gheorghe-Teodor Bercea 3c505ae31d
Split convolution into explicit padding and unpaded convolution. (#82)
* Split convolution into explicit padding and unpaded convolution.

* Refactor code. Add test.
2020-02-14 16:06:38 -05:00
chentong bbdf4e3b4d Merge remote-tracking branch 'upstream/master' into shapeinference-pad
Conflicts:
	test/mlir/onnx/onnx_shape_inference.mlir
2020-02-14 15:35:47 -05:00
Gheorghe-Teodor Bercea 17d84901b7
Allow 1-D convolutions. (#86)
* Fix check.

* Fix comment.
2020-02-14 10:54:08 -05:00
Tung D. Le b521719587
Lower Matmul operation to Krnl dialect (#57)
* Allocate memory for matmul's result

* Group cases

* Add support of N-D x N-D, N>=2

* Revise createIterateOperandPack

* Add 1-D x 1-D

* Add 1-D x N-D

* Add MLIR tests

* Change variable names

* Change type from int to int64_t for indices

* Change variable names

* Change int64_t back to int

* Change int64_t back to int

* Change int64_t back to int

* Use decltype

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-02-14 10:43:17 -05:00
chentong c3041bfb43 shape inference for pad with constant pads 2020-02-13 19:56:05 -05:00
chentong319 49dae74eab
Create constant pad (#75)
* handle pad op which does not have the optional third argment

* rewrite PadConstantValue with constant pad into PadConstantValuePad

* add test for PadConstantValuePad

* update onnx.md
2020-02-11 15:32:01 -05:00
Gheorghe-Teodor Bercea 094be4f37a
Add support for strides when emitting convolution loop nest. (#76)
* Add support for strides when emitting convolution loop nest.

* Only emit stride multiplication if strides is greater than one.

* Add test.
2020-02-11 11:53:13 -05:00
Tung D. Le adad9e24bd
Add support of negative dimensions (#66)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-02-11 10:37:47 -05:00
Tung D. Le 2c7046ff5f
Lowering ReductionMax, ReductionMin, ReductionProd and ReductionSum (#31)
* Shape inference for reduction

* Lower ReduceSum

* Support list-like attributes

* Add ReduceMax, ReduceMin, ReduceProd

* Add tests

* Emit errors for unsupported types

* Typos

* Add backend test

* Fix axis computation

* Update the use of attributes

* Use SmallVector

* Address stylistic comments

* Change type from int to int64_t for indices

* Change type from int to int64_t for indices
2020-02-10 21:38:19 +08:00
Gheorghe-Teodor Bercea 0272451521
Lower convolution to KRNL dialect. (#65)
* Ensure data shape is at least 4.

* First version of convolution.

* Simplify code for KRNL lowering.

* Add test without padding or strides.

* Refactor code for lowering frontend operations to KRNL dialect.

* Add test for conv with no bias and no padding.

* Add test with group greater than one.

* Address comment.
2020-02-07 16:51:32 -05:00
Tung D. Le 0564c0eaef
Add constraints for matmul-add fusion (#67)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-02-07 13:51:44 -05:00
Haruki Imai 477227a0ec
Added lowering of SignOp (#21)
* Support lowering of SignOp

* Fixed test code for signop of integer input

* Inserted Sigh and Reciprocal in SharingWork.md (Reciprocal is for past commit 7e3f96e)

* Added test for Sign Op

* Fixed minus_one -> minusOne

* Fixed test for signop
2020-02-04 22:27:17 +08:00
Tung D. Le 2b56c09454
Rewrite ReduceL1, ReduceL2, ReduceLogSum, ReduceLogSumExp, ReduceSumSquare in the ONNX dialect (#38)
* Rewrite ReduceSumSquare

* Edit gen_doc.py

* Revise the code

* Do shape inference after canonicalization so that there is no need to implement shape inference of rewritten ops

* Rewrite ReduceL2

* Add onnx_rewrite.cpp for all rewriting for ONNX ops

* Rewrite ReduceL1, ReduceLogSum, ReduceLogSumExp

* Edit comments

* Change the use of -> to .

* Checkout gen_doc.py from the master branch

* Use emplace_back instead of push_back

* Revise the code

* Edit comments

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-01-31 19:00:39 +08:00
Alexandre Eichenberger 0d77840969
Inference maxpool (#48)
* first steps for shape inference of maxpool

* setps forward

* ongoing

* working version

* first steps for shape inference of maxpool

* setps forward

* ongoing

* working version

* fix errors introduced by github merge

* changes suggested by Doru

* updates

* requested fixes

* reqested changes

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-01-30 14:30:28 -05:00
Gheorghe-Teodor Bercea 9fb826ae7e
Lower transpose operation to KRNL dialect (#54)
* Lower transpose operation.

* Fix IndetityOp.

* Add tests.

* Add backend tests.

* Clean-up code.

* Move transpose code and improve comment.
2020-01-30 11:44:56 -05:00
Tung D. Le 400676e371
Lowering Gemm (#19)
* Initial implementation

* Support transposing inputs

* Revise unidirectional broadcasting and unknown dimensions

* Revise gemm

* Add testcase

* Rename some variables

* Update SharingWork.md

* Change from the use of Value* to Value

* Insert deallocation

* Initilize the output matrix and fix wrong computation

* Add end-to-end testcases

* Edit lowering tests

* Change attribute names

* Use emplace_push for SmallVector

* Use the new way of getting attributes

* Revise the use of attributes

* Check the bias's shape

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-01-29 11:11:49 -05:00
Tung D. Le 9e82d388f0
Add support for Unsqueeze (#50)
* Infer shape for Unsqueeze

* Lower Unsqueeze

* Revise

* Turn off backend tests

* Compute tensorSize for static shape

* Compute tensorSize with unknown dims

* Edit tests

* Update the use of attributes

* Add e2e tests

* Use SmallVector

* Remove return

* Check whether the operand is ranked or not

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-01-29 10:46:02 -05:00
Tung D. Le 5b44169aaa
Support dimension zero in reshape (#55)
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-01-29 10:41:09 -05:00
Tung D. Le f3047943a1
Handle 1-D MATMUL N-D (#56) 2020-01-29 10:35:05 -05:00
Tung D. Le 195bf9d15d Add KrnlSqrtOp (#22)
* Initial lowering of KrnlSqrtOp

* Fix errors and add a testcase

* typos

* Add the MLIR example

* Restore doc/doc_check/CMakeLists.txt

* Clean the code

* Edit comments

* Remove redundant parts

* Chang the use of -> to .

* Add a test for f64

* Support ONNXSqrtOp

* Fix indentation

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-01-28 11:10:47 -05:00
Gheorghe-Teodor Bercea 3f5c543782
Merge branch 'master' into matmul-shape 2020-01-27 11:37:40 -05:00
chentong319 c74f814f64 Add attributes as operation parameters (#45)
* add attributes of Op into parameters

* fix rewrite rule for GemmOp with attributes

* use I64Attr instead of I32Attr and modify test cases for the changes in attributes

* add output name (prefixed with o_) to Op definition

* update shape inference for the new attributes
2020-01-27 10:09:14 -05:00
Gheorghe-Teodor Bercea 696da50d2a
Merge branch 'master' into matmul-shape 2020-01-24 15:53:02 -05:00
Yasushi Negishi 383a5c31ac Support Softplus and Softsign operations (#17)
* Support Softplus and Softsign operations

* Add the default shape inference for the transposition operation.

* Fix conflict with master

* Fix conflict with master branch

* Add test for softplus and softsign in test/backend/test.py

* Re-enable Reciprocal tests.

Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-01-23 21:18:38 -07:00
Doru Bercea 07d28769d3 Merge remote-tracking branch 'origin/master' into matmul-shape 2020-01-23 11:53:53 -05:00
Doru Bercea 7dda698e7e Add test with dilations and auto padding set to SAME_UPPER. 2020-01-22 16:40:33 -05:00
Doru Bercea 68efd21064 Fix dilation formula in the code. 2020-01-22 16:34:59 -05:00
Doru Bercea 050d7d277d Fix test. 2020-01-22 16:12:09 -05:00
Doru Bercea 0bc07ef661 Merge remote-tracking branch 'origin/master' into matmul-shape 2020-01-22 15:29:09 -05:00
Doru Bercea ea45cbcca9 Add support for dilations attribute and add tests. 2020-01-22 14:40:10 -05:00
Tian Jin 51b0f4c9dd
Chentong319 attribute with variant (#25)
* change the read-in of attribute, using variant

* Use backported variant.

* Reduce code duplication.

* 1. Make array attribute parsing more clear.
2. int -> int64_t.

* 1. Fix how array attributes are imported.

* 1. Fix clang-tidy warnings.

* 1. Nit: fix clang-tidy warnings.

* Fix MaxPool node construction.

* Fix call to MaxPool.

* Comment out backend tests that fail.

* Add path to variant submodule to enable include file detection.

* Allow unused argument to avoid special casing generator.

* Address attribute related e2e test failures for Hard sigmoid,Elu,LeakyRelu,Selu,Softmax

Co-authored-by: chentong319 <chentong@us.ibm.com>
Co-authored-by: Gheorghe-Teodor Bercea <gt.bercea@gmail.com>
2020-01-21 19:36:21 -07:00
Tung D. Le e89e51699b Lowering softmax (#14)
* Rebase

* Use max normalization

* Handle axis

* Add tests

* Update SharingWork.md

* Remove redundant spaces

* Format code

* Rebase

* Change from the use of Value* to Value

* Add end-to-end tests

Co-authored-by: Tian Jin <tjingrant@gmail.com>
2020-01-20 21:57:32 -05:00
Doru Bercea f0b484c0bc Add test for transpose with permutation. 2020-01-20 14:54:40 -05:00
Gheorghe-Teodor Bercea a87f01747a
Merge branch 'master' into matmul-shape 2020-01-15 18:03:03 -05:00
Doru Bercea a42fdd08f3 Fix Gemm translation to ONNX dialect. 2020-01-15 14:11:32 -05:00
Doru Bercea da0e9b01b1 Fix 1 and 2 dimensional cases. Add test for 1 and 2 dimensional combinations. 2020-01-14 10:47:24 -05:00
Doru Bercea 642f77abed Add additional dynamic dimension. 2020-01-14 10:47:24 -05:00
Doru Bercea 95ebf3e23a Add test for multypling stacks of matrices. 2020-01-14 10:47:24 -05:00
Doru Bercea ae966cdee9 Add tests for matrices and stack of matrices combinations. 2020-01-14 10:47:24 -05:00
Doru Bercea a5f1d39c20 Add tests for matrices and stack of matrices combinations. 2020-01-14 10:47:24 -05:00
Doru Bercea 6478c88cdc Add test for all one dimensional case. 2020-01-14 10:47:24 -05:00
Doru Bercea 151f4f8c44 Add the default shape inference for the transposition operation. 2020-01-09 13:50:38 -05:00
Tung D. Le 44ec333dfa Update test cases 2020-01-08 13:11:57 +09:00
Tung D. Le 3d4ad52011 Rewrite tanh using TanhOp, add log, cos 2020-01-08 12:11:21 +09:00
TUNG LEDUC 06a968d4a1 [MLIR] Add broadcasting support for element wise operations (#398)
* Add broadcasting support for elementwise operations

* Remove MLIRDialect from MLIRWholeArchiveLibs

* Rewrite getLoopIVsForBroadcasting

* Compute dimensions for allocating result memory

* Compute dimensions for allocating result memory (revised)

* Use static dimension for element-wise operation testcases

* Add a test for addition with broadcasting

* Missed Traits.h when merging

* Revise

* Update SharedWork.md

* Broadcasting for variadic operations

* Edit comments

* Update SharedWork.md

* Reorganize the code

* Add CHECK-LABEL for test_add_with_broadcasting
2019-12-21 02:08:27 -05:00
Haruki Imai 7e3f96e642 [MLIR] Add support for Reciprocal (#397)
* Added support for Reciprocal

* Fixed format
2019-12-21 02:07:44 -05:00
GHEORGHE-TEOD BERCEA e81a7654f9 [MLIR] Add support for reshape (#390)
* Add reshape op handling.

* Lower reshape to KRNL dialect.

* Add comments.

* Propagate reshape to KRNL IR.

* Lower KRNL reshape to affine and standard ops level dialects.

* Add lowering of reshape operation to Krnl and LLVM Dialects.

* Add test for LLVM IR dialect output for reshape.

* Fix rebase.

* Fix test variable.

* Emit errors during reshape shape inference. Address other reviewer comments.
2019-12-21 02:06:14 -05:00
TUNG LEDUC 5ed79083d5 [MLIR] Add support for Max, Min, Sum, Elu, Selu, LeakyRelu, HardSigmoid (#395)
* Lower ONNXSumOp

* Add inferShapes() and test cases

* Load the first operand to the result

* Update SharingWork.md

* Update SharingWork.md

* Update SharingWork.md

* Add support for Max, Min

* Pass operation instead of location to mapToLowerScalarOp

* Add support for Elu, Selu, LeakyRelu, HardSigmoid

* Add test cases

* Update SharingWork.md

* Rewrite the part of lowering variadic ops and use it for binary ops

* Use two diffenrent templates for Unary and Variadic Ops

* Revise the code
2019-12-21 02:02:09 -05:00
TUNG LEDUC 45608282e0 [MLIR] Add support for Relu (#392)
* Add support for Relu

* Add comments
2019-12-21 01:38:16 -05:00
TUNG LEDUC 1c3176bf9f [MLIR] Lower ONNX element-wise unary ops: Exp, Tanh, Sinh, Cosh, Sigmoid (#389)
* Lower ExpOp

* Lower ONNXTanhOp

* Lower Exp Tanh, Sinh, and Cosh

* Lower ONNX Sigmoid op

* Merge

* Specialize template lowerScalarOp

* Unify ONNXEWUnaryOpLowering and ONNXEWBinaryOpLowering

* Support multiple types

* Reformat the code

* Add test cases

* Reformat the code

* Change names

* Apply clang-format

* Update variable names
2019-12-21 01:37:29 -05:00
Tian Jin 0048f2fd86 clean up 2019-12-21 01:36:03 -05:00
TUNG LEDUC c3ef1d93ae [MLIR] Lower ONNX element-wise binary ops: Mul, Div, Sub, And, Or, Xor (#388)
* Lower ONNX element-wise binary ops: Mul, Div, Sub, And, Or, Xor

* Edit gen_doc.py to avoid changes about AnyTypeOf<[AnyMemRef, AnyTensor]>

* Miss a space

* Add tests

* Shorten ONNXElementWiseBinaryOpLowering into ONNXEWBinaryOpLowering

* Move lowering patterns into runOnModule()

* Redundant space
2019-12-21 01:35:31 -05:00
GHEORGHE-TEOD BERCEA 7fb2f80dce [MLIR] Add support for dealloc insertion (#386)
* Add support for dealloc op.

* Check dealloc for returned result not present.
2019-12-21 01:34:48 -05:00
GHEORGHE-TEOD BERCEA 652ce4b7d4 Add test for checking lowering of Add op to KRNL IR (#385)
* Add test for checking lowering of Add op to KRNL IR.

* Add test file.
2019-12-21 01:20:36 -05:00
TUNG LEDUC d61cf35471 [MLIR] Add one more test case for MatMul-Add fusion (#380)
* Add one more testcase for matmul-add fusion

* Code format for identity elimination testcase
2019-12-21 00:51:54 -05:00
Tian Jin 004762c13d [MLIR] Remove module from test (#379)
* Remove module from test

* Update onnx_canonicalization.mlir
2019-12-21 00:51:23 -05:00
TUNG LEDUC 53ab014a1d [MLIR] Canonicalization pattern for eliminating identity ops (#377)
* Canonicalization pattern for eliminating identity ops

* Add a test for the identity elimination rule

* Remove frontend from test

* Use CHECK-NEXT instead of CHECK
2019-12-21 00:47:22 -05:00
GHEORGHE-TEOD BERCEA bee32e2041 Fix rebase errors. (#378) 2019-12-21 00:46:29 -05:00
TONG CHEN 3f68c5420d [MLIR] generate op from onnx document (#366)
* generate op from onnx document

* Restore FullGemm

* update the op attribute for shape inference and canonicalizer

* Update onnx_canonicalization.mlir
2019-12-21 00:40:40 -05:00
Tian Jin d01ac7732f [MLIR] compartmentalize build script (#369)
* compartmentalize build script, temporarily remove dependency of onnf_opt on helper.cpp

* fix test includes

* fix op directory include

* compiler -> op

* compiler test depends on boost system

* fix function name

* specify libcompiler dependencies

* let cmake take care of transitive dependencies

* remove unnecessary includes

* use ONNF_SRC_ROOT and ONNF_BIN_ROOT

* allow whole-archive linked libraries to be appended

* [MLIR] Support filecheck (#371)

* support lit+FileCheck

* add lit into build script

* format MLIR.cmake

* format cmake

* [MLIR] Remove input/output ops (#372)

* remove input/output ops

* get output tensor type from symbol table
2019-12-21 00:34:51 -05:00