feat(compiler): Add operation interface for batchable operations

This adds a new operation interface that allows an operation to
specify that a batched version of the operation exists that applies it
on the elements of a flat tensor in parallel.
This commit is contained in:
Andi Drebes
2022-11-10 16:39:06 +01:00
parent c5ceccaeee
commit 3ce7c96f3f
7 changed files with 89 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
add_subdirectory(Dialect)
add_subdirectory(Conversion)
add_subdirectory(Transforms)
add_subdirectory(Interfaces)

View File

@@ -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_INTERFACES_BATCHABLEINTERFACE_H_
#define CONCRETELANG_INTERFACES_BATCHABLEINTERFACE_H_
#include <mlir/IR/ImplicitLocOpBuilder.h>
#include <mlir/IR/OpDefinition.h>
#include <concretelang/Interfaces/BatchableInterface.h.inc>
#endif // CONCRETELANG_INTERFACES_BATCHABLEINTERFACE_H_

View File

@@ -0,0 +1,52 @@
#ifndef CONCRETELANG_INTERFACES_BATCHABLEINTERFACE
#define CONCRETELANG_INTERFACES_BATCHABLEINTERFACE
include "mlir/IR/OpBase.td"
def BatchableOpInterface : OpInterface<"BatchableOpInterface"> {
let description = [{
Interface for operations processing a scalar that can be batched
if invoked multiple times with different, independent operands.
}];
let cppNamespace = "::mlir::concretelang";
let methods = [
InterfaceMethod<[{
Return the scalar operand that can be batched in a tensor to
be passed to the corresponding batched operation.
}],
/*retTy=*/"::mlir::OpOperand&",
/*methodName=*/"getBatchableOperand",
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
llvm_unreachable("getBatchableOperand not implemented");
}]
>,
InterfaceMethod<[{
Return all operands that cannot be batched.
}],
/*retTy=*/"::mlir::OperandRange",
/*methodName=*/"getNonBatchableOperands",
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
llvm_unreachable("getNonBatchableOperands not implemented");
}]
>,
InterfaceMethod<[{
Create the batched operation and return it as a value.
}],
/*retTy=*/"::mlir::Value",
/*methodName=*/"createBatchedOperation",
/*args=*/(ins "::mlir::ImplicitLocOpBuilder&":$builder,
"::mlir::Value":$batchedOperands),
/*methodBody=*/"",
/*defaultImplementation=*/[{
llvm_unreachable("createBatchedOperation not implemented");
}]
>
];
}
#endif // CONCRETELANG_INTERFACES_BATCHABLEINTERFACE

View File

@@ -0,0 +1 @@
add_mlir_interface(BatchableInterface)

View File

@@ -6,6 +6,7 @@ add_subdirectory(Runtime)
add_subdirectory(ClientLib)
add_subdirectory(Bindings)
add_subdirectory(ServerLib)
add_subdirectory(Interfaces)
# CAPI needed only for python bindings
if (CONCRETELANG_BINDINGS_PYTHON_ENABLED)

View File

@@ -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/Interfaces/BatchableInterface.h>
#include <concretelang/Interfaces/BatchableInterface.cpp.inc>

View File

@@ -0,0 +1,12 @@
add_mlir_library(ConcretelangInterfaces
BatchableInterface.cpp
ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/concretelang/Interfaces
DEPENDS
mlir-headers
LINK_LIBS PUBLIC
MLIRIR
)