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
15
17#include "mlir/IR/Matchers.h"
21
22#include <string>
23
24//===----------------------------------------------------------------------===//
25// TOSA dialect and structs includes.
26//===----------------------------------------------------------------------===//
27
28#include "mlir/Dialect/Tosa/IR/TosaEnums.h.inc"
29#include "mlir/Dialect/Tosa/IR/TosaOpsDialect.h.inc"
31
32namespace mlir {
33class PatternRewriter;
34
35namespace tosa {
36
37ParseResult parseVariableOpTypeOrInitialValue(OpAsmParser &parser,
38 DenseElementsAttr &varShapeAttr,
39 TypeAttr &typeAttr,
40 Attribute &initialValueAttr);
41void printVariableOpTypeOrInitialValue(OpAsmPrinter &p, Operation *op,
42 DenseElementsAttr varShapeAttr,
43 TypeAttr typeAttr,
44 Attribute initialValueAttr);
45} // namespace tosa
46} // namespace mlir
47
48#include "mlir/Dialect/Tosa/IR/TosaInterfaces.h.inc"
49
50namespace mlir {
51namespace OpTrait {
52namespace tosa {
53
54/// This class indicates that an op is tosa-elementwise (permits broadcasting,
55/// unlike Elementwise trait).
56template <typename ConcreteType>
58 : public TraitBase<ConcreteType, TosaElementwiseOperator> {};
59
61/// This class verifies that tosa shape operands are compile time resolvable
62template <typename ConcreteType>
64 : public TraitBase<ConcreteType, TosaResolvableShapeOperands> {
65public:
66 static LogicalResult verifyTrait(Operation *op) {
68 }
69};
70
71/// This class indicates that op operates on tosa shape types
72template <typename ConcreteType>
73class TosaShapeOperator : public TraitBase<ConcreteType, TosaShapeOperator> {};
74
76/// This class indicates that op operates on tosa shape types
77template <typename ConcreteType>
79 : public TraitBase<ConcreteType, TosaShapeOperatorWithSameRanks> {
80public:
81 static LogicalResult verifyTrait(Operation *op) {
83 }
84};
85
86} // namespace tosa
87} // namespace OpTrait
88
89namespace tosa {
90
92
93/// Represents a dimension in the shape of a tensor that can be inferred
94/// based on the other provided dimensions. For example, in a reshape
95/// operation, -1 can be used to indicate a size that is the remainder
96/// of the other dimensions.
98} // namespace tosa
99} // namespace mlir
100
101#define GET_ATTRDEF_CLASSES
102#include "mlir/Dialect/Tosa/IR/TosaAttributes.h.inc"
103
104#define GET_TYPEDEF_CLASSES
105#include "mlir/Dialect/Tosa/IR/TosaOpsTypesBase.h.inc"
106
107#define GET_OP_CLASSES
108#include "mlir/Dialect/Tosa/IR/TosaOps.h.inc"
109
110namespace mlir {
111namespace tosa {
112
113// Create a rank-1 const tensor for zero point of the source tensor.
114std::optional<Value> createZeroPointTensor(OpBuilder &builder, Location loc,
115 Type srcElemType, int64_t zp = 0);
116
117// Create a pad-const const tensor with value of `val` of required data-type
118Value createPadConstTensor(OpBuilder &builder, Location loc, Value src,
119 int32_t val = 0);
120
121// returns type of variable op
122RankedTensorType getVariableType(VariableOp variableOp);
123
124// Returns the bitwidth of a TOSA tensor element type
125unsigned getBitWidth(Type type);
126
127// Returns the storage element type for a given type
129
130// Returns the storage element type for a given value
132
133// Verify that a given type is a valid block scaled tensor type
134LogicalResult verifyBlockScaledTensorType(
135 mlir::Type type,
137 bool allowScaleValues = false);
138
139// Returns a diagnostic suffix string for a type verification failure, or
140// empty string if the type is valid
142
143} // namespace tosa
144} // namespace mlir
145
146#endif // MLIR_DIALECT_TOSA_IR_TOSAOPS_H
This class represents a diagnostic that is inflight and set to be reported.
Helper class for implementing traits.
This class indicates that an op is tosa-elementwise (permits broadcasting, unlike Elementwise trait).
Definition TosaOps.h:58
This class verifies that tosa shape operands are compile time resolvable.
Definition TosaOps.h:64
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:66
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:79
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:81
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:73
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:5585
LogicalResult verifyTosaResolvableShapeOperands(Operation *op)
Definition TosaOps.cpp:5572
Type getStorageElementTypeOrSelf(Type type)
Definition TosaOps.cpp:281
RankedTensorType getVariableType(VariableOp variableOp)
ParseResult parseVariableOpTypeOrInitialValue(OpAsmParser &parser, DenseElementsAttr &varShapeAttr, TypeAttr &typeAttr, Attribute &initialValueAttr)
Definition TosaOps.cpp:223
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:97
void printVariableOpTypeOrInitialValue(OpAsmPrinter &p, Operation *op, DenseElementsAttr varShapeAttr, TypeAttr typeAttr, Attribute initialValueAttr)
Definition TosaOps.cpp:248
unsigned getBitWidth(Type type)
Definition TosaOps.cpp:327
std::optional< Value > createZeroPointTensor(OpBuilder &builder, Location loc, Type srcElemType, int64_t zp=0)
Definition TosaOps.cpp:5536
bool isa_tosa_shape_type(mlir::Type t)
Definition TosaOps.cpp:5560
Value createPadConstTensor(OpBuilder &builder, Location loc, Value src, int32_t val=0)
Definition TosaOps.cpp:312
LogicalResult verifyBlockScaledTensorType(mlir::Type type, llvm::function_ref< mlir::InFlightDiagnostic()> emitError=nullptr, bool allowScaleValues=false)
Definition TosaOps.cpp:440
std::string getTosaTensorTypeErrorMessage(mlir::Type type)
Definition TosaOps.cpp:499
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.