-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tobias Gysi
committed
Dec 15, 2019
1 parent
6a7fc22
commit b4eeef0
Showing
29 changed files
with
1,225 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set(LLVM_TARGET_DEFINITIONS StencilOps.td) | ||
|
||
# Generate the class interfaces | ||
mlir_tablegen(StencilOps.h.inc -gen-op-decls) | ||
# Generate the actual implementation | ||
mlir_tablegen(StencilOps.cpp.inc -gen-op-defs) | ||
|
||
add_public_tablegen_target(MLIRStencilOpsIncGen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef MLIR_DIALECT_STENCIL_PASSES_H | ||
#define MLIR_DIALECT_STENCIL_PASSES_H | ||
|
||
#include "mlir/Pass/Pass.h" | ||
|
||
namespace mlir { | ||
namespace stencil { | ||
|
||
} // namespace stencil | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_STENCIL_PASSES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef Stencil_BASE | ||
#define Stencil_BASE | ||
|
||
#ifndef OP_BASE | ||
include "mlir/IR/OpBase.td" | ||
#endif // OP_BASE | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Stencil dialect definition | ||
//===----------------------------------------------------------------------===// | ||
|
||
def Stencil_Dialect : Dialect { | ||
let name = "stencil"; | ||
|
||
let description = [{ | ||
A simple stencil dialect in MLIR. | ||
}]; | ||
|
||
let cppNamespace = "stencil"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Stencil type definitions | ||
//===----------------------------------------------------------------------===// | ||
|
||
def Stencil_IsViewType : CPred<"$_self.isa<::mlir::stencil::ViewType>()">; | ||
def Stencil_IsFieldType : CPred<"$_self.isa<::mlir::stencil::FieldType>()">; | ||
|
||
def Stencil_View : Type<Stencil_IsViewType, "a view on a field">; | ||
def Stencil_Field : Type<Stencil_IsFieldType, "a field">; | ||
def Stencil_ElementType : AnyTypeOf<[I64, F64]>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Stencil op definition | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Base class for all Stencil ops. | ||
class Stencil_Op<string mnemonic, list<OpTrait> traits = []> : | ||
Op<Stencil_Dialect, mnemonic, traits> { | ||
|
||
// For each Stencil op, the following static functions need to be defined in | ||
// StencilOps.cpp: | ||
// | ||
// * static ParseResult parse<op-c++-class-name>(OpAsmParser &parser, | ||
// OperationState &state); | ||
// * static void print(OpAsmPrinter &p, <op-c++-class-name> op) | ||
// * static LogicalResult verify(<op-c++-class-name> op) | ||
let parser = [{ return ::parse$cppClass(parser, result); }]; | ||
let printer = [{ ::print(*this, p); }]; | ||
let verifier = [{ return ::verify(*this); }]; | ||
} | ||
|
||
|
||
#endif // Stencil_BASE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef MLIR_DIALECT_STENCIL_STENCILDIALECT_H | ||
#define MLIR_DIALECT_STENCIL_STENCILDIALECT_H | ||
|
||
#include "mlir/IR/Dialect.h" | ||
#include "mlir/IR/Function.h" | ||
|
||
|
||
namespace mlir { | ||
namespace stencil { | ||
|
||
class StencilDialect : public Dialect { | ||
public: | ||
explicit StencilDialect(MLIRContext *context); | ||
|
||
/// Returns the prefix used in the textual IR to refer to Stencil operations | ||
static StringRef getDialectNamespace() { return "stencil"; } | ||
|
||
static StringRef getStencilFunctionAttrName() { return "stencil.function"; } | ||
static StringRef getStencilProgramAttrName() { return "stencil.program"; } | ||
|
||
static bool isStencilFunction(FuncOp funcOp) { | ||
return !!funcOp.getAttr(getStencilFunctionAttrName()); | ||
} | ||
static bool isStencilProgram(FuncOp funcOp) { | ||
return !!funcOp.getAttr(getStencilProgramAttrName()); | ||
} | ||
|
||
/// Parses a type registered to this dialect | ||
Type parseType(DialectAsmParser &parser) const override; | ||
|
||
/// Prints a type registered to this dialect | ||
void printType(Type type, DialectAsmPrinter &os) const override; | ||
}; | ||
|
||
} // namespace stencil | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_STENCIL_STENCILDIALECT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef MLIR_DIALECT_STENCIL_STENCILOPS_H | ||
#define MLIR_DIALECT_STENCIL_STENCILOPS_H | ||
|
||
#include "mlir/IR/Function.h" | ||
#include "Dialect/Stencil/StencilTypes.h" | ||
|
||
namespace mlir { | ||
namespace stencil { | ||
|
||
/// Retrieve the class declarations generated by TableGen | ||
#define GET_OP_CLASSES | ||
#include "Dialect/Stencil/StencilOps.h.inc" | ||
|
||
} // namespace stencil | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_STENCIL_STENCILOPS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#ifndef STENCIL_OPS | ||
#define STENCIL_OPS | ||
|
||
#ifndef STENCIL_BASE | ||
include "Dialect/Stencil/StencilBase.td" | ||
#endif // STENCIL_BASE | ||
|
||
def Stencil_AccessOp : Stencil_Op<"access"> { | ||
let summary = "view access operation"; | ||
let description = [{ | ||
This operation takes a view as an input as well as an offset | ||
attribute and return the corresponding element from the view's | ||
underlying field. The offset is specified relatively to the | ||
current position. | ||
|
||
Example: | ||
|
||
%0 = stencil.access %view[-1, 0, 0] : !stencil.view<?x?x?xf64> | ||
}]; | ||
|
||
let arguments = (ins Stencil_View:$view, I64ArrayAttr:$offset); | ||
let results = (outs Stencil_ElementType:$res); | ||
|
||
let builders = [OpBuilder<"Builder *, OperationState &, Value *," | ||
"ArrayRef<int64_t>">]; | ||
|
||
let extraClassDeclaration = [{ | ||
static StringRef getOffsetAttrName() { return "offset"; } | ||
SmallVector<int64_t, 3> getOffset() { | ||
SmallVector<int64_t, 3> offsetAttr; | ||
for(auto &attr : offset().cast<ArrayAttr>().getValue()) { | ||
offsetAttr.push_back(attr.cast<IntegerAttr>().getValue().getSExtValue()); | ||
} | ||
return offsetAttr; | ||
} | ||
}]; | ||
} | ||
|
||
def Stencil_LoadOp : Stencil_Op<"load"> { | ||
let arguments = (ins Stencil_Field:$field); | ||
let results = (outs Stencil_View:$res); | ||
|
||
let builders = [OpBuilder<"Builder *, OperationState &, Value *," | ||
"ArrayRef<int64_t> = {-1, -1, -1}">]; | ||
|
||
let extraClassDeclaration = [{ | ||
stencil::ViewType getResultViewType() { | ||
return res()->getType().cast<stencil::ViewType>(); | ||
} | ||
}]; | ||
} | ||
|
||
def Stencil_StoreOp : Stencil_Op<"store"> { | ||
let arguments = (ins Stencil_Field:$field, Stencil_View:$view); | ||
let results = (outs); | ||
|
||
let extraClassDeclaration = [{ | ||
stencil::FieldType getFieldType() { | ||
return field()->getType().cast<stencil::FieldType>(); | ||
} | ||
stencil::ViewType getViewType() { | ||
return view()->getType().cast<stencil::ViewType>(); | ||
} | ||
}]; | ||
} | ||
|
||
def Stencil_ApplyOp : Stencil_Op<"apply"> { | ||
let arguments = (ins SymbolRefAttr:$callee, Variadic<AnyType>:$operands); | ||
let results = (outs Stencil_View:$res); | ||
|
||
let builders = [ | ||
OpBuilder<"Builder *builder, OperationState &result, FuncOp callee," | ||
"stencil::ViewType viewType, ArrayRef<Value *> operands = {}">]; | ||
|
||
let extraClassDeclaration = [{ | ||
stencil::ViewType getResultViewType() { | ||
return res()->getType().cast<stencil::ViewType>(); | ||
} | ||
|
||
static StringRef getCalleeAttrName() { return "callee"; } | ||
FunctionType getCalleeType(); | ||
FuncOp getCallee() { | ||
return getParentOfType<ModuleOp>().lookupSymbol<FuncOp>(callee().getLeafReference()); | ||
} | ||
|
||
/// Get the argument operands to the called function. | ||
operand_range getArgOperands() { | ||
return {arg_operand_begin(), arg_operand_end()}; | ||
} | ||
|
||
operand_iterator arg_operand_begin() { return operand_begin(); } | ||
operand_iterator arg_operand_end() { return operand_end(); } | ||
}]; | ||
} | ||
|
||
def Stencil_CallOp : Stencil_Op<"call"> { | ||
let arguments = (ins SymbolRefAttr:$callee, I64ArrayAttr:$offset, Variadic<AnyType>:$operands); | ||
let results = (outs Stencil_ElementType:$res); | ||
|
||
let builders = [ | ||
OpBuilder<"Builder *builder, OperationState &result, FuncOp callee," | ||
"stencil::ViewType viewType, ArrayRef<int64_t> offset," | ||
"ArrayRef<Value *> operands = {}">]; | ||
|
||
let extraClassDeclaration = [{ | ||
stencil::ViewType getResultViewType() { | ||
return res()->getType().cast<stencil::ViewType>(); | ||
} | ||
|
||
static StringRef getCalleeAttrName() { return "callee"; } | ||
FunctionType getCalleeType(); | ||
FuncOp getCallee() { | ||
return getParentOfType<ModuleOp>().lookupSymbol<FuncOp>(callee().getLeafReference()); | ||
} | ||
static StringRef getOffsetAttrName() { return "offset"; } | ||
SmallVector<int64_t, 3> getOffset() { | ||
SmallVector<int64_t, 3> offsetAttr; | ||
for(auto &attr : offset().cast<ArrayAttr>().getValue()) { | ||
offsetAttr.push_back(attr.cast<IntegerAttr>().getValue().getSExtValue()); | ||
} | ||
return offsetAttr; | ||
} | ||
|
||
/// Get the argument operands to the called function. | ||
operand_range getArgOperands() { | ||
return {arg_operand_begin(), arg_operand_end()}; | ||
} | ||
|
||
operand_iterator arg_operand_begin() { return operand_begin(); } | ||
operand_iterator arg_operand_end() { return operand_end(); } | ||
}]; | ||
} | ||
|
||
#endif // STENCIL_OPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#ifndef MLIR_DIALECT_STENCIL_STENCILTYPES_H | ||
#define MLIR_DIALECT_STENCIL_STENCILTYPES_H | ||
|
||
#include "mlir/IR/TypeSupport.h" | ||
#include "mlir/IR/Types.h" | ||
|
||
namespace mlir { | ||
namespace stencil { | ||
|
||
enum StencilTypes { | ||
Field = Type::FIRST_STENCIL_TYPE, | ||
View, | ||
LAST_USED_STENCIL_TYPE = View | ||
}; | ||
|
||
struct FieldTypeStorage; | ||
class FieldType : public Type::TypeBase<FieldType, Type, FieldTypeStorage> { | ||
public: | ||
// Used for generic hooks in TypeBase. | ||
using Base::Base; | ||
|
||
/// Construction hook. | ||
/// | ||
/// Create a field type of given `shape` containing elements of type | ||
/// `elementType`. | ||
/// | ||
/// Note: `shape` must contain 3 elements, -1 being used to specify an unknown | ||
/// size. | ||
static FieldType get(MLIRContext *context, Type elementType, | ||
ArrayRef<int64_t> shape); | ||
|
||
/// Used to implement LLVM-style casts. | ||
static bool kindof(unsigned kind) { return kind == StencilTypes::Field; } | ||
|
||
/// Return the type of the field elements. | ||
Type getElementType(); | ||
/// Return the shape of the field. | ||
ArrayRef<int64_t> getShape(); | ||
}; | ||
|
||
struct ViewTypeStorage; | ||
class ViewType : public Type::TypeBase<ViewType, Type, ViewTypeStorage> { | ||
public: | ||
// Used for generic hooks in TypeBase. | ||
using Base::Base; | ||
|
||
/// Construction hook. | ||
/// | ||
/// Create a field type of given `shape` containing elements of type | ||
/// `elementType`. | ||
/// | ||
/// Note: `shape` must contain 3 elements, -1 being used to specify an unknown | ||
/// size. | ||
static ViewType get(MLIRContext *context, Type elementType, | ||
ArrayRef<int64_t> shape); | ||
|
||
/// Used to implement LLVM-style casts. | ||
static bool kindof(unsigned kind) { return kind == StencilTypes::View; } | ||
|
||
/// Return the type of the field elements. | ||
Type getElementType(); | ||
/// Return the shape of the field. | ||
ArrayRef<int64_t> getShape(); | ||
}; | ||
|
||
} // namespace stencil | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_STENCIL_STENCILTYPES_H |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.