mirror of
https://github.com/luxfhe/torus.git
synced 2026-10-30 17:07:26 +00:00
The CPU backend was a Rust crate built on the upstream tfhe library, and the tfhers layer existed to move ciphertexts between that library and this compiler. Both are gone, along with everything that reached into them: the Python module and its MLIR conversions, the client-spec field that carried their parameters, the C++ import/export bridge to their C symbols, and the pybind block that published it. backends/torus-cpu/noise-model stays. It depends on no crypto library — it is the noise arithmetic the optimizer needs, and the optimizer is what this repository's CI builds. The compiler no longer has a CPU backend linked. The replacement is the C++ and GPU kernel path, which is a port rather than a rename, so it is stated here rather than implied.
244 lines
10 KiB
CMake
244 lines
10 KiB
CMake
cmake_minimum_required(VERSION 3.17)
|
|
|
|
project(toruscompiler LANGUAGES C CXX)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|
set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 0)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
# Needed on linux with clang 15 and on MacOS because cxx emits dollars in the optimizer C++ API
|
|
add_definitions("-Wno-dollar-in-identifier-extension")
|
|
add_definitions("-Wno-c++98-compat-extra-semi")
|
|
add_definitions("-Wno-strict-aliasing")
|
|
add_definitions("-Wno-date-time")
|
|
add_definitions("-Wno-suggest-override")
|
|
add_definitions("-Wno-ctad-maybe-unsupported")
|
|
add_definitions("-Wall ")
|
|
add_definitions("-Werror ")
|
|
add_definitions("-Wfatal-errors")
|
|
|
|
# If we are trying to build the compiler with LLVM/MLIR as libraries
|
|
if(NOT DEFINED LLVM_EXTERNAL_TORUSLANG_SOURCE_DIR)
|
|
message(FATAL_ERROR "Torus compiler requires a unified build with LLVM/MLIR")
|
|
endif()
|
|
|
|
# CMake library generation settings.
|
|
set(BUILD_SHARED_LIBS
|
|
OFF
|
|
CACHE BOOL "Default to building a static mondo-lib")
|
|
set(CMAKE_PLATFORM_NO_VERSIONED_SONAME
|
|
ON
|
|
CACHE BOOL "Python soname linked libraries are bad")
|
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN
|
|
ON
|
|
CACHE BOOL "Hide inlines")
|
|
|
|
# The -fvisibility=hidden option only works for static builds.
|
|
if(BUILD_SHARED_LIBS AND (CMAKE_CXX_VISIBILITY_PRESET STREQUAL "hidden"))
|
|
message(FATAL_ERROR "CMAKE_CXX_VISIBILITY_PRESET=hidden is incompatible \
|
|
with BUILD_SHARED_LIBS.")
|
|
endif()
|
|
|
|
set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir) # --src-root
|
|
set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include) # --includedir
|
|
set(MLIR_TABLEGEN_OUTPUT_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
|
|
set(MLIR_TABLEGEN_EXE $<TARGET_FILE:mlir-tblgen>)
|
|
include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
|
|
include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR}/cmake/modules")
|
|
|
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
|
include_directories(${PROJECT_BINARY_DIR}/include)
|
|
link_directories(${LLVM_BUILD_LIBRARY_DIR})
|
|
add_definitions(${LLVM_DEFINITIONS})
|
|
|
|
if(DEFINED LLVM_USE_LINKER AND (NOT ${LLVM_USE_LINKER} STREQUAL ""))
|
|
message(INFO " Using custom Linker: ${CMAKE_LINKER}")
|
|
else()
|
|
message(INFO " Using standard linker")
|
|
endif()
|
|
|
|
# Custom doc generation function
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
|
include(AddToruslangDoc)
|
|
set(TORUSLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Torus Security curves Configuration
|
|
# -------------------------------------------------------------------------------
|
|
include_directories(${PROJECT_SOURCE_DIR}/../../../tools/parameter-curves/torus-security-curves-cpp/include)
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Torus Protocol
|
|
# -------------------------------------------------------------------------------
|
|
set(TORUS_PROTOCOL_DIR "${PROJECT_SOURCE_DIR}/../../../tools/torus-protocol")
|
|
add_subdirectory(${TORUS_PROTOCOL_DIR} torus-protocol)
|
|
get_target_property(TORUS_PROTOCOL_GEN_DIR torus-protocol BINARY_DIR)
|
|
set(TORUS_PROTOCOL_CAPNP_SRC "${TORUS_PROTOCOL_GEN_DIR}/capnp_src_dir/c++/src")
|
|
include_directories(${TORUS_PROTOCOL_GEN_DIR})
|
|
include_directories(${TORUS_PROTOCOL_CAPNP_SRC})
|
|
add_dependencies(mlir-headers torus-protocol)
|
|
install(TARGETS torus-protocol EXPORT torus-protocol)
|
|
install(EXPORT torus-protocol DESTINATION "./")
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Torus Optimizer
|
|
# -------------------------------------------------------------------------------
|
|
|
|
set(TORUS_OPTIMIZER_DIR "${PROJECT_SOURCE_DIR}/../../torus-optimizer")
|
|
set(TORUS_OPTIMIZER_INCLUDE_DIR "${TORUS_OPTIMIZER_DIR}/torus-optimizer-cpp/src/cpp")
|
|
include_directories(${TORUS_OPTIMIZER_INCLUDE_DIR})
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Torus Backends
|
|
# -------------------------------------------------------------------------------
|
|
|
|
set(TORUS_BACKENDS_DIR "${PROJECT_SOURCE_DIR}/../../../backends")
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Torus CPU Configuration
|
|
# -------------------------------------------------------------------------------
|
|
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Torus CPU Noise Model Configuration
|
|
# -------------------------------------------------------------------------------
|
|
|
|
set(TORUS_CPU_NOISE_MODEL_DIR "${TORUS_BACKENDS_DIR}/torus-cpu/noise-model")
|
|
set(TORUS_CPU_NOISE_MODEL_INCLUDE_DIR "${TORUS_CPU_NOISE_MODEL_DIR}/include")
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# RUST DEPS BUNDLE
|
|
# -------------------------------------------------------------------------------
|
|
|
|
set(RUST_DEPS_BUNDLE_DIR "${PROJECT_SOURCE_DIR}/../../../tools/rust_deps_bundle")
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
set(RUST_DEPS_BUNDLE_BUILD_DIR "${RUST_DEPS_BUNDLE_DIR}/target/debug")
|
|
set(RUST_DEPS_BUNDLE_TARGET "")
|
|
else()
|
|
set(RUST_DEPS_BUNDLE_BUILD_DIR "${RUST_DEPS_BUNDLE_DIR}/target/release")
|
|
set(RUST_DEPS_BUNDLE_TARGET "--release")
|
|
endif()
|
|
set(RUST_DEPS_BUNDLE_LIB "${RUST_DEPS_BUNDLE_BUILD_DIR}/librust_deps_bundle.a")
|
|
|
|
ExternalProject_Add(
|
|
rust_deps_bundle_build
|
|
DOWNLOAD_COMMAND ""
|
|
CONFIGURE_COMMAND "" OUTPUT "${RUST_DEPS_BUNDLE_LIB}"
|
|
BUILD_ALWAYS true
|
|
BUILD_COMMAND cargo +nightly-2024-09-30 build ${RUST_DEPS_BUNDLE_TARGET}
|
|
BINARY_DIR "${RUST_DEPS_BUNDLE_DIR}"
|
|
INSTALL_COMMAND cp ${RUST_DEPS_BUNDLE_LIB} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
|
LOG_BUILD ON
|
|
LOG_OUTPUT_ON_FAILURE ON)
|
|
|
|
add_library(rust_deps_bundle STATIC IMPORTED)
|
|
set_target_properties(rust_deps_bundle PROPERTIES IMPORTED_LOCATION "${RUST_DEPS_BUNDLE_LIB}")
|
|
add_dependencies(rust_deps_bundle rust_deps_bundle_build)
|
|
target_link_libraries(rust_deps_bundle INTERFACE dl)
|
|
|
|
# --------------------------------------------------------------------------------
|
|
# Torus Cuda Configuration
|
|
# --------------------------------------------------------------------------------
|
|
option(TORUSLANG_CUDA_SUPPORT "Support Torus CUDA Execution." OFF)
|
|
|
|
set(TORUS_CUDA_DIR "${TORUS_BACKENDS_DIR}/torus-cuda/implementation")
|
|
|
|
if(TORUSLANG_CUDA_SUPPORT)
|
|
remove_definitions("-Werror ")
|
|
message(STATUS "Building with Torus CUDA execution support")
|
|
find_package(CUDAToolkit REQUIRED)
|
|
message(STATUS "Found CUDA version: ${CUDAToolkit_VERSION}")
|
|
message(STATUS "Found CUDA library dir: ${CUDAToolkit_LIBRARY_DIR}")
|
|
link_directories(${CUDAToolkit_LIBRARY_DIR})
|
|
set(TORUS_CUDA_BUILD_TESTS OFF)
|
|
set(TORUS_CUDA_BUILD_BENCHMARKS OFF)
|
|
add_subdirectory(${TORUS_CUDA_DIR} torus-cuda)
|
|
include_directories(${TORUS_CUDA_DIR}/include)
|
|
include_directories(${CUDAToolkit_INCLUDE_DIRS})
|
|
add_compile_options(-DTORUSLANG_CUDA_SUPPORT)
|
|
endif()
|
|
|
|
# --------------------------------------------------------------------------------
|
|
# Python Configuration
|
|
# -------------------------------------------------------------------------------
|
|
option(TORUSLANG_BINDINGS_PYTHON_ENABLED "Enables TorusLang Python bindings." ON)
|
|
|
|
if(TORUSLANG_BINDINGS_PYTHON_ENABLED)
|
|
message(STATUS "TorusLang Python bindings are enabled.")
|
|
|
|
include(MLIRDetectPythonEnv)
|
|
mlir_configure_python_dev_packages()
|
|
set(TORUSLANG_PYTHON_PACKAGES_DIR ${CMAKE_CURRENT_BINARY_DIR}/python_packages)
|
|
else()
|
|
message(STATUS "TorusLang Python bindings are disabled.")
|
|
endif()
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# DFR - parallel execution configuration
|
|
# -------------------------------------------------------------------------------
|
|
option(TORUSLANG_DATAFLOW_EXECUTION_ENABLED "Enables dataflow execution for TorusLang." ON)
|
|
option(TORUSLANG_TIMING_ENABLED "Enables execution timing." ON)
|
|
|
|
if(TORUSLANG_DATAFLOW_EXECUTION_ENABLED)
|
|
message(STATUS "TorusLang dataflow execution enabled.")
|
|
|
|
include(FetchHpxLibrary)
|
|
fetch_hpx_library()
|
|
|
|
add_compile_options(-DTORUSLANG_DATAFLOW_EXECUTION_ENABLED
|
|
-DHPX_DEFAULT_CONFIG_FILE="${PROJECT_SOURCE_DIR}/hpx.ini")
|
|
|
|
else()
|
|
message(STATUS "TorusLang dataflow execution disabled.")
|
|
endif()
|
|
|
|
if(TORUSLANG_TIMING_ENABLED)
|
|
add_compile_options(-DTORUSLANG_TIMING_ENABLED)
|
|
else()
|
|
message(STATUS "TorusLang execution timing disabled.")
|
|
endif()
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Unit tests
|
|
# -------------------------------------------------------------------------------
|
|
option(TORUSLANG_UNIT_TESTS "Enables the build of unittests" ON)
|
|
option(
|
|
TORUSLANG_UNSECURE_DEBUG
|
|
"Totally unsecure mode where secret keys are filled with zeros. Useful to reveal the body of the ciphertexts when using tracing during debug."
|
|
OFF)
|
|
if(TORUSLANG_UNSECURE_DEBUG)
|
|
message(
|
|
WARNING
|
|
"
|
|
#############################################################################
|
|
## ##
|
|
## !!! WARNING !!! ##
|
|
## ##
|
|
## TORUSLANG_UNSECURE_DEBUG option activated ! This means that the ##
|
|
## secret keys generated will provide ZERO security. This should only be ##
|
|
## used for debugging purpose, and NEVER in a production environment. ##
|
|
## ##
|
|
#############################################################################
|
|
")
|
|
add_compile_definitions(TORUSLANG_GENERATE_UNSECURE_SECRET_KEYS)
|
|
add_compile_definitions(TORUSLANG_TEST_KEYCACHE_PATH="UnsecureKeySetCache")
|
|
endif()
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Benchmarks
|
|
# -------------------------------------------------------------------------------
|
|
option(TORUSLANG_BENCHMARK "Enables the build of benchmarks" ON)
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Handling sub dirs
|
|
# -------------------------------------------------------------------------------
|
|
|
|
add_subdirectory(include)
|
|
add_subdirectory(lib)
|
|
add_subdirectory(src)
|
|
add_subdirectory(tests)
|