Skip to content

Commit

Permalink
feat(compiler): add rust bindings to concrete
Browse files Browse the repository at this point in the history
  • Loading branch information
aPere3 committed Jan 16, 2025
1 parent e9368bc commit 4b27a48
Show file tree
Hide file tree
Showing 3,182 changed files with 1,380,898 additions and 84 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
13 changes: 11 additions & 2 deletions compilers/concrete-compiler/compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ifeq ($(BUILD_TYPE),Debug)
LIBOMP_LINK_TO_LIBSTDCXX_OPT=-DLIBOMP_USE_STDCPPLIB=ON
endif

all: concretecompiler python-bindings build-tests build-benchmarks doc
all: concretecompiler python-bindings build-tests build-benchmarks doc fatlib

# HPX #####################################################

Expand Down Expand Up @@ -195,7 +195,16 @@ clientlib: build-initialized
serverlib: build-initialized
cmake --build $(BUILD_DIR) --target ConcretelangServerLib


ifeq ($(OS), linux)
LIBTOOL_EXTRA_ARGS=--tag=CXX --mode=link cc
else
LIBTOOL_EXTRA_ARGS=
endif
fatlib: build-initialized
cmake --build $(BUILD_DIR) --target ConcretelangRuntimeStatic
cd $(BUILD_DIR)/lib && \
libtool $(LIBTOOL_EXTRA_ARGS) -static -o libConcretelangFat.a lib*.a\
../../../../../backends/concrete-cpu/implementation/target/release/libconcrete_cpu.a

GITHUB_URL=https://api.github.com/repos/zama-ai/concrete-compiler-internal
GITHUB_URL_LIST_ARTIFACTS="${GITHUB_URL}/actions/artifacts?name=${KEYSETCACHENAME}&per_page=1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ClientCircuit {
std::vector<OutputTransformer> outputTransformers,
bool simulated)
: circuitInfo(circuitInfo), inputTransformers(inputTransformers),
outputTransformers(outputTransformers), simulated(simulated){};
outputTransformers(outputTransformers), simulated(simulated) {};
static Result<ClientCircuit>
create(const Message<concreteprotocol::CircuitInfo> &info,
const ClientKeyset &keyset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template <typename Csprng> class CSPRNG {
other.ptr = nullptr;
};

CSPRNG(Csprng *ptr) : ptr(ptr){};
CSPRNG(Csprng *ptr) : ptr(ptr) {};
};

