mratsim / constantine

Constantine: modular, high-performance, zero-dependency cryptography stack for verifiable computation, proof systems and blockchain protocols.
Other
413 stars 44 forks source link

Nvidia MSM proof of concept (serial) #480

Open Vindaar opened 3 weeks ago

Vindaar commented 3 weeks ago

This implements the bucket method on the LLVM target. In principle it is just a direct port of the reference implementation. However, to make it look mostly identical, I added helper macros for for loops and if statements.

In addition, due to the somewhat tricky nature of dealing with LLVM types (especially with respect to pointer types), I added MutableValue and ConstantValue helpers as well as multiple further array types to deal with the different data types part of the calculation.

While I haven't run any benchmarks (or anything resembling a real MSM, only tested with 2 inputs), this is obviously not going to be fast given that it runs entirely in serial.

This was a (to me at least) useful implementation to see how usable one can make the LLVM IR from Nim macros for more complicated code. At the very least it is noticeable that the more complicated the code becomes, the more helper boilerplate code one needs to write to keep it similar to the CPU implementations.