Skip to content

Commit

Permalink
Merge pull request #1268 from WoutLegiest:hl-emit-fpga
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 715876270
  • Loading branch information
copybara-github committed Jan 15, 2025
2 parents c306a1a + e76bae0 commit 79febe7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
27 changes: 6 additions & 21 deletions lib/Target/TfheRustHL/TfheRustHLEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,7 @@ void registerToTfheRustHLTranslation() {
TranslateFromMLIRRegistration reg(
"emit-tfhe-rust-hl", "translate the tfhe-rs dialect to HL Rust code",
[](Operation *op, llvm::raw_ostream &output) {
return translateToTfheRustHL(op, output, /*belfortAPI=*/false);
},
[](DialectRegistry &registry) {
registry.insert<func::FuncDialect, tfhe_rust::TfheRustDialect,
affine::AffineDialect, arith::ArithDialect,
tensor::TensorDialect, memref::MemRefDialect>();
});

TranslateFromMLIRRegistration regFPGA(
"emit-tfhe-rust-hl-fpga",
"translate the tfhe-rs-bool dialect to Rust code for Belfort FPGA "
"HL tfhe-rs API",
[](Operation *op, llvm::raw_ostream &output) {
return translateToTfheRustHL(op, output, /*belfortAPI=*/true);
return translateToTfheRustHL(op, output);
},
[](DialectRegistry &registry) {
registry.insert<func::FuncDialect, tfhe_rust::TfheRustDialect,
Expand All @@ -96,10 +83,9 @@ void registerToTfheRustHLTranslation() {
});
}

LogicalResult translateToTfheRustHL(Operation *op, llvm::raw_ostream &os,
bool belfortAPI) {
LogicalResult translateToTfheRustHL(Operation *op, llvm::raw_ostream &os) {
SelectVariableNames variableNames(op);
TfheRustHLEmitter emitter(os, &variableNames, belfortAPI);
TfheRustHLEmitter emitter(os, &variableNames);
LogicalResult result = emitter.translate(*op);
return result;
}
Expand Down Expand Up @@ -141,7 +127,7 @@ LogicalResult TfheRustHLEmitter::translate(Operation &op) {
}

LogicalResult TfheRustHLEmitter::printOperation(ModuleOp moduleOp) {
os << (belfortAPI ? kFPGAModulePrelude : kModulePrelude) << "\n";
os << kModulePrelude << "\n";

// Find default type of the module and use a Type alias
moduleOp.getOperation()->walk([&](Operation *op) {
Expand Down Expand Up @@ -657,9 +643,8 @@ std::string TfheRustHLEmitter::checkOrigin(Value value) {
}

TfheRustHLEmitter::TfheRustHLEmitter(raw_ostream &os,
SelectVariableNames *variableNames,
bool belfortAPI)
: os(os), variableNames(variableNames), belfortAPI(belfortAPI) {}
SelectVariableNames *variableNames)
: os(os), variableNames(variableNames) {}
} // namespace tfhe_rust
} // namespace heir
} // namespace mlir
9 changes: 2 additions & 7 deletions lib/Target/TfheRustHL/TfheRustHLEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ void registerToTfheRustHLTranslation();

/// Translates the given operation to TfheRustHL.
::mlir::LogicalResult translateToTfheRustHL(::mlir::Operation *op,
llvm::raw_ostream &os,
bool belfortAPI);
llvm::raw_ostream &os);

class TfheRustHLEmitter {
public:
TfheRustHLEmitter(raw_ostream &os, SelectVariableNames *variableNames,
bool belfortAPI);
TfheRustHLEmitter(raw_ostream &os, SelectVariableNames *variableNames);

LogicalResult translate(::mlir::Operation &operation);
bool containsVectorOperands(Operation *op);
Expand All @@ -49,9 +47,6 @@ class TfheRustHLEmitter {
/// values.
SelectVariableNames *variableNames;

// Boolean to keep track if the Belfort API is used or not
bool belfortAPI;

// Functions for printing individual ops
LogicalResult printOperation(::mlir::ModuleOp op);
LogicalResult printOperation(::mlir::func::FuncOp op);
Expand Down
8 changes: 0 additions & 8 deletions lib/Target/TfheRustHL/TfheRustHLTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ use tfhe::prelude::*;
use tfhe::ServerKey;
)rust";

constexpr std::string_view kFPGAModulePrelude = R"rust(
use std::collections::BTreeMap;
use tfhe::boolean::{engine::fpga::{BelfortBooleanServerKey, Gate}, prelude::*};
use crate::server_key_enum::ServerKeyEnum;
use crate::server_key_enum::ServerKeyTrait;
)rust";

} // namespace tfhe_rust
} // namespace heir
} // namespace mlir
Expand Down

0 comments on commit 79febe7

Please sign in to comment.