Skip to content

Commit

Permalink
fixed: template for transversal_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Nov 12, 2024
1 parent e30d14b commit 82080a9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions prover/crypto/ringsis/templates/transversal_hash.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ringsis_{{.ModulusDegree}}_{{.LogTwoBound}}

import (
"runtime"

"github.com/consensys/gnark-crypto/ecc/bls12-377/fr/fft"
"github.com/consensys/linea-monorepo/prover/maths/common/smartvectors"
"github.com/consensys/linea-monorepo/prover/maths/common/vector"
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/utils"
"github.com/consensys/linea-monorepo/prover/utils/parallel"
ppool "github.com/consensys/linea-monorepo/prover/utils/parallel/pool"
)

{{- $bitPerField := 256}}
Expand Down Expand Up @@ -37,7 +36,6 @@ func TransversalHash(
// To optimize memory usage, we limit ourself to hash only 16 columns per
// iteration.
numColumnPerJob int = 16
numWorker = runtime.NumCPU()

// In theory, it should be a div ceil. But in practice we only process power's
// of two number of columns. If that's not the case, then the function will panic
Expand All @@ -54,18 +52,15 @@ func TransversalHash(
constResults = make([]field.Element, {{.ModulusDegree}})
)

parallel.ExecuteChunky(numJobs, func(start, stop int) {

// We process the columns per segment of `numColumnPerJob`
for i := start; i < stop; i++ {

ppool.ExecutePoolChunky(numJobs, func(i int) {
// We process the columns per segment of `numColumnPerJob`
var (
localResult = make([]field.Element, numColumnPerJob*{{.ModulusDegree}})
limbs = make([]field.Element, {{.ModulusDegree}})

// Each segment is processed by packet of `numFieldPerPoly={{$fieldPerPoly}}` rows
startFromCol = start * numColumnPerJob
stopAtCol = stop * numColumnPerJob
startFromCol = i * numColumnPerJob
stopAtCol = (i + 1) * numColumnPerJob
)

for row := 0; row < len(pols); row += {{$fieldPerPoly}} {
Expand Down Expand Up @@ -137,8 +132,7 @@ func TransversalHash(

// copy the segment into the main result at the end
copy(mainResults[startFromCol*{{.ModulusDegree}}:stopAtCol*{{.ModulusDegree}}], localResult)
}
}, numWorker)
})

// Now, we need to reconciliate the results of the buffer with
// the result for each thread
Expand Down

0 comments on commit 82080a9

Please sign in to comment.