mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
feat(cpp): expose dag optimization
This commit is contained in:
@@ -19,18 +19,85 @@ template <typename Exception>
|
||||
void panic [[noreturn]] (const char *msg);
|
||||
#endif // CXXBRIDGE1_PANIC
|
||||
|
||||
struct unsafe_bitcopy_t;
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
class impl;
|
||||
} // namespace
|
||||
|
||||
class String;
|
||||
|
||||
template <typename T>
|
||||
::std::size_t size_of();
|
||||
template <typename T>
|
||||
::std::size_t align_of();
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_STRING
|
||||
#define CXXBRIDGE1_RUST_STRING
|
||||
class String final {
|
||||
public:
|
||||
String() noexcept;
|
||||
String(const String &) noexcept;
|
||||
String(String &&) noexcept;
|
||||
~String() noexcept;
|
||||
|
||||
String(const std::string &);
|
||||
String(const char *);
|
||||
String(const char *, std::size_t);
|
||||
String(const char16_t *);
|
||||
String(const char16_t *, std::size_t);
|
||||
|
||||
static String lossy(const std::string &) noexcept;
|
||||
static String lossy(const char *) noexcept;
|
||||
static String lossy(const char *, std::size_t) noexcept;
|
||||
static String lossy(const char16_t *) noexcept;
|
||||
static String lossy(const char16_t *, std::size_t) noexcept;
|
||||
|
||||
String &operator=(const String &) &noexcept;
|
||||
String &operator=(String &&) &noexcept;
|
||||
|
||||
explicit operator std::string() const;
|
||||
|
||||
const char *data() const noexcept;
|
||||
std::size_t size() const noexcept;
|
||||
std::size_t length() const noexcept;
|
||||
bool empty() const noexcept;
|
||||
|
||||
const char *c_str() noexcept;
|
||||
|
||||
std::size_t capacity() const noexcept;
|
||||
void reserve(size_t new_cap) noexcept;
|
||||
|
||||
using iterator = char *;
|
||||
iterator begin() noexcept;
|
||||
iterator end() noexcept;
|
||||
|
||||
using const_iterator = const char *;
|
||||
const_iterator begin() const noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
const_iterator cbegin() const noexcept;
|
||||
const_iterator cend() const noexcept;
|
||||
|
||||
bool operator==(const String &) const noexcept;
|
||||
bool operator!=(const String &) const noexcept;
|
||||
bool operator<(const String &) const noexcept;
|
||||
bool operator<=(const String &) const noexcept;
|
||||
bool operator>(const String &) const noexcept;
|
||||
bool operator>=(const String &) const noexcept;
|
||||
|
||||
void swap(String &) noexcept;
|
||||
|
||||
String(unsafe_bitcopy_t, const String &) noexcept;
|
||||
|
||||
private:
|
||||
struct lossy_t;
|
||||
String(lossy_t, const char *, std::size_t) noexcept;
|
||||
String(lossy_t, const char16_t *, std::size_t) noexcept;
|
||||
friend void swap(String &lhs, String &rhs) noexcept { lhs.swap(rhs); }
|
||||
|
||||
std::array<std::uintptr_t, 3> repr;
|
||||
};
|
||||
#endif // CXXBRIDGE1_RUST_STRING
|
||||
|
||||
#ifndef CXXBRIDGE1_RUST_STR
|
||||
#define CXXBRIDGE1_RUST_STR
|
||||
class Str final {
|
||||
@@ -601,6 +668,26 @@ std::size_t align_of() {
|
||||
return layout::align_of<T>();
|
||||
}
|
||||
#endif // CXXBRIDGE1_LAYOUT
|
||||
|
||||
namespace detail {
|
||||
template <typename T, typename = void *>
|
||||
struct operator_new {
|
||||
void *operator()(::std::size_t sz) { return ::operator new(sz); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct operator_new<T, decltype(T::operator new(sizeof(T)))> {
|
||||
void *operator()(::std::size_t sz) { return T::operator new(sz); }
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
union MaybeUninit {
|
||||
T value;
|
||||
void *operator new(::std::size_t sz) { return detail::operator_new<T>{}(sz); }
|
||||
MaybeUninit() {}
|
||||
~MaybeUninit() {}
|
||||
};
|
||||
} // namespace cxxbridge1
|
||||
} // namespace rust
|
||||
|
||||
@@ -623,6 +710,8 @@ struct OperationDag final : public ::rust::Opaque {
|
||||
::concrete_optimizer::dag::OperatorIndex add_lut(::concrete_optimizer::dag::OperatorIndex input, ::rust::Slice<const ::std::uint64_t> table, ::std::uint8_t out_precision) noexcept;
|
||||
::concrete_optimizer::dag::OperatorIndex add_dot(::rust::Slice<const ::concrete_optimizer::dag::OperatorIndex> inputs, ::rust::Box<::concrete_optimizer::Weights> weights) noexcept;
|
||||
::concrete_optimizer::dag::OperatorIndex add_levelled_op(::rust::Slice<const ::concrete_optimizer::dag::OperatorIndex> inputs, double lwe_dim_cost_factor, double fixed_cost, double manp, ::rust::Slice<const ::std::uint64_t> out_shape, ::rust::Str comment) noexcept;
|
||||
::concrete_optimizer::v0::Solution optimize_v0(::std::uint64_t security_level, double maximum_acceptable_error_probability) const noexcept;
|
||||
::rust::String dump() const noexcept;
|
||||
~OperationDag() = delete;
|
||||
|
||||
private:
|
||||
@@ -703,6 +792,10 @@ extern "C" {
|
||||
::concrete_optimizer::dag::OperatorIndex concrete_optimizer$cxxbridge1$OperationDag$add_dot(::concrete_optimizer::OperationDag &self, ::rust::Slice<const ::concrete_optimizer::dag::OperatorIndex> inputs, ::concrete_optimizer::Weights *weights) noexcept;
|
||||
|
||||
::concrete_optimizer::dag::OperatorIndex concrete_optimizer$cxxbridge1$OperationDag$add_levelled_op(::concrete_optimizer::OperationDag &self, ::rust::Slice<const ::concrete_optimizer::dag::OperatorIndex> inputs, double lwe_dim_cost_factor, double fixed_cost, double manp, ::rust::Slice<const ::std::uint64_t> out_shape, ::rust::Str comment) noexcept;
|
||||
|
||||
::concrete_optimizer::v0::Solution concrete_optimizer$cxxbridge1$OperationDag$optimize_v0(const ::concrete_optimizer::OperationDag &self, ::std::uint64_t security_level, double maximum_acceptable_error_probability) noexcept;
|
||||
|
||||
void concrete_optimizer$cxxbridge1$OperationDag$dump(const ::concrete_optimizer::OperationDag &self, ::rust::String *return$) noexcept;
|
||||
::std::size_t concrete_optimizer$cxxbridge1$Weights$operator$sizeof() noexcept;
|
||||
::std::size_t concrete_optimizer$cxxbridge1$Weights$operator$alignof() noexcept;
|
||||
} // extern "C"
|
||||
@@ -749,6 +842,16 @@ namespace dag {
|
||||
return concrete_optimizer$cxxbridge1$OperationDag$add_levelled_op(*this, inputs, lwe_dim_cost_factor, fixed_cost, manp, out_shape, comment);
|
||||
}
|
||||
|
||||
::concrete_optimizer::v0::Solution OperationDag::optimize_v0(::std::uint64_t security_level, double maximum_acceptable_error_probability) const noexcept {
|
||||
return concrete_optimizer$cxxbridge1$OperationDag$optimize_v0(*this, security_level, maximum_acceptable_error_probability);
|
||||
}
|
||||
|
||||
::rust::String OperationDag::dump() const noexcept {
|
||||
::rust::MaybeUninit<::rust::String> return$;
|
||||
concrete_optimizer$cxxbridge1$OperationDag$dump(*this, &return$.value);
|
||||
return ::std::move(return$.value);
|
||||
}
|
||||
|
||||
::std::size_t Weights::layout::size() noexcept {
|
||||
return concrete_optimizer$cxxbridge1$Weights$operator$sizeof();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user