MLIR 24.0.0git
TosaOps.h
Go to the documentation of this file.
1//===-- TosaOps.h - TOSA dialect operation definitions ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the TOSA Dialect in MLIR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_TOSA_IR_TOSAOPS_H
14#define MLIR_DIALECT_TOSA_IR_TOSAOPS_H
18#include "mlir/Dialect/Traits.h"
27
28//===----------------------------------------------------------------------===//
29// TOSA dialect and structs includes.
30//===----------------------------------------------------------------------===//
31
32#include "mlir/Dialect/Tosa/IR/TosaEnums.h.inc"
33#include "mlir/Dialect/Tosa/IR/TosaOpsDialect.h.inc"
36namespace mlir {
37class PatternRewriter;
38
39namespace tosa {
40
42 DenseElementsAttr &varShapeAttr,
43 TypeAttr &typeAttr,
44 Attribute &initialValueAttr);
46 DenseElementsAttr varShapeAttr,
47 TypeAttr typeAttr,
48 Attribute initialValueAttr);
49
50#include "mlir/Dialect/Tosa/IR/TosaInterfaces.h.inc"
52} // namespace tosa
53
54namespace OpTrait {
55namespace tosa {
56
57/// This class indicates that an op is tosa-elementwise (permits broadcasting,
58/// unlike Elementwise trait).
59template <typename ConcreteType>
61 : public TraitBase<ConcreteType, TosaElementwiseOperator> {};
62
64/// This class verifies that tosa shape operands are compile time resolvable
65template <typename ConcreteType>
67 : public TraitBase<ConcreteType, TosaResolvableShapeOperands> {
68public:
69 static LogicalResult verifyTrait(Operation *op) {
71 }
72};
73
74/// This class indicates that op operates on tosa shape types
75template <typename ConcreteType>
76class TosaShapeOperator : public TraitBase<ConcreteType, TosaShapeOperator> {};
77
79/// This class indicates that op operates on tosa shape types
80template <typename ConcreteType>
82 : public TraitBase<ConcreteType, TosaShapeOperatorWithSameRanks> {
83public:
84 static LogicalResult verifyTrait(Operation *op) {
86 }
87};
88
89} // namespace tosa
90} // namespace OpTrait
91
92namespace tosa {
93
95
96/// Represents a dimension in the shape of a tensor that can be inferred
97/// based on the other provided dimensions. For example, in a reshape
98/// operation, -1 can be used to indicate a size that is the remainder
99/// of the other dimensions.
101
102} // namespace tosa
103
104} // namespace mlir
105
106#define GET_ATTRDEF_CLASSES
107#include "mlir/Dialect/Tosa/IR/TosaAttributes.h.inc"
108
109#define GET_TYPEDEF_CLASSES
110#include "mlir/Dialect/Tosa/IR/TosaOpsTypesBase.h.inc"
111
112#define GET_OP_CLASSES
113#include "mlir/Dialect/Tosa/IR/TosaOps.h.inc"
114
115namespace mlir {
116namespace tosa {
117
118// Create a rank-1 const tensor for zero point of the source tensor.
119std::optional<Value> createZeroPointTensor(OpBuilder &builder, Location loc,
120 Type srcElemType, int64_t zp = 0);
121
122// Create a pad-const const tensor with value of `val` of required data-type
123Value createPadConstTensor(OpBuilder &builder, Location loc, Value src,
124 int32_t val = 0);
125
126// returns type of variable op
127RankedTensorType getVariableType(VariableOp variableOp);
128
129// Returns the bitwidth of a TOSA tensor element type
130unsigned getBitWidth(Type type);
131
132// Returns the storage element type for a given type
134
135// Returns the storage element type for a given value
137
138// Verify a block scaled tensor type is valid
139LogicalResult verifyBlockScaledTensorType(mlir::Type type,
140 bool allowScaleValues);
141
142} // namespace tosa
143} // namespace mlir
144
145#endif // MLIR_DIALECT_TOSA_IR_TOSAOPS_H
Attributes are known-constant values of operations.
Definition Attributes.h:25
An attribute that represents a reference to a dense vector or tensor object.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
Helper class for implementing traits.
This class indicates that an op is tosa-elementwise (permits broadcasting, unlike Elementwise trait).
Definition TosaOps.h:61
This class verifies that tosa shape operands are compile time resolvable.
Definition TosaOps.h:67
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:69
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:82
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:84
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:76
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
LogicalResult verifyTosaShapeOperatorWithSameRanks(Operation *op)
Definition TosaOps.cpp:5977
LogicalResult verifyTosaResolvableShapeOperands(Operation *op)
Definition TosaOps.cpp:5964
Type getStorageElementTypeOrSelf(Type type)
Definition TosaOps.cpp:583
RankedTensorType getVariableType(VariableOp variableOp)
ParseResult parseVariableOpTypeOrInitialValue(OpAsmParser &parser, DenseElementsAttr &varShapeAttr, TypeAttr &typeAttr, Attribute &initialValueAttr)
Definition TosaOps.cpp:227
constexpr int64_t kInferableDimSize
Represents a dimension in the shape of a tensor that can be inferred based on the other provided dime...
Definition TosaOps.h:100
void printVariableOpTypeOrInitialValue(OpAsmPrinter &p, Operation *op, DenseElementsAttr varShapeAttr, TypeAttr typeAttr, Attribute initialValueAttr)
Definition TosaOps.cpp:252
LogicalResult verifyBlockScaledTensorType(mlir::Type type, bool allowScaleValues)
Definition TosaOps.cpp:742
unsigned getBitWidth(Type type)
Definition TosaOps.cpp:629
std::optional< Value > createZeroPointTensor(OpBuilder &builder, Location loc, Type srcElemType, int64_t zp=0)
Definition TosaOps.cpp:5928
bool isa_tosa_shape_type(mlir::Type t)
Definition TosaOps.cpp:5952
Value createPadConstTensor(OpBuilder &builder, Location loc, Value src, int32_t val=0)
Definition TosaOps.cpp:614
Include the generated interface declarations.