11 unstable releases (4 breaking)

0.5.2 Mar 3, 2023
0.5.1 Dec 1, 2022
0.5.0 Nov 17, 2022
0.3.0 Jun 14, 2022
0.1.2 Nov 16, 2021

#179 in Hardware support

Download history 2093/week @ 2022-12-06 2349/week @ 2022-12-13 712/week @ 2022-12-20 407/week @ 2022-12-27 1602/week @ 2023-01-03 1751/week @ 2023-01-10 1829/week @ 2023-01-17 1457/week @ 2023-01-24 2096/week @ 2023-01-31 2424/week @ 2023-02-07 2284/week @ 2023-02-14 3095/week @ 2023-02-21 2677/week @ 2023-02-28 4437/week @ 2023-03-07 3435/week @ 2023-03-14 2551/week @ 2023-03-21

13,667 downloads per month
Used in 26 crates (2 directly)



CUDA/OpenCL code generator for finite-field arithmetic over prime fields and elliptic curve arithmetic constructed with Rust.

There is also support for Fast Fourier Transform and Multiexponentiation.

This crate usually creates GPU kernels at compile-time. CUDA generates a fatbin, which OpenCL only generates the source code, which is then compiled at run-time.

In order to make things easier to use, there are helper functions available. You would put some code into build.rs, that generates the kernels, and some code into your library which then consumes those generated kernels. The kernels will be directly embedded into your program/library. If something goes wrong, you will get an error at compile-time.

In this example we will make use of the FFT functionality. Add to your build.rs:

use blstrs::Scalar;
use ec_gpu_gen::SourceBuilder;

let source_builder = SourceBuilder::new().add_fft::<Scalar>();

The ec_gpu_gen::generate() takes care of the actual code generation/compilation. It will automatically create a CUDA and/or OpenCL kernel. It will define two environment variables, which are meant for internal use. _EC_GPU_CUDA_KERNEL_FATBIN that points to the compiled CUDA kernel, and _EC_GPU_OPENCL_KERNEL_SOURCE that points to the generated OpenCL source.

Those variables are then picked up by the ec_gpu_gen::program!() macro, which generates a program, for a given GPU device. Using FFT within your library would then look like this:

use blstrs::Scalar;
use ec_gpu_gen::{

let devices = Device::all();
let programs = devices
    .map(|device| ec_gpu_gen::program!(device))
    .collect::<Result<_, _>>()
    .expect("Cannot create programs!");

let mut kern = FftKernel::<Scalar>::create(programs).expect("Cannot initialize kernel!");
kern.radix_fft_many(&mut [&mut coeffs], &[omega], &[log_d]).expect("GPU FFT failed!");

Feature flags

CUDA and OpenCL are supprted, each be enabled with the cuda and opencl feature flags.


~102K SLoC