Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Target/OpenFhePke/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cc_library(
"@llvm-project//mlir:ControlFlowDialect",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:MathDialect",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:SCFDialect",
"@llvm-project//mlir:Support",
Expand Down Expand Up @@ -87,6 +88,7 @@ cc_library(
"@llvm-project//mlir:DialectUtils",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:MathDialect",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:SCFDialect",
"@llvm-project//mlir:Support",
Expand Down
9 changes: 9 additions & 0 deletions lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "mlir/include/mlir/Dialect/Arith/IR/Arith.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Math/IR/Math.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/MemRef/IR/MemRef.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/SCF/IR/SCF.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Tensor/IR/Tensor.h" // from @llvm-project
Expand Down Expand Up @@ -188,6 +189,7 @@ LogicalResult OpenFhePkeEmitter::translate(Operation& op) {
arith::DivFOp, arith::CmpIOp, arith::CmpFOp, arith::SelectOp,
arith::MaxSIOp, arith::MinSIOp>(
[&](auto op) { return printOperation(op); })
.Case<math::SqrtOp>([&](auto op) { return printOperation(op); })
// SCF ops
.Case<scf::IfOp, scf::ForOp, scf::ForallOp, scf::InParallelOp,
scf::YieldOp>([&](auto op) { return printOperation(op); })
Expand Down Expand Up @@ -1133,6 +1135,13 @@ LogicalResult OpenFhePkeEmitter::printOperation(arith::TruncFOp op) {
return success();
}

LogicalResult OpenFhePkeEmitter::printOperation(math::SqrtOp op) {
emitAutoAssignPrefix(op.getResult());
os << "std::sqrt(" << variableNames->getNameForValue(op.getOperand())
<< ");\n";
return success();
}

LogicalResult OpenFhePkeEmitter::printOperation(arith::ExtFOp op) {
// OpenFHE has a convention that all inputs to MakeCKKSPackedPlaintext are
// std::vector<double>, so earlier stages in the pipeline emit typecasts
Expand Down
2 changes: 2 additions & 0 deletions lib/Target/OpenFhePke/OpenFhePkeEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mlir/include/mlir/Dialect/Arith/IR/Arith.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Math/IR/Math.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/MemRef/IR/MemRef.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/SCF/IR/SCF.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Tensor/IR/Tensor.h" // from @llvm-project
Expand Down Expand Up @@ -97,6 +98,7 @@ class OpenFhePkeEmitter {
LogicalResult printOperation(::mlir::arith::SubFOp op);
LogicalResult printOperation(::mlir::arith::DivFOp op);
LogicalResult printOperation(::mlir::arith::TruncFOp op);
LogicalResult printOperation(::mlir::math::SqrtOp op);
LogicalResult printOperation(::mlir::scf::IfOp op);
LogicalResult printOperation(::mlir::scf::ForOp op);
LogicalResult printOperation(::mlir::scf::ForallOp op);
Expand Down
3 changes: 3 additions & 0 deletions lib/Target/OpenFhePke/OpenFhePkeTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace openfhe {

constexpr std::string_view kSourceRelativeOpenfheImport = R"cpp(
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
Expand All @@ -17,6 +18,7 @@ constexpr std::string_view kSourceRelativeOpenfheImport = R"cpp(
)cpp";
constexpr std::string_view kInstallationRelativeOpenfheImport = R"cpp(
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
Expand All @@ -25,6 +27,7 @@ constexpr std::string_view kInstallationRelativeOpenfheImport = R"cpp(
)cpp";
constexpr std::string_view kEmbeddedOpenfheImport = R"cpp(
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
Expand Down
15 changes: 8 additions & 7 deletions lib/Target/OpenFhePke/OpenFheTranslateRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mlir/include/mlir/Dialect/Arith/IR/Arith.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlow.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Math/IR/Math.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/MemRef/IR/MemRef.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/SCF/IR/SCF.h" // from @llvm-project
#include "mlir/include/mlir/Dialect/Tensor/IR/Tensor.h" // from @llvm-project
Expand Down Expand Up @@ -85,13 +86,13 @@ void registerTranslateOptions() {

// Common func to register dialects
static void registerRelevantDialects(DialectRegistry& registry) {
registry.insert<affine::AffineDialect, arith::ArithDialect,
cf::ControlFlowDialect, func::FuncDialect, lwe::LWEDialect,
memref::MemRefDialect, mod_arith::ModArithDialect,
openfhe::OpenfheDialect, polynomial::PolynomialDialect,
preprocessing::PreprocessingDialect, rns::RNSDialect,
scf::SCFDialect, tensor::TensorDialect,
tensor_ext::TensorExtDialect>();
registry.insert<
affine::AffineDialect, arith::ArithDialect, cf::ControlFlowDialect,
func::FuncDialect, lwe::LWEDialect, math::MathDialect,
memref::MemRefDialect, mod_arith::ModArithDialect,
openfhe::OpenfheDialect, polynomial::PolynomialDialect,
preprocessing::PreprocessingDialect, rns::RNSDialect, scf::SCFDialect,
tensor::TensorDialect, tensor_ext::TensorExtDialect>();
}

void registerToOpenFhePkeTranslation() {
Expand Down
Loading