class SoftCSPRNG : public CSPRNG<Csprng> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace error {
/// The type of error used throughout the client/server libs.
class StringError {
public:
StringError(std::string mesg) : mesg(mesg){};
StringError(std::string mesg) : mesg(mesg) {};

std::string mesg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LweSecretKey {
LweSecretKey() = delete;
LweSecretKey(std::shared_ptr<std::vector<uint64_t>> buffer,
Message<concreteprotocol::LweSecretKeyInfo> info)
: buffer(buffer), info(info){};
: buffer(buffer), info(info) {};

static LweSecretKey
fromProto(const Message<concreteprotocol::LweSecretKey> &proto);
Expand Down Expand Up @@ -91,7 +91,7 @@ class LweBootstrapKey {
Message<concreteprotocol::LweBootstrapKeyInfo> info)
: seededBuffer(std::make_shared<std::vector<uint64_t>>()), buffer(buffer),
info(info), decompress_mutext(std::make_shared<std::mutex>()),
decompressed(std::make_shared<bool>(false)){};
decompressed(std::make_shared<bool>(false)) {};

/// @brief Initialize the key from the protocol message.
static LweBootstrapKey
Expand All @@ -117,7 +117,7 @@ class LweBootstrapKey {
: seededBuffer(std::make_shared<std::vector<uint64_t>>()),
buffer(std::make_shared<std::vector<uint64_t>>()), info(info),
decompress_mutext(std::make_shared<std::mutex>()),
decompressed(std::make_shared<bool>(false)){};
decompressed(std::make_shared<bool>(false)) {};
LweBootstrapKey() = delete;

/// @brief The buffer of the seeded key if needed.
Expand Down Expand Up @@ -147,7 +147,7 @@ class LweKeyswitchKey {
Message<concreteprotocol::LweKeyswitchKeyInfo> info)
: seededBuffer(std::make_shared<std::vector<uint64_t>>()), buffer(buffer),
info(info), decompress_mutext(std::make_shared<std::mutex>()),
decompressed(std::make_shared<bool>(false)){};
decompressed(std::make_shared<bool>(false)) {};

/// @brief Initialize the key from the protocol message.
static LweKeyswitchKey
Expand All @@ -173,7 +173,7 @@ class LweKeyswitchKey {
: seededBuffer(std::make_shared<std::vector<uint64_t>>()),
buffer(std::make_shared<std::vector<uint64_t>>()), info(info),
decompress_mutext(std::make_shared<std::mutex>()),
decompressed(std::make_shared<bool>(false)){};
decompressed(std::make_shared<bool>(false)) {};

/// @brief The buffer of the seeded key if needed.
std::shared_ptr<std::vector<uint64_t>> seededBuffer;
Expand Down Expand Up @@ -204,7 +204,7 @@ class PackingKeyswitchKey {
PackingKeyswitchKey() = delete;
PackingKeyswitchKey(std::shared_ptr<std::vector<uint64_t>> buffer,
Message<concreteprotocol::PackingKeyswitchKeyInfo> info)
: buffer(buffer), info(info){};
: buffer(buffer), info(info) {};

static PackingKeyswitchKey
fromProto(const Message<concreteprotocol::PackingKeyswitchKey> &proto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct Keyset {
ServerKeyset server;
ClientKeyset client;

Keyset(){};
Keyset() {};

/// @brief Generates a keyset from infos.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ struct Value {
Tensor<uint64_t>, Tensor<int64_t>>
inner;
Value() = default;
Value(Tensor<uint8_t> inner) : inner(inner){};
Value(Tensor<uint16_t> inner) : inner(inner){};
Value(Tensor<uint32_t> inner) : inner(inner){};
Value(Tensor<uint64_t> inner) : inner(inner){};
Value(Tensor<int8_t> inner) : inner(inner){};
Value(Tensor<int16_t> inner) : inner(inner){};
Value(Tensor<int32_t> inner) : inner(inner){};
Value(Tensor<int64_t> inner) : inner(inner){};
Value(Tensor<uint8_t> inner) : inner(inner) {};
Value(Tensor<uint16_t> inner) : inner(inner) {};
Value(Tensor<uint32_t> inner) : inner(inner) {};
Value(Tensor<uint64_t> inner) : inner(inner) {};
Value(Tensor<int8_t> inner) : inner(inner) {};
Value(Tensor<int16_t> inner) : inner(inner) {};
Value(Tensor<int32_t> inner) : inner(inner) {};
Value(Tensor<int64_t> inner) : inner(inner) {};

/// Turns a server value to a client value, without interpreting the kind of
/// value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace concretelang {

struct ScalarLoweringParameters {
size_t polynomialSize;
ScalarLoweringParameters(size_t polySize) : polynomialSize(polySize){};
ScalarLoweringParameters(size_t polySize) : polynomialSize(polySize) {};
};

/// Create a pass to convert `FHE` dialect to `TFHE` dialect with the scalar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#ifndef CONCRETELANG_SUPPORT_COMPILER_ENGINE_H
#define CONCRETELANG_SUPPORT_COMPILER_ENGINE_H

#include "capnp/message.h"
#include "concrete-protocol.capnp.h"
#include "concretelang/Common/Protocol.h"
#include "concretelang/Conversion/Utils/GlobalFHEContext.h"
#include "concretelang/Support/Encodings.h"
Expand Down Expand Up @@ -125,7 +123,8 @@ struct CompilationOptions {
batchTFHEOps(false), maxBatchSize(std::numeric_limits<int64_t>::max()),
emitSDFGOps(false), unrollLoopsWithSDFGConvertibleOps(false),
optimizeTFHE(true), chunkIntegers(false), chunkSize(4), chunkWidth(2),
encodings(std::nullopt), enableTluFusing(true), printTluFusing(false){};
encodings(std::nullopt), enableTluFusing(true),
printTluFusing(false) {};

/// @brief Constructor for CompilationOptions with default parameters for a
/// specific backend.
Expand Down Expand Up @@ -315,9 +314,6 @@ enum class Target {

class CompilerEngine {
public:



CompilerEngine(std::shared_ptr<CompilationContext> compilationContext)
: overrideMaxEintPrecision(), overrideMaxMANP(), compilerOptions(),
generateProgramInfo(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace concretelang {
/// }
class StreamStringError {
public:
StreamStringError(const llvm::StringRef &s) : buffer(s.str()), os(buffer){};
StreamStringError() : buffer(""), os(buffer){};
StreamStringError(const llvm::StringRef &s) : buffer(s.str()), os(buffer) {};
StreamStringError() : buffer(""), os(buffer) {};

template <typename T> StreamStringError &operator<<(const T &v) {
this->os << v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#ifndef CONCRETELANG_SUPPORT_VARIANTS_H_
#define CONCRETELANG_SUPPORT_VARIANTS_H_

template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> struct overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ std::string roundTrip(const char *module) {
std::string backingString;
llvm::raw_string_ostream os(backingString);

llvm::Expected<mlir::concretelang::CompilationResult>
retOrErr = ce.compile(
module, mlir::concretelang::Target::ROUND_TRIP);
llvm::Expected<mlir::concretelang::CompilationResult> retOrErr =
ce.compile(module, mlir::concretelang::Target::ROUND_TRIP);
if (!retOrErr) {
os << "MLIR parsing failed: " << llvm::toString(retOrErr.takeError());
throw std::runtime_error(os.str());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cargo.lock
target/**
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "concrete-sys"
version = "0.1.0"
edition = "2021"

[dependencies]
autocxx = "0.27.1"
cxx = "1.0"

[build-dependencies]
autocxx-build = "0.27.1"

[dev-dependencies]
ar = "0.9"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.SILENT:

update-includes:
rsync -a \
--include "*/"\
--include "*.h"\
--include "*.hpp"\
--include "*.inc"\
--include "*.def"\
--exclude "*"\
--prune-empty-dirs\
../../../../include/\
../../../../../../concrete-optimizer/concrete-optimizer-cpp/src/cpp/\
../../../../../llvm-project/llvm/include/\
../../../../../llvm-project/mlir/include/\
../../../../build/tools/concretelang/concrete-protocol/capnp_src_dir/c++/src/\
../../../../build/tools/concretelang/concrete-protocol/concrete-protocol.capnp.h\
../../../../build/include/\
../../../../build/tools/mlir/include/\
../../../../build/tools/concretelang/include/\
include
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fn main() {
autocxx_build::Builder::new("src/lib.rs", ["include"])
.extra_clang_args(&["-std=c++17"])
.build()
.unwrap()
.flag_if_supported("-std=c++17")
.file("src/lib.cpp")
.include("src")
.warnings(false)
.compile("concrete-sys");

println!("cargo::rustc-link-search=../../../../build/lib");
println!("cargo::rustc-link-lib=ConcretelangFat");
println!("cargo::rustc-link-lib=curses");
println!("cargo::rustc-link-lib=zstd");
println!("cargo::rustc-link-lib=z");
}
Loading

0 comments on commit 4b27a48

Please sign in to comment.