mirror of
https://github.com/pseXperiments/icicle.git
synced 2026-01-09 15:37:58 -05:00
1.4 KiB
1.4 KiB
Icicle example: Muli-Scalar Multiplication (MSM)
Key-Takeaway
Icicle provides CUDA C++ template function MSM to accelerate Multi-Scalar Multiplication.
Concise Usage Explanation
- Include the curve api
- Configure MSM
- Call msm api
#include "icicle/api/bn254.h"
...
MSMConfig config = default_msm_config();
...
bn254_msm(scalars, points, size, config, &result);
In this example we use BN254 curve. The function computes result = \sum_{i=0}^{size-1} scalars[i] \cdot points[i], where input points[] use affine coordinates, and result uses projective coordinates.
Parameters:
The configuration is passed to the kernel as a structure of type MSMConfig. Some of the most important fields are listed below:
-
are_scalars_on_device,are_points_on_device,are_results_on_device: location of the data -
is_async: blocking vs. non-blocking kernel call -
In addition can pass backend-specific params via config.extConfig. For example CUDA backend accepts a
large_bucket_factorparam.
Running the example
# for CPU
./run.sh -d CPU
# for CUDA
./run.sh -d CUDA -b /path/to/cuda/backend/install/dir
What's in the example
- Define the parameters of MSM
- Generate random inputs on-host
- Configure and execute MSM using on-host data
- Copy inputs on-device
- Configure and execute MSM using on-device data
- Repeat step 3 G2 msm points