Skip to content

Commit 43d0564

Browse files
committed
includes
1 parent 9e5f7f9 commit 43d0564

File tree

10 files changed

+232
-30
lines changed

10 files changed

+232
-30
lines changed

include/mlir/Conversion/PolygeistPasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
77
#include "mlir/Pass/Pass.h"
88
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
9-
#include "polygeist/Dialect.h"
9+
#include "mlir/Dialect/Polygeist/PolygeistDialect.h"
1010
#include <memory>
1111

1212
namespace mlir {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
//===- PolygeistDialect.h - Polygeist dialect -------------------*- C++ -*-===//
1+
//===- BFVDialect.h - BFV dialect -----------------*- C++ -*-===//
22
//
33
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef MLIR_DIALECT_POLYGEIST_IR_POLYGEISTDIALECT_H
10-
#define MLIR_DIALECT_POLYGEIST_IR_POLYGEISTDIALECT_H
9+
#ifndef BFV_BFVDIALECT_H
10+
#define BFV_BFVDIALECT_H
1111

1212
#include "mlir/IR/Dialect.h"
1313

14-
#include "mlir/Dialect/Polygeist/IR/PolygeistOpsDialect.h.inc"
14+
#include "polygeist/PolygeistOpsDialect.h.inc"
1515

16-
#endif // MLIR_DIALECT_POLYGEIST_IR_POLYGEISTDIALECT_H
16+
#endif // BFV_BFVDIALECT_H

include/mlir/Dialect/Polygeist/IR/PolygeistOps.h

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
//===--- PolygeistOps.h ---------------------------------------------------===//
1+
//===- Polygeistps.h - Polygeist dialect ops --------------------*- C++ -*-===//
22
//
33
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef MLIR_DIALECT_POLYGEIST_IR_POLYGEISTOPS_H
10-
#define MLIR_DIALECT_POLYGEIST_IR_POLYGEISTOPS_H
9+
#ifndef POLYGEISTOPS_H
10+
#define POLYGEISTOPS_H
1111

1212
#include "mlir/Dialect/Affine/IR/AffineOps.h"
13+
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1314
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
14-
#include "mlir/Dialect/Polygeist/IR/PolygeistTypes.h"
1515
#include "mlir/Dialect/SCF/IR/SCF.h"
1616
#include "mlir/IR/BuiltinTypes.h"
1717
#include "mlir/IR/Dialect.h"
@@ -23,7 +23,7 @@
2323
#include "llvm/Support/CommandLine.h"
2424

2525
#define GET_OP_CLASSES
26-
#include "mlir/Dialect/Polygeist/IR/PolygeistOps.h.inc"
26+
#include "polygeist/PolygeistOps.h.inc"
2727

2828
#include "mlir/Dialect/Affine/IR/AffineOps.h"
2929
#include "mlir/Dialect/SCF/IR/SCF.h"
@@ -81,8 +81,9 @@ class BarrierElim final
8181
}
8282

8383
Operation *op = barrier;
84-
if (NotTopLevel && isa<mlir::scf::ParallelOp, affine::AffineParallelOp>(
85-
barrier->getParentOp()))
84+
if (NotTopLevel &&
85+
isa<mlir::scf::ParallelOp, mlir::affine::AffineParallelOp>(
86+
barrier->getParentOp()))
8687
return failure();
8788

8889
{
@@ -148,4 +149,84 @@ class BarrierElim final
148149
}
149150
};
150151

151-
#endif // MLIR_DIALECT_POLYGEIST_IR_POLYGEISTOPS_H
152+
struct ValueOrInt {
153+
bool isValue;
154+
mlir::Value v_val;
155+
int64_t i_val;
156+
ValueOrInt(mlir::Value v) { initValue(v); }
157+
void initValue(mlir::Value v) {
158+
using namespace mlir;
159+
if (v) {
160+
IntegerAttr iattr;
161+
if (matchPattern(v, m_Constant(&iattr))) {
162+
i_val = iattr.getValue().getSExtValue();
163+
v_val = nullptr;
164+
isValue = false;
165+
return;
166+
}
167+
}
168+
isValue = true;
169+
v_val = v;
170+
}
171+
172+
ValueOrInt(size_t i) : isValue(false), v_val(), i_val(i) {}
173+
174+
bool operator>=(int64_t v) {
175+
if (isValue)
176+
return false;
177+
return i_val >= v;
178+
}
179+
bool operator>(int64_t v) {
180+
if (isValue)
181+
return false;
182+
return i_val > v;
183+
}
184+
bool operator==(int64_t v) {
185+
if (isValue)
186+
return false;
187+
return i_val == v;
188+
}
189+
bool operator<(int64_t v) {
190+
if (isValue)
191+
return false;
192+
return i_val < v;
193+
}
194+
bool operator<=(int64_t v) {
195+
if (isValue)
196+
return false;
197+
return i_val <= v;
198+
}
199+
bool operator>=(llvm::APInt v) {
200+
if (isValue)
201+
return false;
202+
return i_val >= v.getSExtValue();
203+
}
204+
bool operator>(llvm::APInt v) {
205+
if (isValue)
206+
return false;
207+
return i_val > v.getSExtValue();
208+
}
209+
bool operator==(llvm::APInt v) {
210+
if (isValue)
211+
return false;
212+
return i_val == v.getSExtValue();
213+
}
214+
bool operator<(llvm::APInt v) {
215+
if (isValue)
216+
return false;
217+
return i_val < v.getSExtValue();
218+
}
219+
bool operator<=(llvm::APInt v) {
220+
if (isValue)
221+
return false;
222+
return i_val <= v.getSExtValue();
223+
}
224+
};
225+
226+
enum class Cmp { EQ, LT, LE, GT, GE };
227+
228+
bool valueCmp(Cmp cmp, mlir::AffineExpr expr, size_t numDim,
229+
mlir::ValueRange operands, ValueOrInt val);
230+
231+
bool valueCmp(Cmp cmp, mlir::Value bval, ValueOrInt val);
232+
#endif // POLYGEISTOPS_H

include/mlir/Dialect/Polygeist/IR/PolygeistOps.td

Lines changed: 131 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- PolygeistOps.td - Polygeist op definitions ----------*- tablegen -*-===//
1+
//===- Polygeist.td - Polygeist dialect ops ----------------*- tablegen -*-===//
22
//
33
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,15 +9,47 @@
99
#ifndef POLYGEIST_OPS
1010
#define POLYGEIST_OPS
1111

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"
1612
include "mlir/Interfaces/SideEffectInterfaces.td"
1713
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+
}
1843

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+
}
2153

2254
def CacheLoad
2355
: Polygeist_Op<"cacheload"> {
@@ -28,7 +60,7 @@ def CacheLoad
2860
let results = (outs AnyType:$result);
2961
let builders = [
3062
OpBuilder<(ins "Value":$memref, CArg<"ValueRange", "{}">:$indices), [{
31-
auto memrefType = cast<MemRefType>(memref.getType());
63+
auto memrefType = memref.getType().cast<MemRefType>();
3264
$_state.addOperands(memref);
3365
$_state.addOperands(indices);
3466
$_state.types.push_back(memrefType.getElementType());
@@ -68,6 +100,73 @@ def SubIndexOp : Polygeist_Op<"subindex", [
68100
}];
69101
}
70102

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+
}
71170

72171
def StreamToTokenOp : Polygeist_Op<"stream2token", [
73172
Pure
@@ -92,13 +191,27 @@ def Memref2PointerOp : Polygeist_Op<"memref2pointer", [
92191

93192
let hasFolder = 1;
94193
let hasCanonicalizer = 1;
95-
let hasVerifier = 1;
96194

97195
let extraClassDeclaration = [{
98196
::mlir::Value getViewSource() { return getSource(); }
99197
}];
100198
}
101199

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+
102215
def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
103216
ViewLikeOpInterface, Pure
104217
]> {
@@ -109,13 +222,21 @@ def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
109222

110223
let hasFolder = 1;
111224
let hasCanonicalizer = 1;
112-
let hasVerifier = 1;
113225

114226
let extraClassDeclaration = [{
115227
::mlir::Value getViewSource() { return getSource(); }
116228
}];
117229
}
118230

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+
119240
def TrivialUseOp : Polygeist_Op<"trivialuse"> {
120241
let summary = "memref subview operation";
121242

lib/Dialect/Polygeist/IR/PolygeistDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "polygeist/Dialect.h"
9+
#include "mlir/Dialect/Polygeist/PolygeistDialect.h"
1010
#include "mlir/IR/DialectImplementation.h"
1111
#include "polygeist/Ops.h"
1212

lib/Dialect/Polygeist/IR/PolygeistOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "mlir/IR/Builders.h"
1515
#include "mlir/IR/OpImplementation.h"
1616
#include "mlir/Interfaces/SideEffectInterfaces.h"
17-
#include "polygeist/Dialect.h"
17+
#include "mlir/Dialect/Polygeist/PolygeistDialect.h"
1818

1919
#define GET_OP_CLASSES
2020
#include "polygeist/PolygeistOps.cpp.inc"

lib/Dialect/Polygeist/Transforms/LoopRestructure.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "mlir/IR/RegionGraphTraits.h"
2020
#include "mlir/Pass/Pass.h"
2121
#include "mlir/Transforms/Passes.h"
22-
#include "polygeist/Dialect.h"
22+
#include "mlir/Dialect/Polygeist/PolygeistDialect.h"
2323
#include "polygeist/Passes/Passes.h"
2424
#include "llvm/ADT/SmallPtrSet.h"
2525
#include "llvm/IR/Dominators.h"

lib/Dialect/Polygeist/Transforms/PolygeistCanonicalize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "mlir/Dialect/SCF/IR/SCF.h"
2828
#include "mlir/Dialect/SCF/Transforms/Passes.h"
2929
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
30-
#include "polygeist/Dialect.h"
30+
#include "mlir/Dialect/Polygeist/PolygeistDialect.h"
3131
#include "polygeist/Ops.h"
3232
#include "polygeist/Passes/Passes.h"
3333

tools/cgeist/driver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
#include "llvm/Transforms/IPO/Internalize.h"
7373
#include <fstream>
7474

75-
#include "polygeist/Dialect.h"
75+
#include "mlir/Dialect/Polygeist/PolygeistDialect.h"
7676
#include "polygeist/Passes/Passes.h"
7777

7878
#include <fstream>

0 commit comments

Comments
 (0)