Skip to content

Feat: Reduced operation via karatsuba multiplication algo - #6

Open
nlok5923 wants to merge 1 commit into
Janmajayamall:mainfrom
nlok5923:main
Open

Feat: Reduced operation via karatsuba multiplication algo#6
nlok5923 wants to merge 1 commit into
Janmajayamall:mainfrom
nlok5923:main

Conversation

@nlok5923

@nlok5923 nlok5923 commented Nov 17, 2023

Copy link
Copy Markdown

Benchmark comparisons

Before Karatsuba Multiplication benchmark

After Karatsuba Multiplication benchmark

@Janmajayamall

Janmajayamall commented Nov 22, 2023

Copy link
Copy Markdown
Owner

I benched the update and apparently mul_lazy without karatsuba multiplication performs worse (albeit by few percent) than normal tensoring.

Benched on m6i.8xlarge:

Command: cargo bench bfv/mul_lazy

Before -

bfv/mul_lazy/n=32768/logq=600
                        time:   [73.258 ms 73.440 ms 73.682 ms]
bfv/mul_lazy/n=32768/logq=700
                        time:   [92.830 ms 93.008 ms 93.139 ms]
bfv/mul_lazy/n=32768/logq=750
                        time:   [99.239 ms 99.371 ms 99.593 ms]

After -

bfv/mul_lazy/n=32768/logq=600
                        time:   [78.425 ms 78.873 ms 79.511 ms]
                        change: [+7.2978% +7.8368% +8.3112%] (p = 0.00 < 0.05)
bfv/mul_lazy/n=32768/logq=700
                        time:   [97.026 ms 97.054 ms 97.078 ms]
                        change: [+4.2935% +4.4167% +4.5578%] (p = 0.00 < 0.05)
bfv/mul_lazy/n=32768/logq=750
                        time:   [104.38 ms 104.48 ms 104.58 ms]
                        change: [+4.6334% +4.8922% +5.1423%] (p = 0.00 < 0.05)

I think it is probably due to many non-assign operations required for karatsuba multiplication.

I think before going ahead with merging this, we shall figure out how to improve non-assign vector modular arithmetic operations.

Comment thread bfv/src/evaluator.rs
pq_ctx.mul_assign(&mut c00, &c10); // r02

let sum_r0r2 = pq_ctx.add(&c_r0, &c_r2);
pq_ctx.sub_assign(&mut c00, &sum_r0r2); // r00

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of implementation introduced an extra assignment and i think we can get rid of it.

Do you think this might hindering the performance ?

@Janmajayamall Janmajayamall Nov 23, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think replacing one add with 2 sub_assigns will make up for 4-5% in performance degradation. Just a reminder for me to look into vector modular operations to check what can be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants