Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Detailed Statistics #526

Merged
merged 2 commits into from
Aug 1, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ namespace concretelang {

using StringError = ::concretelang::error::StringError;

enum class PrimitiveOperation {
PBS,
WOP_PBS,
KEY_SWITCH,
CLEAR_ADDITION,
ENCRYPTED_ADDITION,
CLEAR_MULTIPLICATION,
ENCRYPTED_NEGATION,
};

enum class KeyType {
SECRET,
BOOTSTRAP,
KEY_SWITCH,
PACKING_KEY_SWITCH,
};

struct Statistic {
std::string location;
PrimitiveOperation operation;
std::vector<std::pair<KeyType, size_t>> keys;
size_t count;
};

struct CompilationFeedback {
double complexity;

Expand Down Expand Up @@ -45,23 +69,8 @@ struct CompilationFeedback {
/// @brief crt decomposition of outputs, if crt is not used, empty vectors
std::vector<std::vector<int64_t>> crtDecompositionsOfOutputs;

/// @brief number of programmable bootstraps in the entire circuit
uint64_t totalPbsCount = 0;

/// @brief number of key switches in the entire circuit
uint64_t totalKsCount = 0;

/// @brief number of clear additions in the entire circuit
uint64_t totalClearAdditionCount = 0;

/// @brief number of encrypted additions in the entire circuit
uint64_t totalEncryptedAdditionCount = 0;

/// @brief number of clear multiplications in the entire circuit
uint64_t totalClearMultiplicationCount = 0;

/// @brief number of encrypted negations in the entire circuit
uint64_t totalEncryptedNegationCount = 0;
/// @brief statistics
std::vector<Statistic> statistics;

/// Fill the sizes from the client parameters.
void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ declare_mlir_python_sources(
concrete/compiler/library_compilation_result.py
concrete/compiler/library_support.py
concrete/compiler/library_lambda.py
concrete/compiler/parameter.py
concrete/compiler/public_arguments.py
concrete/compiler/public_result.py
concrete/compiler/evaluation_keys.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@ void mlir::concretelang::python::populateCompilerAPISubmodule(
options.simulate = simulate;
});

pybind11::enum_<mlir::concretelang::PrimitiveOperation>(m,
"PrimitiveOperation")
.value("PBS", mlir::concretelang::PrimitiveOperation::PBS)
.value("WOP_PBS", mlir::concretelang::PrimitiveOperation::WOP_PBS)
.value("KEY_SWITCH", mlir::concretelang::PrimitiveOperation::KEY_SWITCH)
.value("CLEAR_ADDITION",
mlir::concretelang::PrimitiveOperation::CLEAR_ADDITION)
.value("ENCRYPTED_ADDITION",
mlir::concretelang::PrimitiveOperation::ENCRYPTED_ADDITION)
.value("CLEAR_MULTIPLICATION",
mlir::concretelang::PrimitiveOperation::CLEAR_MULTIPLICATION)
.value("ENCRYPTED_NEGATION",
mlir::concretelang::PrimitiveOperation::ENCRYPTED_NEGATION)
.export_values();

pybind11::enum_<mlir::concretelang::KeyType>(m, "KeyType")
.value("SECRET", mlir::concretelang::KeyType::SECRET)
.value("BOOTSTRAP", mlir::concretelang::KeyType::BOOTSTRAP)
.value("KEY_SWITCH", mlir::concretelang::KeyType::KEY_SWITCH)
.value("PACKING_KEY_SWITCH",
mlir::concretelang::KeyType::PACKING_KEY_SWITCH)
.export_values();

pybind11::class_<mlir::concretelang::Statistic>(m, "Statistic")
.def_readonly("operation", &mlir::concretelang::Statistic::operation)
.def_readonly("location", &mlir::concretelang::Statistic::location)
.def_readonly("keys", &mlir::concretelang::Statistic::keys)
.def_readonly("count", &mlir::concretelang::Statistic::count);

pybind11::class_<mlir::concretelang::CompilationFeedback>(
m, "CompilationFeedback")
.def_readonly("complexity",
Expand All @@ -132,22 +161,8 @@ void mlir::concretelang::python::populateCompilerAPISubmodule(
.def_readonly(
"crt_decompositions_of_outputs",
&mlir::concretelang::CompilationFeedback::crtDecompositionsOfOutputs)
.def_readonly("total_pbs_count",
&mlir::concretelang::CompilationFeedback::totalPbsCount)
.def_readonly("total_ks_count",
&mlir::concretelang::CompilationFeedback::totalKsCount)
.def_readonly(
"total_clear_addition_count",
&mlir::concretelang::CompilationFeedback::totalClearAdditionCount)
.def_readonly(
"total_encrypted_addition_count",
&mlir::concretelang::CompilationFeedback::totalEncryptedAdditionCount)
.def_readonly("total_clear_multiplication_count",
&mlir::concretelang::CompilationFeedback::
totalClearMultiplicationCount)
.def_readonly("total_encrypted_negation_count",
&mlir::concretelang::CompilationFeedback::
totalEncryptedNegationCount);
.def_readonly("statistics",
&mlir::concretelang::CompilationFeedback::statistics);

pybind11::class_<mlir::concretelang::JitCompilationResult>(
m, "JITCompilationResult");
Expand Down Expand Up @@ -320,6 +335,76 @@ void mlir::concretelang::python::populateCompilerAPISubmodule(
pybind11::class_<clientlib::KeySetCache>(m, "KeySetCache")
.def(pybind11::init<std::string &>());

pybind11::class_<::concretelang::clientlib::LweSecretKeyParam>(
m, "LweSecretKeyParam")
.def_readonly("dimension",
&::concretelang::clientlib::LweSecretKeyParam::dimension);

pybind11::class_<::concretelang::clientlib::BootstrapKeyParam>(
m, "BootstrapKeyParam")
.def_readonly(
"input_secret_key_id",
&::concretelang::clientlib::BootstrapKeyParam::inputSecretKeyID)
.def_readonly(
"output_secret_key_id",
&::concretelang::clientlib::BootstrapKeyParam::outputSecretKeyID)
.def_readonly("level",
&::concretelang::clientlib::BootstrapKeyParam::level)
.def_readonly("base_log",
&::concretelang::clientlib::BootstrapKeyParam::baseLog)
.def_readonly(
"glwe_dimension",
&::concretelang::clientlib::BootstrapKeyParam::glweDimension)
.def_readonly("variance",
&::concretelang::clientlib::BootstrapKeyParam::variance)
.def_readonly(
"polynomial_size",
&::concretelang::clientlib::BootstrapKeyParam::polynomialSize)
.def_readonly(
"input_lwe_dimension",
&::concretelang::clientlib::BootstrapKeyParam::inputLweDimension);

pybind11::class_<::concretelang::clientlib::KeyswitchKeyParam>(
m, "KeyswitchKeyParam")
.def_readonly(
"input_secret_key_id",
&::concretelang::clientlib::KeyswitchKeyParam::inputSecretKeyID)
.def_readonly(
"output_secret_key_id",
&::concretelang::clientlib::KeyswitchKeyParam::outputSecretKeyID)
.def_readonly("level",
&::concretelang::clientlib::KeyswitchKeyParam::level)
.def_readonly("base_log",
&::concretelang::clientlib::KeyswitchKeyParam::baseLog)
.def_readonly("variance",
&::concretelang::clientlib::KeyswitchKeyParam::variance);

pybind11::class_<::concretelang::clientlib::PackingKeyswitchKeyParam>(
m, "PackingKeyswitchKeyParam")
.def_readonly("input_secret_key_id",
&::concretelang::clientlib::PackingKeyswitchKeyParam::
inputSecretKeyID)
.def_readonly("output_secret_key_id",
&::concretelang::clientlib::PackingKeyswitchKeyParam::
outputSecretKeyID)
.def_readonly("level",
&::concretelang::clientlib::PackingKeyswitchKeyParam::level)
.def_readonly(
"base_log",
&::concretelang::clientlib::PackingKeyswitchKeyParam::baseLog)
.def_readonly(
"glwe_dimension",
&::concretelang::clientlib::PackingKeyswitchKeyParam::glweDimension)
.def_readonly(
"polynomial_size",
&::concretelang::clientlib::PackingKeyswitchKeyParam::polynomialSize)
.def_readonly("input_lwe_dimension",
&::concretelang::clientlib::PackingKeyswitchKeyParam::
inputLweDimension)
.def_readonly(
"variance",
&::concretelang::clientlib::PackingKeyswitchKeyParam::variance);

pybind11::class_<mlir::concretelang::ClientParameters>(m, "ClientParameters")
.def_static("deserialize",
[](const pybind11::bytes &buffer) {
Expand Down Expand Up @@ -353,7 +438,16 @@ void mlir::concretelang::python::populateCompilerAPISubmodule(
}
}
return result;
});
})
.def_readonly("secret_keys",
&mlir::concretelang::ClientParameters::secretKeys)
.def_readonly("bootstrap_keys",
&mlir::concretelang::ClientParameters::bootstrapKeys)
.def_readonly("keyswitch_keys",
&mlir::concretelang::ClientParameters::keyswitchKeys)
.def_readonly(
"packing_keyswitch_keys",
&mlir::concretelang::ClientParameters::packingKeyswitchKeys);

pybind11::class_<clientlib::KeySet>(m, "KeySet")
.def_static("deserialize",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .value_exporter import ValueExporter
from .simulated_value_decrypter import SimulatedValueDecrypter
from .simulated_value_exporter import SimulatedValueExporter
from .parameter import Parameter


def init_dfr():
Expand Down
Loading