From b7805f00d35a272f5d888bd0776fc45749708fbe Mon Sep 17 00:00:00 2001 From: Andi Drebes Date: Fri, 25 Nov 2022 14:37:19 +0100 Subject: [PATCH] feat(compiler): Add op interface SDFGConvertibleOpInterface This adds a new operation interface `SDFGConvertibleOpInterface` that allows an operation to specify how it is converted to an SDFG process. The interface consists of a single method `convert` that receives as the arguments the DFG created using `SDFG.init`, a set of SDFG input streams corresponding to the operands and a set of output streams for results. The order of the input and output streams corresponds to the order of the operands and output values, respectively. --- .../concretelang/Dialect/SDFG/CMakeLists.txt | 1 + .../Dialect/SDFG/Interfaces/CMakeLists.txt | 1 + .../Interfaces/SDFGConvertibleInterface.h | 14 +++++++++ .../Interfaces/SDFGConvertibleInterface.td | 31 +++++++++++++++++++ compiler/lib/Bindings/Rust/build.rs | 3 +- compiler/lib/Dialect/SDFG/CMakeLists.txt | 1 + .../Dialect/SDFG/Interfaces/CMakeLists.txt | 14 +++++++++ .../Interfaces/SDFGConvertibleInterface.cpp | 8 +++++ compiler/lib/Support/CMakeLists.txt | 1 + 9 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 compiler/include/concretelang/Dialect/SDFG/Interfaces/CMakeLists.txt create mode 100644 compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.h create mode 100644 compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.td create mode 100644 compiler/lib/Dialect/SDFG/Interfaces/CMakeLists.txt create mode 100644 compiler/lib/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.cpp diff --git a/compiler/include/concretelang/Dialect/SDFG/CMakeLists.txt b/compiler/include/concretelang/Dialect/SDFG/CMakeLists.txt index f33061b2d..7927b605a 100644 --- a/compiler/include/concretelang/Dialect/SDFG/CMakeLists.txt +++ b/compiler/include/concretelang/Dialect/SDFG/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(Interfaces) add_subdirectory(IR) diff --git a/compiler/include/concretelang/Dialect/SDFG/Interfaces/CMakeLists.txt b/compiler/include/concretelang/Dialect/SDFG/Interfaces/CMakeLists.txt new file mode 100644 index 000000000..3487d0972 --- /dev/null +++ b/compiler/include/concretelang/Dialect/SDFG/Interfaces/CMakeLists.txt @@ -0,0 +1 @@ +add_mlir_interface(SDFGConvertibleInterface) diff --git a/compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.h b/compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.h new file mode 100644 index 000000000..18b5c7131 --- /dev/null +++ b/compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.h @@ -0,0 +1,14 @@ +// Part of the Concrete Compiler Project, under the BSD3 License with Zama +// Exceptions. See +// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt +// for license information. + +#ifndef CONCRETELANG_DIALECT_SDFG_INTERFACES_SDFGCONVERTIBLEINTERFACE_H +#define CONCRETELANG_DIALECT_SDFG_INTERFACES_SDFGCONVERTIBLEINTERFACE_H + +#include "mlir/IR/ImplicitLocOpBuilder.h" + +#include "concretelang/Dialect/SDFG/IR/SDFGOps.h" +#include "concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.h.inc" + +#endif diff --git a/compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.td b/compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.td new file mode 100644 index 000000000..018480380 --- /dev/null +++ b/compiler/include/concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.td @@ -0,0 +1,31 @@ +#ifndef CONCRETELANG_DIALECT_SDFG_INTERFACES_SDFGCONVERTIBLEINTERFACE +#define CONCRETELANG_DIALECT_SDFG_INTERFACES_SDFGCONVERTIBLEINTERFACE + +include "mlir/IR/OpBase.td" + +def SDFG_SDFGConvertibleOpInterface : OpInterface<"SDFGConvertibleOpInterface"> { + let description = [{ + Interface for operations processing a scalar that can be batched + if invoked multiple times with different, independent operands. + }]; + let cppNamespace = "::mlir::concretelang::SDFG"; + + let methods = [ + InterfaceMethod<[{ + Create the associated operation and return it as a value. + }], + /*retTy=*/"::mlir::concretelang::SDFG::MakeProcess", + /*methodName=*/"convert", + /*args=*/(ins "::mlir::ImplicitLocOpBuilder&":$builder, + "::mlir::Value":$dfg, + "::mlir::ValueRange":$inStreams, + "::mlir::ValueRange":$outStreams), + /*methodBody=*/"", + /*defaultImplementation=*/[{ + llvm_unreachable("convert not implemented"); + }] + > + ]; +} + +#endif // CONCRETELANG_DIALECT_SDFG_INTERFACES_SDFGCONVERTIBLEINTERFACE diff --git a/compiler/lib/Bindings/Rust/build.rs b/compiler/lib/Bindings/Rust/build.rs index 77a1e6288..830dccb09 100644 --- a/compiler/lib/Bindings/Rust/build.rs +++ b/compiler/lib/Bindings/Rust/build.rs @@ -241,7 +241,7 @@ const LLVM_STATIC_LIBS: [&str; 51] = [ "LLVMX86Info", ]; -const CONCRETE_COMPILER_LIBS: [&str; 30] = [ +const CONCRETE_COMPILER_LIBS: [&str; 31] = [ "RTDialect", "RTDialectTransforms", "ConcretelangSupport", @@ -255,6 +255,7 @@ const CONCRETE_COMPILER_LIBS: [&str; 30] = [ "TFHEGlobalParametrization", "ConcretelangClientLib", "ConcretelangBConcreteTransforms", + "ConcretelangSDFGInterfaces", "CONCRETELANGCAPISupport", "FHELinalgDialect", "ConcretelangInterfaces", diff --git a/compiler/lib/Dialect/SDFG/CMakeLists.txt b/compiler/lib/Dialect/SDFG/CMakeLists.txt index f33061b2d..7927b605a 100644 --- a/compiler/lib/Dialect/SDFG/CMakeLists.txt +++ b/compiler/lib/Dialect/SDFG/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(Interfaces) add_subdirectory(IR) diff --git a/compiler/lib/Dialect/SDFG/Interfaces/CMakeLists.txt b/compiler/lib/Dialect/SDFG/Interfaces/CMakeLists.txt new file mode 100644 index 000000000..49d661565 --- /dev/null +++ b/compiler/lib/Dialect/SDFG/Interfaces/CMakeLists.txt @@ -0,0 +1,14 @@ +add_mlir_dialect_library( + ConcretelangSDFGInterfaces + SDFGConvertibleInterface.cpp + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/SDFG + DEPENDS + mlir-headers + LINK_LIBS + PUBLIC + SDFGDialect + MLIRIR + MLIRMemRefDialect + MLIRPass + MLIRTransforms) diff --git a/compiler/lib/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.cpp b/compiler/lib/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.cpp new file mode 100644 index 000000000..e58cab497 --- /dev/null +++ b/compiler/lib/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.cpp @@ -0,0 +1,8 @@ +// Part of the Concrete Compiler Project, under the BSD3 License with Zama +// Exceptions. See +// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt +// for license information. + +#include "concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.h" + +#include "concretelang/Dialect/SDFG/Interfaces/SDFGConvertibleInterface.cpp.inc" diff --git a/compiler/lib/Support/CMakeLists.txt b/compiler/lib/Support/CMakeLists.txt index a10082093..9aae93646 100644 --- a/compiler/lib/Support/CMakeLists.txt +++ b/compiler/lib/Support/CMakeLists.txt @@ -27,6 +27,7 @@ add_mlir_library( RTDialectAnalysis ConcretelangTransforms ConcretelangBConcreteTransforms + ConcretelangSDFGInterfaces LinalgExtras ConcreteDialectTransforms concrete_optimizer