1
- //===- PolygeistOps .td - Polygeist op definitions ----------*- tablegen -*-===//
1
+ //===- Polygeist .td - Polygeist dialect ops ------ ----------*- 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 "mlir/Dialect/LLVMIR/LLVMOpBase.td"
13
- include "mlir/Dialect/LLVMIR/LLVMInterfaces.td"
14
- include "mlir/Dialect/Polygeist/IR/PolygeistBase.td"
15
- include "mlir/Dialect/Polygeist/IR/PolygeistTypes.td"
16
12
include "mlir/Interfaces/SideEffectInterfaces.td"
17
13
include "mlir/Interfaces/ViewLikeInterface.td"
14
+ include "mlir/Interfaces/ControlFlowInterfaces.td"
15
+ include "mlir/IR/SymbolInterfaces.td"
16
+
17
+ include "mlir/Dialect/Polygeist/IR/PolygeistDialect.td"
18
+ include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
19
+ include "mlir/Dialect/LLVMIR/LLVMInterfaces.td"
20
+
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
+ }
18
43
19
- class Polygeist_Op<string mnemonic, list<Trait> traits = []>
20
- : Op<Polygeist_Dialect, mnemonic, traits>;
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
+ }
21
53
22
54
def CacheLoad
23
55
: Polygeist_Op<"cacheload"> {
@@ -28,7 +60,7 @@ def CacheLoad
28
60
let results = (outs AnyType:$result);
29
61
let builders = [
30
62
OpBuilder<(ins "Value":$memref, CArg<"ValueRange", "{}">:$indices), [{
31
- auto memrefType = cast<MemRefType>( memref.getType());
63
+ auto memrefType = memref.getType().cast<MemRefType>( );
32
64
$_state.addOperands(memref);
33
65
$_state.addOperands(indices);
34
66
$_state.types.push_back(memrefType.getElementType());
@@ -68,6 +100,73 @@ def SubIndexOp : Polygeist_Op<"subindex", [
68
100
}];
69
101
}
70
102
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
+ }
71
170
72
171
def StreamToTokenOp : Polygeist_Op<"stream2token", [
73
172
Pure
@@ -92,13 +191,27 @@ def Memref2PointerOp : Polygeist_Op<"memref2pointer", [
92
191
93
192
let hasFolder = 1;
94
193
let hasCanonicalizer = 1;
95
- let hasVerifier = 1;
96
194
97
195
let extraClassDeclaration = [{
98
196
::mlir::Value getViewSource() { return getSource(); }
99
197
}];
100
198
}
101
199
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
+
102
215
def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
103
216
ViewLikeOpInterface, Pure
104
217
]> {
@@ -109,13 +222,21 @@ def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
109
222
110
223
let hasFolder = 1;
111
224
let hasCanonicalizer = 1;
112
- let hasVerifier = 1;
113
225
114
226
let extraClassDeclaration = [{
115
227
::mlir::Value getViewSource() { return getSource(); }
116
228
}];
117
229
}
118
230
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
+
119
240
def TrivialUseOp : Polygeist_Op<"trivialuse"> {
120
241
let summary = "memref subview operation";
121
242
0 commit comments