Skip to content
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

Implement ec_gpu:GpuField for Fp/Fq #31

Merged
merged 4 commits into from
Mar 24, 2022
Merged

Implement ec_gpu:GpuField for Fp/Fq #31

merged 4 commits into from
Mar 24, 2022

Conversation

vmx
Copy link
Contributor

@vmx vmx commented Mar 4, 2022

This commit introduces a new feature called "gpu", which enables an
ec_gpu:GpuField implementation of Fp and Fq. This enables the
field arithmetics to be run on a GPU.

The code to convert from a u64 to a u32 vector was taken from
https://github.com/filecoin-project/blstrs/blob/07a84f9727d2fb7387efb2df0f17ddc5d35571d3/src/lib.rs#L102-L108

This commit introduces a new feature called "gpu", which enables an
`ec_gpu:GpuField` implementation of `Fp` and `Fq`. This enables the
field arithmetics to be run on a GPU.

The code to convert from a u64 to a u32 vector was taken from
https://github.com/filecoin-project/blstrs/blob/07a84f9727d2fb7387efb2df0f17ddc5d35571d3/src/lib.rs#L102-L108
Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@str4d
Copy link
Contributor

str4d commented Mar 9, 2022

@vmx can you confirm this will close #22? At the time I opened that issue, it looked to me like we'd need to implement GpuEngine in this crate; has the API changed?

@vmx
Copy link
Contributor Author

vmx commented Mar 9, 2022

@str4d it won't close all things from #22. It will enable finite field arithmetic, but nothing else yet. Though we surely want halo2 to run on the GPU, so I'd consider this PR as a first step towards that goal.

@str4d
Copy link
Contributor

str4d commented Mar 11, 2022

#22 is documented as covering only this change:

  • The curve implementation needs to support producing the GPU kernel for finite field arithmetic.

My question above was, is that what this PR achieves? And what (if any) purpose does the GpuEngine trait (which existed in October last year) serve? (EDIT: I see it still exists.)

src/fields.rs Outdated Show resolved Hide resolved
src/fields/fp.rs Show resolved Hide resolved
src/fields/fq.rs Show resolved Hide resolved
src/fields.rs Show resolved Hide resolved
@vmx
Copy link
Contributor Author

vmx commented Mar 11, 2022

My question above was, is that what this PR achieves?

It will enable finite field arithmetic to be run on GPUs. This can, e.g. be used by Neptune to run Poseidon hashing with the paste curves (lurk-lab/neptune#135).

vmx and others added 2 commits March 11, 2022 17:37
Co-authored-by: str4d <thestr4d@gmail.com>
@DrPeterVanNostrand
Copy link

Hi @str4d

This PR allows the field arithmetic kernel source code to be generated for the Pasta scalar fields using ec_gpu_gen::field::<F>() (for example, as we do in neptune here).

The curve implementation needs to support producing the GPU kernel for finite field arithmetic.

I believe that this PR does that (cc. @vmx). What this PR does not achieve is the ability to generate FFT and MSM kernels for the Pasta curves.

Implementing GpuEngine for the Pallas and Vesta curves would allow for the generation of each curve's FFT and MSM kernel's source code (I believe by calling ec_gpu_gen::gen_source() link). For example, we implement GpuEngine for Bls12 (here) and generate FFT and MSM kernel source code for the G1 and G2 curves in bellperson here.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@str4d str4d merged commit 2796b6b into zcash:main Mar 24, 2022
@vmx vmx deleted the ec-gpu branch March 24, 2022 18:47
@str4d str4d mentioned this pull request Apr 2, 2022
vmx added a commit to filecoin-project/fil_pasta_curves that referenced this pull request Nov 25, 2022
The code base is now on Rust 1.56 and Rust edition 2021. As per
zcash#31 (comment)
the code can now be simplified. This commit is also adding a test
for the u64_to_u32 function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants