How to Create an Engine
CPU
Basic Engine
Engine()
- This is the default way to create an engine. It requires no additional configuration and supports a multiplicative depth of 7 (i.e. 7 levels).
Maximum Multiplication Count
Engine(max_level)
- Adjusts the engine parameters based on the multiplication count. Within a parameter, the lower the
log_coeff_count
, the faster the operations, but with a limitation on the maximum multiplication count. Memory usage increases with the number of multiplications, so it is recommended to configure the engine based on the required number of multiplications.
from desilofhe import Engine
tiny_engine = Engine(max_level=2)
small_engine = Engine(max_level=7)
medium_engine = Engine(max_level=17)
large_engine = Engine(max_level=36)
huge_engine = Engine(max_level=77)
Custom Parameters
Engine(log_coeff_count, special_prime_count)
- For advanced users, this allows specifying values outside of predefined parameter sets.
log_coeff_count
refers to the binary logarithm of the size of the polynomial.special_prime_count
determines the partition size for key switching.
- Recommended configurations:
from desilofhe import Engine # Multiplication count 0 ~ 2: tiny_engine = Engine(log_coeff_count=13, special_prime_count=1) # Multiplication count 3 ~ 7: small_engine = Engine(log_coeff_count=14, special_prime_count=1) # Multiplication count 8 ~ 16: medium_engine = Engine(log_coeff_count=15, special_prime_count=2) # Multiplication count 17 ~ 34: large_engine = Engine(log_coeff_count=16, special_prime_count=4) # Multiplication count 35 ~ 72: huge_engine = Engine(log_coeff_count=17, special_prime_count=6)
Bootstrap
Engine(use_bootstrap=True)
- For advanced users, use this option to enable bootstrapping. It is created with
log_coeff_count=16
andspecial_prime_count
=4. The bootstrapping feature is not available belowlog_coeff_count=15
, nor starting fromlog_coeff_count=17
because the key size becomes too large.
Multiparty Computation
Engine(use_multiparty=True)
- You can also configure the engine to use multiparty computation. The default configuration supports a multiplicative depth of 4 (i.e. 4 levels). For detailed information on multiparty computation, please refer to the Multiparty Computation page.
from desilofhe import Engine
small_engine = Engine(max_level=1, use_multiparty=True)
medium_engine = Engine(max_level=4, use_multiparty=True)
large_engine = Engine(max_level=12, use_multiparty=True)
huge_engine = Engine(max_level=29, use_multiparty=True)
GPU
-
All the above engine creation methods can be modified to run on GPU by setting the
mode="gpu"
.Engine(mode="gpu")
Engine(max_level=7, mode="gpu")
Engine(log_coeff_count=14, special_prime_count=1, mode="gpu")
Engine(use_bootstrap=True, mode="gpu")
Currently, it is designed for a single device machine, and support for multiple devices will be added in the future. By default, it operates on device 0.
from desilofhe import Engine engine = Engine(mode="gpu") tiny_engine = Engine(max_level=2, mode="gpu") small_engine = Engine(max_level=7, mode="gpu") medium_engine = Engine(max_level=17, mode="gpu") large_engine = Engine(max_level=36, mode="gpu") huge_engine = Engine(max_level=77, mode="gpu") tiny_engine = Engine(log_coeff_count=13, special_prime_count=1, mode="gpu") small_engine = Engine(log_coeff_count=14, special_prime_count=1, mode="gpu") medium_engine = Engine(log_coeff_count=15, special_prime_count=2, mode="gpu") large_engine = Engine(log_coeff_count=16, special_prime_count=4, mode="gpu") huge_engine = Engine(log_coeff_count=17, special_prime_count=6, mode="gpu") bootstrap_engine = Engine(use_bootstrap=True, mode="gpu")
-
512 CUDA threads are used by default. You can adjust the thread count as needed. For example, if you want to set the thread count to 128:
Engine("gpu", thread_count=128)
Engine(max_level, "gpu", thread_count=128)
Engine(log_coeff_count, special_prime_count, "gpu", thread_count=128)
Engine(use_bootstrap=True, mode="gpu", thread_count=128)
CPU Parallel
-
Similar to the GPU configuration, you can enable parallel computation on the CPU by setting
mode="parallel"
for all the engine creation methods.Engine(mode="parallel")
Engine(max_level=7, mode="parallel")
Engine(log_coeff_count=14, special_prime_count=1, mode="parallel")
Engine(use_bootstrap=True, mode="parallel")
from desilofhe import Engine engine = Engine(mode="parallel") tiny_engine = Engine(max_level=2, mode="parallel") small_engine = Engine(max_level=7, mode="parallel") medium_engine = Engine(max_level=17, mode="parallel") large_engine = Engine(max_level=36, mode="parallel") huge_engine = Engine(max_level=77, mode="parallel") tiny_engine = Engine(log_coeff_count=13, special_prime_count=1, mode="parallel") small_engine = Engine( log_coeff_count=14, special_prime_count=1, mode="parallel" ) medium_engine = Engine( log_coeff_count=15, special_prime_count=2, mode="parallel" ) large_engine = Engine( log_coeff_count=16, special_prime_count=4, mode="parallel" ) huge_engine = Engine(log_coeff_count=17, special_prime_count=6, mode="parallel") bootstrap_engine = Engine(use_bootstrap=True, mode="parallel")
-
4 threads are used by default. You can adjust the thread count as needed. For example, if you want to set the thread count to 128:
Engine("parallel", thread_count=128)
Engine(max_level, "parallel", thread_count=128)
Engine(log_coeff_count, special_prime_count, "parallel", thread_count=128)
Engine(use_bootstrap=True, mode="parallel", thread_count=128)