엔진 생성 방법
CPU
기본
Engine()
-
제일 기본적인 엔진 생성 방식입니다. 아무것도 추가로 설정할 필요없이 최대 7번까지의 곱셈을 지원합니다.
최대 곱셈 횟수 지정
Engine(max_level)
-
곱셈 횟수에 따라서 엔진의 파라미터를 조정할 수 있습니다. 파라미터의
log_coeff_count
가 낮을 수록 연산은 빠르지만, 최대 곱셈횟수에 제한이 있습니다. 메모리 사용량도 곱셈 횟수가 높을수록 커지기 때문에, 필요한 곱셈 횟수만큼만 설정하는 것을 권장합니다.
파라미터 지정
Engine(log_coeff_count, special_prime_count)
-
전문가용입니다. 사전에 구성된 티어들 이외의 값을 지정하고 싶을 때 사용할 수 있습니다. coeff_count는 하나의 ciphertext에 암호화되는 계수의 숫자를 의미하고,
log_coeff_count
는 거기에 log를 취한 값입니다.special_prime_count
는 키 스위칭을 할 때 하나의 파티션의 크기를 지정합니다.- 권장 설정값은 다음과 같습니다.
- 곱셈 횟수 0 ~ 2: 13, 1
- 곱셈 횟수 3 ~ 7: 14, 1
- 곱셈 횟수 8 ~ 17: 15, 2
- 곱셈 횟수 18 ~ 36: 16, 4
- 곱셈 횟수 37 ~ 77: 17, 6
from desilofhe import Engine tiny_engine = Engine(log_coeff_count=13, special_prime_count=1) small_engine = Engine(log_coeff_count=14, special_prime_count=1) medium_engine = Engine(log_coeff_count=15, special_prime_count=2) large_engine = Engine(log_coeff_count=16, special_prime_count=4) huge_engine = Engine(log_coeff_count=17, special_prime_count=6)
- 권장 설정값은 다음과 같습니다.
부트스트랩(부트스트랩) 사용
Engine(use_bootstrap=True)
-
전문가용입니다. 부트스트랩을 사용하고 싶을 때 사용할 수 있습니다. log_coeff_count 16, special_prime_count 4로 생성됩니다. 15 이하에서는 부트스트랩이 기능하지 않고, 17부터는 키가 너무 커서 일단 지원하지 않습니다.
다자간 연산 사용
Engine(use_multiparty=True)
-
자세한 사용법에 대해서는 다자간 연산 페이지를 참고하세요.
GPU
-
위의 네가지 생성 방법 모두에
gpu
라는 모드를 줄 경우에 모든 연산이 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")
현재 device 1개의 머신만을 상정해서 개발되었습니다. 추후에 여러 device를 지원할 예정입니다. 현재는 기본적으로 0번 device에서 동작합니다.
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 스레드를 사용합니다. 스레드 갯수를 조절하고 싶으면 추가로 스레드 갯수를 지정할 수 있습니다.
Engine("gpu", thread_count=thread_count)
Engine(max_level, "gpu", thread_count=thread_count)
Engine(log_coeff_count, special_prime_count, "gpu", thread_count=thread_count)
Engine(use_bootstrap=True, mode="gpu", thread_count=thread_count)
CPU Parallel
-
위의 네가지 생성 방법 모두에
parallel
라는 모드를 줄 경우에 모든 연산이 CPU에서 병렬로 수행됩니다.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개의 연산 스레드를 사용합니다. 스레드 갯수를 조절하고 싶으면 추가로 스레드 갯수를 지정할 수 있습니다.
Engine("parallel", thread_count=thread_count)
Engine(max_level, "parallel", thread_count=thread_count)
Engine(log_coeff_count, special_prime_count, "parallel", thread_count=thread_count)
Engine(use_bootstrap=True, mode="parallel", thread_count=thread_count)