mirror of
https://github.com/luxfhe/torus.git
synced 2026-10-30 17:07:26 +00:00
Forked from upstream concrete (BSD-3-Clause-Clear, © 2024 ZAMA) at HEAD
ecb729bb. Modifications copyright © 2026 Lux Industries Inc.
Rebranding scope:
- Python module concrete → torus (across frontends/torus-python)
- Rust module concrete-* → torus-* (across frontends/torus-rust)
- MLIR dialect concretelang → toruslang (across compilers/torus-compiler)
- Compiler optimizer concrete-optimizer → torus-optimizer
- Backend concrete-cpu / concrete-cuda → torus-cpu / torus-cuda
- Wire protocol concrete-protocol → torus-protocol
- Parameter-curves concrete-security-curves-* → torus-security-curves-*
- Public symbols concretelib → toruslib, ConcreteLang → TorusLang
- URLs github.com/zama-ai/concrete → github.com/luxfhe/torus
- URLs docs.zama.ai/concrete → docs.luxfhe.com/torus
Legal compliance:
- LICENSE.txt retains original Copyright © 2024 ZAMA verbatim (§1-§2)
- LICENSE.txt adds modifications copyright © 2026 Lux Industries Inc.
- §3 endorsement clause: Torus is marketed exclusively as a Lux product;
no Zama name used in README, docs, or marketing
- NOTICE file provides factual attribution per legal best practice
(not endorsement; required by upstream BSD-3-Clause-Clear)
README + NOTICE rewritten from scratch with Lux brand:
- Quick-start in Python (torus.fhe)
- Architecture diagram showing the gen-1 vtbl integration path
(luxcpp/gpu → lux-private/gpu-kernels for CUDA/Metal/WebGPU)
- Scheme coverage table: TFHE (luxfi/fhe), CKKS/BGV/BFV (luxfi/lattice)
- Lux FHE family table: Torus / TorusVM / TorusEVM / TorusML / TorusNet
Known limitations (phase-2A scope):
- PyPI package torus-fhe not yet published; the torus Python module
is renamed structurally but pip-installable distribution is a
follow-up (Phase 2A.1)
- MLIR dialect rename is text-level; the compiler-internal LLVM
rebuild (concrete-compiler-internal-llvm-project submodule) is
structural and works; tablegen files renamed concrete→torus but the
generated .inc files in the source tree will regenerate at build
time
- backends/torus-cuda/implementation/ is an upstream submodule
pointer to the tfhe-rs source (not fetched in the staging clone);
the CUDA backend body is delivered out-of-tree
- ~100 test-fixture variable names like concrete_encoded_sample
retain "concrete" as a math term (vs symbolic); these are inside
tests/, not the public API; cleanup is a follow-up commit
- 295 Python `from concrete import ...` residuals in luxfhe/ml-sdk
consumer remain; that repo's import update is Phase 2B
This commit is the seed for the luxfhe/torus repo. Push as the first
commit to a fresh GitHub repo; do not re-import upstream Zama git
history.
159 lines
7.4 KiB
C++
159 lines
7.4 KiB
C++
#ifndef UINT_TESTS_COMMON_ASSERT_H
|
|
#define UINT_TESTS_COMMON_ASSERT_H
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
#include <toruslang/Runtime/DFRuntime.hpp>
|
|
#include <gtest/gtest.h>
|
|
|
|
#define ASSERT_LLVM_ERROR(err) \
|
|
{ \
|
|
llvm::Error e = err; \
|
|
if (e) { \
|
|
handleAllErrors(std::move(e), [](const llvm::ErrorInfoBase &ei) { \
|
|
ASSERT_TRUE(false) << ei.message(); \
|
|
}); \
|
|
} \
|
|
}
|
|
|
|
#define DISCARD_LLVM_ERROR(err) \
|
|
{ \
|
|
llvm::Error e = std::move(err); \
|
|
if (e) { \
|
|
handleAllErrors(std::move(e), [](const llvm::ErrorInfoBase &ei) { \
|
|
ASSERT_TRUE(true); \
|
|
}); \
|
|
} \
|
|
}
|
|
|
|
// Checks that the value `val` is not in an error state. Returns
|
|
// `true` if the test passes, otherwise `false`.
|
|
template <typename T>
|
|
static bool assert_expected_success(llvm::Expected<T> &val) {
|
|
if (!((bool)val)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// Checks that the value `val` is not in an error state. Returns
|
|
// `true` if the test passes, otherwise `false`.
|
|
template <typename T>
|
|
static bool assert_expected_success(llvm::Expected<T> &&val) {
|
|
return assert_expected_success(val);
|
|
}
|
|
|
|
// Checks that the value `val` is not in an error state. Returns
|
|
// `true` if the test passes, otherwise `false`.
|
|
template <typename T>
|
|
static bool assert_expected_failure(llvm::Expected<T> &&val) {
|
|
if (!((bool)val)) {
|
|
if (!mlir::toruslang::dfr::_dfr_is_root_node()) {
|
|
llvm::toString(val.takeError());
|
|
return true;
|
|
}
|
|
// We need to consume the error, so let's do it here
|
|
llvm::errs() << "assert_expected_failure: "
|
|
<< llvm::toString(val.takeError()) << "\n";
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Checks that the value `val` of type `llvm::Expected<T>` is not in
|
|
// an error state.
|
|
#define ASSERT_EXPECTED_SUCCESS(val) \
|
|
do { \
|
|
if (!assert_expected_success(val)) { \
|
|
GTEST_FATAL_FAILURE_("Expected<T> in error state") \
|
|
<< llvm::toString(val.takeError()); \
|
|
} \
|
|
} while (0)
|
|
|
|
// Checks that the value `val` of type `llvm::Expected<T>` is in
|
|
// an error state.
|
|
#define ASSERT_EXPECTED_FAILURE(val) \
|
|
do { \
|
|
if (!assert_expected_failure(val)) \
|
|
GTEST_FATAL_FAILURE_("Expected<T> not in error state"); \
|
|
} while (0)
|
|
|
|
// Checks that the value `val` is not in an error state and is equal
|
|
// to the value given in `exp`. Returns `true` if the test passes,
|
|
// otherwise `false`.
|
|
template <typename T, typename V>
|
|
static bool assert_expected_value(llvm::Expected<T> &val, const V &exp) {
|
|
if (!assert_expected_success(val))
|
|
return false;
|
|
|
|
if (!(val.get() == static_cast<T>(exp))) {
|
|
llvm::errs() << "Expected value " << exp << ", but got " << val.get()
|
|
<< "\n";
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// Checks that the value `val` is not in an error state and is equal
|
|
// to the value given in `exp`. Returns `true` if the test passes,
|
|
// otherwise `false`.
|
|
template <typename T, typename V>
|
|
static bool assert_expected_value(llvm::Expected<T> &&val, const V &exp) {
|
|
return assert_expected_value(val, exp);
|
|
}
|
|
|
|
// Checks that the value `val` of type `llvm::Expected<T>` is not in
|
|
// an error state and is equal to the value of type `T` given in
|
|
// `exp`.
|
|
#define ASSERT_EXPECTED_VALUE(val, exp) \
|
|
do { \
|
|
if (!assert_expected_value(val, exp)) { \
|
|
GTEST_FATAL_FAILURE_("Expected<T> with wrong value") \
|
|
<< llvm::toString(val.takeError()); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define ASSERT_EQ_OUTCOME(val, exp) \
|
|
if (!val.has_value()) { \
|
|
std::string msg = "ERROR: <" + val.error().mesg + "> \n"; \
|
|
GTEST_FATAL_FAILURE_(msg.c_str()); \
|
|
}; \
|
|
ASSERT_EQ(val.value(), exp);
|
|
|
|
#define ASSERT_ASSIGN_OUTCOME_VALUE(ident, val) \
|
|
auto ident__ = val; \
|
|
if (!ident__.has_value()) { \
|
|
std::string msg = "Outcome failure " + ident__.error().mesg; \
|
|
GTEST_FATAL_FAILURE_(msg.c_str()); \
|
|
} \
|
|
auto ident = std::move(ident__.value());
|
|
|
|
#define ASSERT_OUTCOME_HAS_VALUE(val) \
|
|
{ \
|
|
auto tmp = val; \
|
|
if (!tmp.has_value()) { \
|
|
std::string msg = "Outcome failure " + tmp.error().mesg; \
|
|
GTEST_FATAL_FAILURE_(msg.c_str()); \
|
|
} \
|
|
}
|
|
|
|
#define ASSERT_OUTCOME_HAS_FAILURE(val) \
|
|
{ \
|
|
auto tmp = val; \
|
|
if (tmp.has_value()) { \
|
|
GTEST_FATAL_FAILURE_("Outcome value when failure expected"); \
|
|
} \
|
|
}
|
|
|
|
#define ASSERT_OUTCOME_HAS_FAILURE_WITH_ERRORMSG(val, errmsg) \
|
|
{ \
|
|
auto tmp = val; \
|
|
if (tmp.has_value()) { \
|
|
GTEST_FATAL_FAILURE_("Outcome value when failure expected"); \
|
|
} \
|
|
ASSERT_EQ(tmp.error().mesg, errmsg); \
|
|
}
|
|
|
|
#endif
|