Hecatia
Thesis で作っているHEコンパイラ
Hecatia: Homomorphic Encryption Compiler for Auto-vectorizaTIon using equAlity-saturation
Architecture
Rustを用い, cargo workspace として複数の crate(パッケージのこと)に分けている
homc: CLIhomir: HomIRhomir-codegen-lattigo: HomIR -> Lattigohomir-interpreter: HomIR のインタプリタhomir-profile: HomIR 実行時のプロファイルのビジュアライザhomml: HomML 定義, HomML -> HomIR へのloweringhomml-optimizer: Equality Saturation による式表現最適化executor(Go): Lattigo 実行用homml-kernels: HomML で書かれたHEアプリケーション
コンパイラ
書き換え規則
-
準同型演算に関するもの
- 可換性
hom-add-comm:(+ ?a ?b) => (+ ?b ?a)hom-sub-comm:(- ?a ?b) => (- ?b ?a)hom-mul-comm:(* ?a ?b) => (* ?b ?a)hom-add-self:(+ ?a ?a) => (* ?a (ecd (const 2)))hom
- 結合性
hom-add-assoc:(+ ?a (+ ?b ?c)) <=> (+ (+ ?a ?b) ?c)
- 分配律
hom-add-dist:(+ (* ?a ?c) (* ?b ?c)) => (* (+ ?a ?b) ?c)
- 0元
hom-mul-0hom-rot-0
- 単位元
hom-mul-1
- 可換性
-
simd_index_op
(vec (# ?a 1) (?a 3) (?a 2) (?a 4))
=> (simd-index-op)
(lintrans ?a (vec 1 3 2 4))
simd_bin_op
(vec (+ ?a1 ?b1) (+ ?a2 ?a2) ...)
=> (simd-bin-op)
(+. (vec ?a1 ?a2 ...) (vec ?b1 ?b2 ...))
-
ループに関するもの
-
(+ (+ (* x 3) x) (* x 3)) => (let _1 (* x 3)); (+ (+ _1 x) _1)
-
rep .+を+を変換するrule ✅ 2024-07-17 -
行列積しかしない計算グラフならパッキングの段階で予め転置した状態で入れたい
- やはり最適なデータ配置も考える?
-
blur filterの最適化もしよう ✅ 2024-07-17
-
各IR毎に実行時間取れるように ✅ 2024-07-17
-
profileコマンド, 個で比較できるように ✅ 2024-07-17- 変えて和積の計測とかしたいので
-
optimizeにかかった時間表示
-
egg v0.9 に上げよう
-
solverを使うoption
-
explanationでは CSE やるが, lowering の時にしてくれないので、自前で実装する必要がある ✅ 2024-07-17
- criticalな部分ではないが実装する必要あり
-
Total Sum folding
-
ポスター Equality Saturation 部分
-
- 今日実装まで終わったら良い
- rewrite ruleを考える
-
Transclude of porcupine-a-synthesizing-compiler-for-vectorized-homomorphic-encryption#he-kernels
-
Applications
-
benchmark は Porcupine によって考案された
- extended version に擬似コードある
- IEEEなので見れなかった
- extended version に擬似コードある
-
no inter-element dependencies
- ex. 線形方程式
-
simple accumulator patterns
- ハミング距離()
- に対して
NEQ(a,b)=XOR(a,b)=
- に対して
- L2距離()
- ハミング距離()
-
complex dependencies across a multitude defferent vector elements
- ex. (平方根なし) Roberts cross - Wikipedia
-
64x64ピクセルの画像を表す長さ4096のベクトル
-
- 色々issues潰した
- rescale opで扱えるように ✅ 2024-07-17
- bootstrap
bs: idみたいに明示的に呼べるように ✅ 2024-07-17 - op毎のlevel, 精度, 時間とかprofiling出来るように
-
if/elsesupport ✅ 2024-07-17 - interactive support ✅ 2024-07-17
- idea
magnetizer: local callでもgRPCでも統一的にfn呼べるcrate - serdeの機能で様々な形態のJSONを列挙型として扱う - igagurimk2の日記
-
hommlで一通りlambdaのサポートが出来た ^7774ba- 行列積が正しくないのは
-
matmul動くまでバグ取り
- バグ修正
- homml-optimizer SIMD
- 線形変換 は遅い?
- 小さいケースだとマスクしてrotした方が早い
- shift network について調査, 実装?
- インデックスアクセス構文の導入
- スライド by 2022-09-21
2022-05-16 parserplain-executoroptimizerconnector
作っていた
- lowering 完成
- set_index 動くように
- egg:
Applierを作った - Increasing number of attempts ver. 2021 - Speaker Deck
- 試行回数の増やし方: ITエンジニアリングのエッセンスが詰まっている
- Microsoft SEAL
- について計算順序の違いで誤差とか変わるか検証
実験 HEカーネルに対するコンパイル時最適化時間
\begin{table}
\centering
\caption{HEカーネルに対する最適化時間}
\begin{tabular}{llll}
\toprule
{} & baseline(ms) & 等式飽和(ms) & ソルバ(ms) \\
kernel & & & \\
\midrule
内積($n=4$) & 0.1242 & 51.9 & 42.69 \\
行列積($d=2$) & 0.4154 & 79.53 & - \\
行列積($d=3$) & - & 125.7 & 151.4 \\
\bottomrule
\end{tabular}
\end{table}実験: 生成されたHEカーネルに対する実行時間
\begin{table}
\centering
\caption{生成されたHEカーネルに対する実行時間}
\begin{tabular}{llll}
\toprule
{} & baseline(ms) & 等式飽和(ms) & ソルバ(ms) \\
kernel & & & \\
\midrule
内積($n=4$) & - & - & - \\
行列積($d=2$) & - & - & - \\
行列積($d=3$) & - & - & - \\
\bottomrule
\end{tabular}
\end{table}-
flatten_then修正 -
homcoptimize -> lowering -> codegen コマンドを分離 -
loweringのバグ修正, golangで未使用な変数が生成されないように -
op-get-exchange規則を追加し, Total Sum > rewrite が出来るように
(let v (ecd (const 1)))
(let c (enc v)) @local
のとき, ASTは上から順に構築するので1Passでは v に @local を付けられない
-
逆順で
Ir[]iterしてpropagateさせた -
mult_depthも全体だけで良いのでIR列に対して計算できれば良い- profileで途中のscale, level追いたくなったら後から
Ir[]にコメント挿入すれば良い
- profileで途中のscale, level追いたくなったら後から
-
#,#=はmacro
- CBC solverで解く時にどういう定式化をしているか ✅ 2024-07-17
(let i 0 (let j 1 (then
(let k 0 (+. i k)) => (+. i 0)
(let k 1 (+. i k)) => (+. i 1)
)))
when it has no changes before and after let-expand in data. E-Graph is regarded as saturated.
2022-12-07
これ治ったと思ったが治っていない? todo
-
行列積 HE kernel について で
- naive
- simd化された
-
で最適化時間, 速度, 命令数, ノイズ推移比較
-
lattigo の線形変換を調査する
-
スカラ演算をvectorizeする
simdruleをexample実装する- `(vec (#. ? ?) (#. ? ?) …) -> (# (vec ? ? …) (vec ? ? …))
-
lintrans演算を実装する
- 順不同で
(get a i)をまとめられるようにする- まずはランダムな順番の
(get a i)を(lintrans a (vec i i i i))に出来るように - 行, 列, diagな
(get)をまとめられるように ✅ 2024-07-17
- まずはランダムな順番の
- ループ展開をしたものに対して上手く
(lintrans)に出来るかどうか ✅ 2024-07-17 - profileモードで出力したJSONを
react-flowで可視化 ✅ 2024-07-17- 各depthでのノイズ量とかみたい ✅ 2024-07-17
- HE Girl 「可換性, 結合性を書き換え規則に含めると状態数が爆発するので注意
[1]」
- 線形変換による方法とSIMD化されたものの比較 ✅ 2024-07-17
- compileするときにoptエラー
- mlの要素 ex.
(vec 4 5 6 7) => (vec 6 6 6 7)自体が書き換わっているのでmergeあたりか?
- mlの要素 ex.
-
flatten_thenを作る 2.5h - 線形変換自体を最適化する ✅ 2024-07-17
- compileするときにoptエラー
- IRの mult-depth バグ修正 3.5h
- 愚直にshift networkを作ってそれを最適化(=回転量最小化)するでも良さそう
- naiveな行列積から 線形変換によるHE行列積 への変換を構成する.
Secure Outsourced Matrix Computation and Application to Neural Networks > 2 3 Linear Transfomations
- profileにtimeを追加してop毎に時間出せるようにする
- lintrans-matmulとcompiler-optimized-matmulの比較をする
indexingから線形変換為の定数行列を作成するコードwip
- ループ展開せずに
repに対し直接変換出来たら良いと思って repのループ定数の直積 ex.i => 0..2, j in 0..2 => (i, j) = [(0, 0), (0, 1), (1, 0), (1, 1)]から直積を作成しループ変数を使う式ex. i + j = [0, 1, 1, 2]を評価して定数化する- -> 辛いので, indexing列から定数行列作る