Skip to content

Commit

Permalink
gc gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiaobleach committed Mar 14, 2024
1 parent a569b26 commit 2158dc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions backend/groth16/bn254/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 @@ -48,6 +49,7 @@ 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 @@ -157,7 +159,7 @@ func (pk *ProvingKey) setupDevicePointers() error {
pk.G1.Z = make([]curve.G1Affine, 1)
pk.G1.K = nil
pk.Domain = fft.Domain{Cardinality: pk.Domain.Cardinality}

runtime.GC()
return nil
}

Expand Down Expand Up @@ -445,11 +447,9 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, fullWitness witness.Witness, opts ...b
log.Debug().Dur("took", time.Since(start)).Msg("prover done")

// free device/GPU memory that is not needed for future proofs (scalars/hpoly)
go func() {
iciclegnark.FreeDevicePointer(wireValuesADevice.P)
iciclegnark.FreeDevicePointer(wireValuesBDevice.P)
iciclegnark.FreeDevicePointer(h)
}()
iciclegnark.FreeDevicePointer(wireValuesADevice.P)
iciclegnark.FreeDevicePointer(wireValuesBDevice.P)
iciclegnark.FreeDevicePointer(h)

return proof, nil
}
Expand Down
11 changes: 6 additions & 5 deletions backend/groth16/bw6-761/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 @@ -48,6 +49,7 @@ 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 @@ -158,6 +160,7 @@ func (pk *ProvingKey) setupDevicePointers() error {
pk.G1.K = nil
pk.Domain = fft.Domain{Cardinality: pk.Domain.Cardinality}

runtime.GC()
return nil
}

Expand Down Expand Up @@ -446,11 +449,9 @@ func Prove(r1cs *cs.R1CS, pk *ProvingKey, fullWitness witness.Witness, opts ...b
log.Debug().Dur("took", time.Since(start)).Msg("prover done")

// free device/GPU memory that is not needed for future proofs (scalars/hpoly)
go func() {
iciclegnark.FreeDevicePointer(wireValuesADevice.P)
iciclegnark.FreeDevicePointer(wireValuesBDevice.P)
iciclegnark.FreeDevicePointer(h)
}()
iciclegnark.FreeDevicePointer(wireValuesADevice.P)
iciclegnark.FreeDevicePointer(wireValuesBDevice.P)
iciclegnark.FreeDevicePointer(h)

return proof, nil
}
Expand Down

0 comments on commit 2158dc6

Please sign in to comment.