forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TOSA] Add Tosa_Shape type and ConstShapeOp
Adds: 1. tosa shape type to Tosa dialect e.g., !tosa.shape<4> is a type for rank-4 shape values (size-4 array of index values) 2. const_shape operator 3. trait TosaShapeOperator, added to tosa shape operators, and a verifier that all operands and results of operator are tosa shapes 4. trait TosaResolvableShapeOperands, added to all tosa operators, and a verifier that every tosa shape operand is produced by a tosa shape operator (indicated by trait TosaShapeOperator) 5. trait TosaShapeOperatorWithSameRanks, added to Tosa_ElementwiseShapeOp and a verifier that all operands and result shapes have same ranks 5. changed TileOp's multiples from attribute to input, of !tosa.shape type. 6. add folder for tosa ConstShape operator Signed-off-by: Jerry Ge <[email protected]> Signed-off-by: Tai Ly <[email protected]> Change-Id: I0213f99f5816b648f732b01fe8bd196956f1dfc8
- Loading branch information
Showing
18 changed files
with
441 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//===-- TosaShapeOps.td - TOSA dialect utility operations --*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines shape operators for the TOSA dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TOSA_SHAPE_OPS | ||
#define TOSA_SHAPE_OPS | ||
|
||
include "mlir/IR/OpBase.td" | ||
|
||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
include "mlir/Interfaces/InferTypeOpInterface.td" | ||
include "mlir/Interfaces/LoopLikeInterface.td" | ||
include "mlir/Dialect/Tosa/IR/TosaInterfaces.td" | ||
|
||
include "mlir/Dialect/Tosa/IR/TosaTypesBase.td" | ||
include "mlir/Dialect/Tosa/IR/TosaOpBase.td" | ||
include "mlir/Dialect/Tosa/IR/TosaTypes.td" | ||
|
||
// Op trait: operator has operands and results with TOSA shape type | ||
def TosaShapeOperator : NativeOpTrait<"TosaShapeOperator"> { | ||
let cppNamespace = "mlir::OpTrait::tosa"; | ||
} | ||
|
||
class Tosa_ShapeOp<string mnemonic, list<Trait> traits = []> | ||
: Tosa_Op<mnemonic, !listconcat(traits, [TosaShapeOperator, Pure])> { | ||
|
||
let assemblyFormat = | ||
"operands attr-dict `:` functional-type(operands, results)"; | ||
|
||
let hasFolder = 1; | ||
} | ||
|
||
// op trait: shape operator has same ranks for operands and results | ||
def TosaShapeOperatorWithSameRanks : NativeOpTrait<"TosaShapeOperatorWithSameRanks"> { | ||
let cppNamespace = "mlir::OpTrait::tosa"; | ||
} | ||
|
||
class Tosa_ElementwiseShapeOp<string mnemonic, list<Trait> traits = []> | ||
: Tosa_ShapeOp<mnemonic, !listconcat(traits, [TosaShapeOperatorWithSameRanks])> { | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Operator: ConstShape | ||
//===----------------------------------------------------------------------===// | ||
def Tosa_ConstShapeOp : Tosa_ShapeOp<"const_shape", [ConstantLike, Pure]> { | ||
let summary = "Constant Shape op."; | ||
|
||
let description = [{ | ||
A node containing constant data for use as the input to an shape operation. May | ||
hold data only in index data type. | ||
|
||
Example: | ||
|
||
```mlir | ||
// Generic form | ||
%out = "tosa.const_shape"() {value = dense<0> : tensor<4xindex>} : () -> !tosa.shape<4> | ||
``` | ||
}]; | ||
|
||
let arguments = (ins | ||
IndexElementsAttr:$value | ||
); | ||
|
||
let results = (outs | ||
Tosa_Shape:$output | ||
); | ||
|
||
let hasVerifier = 1; | ||
} | ||
|
||
#endif // TOSA_SHAPE_OPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//===-- TosaTypes.td - TOSA type definitions ---------------*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the type definitions for the TOSA dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TOSA_TYPES | ||
#define TOSA_TYPES | ||
|
||
include "mlir/IR/AttrTypeBase.td" | ||
include "mlir/IR/OpBase.td" | ||
|
||
include "mlir/Dialect/Tosa/IR/TosaOpBase.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Tosa Type Definitions. | ||
//===----------------------------------------------------------------------===// | ||
|
||
// The base class for Tosa dialect types. | ||
class Tosa_Type<string name, string typeMnemonic, list<Trait> traits = []> | ||
: TypeDef<Tosa_Dialect, name, traits> { | ||
let mnemonic = typeMnemonic; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ShapeType | ||
//===----------------------------------------------------------------------===// | ||
def Tosa_Shape : Tosa_Type<"shape", "shape"> { | ||
let summary = "Shape with static rank and Index element type"; | ||
let description = [{ | ||
Syntax: | ||
|
||
``` | ||
shape-type ::= `shape` `<` rank `>` | ||
``` | ||
Values with shape type represents a shape with a fixed rank and a list of dimensions. | ||
Rank must be zero or a positive integer. | ||
Each dimension is represented by the builtin Index type. | ||
|
||
Examples: | ||
|
||
```mlir | ||
// Shape with rank of four, for example, [1, 1, 8, 16]: | ||
!tosa.shape<4> | ||
|
||
// Shape with rank of one, for example, [16]: | ||
!tosa.shape<1> | ||
|
||
// Shape with rank zero, for example, [] (i.e., shape of scalar values): | ||
!tosa.shape<0> | ||
``` | ||
}]; | ||
let parameters = (ins | ||
"int":$rank | ||
); | ||
let builders = [ | ||
TypeBuilder<(ins "int":$rank)> | ||
]; | ||
let assemblyFormat = "`<` $rank `>`"; | ||
|
||
let genVerifyDecl = 1; | ||
} | ||
|
||
def IsTosaShapeType : CPred<"mlir::tosa::isa_tosa_shape_type($_self)">; | ||
|
||
// Whether a Tosa Shape type has a rank equal to the specified rank. | ||
class IsTosaShapeOfRankPred<int rank> : And<[ | ||
IsTosaShapeType, | ||
CPred<[{::llvm::cast<::mlir::tosa::shapeType>($_self).getRank() == }] # rank> | ||
]>; | ||
|
||
class TosaShapeOfRank<int rank> : | ||
Type<IsTosaShapeOfRankPred<rank>, | ||
"Tosa shape type of rank " # rank | ||
>; | ||
|
||
def Rank1TosaShape : TosaShapeOfRank<1>; | ||
def Rank2TosaShape : TosaShapeOfRank<2>; | ||
def Rank4TosaShape : TosaShapeOfRank<4>; | ||
|
||
#endif // TOSA_TYPES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.