-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: create
PISA
dialect (+ emitter and passes)
- Loading branch information
1 parent
7ca72cb
commit 354011d
Showing
38 changed files
with
1,112 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# PISA dialect implementation | ||
|
||
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library") | ||
|
||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "Dialect", | ||
srcs = [ | ||
"PISADialect.cpp", | ||
], | ||
hdrs = [ | ||
"PISADialect.h", | ||
"PISAOps.h", | ||
], | ||
deps = [ | ||
"dialect_inc_gen", | ||
"ops_inc_gen", | ||
":PISAOps", | ||
"@llvm-project//llvm:Support", | ||
"@llvm-project//mlir:IR", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "PISAOps", | ||
srcs = [ | ||
"PISAOps.cpp", | ||
], | ||
hdrs = [ | ||
"PISADialect.h", | ||
"PISAOps.h", | ||
], | ||
deps = [ | ||
":dialect_inc_gen", | ||
":ops_inc_gen", | ||
"@llvm-project//llvm:Support", | ||
"@llvm-project//mlir:ArithDialect", | ||
"@llvm-project//mlir:IR", | ||
"@llvm-project//mlir:InferTypeOpInterface", | ||
"@llvm-project//mlir:Support", | ||
], | ||
) | ||
|
||
td_library( | ||
name = "td_files", | ||
srcs = [ | ||
"PISADialect.td", | ||
"PISAOps.td", | ||
], | ||
# include from the heir - root to enable fully - qualified include - paths | ||
includes = ["../../../.."], | ||
deps = [ | ||
"@heir//lib/Utils/DRR", | ||
"@llvm-project//mlir:BuiltinDialectTdFiles", | ||
"@llvm-project//mlir:InferTypeOpInterfaceTdFiles", | ||
"@llvm-project//mlir:OpBaseTdFiles", | ||
"@llvm-project//mlir:SideEffectInterfacesTdFiles", | ||
], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "dialect_inc_gen", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-dialect-decls", | ||
], | ||
"PISADialect.h.inc", | ||
), | ||
( | ||
[ | ||
"-gen-dialect-defs", | ||
], | ||
"PISADialect.cpp.inc", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "PISADialect.td", | ||
deps = [ | ||
":td_files", | ||
], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "ops_inc_gen", | ||
tbl_outs = [ | ||
( | ||
["-gen-op-decls"], | ||
"PISAOps.h.inc", | ||
), | ||
( | ||
["-gen-op-defs"], | ||
"PISAOps.cpp.inc", | ||
), | ||
( | ||
["-gen-op-doc"], | ||
"PISAOps.md", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "PISAOps.td", | ||
deps = [ | ||
":dialect_inc_gen", | ||
":td_files", | ||
], | ||
) |
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,28 @@ | ||
#include "lib/Dialect/PISA/IR/PISADialect.h" | ||
|
||
#include "mlir/include/mlir/IR/DialectImplementation.h" // from @llvm-project | ||
|
||
// NOLINTNEXTLINE(misc-include-cleaner): Required to define PISAOps | ||
|
||
#include "lib/Dialect/PISA/IR/PISAOps.h" | ||
|
||
// Generated definitions | ||
#include "lib/Dialect/PISA/IR/PISADialect.cpp.inc" | ||
|
||
#define GET_OP_CLASSES | ||
#include "lib/Dialect/PISA/IR/PISAOps.cpp.inc" | ||
|
||
namespace mlir { | ||
namespace heir { | ||
namespace pisa { | ||
|
||
void PISADialect::initialize() { | ||
addOperations< | ||
#define GET_OP_LIST | ||
#include "lib/Dialect/PISA/IR/PISAOps.cpp.inc" | ||
>(); | ||
} | ||
|
||
} // namespace pisa | ||
} // namespace heir | ||
} // namespace mlir |
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,10 @@ | ||
#ifndef LIB_DIALECT_PISA_IR_PISADIALECT_H_ | ||
#define LIB_DIALECT_PISA_IR_PISADIALECT_H_ | ||
|
||
#include "mlir/include/mlir/IR/Builders.h" // from @llvm-project | ||
#include "mlir/include/mlir/IR/Dialect.h" // from @llvm-project | ||
|
||
// Generated headers (block clang-format from messing up order) | ||
#include "lib/Dialect/PISA/IR/PISADialect.h.inc" | ||
|
||
#endif // LIB_DIALECT_PISA_IR_PISADIALECT_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,16 @@ | ||
#ifndef LIB_DIALECT_PISA_IR_PISADIALECT_TD_ | ||
#define LIB_DIALECT_PISA_IR_PISADIALECT_TD_ | ||
|
||
include "mlir/IR/DialectBase.td" | ||
|
||
def PISA_Dialect : Dialect { | ||
let name = "pisa"; | ||
let description = [{ | ||
// FIXME: add documentation | ||
The `pisa` dialect is ... | ||
}]; | ||
|
||
let cppNamespace = "::mlir::heir::pisa"; | ||
} | ||
|
||
#endif // LIB_DIALECT_PISA_IR_PISADIALECT_TD_ |
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,7 @@ | ||
#include "lib/Dialect/PISA/IR/PISAOps.h" | ||
|
||
namespace mlir { | ||
namespace heir { | ||
namespace pisa {} // namespace pisa | ||
} // namespace heir | ||
} // namespace mlir |
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,11 @@ | ||
#ifndef LIB_DIALECT_PISA_IR_PISAOPS_H_ | ||
#define LIB_DIALECT_PISA_IR_PISAOPS_H_ | ||
|
||
#include "lib/Dialect/PISA/IR/PISADialect.h" | ||
#include "mlir/include/mlir/IR/BuiltinOps.h" // from @llvm-project | ||
#include "mlir/include/mlir/Interfaces/InferTypeOpInterface.h" // from @llvm-project | ||
|
||
#define GET_OP_CLASSES | ||
#include "lib/Dialect/PISA/IR/PISAOps.h.inc" | ||
|
||
#endif // LIB_DIALECT_PISA_IR_PISAOPS_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,102 @@ | ||
#ifndef LIB_DIALECT_PISA_IR_PISAOPS_TD_ | ||
#define LIB_DIALECT_PISA_IR_PISAOPS_TD_ | ||
|
||
include "lib/Dialect/PISA/IR/PISADialect.td" | ||
include "mlir/IR/BuiltinAttributes.td" | ||
include "mlir/IR/CommonTypeConstraints.td" | ||
include "mlir/IR/OpBase.td" | ||
include "mlir/Interfaces/InferTypeOpInterface.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
|
||
def Tensor8192I32 : TypeConstraint<CPred<[{ | ||
mlir::isa<mlir::RankedTensorType>($_self) && | ||
mlir::cast<mlir::RankedTensorType>($_self).getRank() == 1 && | ||
mlir::cast<mlir::RankedTensorType>($_self).getDimSize(0) == 8192 && | ||
mlir::cast<mlir::RankedTensorType>($_self).getElementType().isInteger(32) | ||
}]>, "tensor<8192xi32>">; | ||
|
||
class PISA_Op<string mnemonic, list<Trait> traits = [Pure]> : | ||
Op<PISA_Dialect, mnemonic, traits> { | ||
let cppNamespace = "::mlir::heir::pisa"; | ||
} | ||
|
||
class PISA_BinaryOp<string mnemonic, list<Trait> traits = []> : | ||
PISA_Op<mnemonic, traits # [SameOperandsAndResultType]>, | ||
Arguments<(ins Tensor8192I32:$lhs, Tensor8192I32:$rhs, I32Attr:$q, I32Attr:$i)>, | ||
Results<(outs Tensor8192I32:$output)> { | ||
let assemblyFormat = "$lhs `,` $rhs attr-dict `:` qualified(type($output))"; | ||
} | ||
|
||
def PISA_AddOp : PISA_BinaryOp<"add", [Commutative]> { | ||
let summary = "addition operation"; | ||
let description = [{ | ||
Computes addition of two polynomials (irrespective of ntt/coefficient representation). | ||
}]; | ||
} | ||
|
||
def PISA_SubOp : PISA_BinaryOp<"sub", []> { | ||
let summary = "subtraction operation"; | ||
let description = [{ | ||
Computes subtraction of two polynomials (irrespective of ntt/coefficient representation). | ||
}]; | ||
} | ||
|
||
def PISA_MulOp : PISA_BinaryOp<"mul", [Commutative]> { | ||
let summary = "multiplication operation"; | ||
let description = [{ | ||
Computes addition of two polynomials (in ntt representation). | ||
}]; | ||
} | ||
|
||
def PISA_MuliOp : PISA_Op<"muli", [SameOperandsAndResultType]> { | ||
let summary = "multiplication-with-immediate operation"; | ||
let description = [{ | ||
Computes multiplication of a polynomial (in ntt representation) with a constant. | ||
}]; | ||
let arguments = (ins Tensor8192I32:$lhs, I32Attr:$q, I32Attr:$i, I32Attr:$imm); | ||
let results = (outs Tensor8192I32:$output); | ||
let assemblyFormat = "$lhs attr-dict `:` qualified(type($output))"; | ||
} | ||
|
||
def PISA_MacOp : PISA_Op<"mac", [SameOperandsAndResultType]> { | ||
let summary = "multiply-and-accumulate operation"; | ||
let description = [{ | ||
Computes multiplication of two polynomials (in ntt representation) and adds the result to a third polynomial. | ||
}]; | ||
let arguments = (ins Tensor8192I32:$lhs, Tensor8192I32:$rhs, Tensor8192I32:$acc, I32Attr:$q, I32Attr:$i); | ||
let results = (outs Tensor8192I32:$output); | ||
let assemblyFormat = "$lhs `,` $rhs `,` $acc attr-dict `:` qualified(type($output))"; | ||
} | ||
|
||
def PISA_MaciOp : PISA_Op<"maci", [SameOperandsAndResultType]> { | ||
let summary = "multiply-and-accumulate-with-immediate operation"; | ||
let description = [{ | ||
Computes multiplication of a polynomial (in ntt representation) with a constant and adds the result to a third polynomial. | ||
}]; | ||
let arguments = (ins Tensor8192I32:$lhs, Tensor8192I32:$acc, I32Attr:$q, I32Attr:$i, I32Attr:$imm); | ||
let results = (outs Tensor8192I32:$output); | ||
let assemblyFormat = "$lhs `,` $acc attr-dict `:` qualified(type($output))"; | ||
} | ||
|
||
def PISA_NTTOp : PISA_Op<"ntt", [SameOperandsAndResultType]> { | ||
let summary = "number-theoretic-transform operation"; | ||
let description = [{ | ||
Computes number-theoretic-transform of a polynomial. | ||
}]; | ||
let arguments = (ins Tensor8192I32:$poly, Tensor8192I32:$w, I32Attr:$q, I32Attr:$i); | ||
let results = (outs Tensor8192I32:$output); | ||
let assemblyFormat = "$poly `,` $w attr-dict `:` qualified(type($output))"; | ||
} | ||
|
||
def PISA_INTTOp : PISA_Op<"intt", [SameOperandsAndResultType]> { | ||
let summary = "inverse number-theoretic-transform operation"; | ||
let description = [{ | ||
Computes inverse number-theoretic-transform of a polynomial. | ||
}]; | ||
let arguments = (ins Tensor8192I32:$poly, Tensor8192I32:$w, I32Attr:$q, I32Attr:$i); | ||
let results = (outs Tensor8192I32:$output); | ||
let assemblyFormat = "$poly `,` $w attr-dict `:` qualified(type($output))"; | ||
} | ||
|
||
|
||
#endif // LIB_DIALECT_PISA_IR_PISAOPS_TD_ |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(PolynomialToPISA) | ||
add_subdirectory(PolynomialToStandard) |
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,45 @@ | ||
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library") | ||
|
||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "PolynomialToPISA", | ||
srcs = ["PolynomialToPISA.cpp"], | ||
hdrs = ["PolynomialToPISA.h"], | ||
deps = [ | ||
":pass_inc_gen", | ||
"@heir//lib/Dialect/ModArith/IR:Dialect", | ||
"@heir//lib/Dialect/PISA/IR:Dialect", | ||
"@heir//lib/Utils/ConversionUtils", | ||
"@llvm-project//mlir:IR", | ||
"@llvm-project//mlir:Pass", | ||
"@llvm-project//mlir:PolynomialDialect", | ||
"@llvm-project//mlir:Transforms", | ||
], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "pass_inc_gen", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-pass-decls", | ||
"-name=PolynomialToPISA", | ||
], | ||
"PolynomialToPISA.h.inc", | ||
), | ||
( | ||
["-gen-pass-doc"], | ||
"PolynomialToPISA.md", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "PolynomialToPISA.td", | ||
deps = [ | ||
"@llvm-project//mlir:OpBaseTdFiles", | ||
"@llvm-project//mlir:PassBaseTdFiles", | ||
], | ||
) |
Empty file.
Oops, something went wrong.