Skip to content

Commit

Permalink
test: re-enable all benchmarks + parallel benchmark for bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
lehugueni committed Jan 21, 2025
1 parent 9074893 commit aa5a921
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 79 deletions.
83 changes: 8 additions & 75 deletions circuits/ckks/bootstrapping/evaluator_benchmarks_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package bootstrapping

import (
"fmt"
"sync"
"testing"
"time"

// "time"

"github.com/stretchr/testify/require"

"github.com/tuneinsight/lattigo/v6/core/rlwe"
"github.com/tuneinsight/lattigo/v6/ring"

"github.com/tuneinsight/lattigo/v6/schemes/ckks"
)
Expand All @@ -33,81 +28,19 @@ func BenchmarkConcurrentBootstrap(b *testing.B) {

b.Run(ParamsToString(params, btpParams.LogMaxDimensions().Cols, "Bootstrap/"), func(b *testing.B) {
var err error
var ctBtp1, ctBtp2 *rlwe.Ciphertext
var wg sync.WaitGroup
eval, err := NewEvaluator(btpParams, evk)
for i := 0; i < b.N; i++ {
b.StopTimer()
ct1 := ckks.NewCiphertext(params, 1, 0)
ct2 := ckks.NewCiphertext(params, 1, 0)
b.StartTimer()
wg.Add(1)
go func(ctIn *rlwe.Ciphertext) {
var err error
defer wg.Done()
ctBtp2, err = eval.Bootstrap(ctIn)
require.NoError(b, err)
}(ct2)
ctBtp1, err = eval.Bootstrap(ct1)
require.NoError(b, err)
wg.Wait()
fmt.Println(ctBtp1.Level(), ctBtp2.Level())
}
require.NoError(b, err)
ct1 := ckks.NewCiphertext(params, 1, 0)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err = eval.Bootstrap(ct1)
}
})
})

}

func BenchmarkAlloc(b *testing.B) {
b.Skip()

paramSet := DefaultParametersDense[0]

params, err := ckks.NewParametersFromLiteral(paramSet.SchemeParams)
require.NoError(b, err)

btpParams, err := NewParametersFromLiteral(params, paramSet.BootstrappingParams)
require.Nil(b, err)

kgen := rlwe.NewKeyGenerator(params)
sk := kgen.GenSecretKeyNew()

evk, _, err := btpParams.GenEvaluationKeys(sk)
require.NoError(b, err)

eval, err := NewEvaluator(btpParams, evk)
require.NoError(b, err)

b.Run("Pool", func(b *testing.B) {

for i := 0; i < b.N; i++ {

pol0 := eval.GetBuffQPPool().Get()
pol1 := eval.GetBuffQPPool().Get()
// pol0 := ringqp.NewPoly()
// pol1 := ringqp.NewPoly()
tmpCt := rlwe.Ciphertext{}
tmpCt.Value = []ring.Poly{pol0.Q, pol1.Q}

eval.GetBuffQPPool().Put(pol0)
eval.GetBuffQPPool().Put(pol1)
}
})
// b.Run("Buff", func(b *testing.B) {
//
// // var err error
//
// for i := 0; i < b.N; i++ {
//
// pol0 := eval.GetBuffQP()[0]
// pol1 := eval.GetBuffQP()[1]
// tmpCt := rlwe.Ciphertext{}
// tmpCt.Value = []ring.Poly{pol0.Q, pol1.Q}
//
// // ScaleDown
// }
// })
}

func BenchmarkBootstrap(b *testing.B) {

b.Skip()
Expand Down
8 changes: 8 additions & 0 deletions core/rlwe/rlwe_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ func benchEvaluator(tc *TestContext, bpw2 int, b *testing.B) {
}
})
}

b.Run(testString(params, params.MaxLevelQ(), params.MaxLevelP(), bpw2, "Evaluator/BuffQPPool"), func(b *testing.B) {
for i := 0; i < b.N; i++ {
pol := eval.BuffQPPool.Get()
eval.BuffQPPool.Put(pol)
}

})
}
8 changes: 4 additions & 4 deletions schemes/ckks/ckks_benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func BenchmarkCKKS(b *testing.B) {
default:
testParams = []ParametersLiteral{
{
LogN: 16,
LogQ: []int{50, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40},
LogN: 14,
LogQ: []int{50, 40, 40, 40, 40, 40, 40, 40},
LogP: []int{60},
LogDefaultScale: 40,
RingType: ring.Standard,
Expand All @@ -37,8 +37,8 @@ func BenchmarkCKKS(b *testing.B) {
tc := NewTestContext(paramsLiteral)

for _, testSet := range []func(tc *TestContext, b *testing.B){
// benchEncoder,
// benchEvaluator,
benchEncoder,
benchEvaluator,
benchEvaluatorParallel,
} {
testSet(tc, b)
Expand Down

0 comments on commit aa5a921

Please sign in to comment.