-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update icicle version #18
base: main
Are you sure you want to change the base?
Conversation
var newElement icicle_bn254.Projective | ||
FromG1AffineGnark(&e, &newElement) | ||
|
||
newElements = append(newElements, *StripZ(&newElement)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use newElement.ProjectiveToAffine
. I think it is more future proof for cases where z != 1
fb := f.ToBytesLittleEndian() | ||
var b32 [32]byte | ||
copy(b32[:], fb[:32]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use fp.Bytes here instead of hardcoded values for the size of the array
type OnDeviceData struct { | ||
P unsafe.Pointer | ||
Size int | ||
func MsmOnDevice(gnarkPoints []bn254.G1Affine, gnarkScalars []fr.Element) (*bn254.G1Affine, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous API, MsmOnDevice
was meant to use data already on the device. I suggest we either make a generic MSM function that can accept both DeviceSlice and Host data OR have two separate functions each handling one case
iciclePoints := HostSliceFromPoints(gnarkPoints) | ||
icicleScalars := HostSliceFromScalars(gnarkScalars) | ||
|
||
cfg := core.GetDefaultMSMConfig() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should expose this in the API so users can use streams and change the primitive config depending on their own needs (like setting that points and/or scalars are in Montgomery form).
cfg := core.GetDefaultMSMConfig() | ||
var p icicle_bn254.Projective | ||
var out core.DeviceSlice | ||
_, e := out.Malloc(p.Size(), p.Size()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently only supports a single MSM and not batching. We should update the API to allow for batched MSM operations
} | ||
|
||
func INttOnDevice(scalars_d, twiddles_d, cosetPowers_d unsafe.Pointer, size, sizeBytes int, isCoset bool) unsafe.Pointer { | ||
ReverseScalars(scalars_d, size) | ||
func Ntt[T any](gnarkScalars fr.Vector, dir core.NTTDir, cfg *core.NTTConfig[T]) (fr.Vector, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't support using data already on the device or keeping results on the device for later use
// func INttOnDevice(scalars_d, twiddles_d, cosetPowers_d unsafe.Pointer, size, sizeBytes int, isCoset bool) unsafe.Pointer { | ||
// ReverseScalars(scalars_d, size) | ||
|
||
ReverseScalars(scalars_out, size) | ||
} | ||
// scalarsInterp := icicle_bn254.Interpolate(scalars_d, twiddles_d, cosetPowers_d, size, isCoset) | ||
|
||
func MsmOnDevice(scalars_d, points_d unsafe.Pointer, count int, convert bool) (bn254.G1Jac, unsafe.Pointer, error) { | ||
pointBytes := fp.Bytes * 3 // 3 Elements because of 3 coordinates | ||
out_d, _ := goicicle.CudaMalloc(pointBytes) | ||
// return scalarsInterp | ||
// } | ||
|
||
icicle.Commit(out_d, scalars_d, points_d, count, 10) | ||
// func NttOnDevice(scalars_out, scalars_d, twiddles_d, coset_powers_d unsafe.Pointer, size, twid_size, size_bytes int, isCoset bool) { | ||
// res := icicle_bn254.Ntt(scalars_out, scalars_d, twiddles_d, coset_powers_d, size, twid_size, isCoset) | ||
|
||
if convert { | ||
outHost := make([]icicle.G1ProjectivePoint, 1) | ||
goicicle.CudaMemCpyDtoH[icicle.G1ProjectivePoint](outHost, out_d, pointBytes) | ||
// if res.IcicleErrorCode != core.IcicleErrorCode(0) { | ||
// fmt.Print("Issue evaluating") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove any commented code
func INttOnDevice(scalars_d, twiddles_d, cosetPowers_d unsafe.Pointer, size, sizeBytes int, isCoset bool) unsafe.Pointer { | ||
ReverseScalars(scalars_d, size) | ||
func Ntt[T any](gnarkScalars fr.Vector, dir core.NTTDir, cfg *core.NTTConfig[T]) (fr.Vector, error) { | ||
icicleScalars := core.HostSliceFromElements(BatchConvertFromFrGnark(gnarkScalars)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For ntt, we really only need to convert from uint64 to uint32 since Montgomery form is supported
No description provided.