Skip to content

Commit

Permalink
add gc load
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiaobleach committed Mar 11, 2024
1 parent d02f18f commit 87e78f1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/groth16/bls12-377/icicle/icicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"math/bits"
"runtime"
"sync"
"time"
"unsafe"
Expand Down Expand Up @@ -50,6 +51,9 @@ func (pk *ProvingKey) setupDevicePointers() error {
if pk.deviceInfo != nil {
return nil
}

runtime.GC()

pk.deviceInfo = &deviceInfo{}
n := int(pk.Domain.Cardinality)
sizeBytes := n * fr.Bytes
Expand Down Expand Up @@ -111,6 +115,7 @@ func (pk *ProvingKey) setupDevicePointers() error {

// free
pk.Domain = fft.Domain{Cardinality: pk.Domain.Cardinality}
runtime.GC()

/************************* Start G1 Device Setup ***************************/
/************************* A ***************************/
Expand All @@ -119,13 +124,15 @@ func (pk *ProvingKey) setupDevicePointers() error {
go iciclegnark.CopyPointsToDevice(pk.G1.A, pointsBytesA, copyADone) // Make a function for points
pk.G1Device.A = <-copyADone
pk.G1.A = nil
runtime.GC()

/************************* B ***************************/
pointsBytesB := len(pk.G1.B) * fp.Bytes * 2
copyBDone := make(chan unsafe.Pointer, 1)
go iciclegnark.CopyPointsToDevice(pk.G1.B, pointsBytesB, copyBDone) // Make a function for points
pk.G1Device.B = <-copyBDone
pk.G1.B = nil
runtime.GC()

/************************* K ***************************/
var pointsNoInfinity []curve.G1Affine
Expand All @@ -142,20 +149,23 @@ func (pk *ProvingKey) setupDevicePointers() error {
go iciclegnark.CopyPointsToDevice(pointsNoInfinity, pointsBytesK, copyKDone) // Make a function for points
pk.G1Device.K = <-copyKDone
pk.G1.K = nil
runtime.GC()

/************************* Z ***************************/
pointsBytesZ := len(pk.G1.Z) * fp.Bytes * 2
copyZDone := make(chan unsafe.Pointer, 1)
go iciclegnark.CopyPointsToDevice(pk.G1.Z, pointsBytesZ, copyZDone) // Make a function for points
pk.G1Device.Z = <-copyZDone
pk.G1.Z = make([]curve.G1Affine, 1)
runtime.GC()

/************************* Start G2 Device Setup ***************************/
pointsBytesB2 := len(pk.G2.B) * fp.Bytes * 4
copyG2BDone := make(chan unsafe.Pointer, 1)
go iciclegnark.CopyG2PointsToDevice(pk.G2.B, pointsBytesB2, copyG2BDone) // Make a function for points
pk.G2Device.B = <-copyG2BDone
pk.G2.B = nil
runtime.GC()

return nil
}
Expand Down

0 comments on commit 87e78f1

Please sign in to comment.