Skip to content

Commit

Permalink
fix edge case when chunk len is 1 and multithread worker num
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jul 7, 2024
1 parent acd9a42 commit 9e4c04a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
24 changes: 12 additions & 12 deletions encoding/kzg/prover/gpu/multiframe_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func (p *GpuComputeDevice) ComputeMultiFrameProof(polyFr []fr.Element, numChunks
l := chunkLen
numPoly := uint64(len(polyFr)) / dimE / chunkLen
fmt.Println("numPoly", numPoly)
fmt.Println("dimE", dimE)
fmt.Println("l", l)

begin := time.Now()

Expand Down Expand Up @@ -113,6 +115,16 @@ func (p *GpuComputeDevice) ComputeMultiFrameProof(polyFr []fr.Element, numChunks
}
preprocessDone := time.Now()

/*
for i := 0; i < int(l*numPoly); i++ {
vec := coeffStore[i]
for j := 0; j < len(vec); j++ {
fmt.Printf("%v ", vec[j].String())
}
fmt.Println()
}
*/

// Start using GPU
p.GpuLock.Lock()
defer p.GpuLock.Unlock()
Expand All @@ -125,18 +137,6 @@ func (p *GpuComputeDevice) ComputeMultiFrameProof(polyFr []fr.Element, numChunks
}
nttDone := time.Now()

/*
fmt.Println("after fft")
vec := gpu_utils.ConvertScalarFieldsToFrBytes(coeffStoreFft)
for i := 0; i < int(l*numPoly); i++ {
length := int(dimE) * 2
for j := 0; j < length; j++ {
fmt.Printf("%v ", vec[i*length+j].String())
}
fmt.Println()
}
*/

// transpose the FFT tranformed matrix
coeffStoreFftTranspose, err := Transpose(coeffStoreFft, int(l), int(numPoly), int(dimE)*2)
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions encoding/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func readpoints() {
func TestKzgRs() {
isSmallTest := false

numSymbols := 4096 * 8
numSymbols := 4096 / 8
// encode parameters
numNode := uint64(4096) // 200
numSys := uint64(512) // 180
Expand All @@ -72,7 +72,7 @@ func TestKzgRs() {
}

if isSmallTest {
numSymbols = 4
numSymbols = 2
numNode = 4
numSys = 2
numPar = numNode - numSys
Expand All @@ -96,7 +96,7 @@ func TestKzgRs() {
// create encoding object
p, _ := prover.NewProver(kzgConfig, true)

p.UseGpu = true
p.UseGpu = false

params := encoding.EncodingParams{NumChunks: numNode, ChunkLength: uint64(numSymbols) / uint64(numSys)}
enc, _ := p.GetKzgEncoder(params)
Expand Down Expand Up @@ -139,6 +139,11 @@ func TestKzgRs() {
log.Fatal("leading coset inconsistency")
}

// special case when chunk Len =1, we need to artificially use root doubled
if params.ChunkLength == uint64(1) {
j *= 2
}

lc := enc.Fs.ExpandedRootsOfUnity[uint64(j)]

g2Atn, err := kzg.ReadG2Point(uint64(len(f.Coeffs)), kzgConfig)
Expand Down
8 changes: 8 additions & 0 deletions encoding/utils/gpu_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func IcicleProjectiveToGnarkAffine(p bn254_icicle.Projective) bn254.G1Affine {
func HostSliceIcicleProjectiveToGnarkAffine(ps core.HostSlice[bn254_icicle.Projective], numWorker int) []bn254.G1Affine {
output := make([]bn254.G1Affine, len(ps))

if len(ps) < numWorker {
numWorker = len(ps)
}

var wg sync.WaitGroup

interval := int(math.Ceil(float64(len(ps)) / float64(numWorker)))
Expand Down Expand Up @@ -112,6 +116,10 @@ func HostSliceIcicleProjectiveToGnarkAffine(ps core.HostSlice[bn254_icicle.Proje
func ConvertFrToScalarFieldsBytesThread(data []fr.Element, numWorker int) []bn254_icicle.ScalarField {
scalars := make([]bn254_icicle.ScalarField, len(data))

if len(data) < numWorker {
numWorker = len(data)
}

var wg sync.WaitGroup

interval := int(math.Ceil(float64(len(data)) / float64(numWorker)))
Expand Down

0 comments on commit 9e4c04a

Please sign in to comment.