How to Create an Engine
Vector (CKKS)
Engine()- This is the default way to create a vector engine. It requires no additional configuration and supports a multiplicative depth of 7 (i.e. 7 levels).
Maximum Level
Engine(max_level)- Adjusts the engine parameters based on the maximum multiplicative Level. In general larger levels require larger slot counts. Memory usage and calculation time increases with the number of levels and the slot count, 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)
Slot count per max_level
| Max Level | Slot Count |
|---|---|
| 0 - 2 | 4096 |
| 3 - 7 | 8192 |
| 8 - 17 | 16384 |
| 18 - 36 | 32768 |
Bootstrap
Engine(bootstrap=True)- Use this option to enable the bootstrapping operation, which restores a ciphertext to have 17 multiplicative levels.
Multiparty Computation
Engine(multiparty=True)- You can also configure the engine to use multiparty computation. The default configuration supports a multiplicative depth of 10 (i.e. 10 levels). For detailed information on multiparty computation, please refer to the Multiparty Computation page.
from desilofhe import Engine
small_multiparty_engine = Engine(max_level=4, multiparty=True)
medium_multiparty_engine = Engine(max_level=10, multiparty=True)
large_multiparty_engine = Engine(max_level=23, multiparty=True)
Slot count per max_level
| Max Level | Slot Count |
|---|---|
| 0 - 4 | 8192 |
| 8 - 10 | 16384 |
| 11 - 23 | 32768 |
Matrix (GL) Engine
Engine(form)- This is the default way to create a matrix engine. It requires no additional configuration and supports a multiplicative depth of 7 (i.e. 7 levels). The shape of the engine is (256, 32, 32).
Shape
Engine(shape)- Adjusts the engine parameters based on the input shape. The shape determines the maximum level. Memory usage and calculation time increases with the shape and the number of levels, so it is recommended to configure the engine based on the required matrix dimension and number of multiplications.
from desilofhe import Engine
tiny_matrix_engine = Engine(shape=(256, 16, 16))
small_matrix_engine = Engine(shape=(256, 32, 64))
medium_matrix_engine = Engine(shape=(256, 64, 64))
Supported Shapes:
| Shape | Max Level |
|---|---|
| (256, 16, 16) | 2 |
| (256, 32, 32) | 7 |
| (256, 64, 64) | 17 |
| (162, 32, 32) | 3 |
| (162, 64, 64) | 9 |
| (162, 128, 128) | 21 |
| (486, 16, 16) | 7 |
| (486, 32, 32) | 16 |
| (486, 64, 64) | 33 |
GPU
-
All the above engine creation methods can be modified to run on GPU by setting the
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") bootstrap_engine = Engine(bootstrap=True, mode="gpu") small_multiparty_engine = Engine(max_level=4, multiparty=True, mode="gpu") medium_multiparty_engine = Engine(max_level=10, multiparty=True, mode="gpu") large_multiparty_engine = Engine(max_level=23, multiparty=True, mode="gpu") matrix_engine = Engine(form="matrix", mode="gpu") tiny_matrix_engine = Engine(shape=(256, 16, 16), mode="gpu") small_matrix_engine = Engine(shape=(256, 32, 64), mode="gpu") medium_matrix_engine = Engine(shape=(256, 64, 64), mode="gpu")-
1024 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(mode="gpu", thread_count=128)Engine(max_level=16, mode="gpu", thread_count=128)Engine(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. 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") 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") matrix_engine = Engine(form="matrix", mode="parallel") tiny_matrix_engine = Engine(shape=(256, 16, 16), mode="parallel") small_matrix_engine = Engine(shape=(256, 32, 64), mode="parallel") medium_matrix_engine = Engine(shape=(256, 64, 64), 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 16:
Engine(mode="parallel", thread_count=16)Engine(max_level=16, mode="parallel", thread_count=16)Engine(bootstrap=True, mode="parallel", thread_count=16)