Icicle example: Muli-Scalar Multiplication (MSM)
Key-Takeaway
Icicle provides CUDA C++ template function MSM to accelerate Multi-Scalar Multiplication.
Concise Usage Explanation
- Select the curve
- Include an MSM template
- Configure MSM
- Call the template
#define CURVE_ID 1
#include "icicle/appUtils/msm/msm.cu"
...
msm::MSMConfig config = {...};
...
msm::MSM<scalar_t, affine_t, projective_t>(scalars, points, size, config, &result);
In this example we use BN254 curve (CURVE_ID=1). 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 msm::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 -
large_bucket_factor: distinguishes between large bucket and normal bucket sizes. If there is a scalar distribution that is skewed heavily to a few values we can operate on those separately from the rest of the values. The ideal value here can vary by circuit (based on the distribution of scalars) but start with 10 and adjust to see if it improves performance.
Running the example
cdto your example directory- compile with
./compile.sh - run with
./run.sh
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 the above steps for G2 points