1
- //===- Polygeist .td - Polygeist dialect ops ------ ----------*- tablegen -*-===//
1
+ //===- PolygeistOps .td - Polygeist op definitions ----------*- tablegen -*-===//
2
2
//
3
3
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
9
9
#ifndef POLYGEIST_OPS
10
10
#define POLYGEIST_OPS
11
11
12
- include "Dialect.td"
13
- include "mlir/Interfaces/SideEffectInterfaces.td"
14
- include "mlir/Interfaces/ViewLikeInterface.td"
15
- include "mlir/Interfaces/ControlFlowInterfaces.td"
16
- include "mlir/IR/SymbolInterfaces.td"
17
-
18
12
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
19
13
include "mlir/Dialect/LLVMIR/LLVMInterfaces.td"
14
+ include "mlir/Dialect/Polygeist/IR/PolygeistBase.td"
15
+ include "mlir/Dialect/Polygeist/IR/PolygeistTypes.td"
16
+ include "mlir/Interfaces/SideEffectInterfaces.td"
17
+ include "mlir/Interfaces/ViewLikeInterface.td"
20
18
21
- def UndefOp
22
- : Polygeist_Op<"undef", [Pure]> {
23
- let summary = "More flexible undef op";
24
- let skipDefaultBuilders = 1;
25
- let results = (outs AnyType:$result);
26
- let builders = [
27
- OpBuilder<(ins "Type":$type), [{
28
- $_state.types.push_back(type);
29
- }]>];
30
- let hasCanonicalizer = true;
31
- }
32
-
33
- def NoopOp
34
- : Polygeist_Op<"noop",
35
- [DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
36
- let summary = "Noop for preventing folding or transformations";
37
- let arguments = (ins Variadic<Index>:$blockDims);
38
- let skipDefaultBuilders = 1;
39
- let builders = [
40
- OpBuilder<(ins "ValueRange":$indices)>];
41
- let description = [{}];
42
- }
43
-
44
- def GetDeviceGlobalOp
45
- : Polygeist_Op<"get_device_global",
46
- [DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
47
- DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
48
- let summary = "";
49
- let arguments = (ins FlatSymbolRefAttr:$name);
50
- let results = (outs AnyStaticShapeMemRef:$result);
51
- let description = [{}];
52
- }
19
+ class Polygeist_Op<string mnemonic, list<Trait> traits = []>
20
+ : Op<Polygeist_Dialect, mnemonic, traits>;
53
21
54
22
def CacheLoad
55
23
: Polygeist_Op<"cacheload"> {
@@ -60,7 +28,7 @@ def CacheLoad
60
28
let results = (outs AnyType:$result);
61
29
let builders = [
62
30
OpBuilder<(ins "Value":$memref, CArg<"ValueRange", "{}">:$indices), [{
63
- auto memrefType = memref.getType(). cast<MemRefType>();
31
+ auto memrefType = cast<MemRefType>(memref.getType() );
64
32
$_state.addOperands(memref);
65
33
$_state.addOperands(indices);
66
34
$_state.types.push_back(memrefType.getElementType());
@@ -100,73 +68,6 @@ def SubIndexOp : Polygeist_Op<"subindex", [
100
68
}];
101
69
}
102
70
103
- def GPUBlockOp : Polygeist_Op<"gpu_block", [
104
- RecursiveMemoryEffects,
105
- SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]>,
106
- Arguments<(ins Index:$blockIndexX, Index:$blockIndexY, Index:$blockIndexZ)> {
107
- let summary = "Wraps a GPU kernel block to prevent restructuring";
108
- let regions = (region SizedRegion<1>:$region);
109
- let skipDefaultBuilders = 1;
110
- let builders = [OpBuilder<(ins
111
- "Value":$blockIndexX, "Value":$blockIndexY, "Value":$blockIndexZ)>];
112
- }
113
-
114
- def GPUThreadOp : Polygeist_Op<"gpu_thread", [
115
- RecursiveMemoryEffects,
116
- SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]>,
117
- Arguments<(ins Index:$threadIndexX, Index:$threadIndexY, Index:$threadIndexZ)> {
118
- let summary = "Wraps a GPU kernel thread to prevent restructuring";
119
- let regions = (region SizedRegion<1>:$region);
120
- let skipDefaultBuilders = 1;
121
- let builders = [OpBuilder<(ins
122
- "Value":$threadIndexX, "Value":$threadIndexY, "Value":$threadIndexZ)>];
123
- }
124
-
125
- def AlternativesOp : Polygeist_Op<"alternatives", [
126
- RecursiveMemoryEffects]> {
127
- let summary = "Provides several alternatives kernels for gpu code";
128
- let regions = (region VariadicRegion<SizedRegion<1>>:$regions);
129
- let skipDefaultBuilders = 1;
130
- let builders = [OpBuilder<(ins "int":$regionNum)>];
131
- let hasCanonicalizer = 1;
132
- }
133
-
134
- def GPUWrapperOp : Polygeist_Op<"gpu_wrapper", [
135
- RecursiveMemoryEffects,
136
- AutomaticAllocationScope,
137
- SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]> {
138
- let arguments = (ins Variadic<Index>:$blockDims);
139
- let summary = "Indicates the region contained must be executed on the GPU";
140
- let description = [{
141
- The optional arguments to this operation are suggestions about what block
142
- dimensions this gpu kernel should have - usually taken from kernel launch
143
- params
144
- }];
145
- let results = (outs Index : $result);
146
- let regions = (region SizedRegion<1>:$region);
147
- let skipDefaultBuilders = 1;
148
- let builders = [
149
- OpBuilder<(ins "ValueRange":$blockSizes)>,
150
- OpBuilder<(ins)>];
151
- }
152
-
153
- def GPUErrorOp : Polygeist_Op<"gpu_error", [
154
- RecursiveMemoryEffects,
155
- SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]>,
156
- Arguments<(ins)> {
157
- let summary = "Gets the error returned by the gpu operation inside";
158
- // TODO should be i32, not index
159
- let results = (outs Index : $result);
160
- let regions = (region SizedRegion<1>:$region);
161
- let skipDefaultBuilders = 1;
162
- let builders = [OpBuilder<(ins)>];
163
-
164
- }
165
-
166
- def PolygeistYieldOp : Polygeist_Op<"polygeist_yield", [Pure, ReturnLike, Terminator,
167
- ParentOneOf<["AlternativesOp", "GPUWrapperOp", "GPUErrorOp", "GPUBlockOp", "GPUThreadOp"]>]> {
168
- let summary = "Polygeist ops terminator";
169
- }
170
71
171
72
def StreamToTokenOp : Polygeist_Op<"stream2token", [
172
73
Pure
@@ -191,27 +92,13 @@ def Memref2PointerOp : Polygeist_Op<"memref2pointer", [
191
92
192
93
let hasFolder = 1;
193
94
let hasCanonicalizer = 1;
95
+ let hasVerifier = 1;
194
96
195
97
let extraClassDeclaration = [{
196
98
::mlir::Value getViewSource() { return getSource(); }
197
99
}];
198
100
}
199
101
200
- def MemrefCastOp : Polygeist_Op<"memref_cast", [
201
- ViewLikeOpInterface, Pure
202
- ]> {
203
- let summary = "Cast memrefs like c/c++ pointers";
204
-
205
- let arguments = (ins AnyMemRef : $source);
206
- let results = (outs AnyMemRef : $result);
207
-
208
- //let hasFolder = 1;
209
- //let hasCanonicalizer = 1;
210
- let extraClassDeclaration = [{
211
- ::mlir::Value getViewSource() { return getSource(); }
212
- }];
213
- }
214
-
215
102
def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
216
103
ViewLikeOpInterface, Pure
217
104
]> {
@@ -222,21 +109,13 @@ def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
222
109
223
110
let hasFolder = 1;
224
111
let hasCanonicalizer = 1;
112
+ let hasVerifier = 1;
225
113
226
114
let extraClassDeclaration = [{
227
115
::mlir::Value getViewSource() { return getSource(); }
228
116
}];
229
117
}
230
118
231
- def GetFuncOp : Polygeist_Op<"get_func",
232
- [Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
233
- let summary = "get the pointer pointing to a function";
234
- let arguments = (ins FlatSymbolRefAttr:$name);
235
- let results = (outs LLVM_AnyPointer : $result);
236
- // let assemblyFormat = "$name `:` type($result) attr-dict";
237
- let hasCanonicalizer = 1;
238
- }
239
-
240
119
def TrivialUseOp : Polygeist_Op<"trivialuse"> {
241
120
let summary = "memref subview operation";
242
121
0 commit comments