Skip to content

Commit

Permalink
feat(bench): PoC of integration with zkalc (#425)
Browse files Browse the repository at this point in the history
* feat(bench): PoC of integration with zkalc

* feat(bench): zkalc prepare for adding pairing benches - generic type resulution issue

* feat(bench): add pairing and G2 bench for zkalc and nimble build script

* fix nimble dependencies

* feat(bench-zkalc): polish and output json bench file

* fix(nimble): version gate task-level dependencies

* fix(deps): std/os instead of commandline for 1.6.x and gmp@#head

* fix(deps): .nimble and nimble have different versioning format

* fix(zkalc): workaround generic sandwich bug in Nim 1.6.x nim-lang/Nim#8677 nim-lang/Nim#11225

* fix(zkalc CI): skip zkalc build on 32-bit CI as it needs clang multilib

* fix(zkalc CI): skip Windows as Clang throws fatal error LNK1107
  • Loading branch information
mratsim authored Jul 12, 2024
1 parent 405ec70 commit 52a8fc4
Show file tree
Hide file tree
Showing 38 changed files with 750 additions and 80 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ jobs:
run: |
pacman -S --needed --noconfirm mingw-w64-x86_64-gmp mingw-w64-x86_64-llvm
nimble refresh --verbose -y
nimble install --verbose -y gmp@#head jsony asynctools yaml@1.1.0
nimble install --verbose -y gmp@#head jsony asynctools yaml@1.1.0 cliche
cd constantine
go mod download -modfile=go_test.mod
Expand All @@ -272,7 +272,7 @@ jobs:
shell: bash
run: |
nimble refresh --verbose -y
nimble install --verbose -y gmp@#head jsony asynctools yaml@1.1.0
nimble install --verbose -y gmp@#head jsony asynctools yaml@1.1.0 cliche
cd constantine
go mod download -modfile=go_test.mod
Expand Down Expand Up @@ -337,6 +337,24 @@ jobs:
cd constantine
CTT_ASM=0 cargo test -- --nocapture
- name: Compile Constantine Zkalc benchmark (no assembly)
# Skip 32-bit as that would need clang-multilib or -m32
# Skip Windows as clang throws fatal error LNK1107
if: matrix.target.BACKEND == 'NO_ASM' && matrix.target.cpu != 'i386' && runner.os != 'Windows'
shell: bash
run: |
cd constantine
CTT_ASM=0 nimble make_zkalc
- name: Compile Constantine Zkalc benchmark (with assembly)
# Skip 32-bit as that would need clang-multilib or -m32
# Skip Windows as clang throws fatal error LNK1107
if: matrix.target.BACKEND == 'ASM' && matrix.target.cpu != 'i386' && runner.os != 'Windows'
shell: bash
run: |
cd constantine
nimble make_zkalc
- name: Run Constantine in-depth tests (Unix - with GMP, with Assembly)
if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM'
shell: bash
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Executables shall be put in an ignored build/ directory
# Build artifacts shall be put in an ignored build/ directory
# Ignore dynamic, static libs and libtool archive files
# -----------------------------------------------------------------------------------------
build/
Expand Down Expand Up @@ -54,4 +54,5 @@ Cargo.lock
# Perf artifacts
# -----------------------------------------------------------------------------------------
perf.data
perf.data.old
perf.data.old
*.bench.json
5 changes: 3 additions & 2 deletions benchmarks/bench_elliptic_parallel_template.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ proc multiAddParallelBench*(EC: typedesc, numInputs: int, iters: int) =
type BenchMsmContext*[EC] = object
tp: Threadpool
numInputs: int
coefs: seq[getBigInt(EC.F.Name, kScalarField)]
coefs: seq[getBigInt(EC.getName(), kScalarField)]
points: seq[affine(EC)]

proc createBenchMsmContext*(EC: typedesc, inputSizes: openArray[int]): BenchMsmContext[EC] =
Expand All @@ -66,6 +66,7 @@ proc createBenchMsmContext*(EC: typedesc, inputSizes: openArray[int]): BenchMsmC
const bits = EC.getScalarField().bits()
type ECaff = affine(EC)

result.numInputs = maxNumInputs
result.points = newSeq[ECaff](maxNumInputs)
result.coefs = newSeq[BigInt[bits]](maxNumInputs)

Expand All @@ -81,7 +82,7 @@ proc createBenchMsmContext*(EC: typedesc, inputSizes: openArray[int]): BenchMsmC
var tmp = threadRng.random_unsafe(EC)
tmp.clearCofactor()
points[i].affine(tmp)
coefs[i] = rng.random_unsafe(BigInt[bits])
coefs[i] = threadRng.random_unsafe(BigInt[bits])

let chunks = balancedChunksPrioNumber(0, maxNumInputs, result.tp.numThreads)

Expand Down
Loading

0 comments on commit 52a8fc4

Please sign in to comment.