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#include <string>
30//===----------------------------------------------------------------------===//
31// TOSA dialect and structs includes.
32//===----------------------------------------------------------------------===//
34#include "mlir/Dialect/Tosa/IR/TosaEnums.h.inc"
35#include "mlir/Dialect/Tosa/IR/TosaOpsDialect.h.inc"
37
38namespace mlir {
39class PatternRewriter;
40
41namespace tosa {
44 DenseElementsAttr &varShapeAttr,
45 TypeAttr &typeAttr,
46 Attribute &initialValueAttr);
48 DenseElementsAttr varShapeAttr,
49 TypeAttr typeAttr,
50 Attribute initialValueAttr);
52#include "mlir/Dialect/Tosa/IR/TosaInterfaces.h.inc"
53
54} // namespace tosa
55
56namespace OpTrait {
57namespace tosa {
58
59/// This class indicates that an op is tosa-elementwise (permits broadcasting,
60/// unlike Elementwise trait).
61template <typename ConcreteType>
63 : public TraitBase<ConcreteType, TosaElementwiseOperator> {};
64
66/// This class verifies that tosa shape operands are compile time resolvable
67template <typename ConcreteType>
69 : public TraitBase<ConcreteType, TosaResolvableShapeOperands> {
70public:
71 static LogicalResult verifyTrait(Operation *op) {
73 }
74};
75
76/// This class indicates that op operates on tosa shape types
77template <typename ConcreteType>
78class TosaShapeOperator : public TraitBase<ConcreteType, TosaShapeOperator> {};
79
81/// This class indicates that op operates on tosa shape types
82template <typename ConcreteType>
84 : public TraitBase<ConcreteType, TosaShapeOperatorWithSameRanks> {
85public:
86 static LogicalResult verifyTrait(Operation *op) {
88 }
89};
90
91} // namespace tosa
92} // namespace OpTrait
93
94namespace tosa {
95
97
98/// Represents a dimension in the shape of a tensor that can be inferred
99/// based on the other provided dimensions. For example, in a reshape
100/// operation, -1 can be used to indicate a size that is the remainder
101/// of the other dimensions.
103
104} // namespace tosa
105
106} // namespace mlir
107
108#define GET_ATTRDEF_CLASSES
109#include "mlir/Dialect/Tosa/IR/TosaAttributes.h.inc"
110
111#define GET_TYPEDEF_CLASSES
112#include "mlir/Dialect/Tosa/IR/TosaOpsTypesBase.h.inc"
113
114#define GET_OP_CLASSES
115#include "mlir/Dialect/Tosa/IR/TosaOps.h.inc"
116
117namespace mlir {
118namespace tosa {
119
120// Create a rank-1 const tensor for zero point of the source tensor.
121std::optional<Value> createZeroPointTensor(OpBuilder &builder, Location loc,
122 Type srcElemType, int64_t zp = 0);
123
124// Create a pad-const const tensor with value of `val` of required data-type
125Value createPadConstTensor(OpBuilder &builder, Location loc, Value src,
126 int32_t val = 0);
127
128// returns type of variable op
129RankedTensorType getVariableType(VariableOp variableOp);
130
131// Returns the bitwidth of a TOSA tensor element type
132unsigned getBitWidth(Type type);
133
134// Returns the storage element type for a given type
136
137// Returns the storage element type for a given value
139
140// Verify that a given type is a valid block scaled tensor type
141LogicalResult verifyBlockScaledTensorType(
142 mlir::Type type,
144 bool allowScaleValues = false);
145
146// Returns a diagnostic suffix string for a type verification failure, or
147// empty string if the type is valid
149
150} // namespace tosa
151} // namespace mlir
152
153#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.
This class represents a diagnostic that is inflight and set to be reported.
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:63
This class verifies that tosa shape operands are compile time resolvable.
Definition TosaOps.h:69
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:71
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:84
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:86
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:78
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:6027
LogicalResult verifyTosaResolvableShapeOperands(Operation *op)
Definition TosaOps.cpp:6014
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:102
void printVariableOpTypeOrInitialValue(OpAsmPrinter &p, Operation *op, DenseElementsAttr varShapeAttr, TypeAttr typeAttr, Attribute initialValueAttr)
Definition TosaOps.cpp:252
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:5978
bool isa_tosa_shape_type(mlir::Type t)
Definition TosaOps.cpp:6002
Value createPadConstTensor(OpBuilder &builder, Location loc, Value src, int32_t val=0)
Definition TosaOps.cpp:614
LogicalResult verifyBlockScaledTensorType(mlir::Type type, llvm::function_ref< mlir::InFlightDiagnostic()> emitError=nullptr, bool allowScaleValues=false)
Definition TosaOps.cpp:742
std::string getTosaTensorTypeErrorMessage(mlir::Type type)
Definition TosaOps.cpp:801
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.