Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gc load #14

Open
wants to merge 4 commits into
base: tag-20240120-gnark-icicle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 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 Expand Up @@ -225,13 +235,13 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, fullWitness witness.Witness, opts ...b
solver.OverrideHint(r1cs.GkrInfo.ProveHintID, cs.GkrProveHint(r1cs.GkrInfo.HashName, &gkrData)))
}

//solveLock.Lock()
solveLock.Lock()
_solution, err := r1cs.Solve(fullWitness, solverOpts...)
if err != nil {
//solveLock.Unlock()
solveLock.Unlock()
return nil, err
}
//solveLock.Unlock()
solveLock.Unlock()

solution := _solution.(*cs.R1CSSolution)
wireValues := []fr.Element(solution.W)
Expand Down
4 changes: 3 additions & 1 deletion backend/groth16/groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ func Setup(r1cs constraint.ConstraintSystem) (ProvingKey, VerifyingKey, error) {
return nil, nil, err
}
if icicle_bls12377.HasIcicle {
return &icicle_bls12377.ProvingKey{ProvingKey: &pk}, &vk, nil
iciclePk := &icicle_bls12377.ProvingKey{ProvingKey: &pk}
err := icicle_bls12377.SetupDevicePointers(iciclePk)
return iciclePk, &vk, err
}
return &pk, &vk, nil
case *cs_bls12381.R1CS:
Expand Down
2 changes: 1 addition & 1 deletion constraint/bls12-377/solver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.