-
Notifications
You must be signed in to change notification settings - Fork 0
rust examples #28
base: main
Are you sure you want to change the base?
rust examples #28
Conversation
fn main() { | ||
let size = 1 << 23; | ||
let scalars = ScalarCfg::generate_random(size); | ||
let mut ntt_results: DeviceSlice<'_, ScalarField> = DeviceSlice::cuda_malloc(size).unwrap(); |
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 describe the current API, uses HostOrDeviceSlice
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.
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.
The examples are outdated as well and are being updated here https://github.com/ingonyama-zk/icicle/pull/355/files#diff-9aed8b9a6bb53f20c6b8404dc4ec6fa942462b28ea5aaa7e82644901a73424b0R51
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.
oh ok thanks
Using `ScalarCfg::generate_random` we generate random inputs for our `NTT` method, we also initialize the domain `initialize_domain` this generates twiddle factors which will be used to compute NTTs. | ||
|
||
We also create a CUDA stream by calling `CudaStream::create().unwrap()`, this stream will be used to send the data over to the GPU and return the result. | ||
|
||
|
||
By calling `ntt::ntt(scalars.as_slice(), ntt::NTTDir::kForward, &cfg, ntt_results.as_slice()).unwrap();` we send the configurations, scalars and result pointer over to the GPU to preform the NTT computation. | ||
|
||
By default CUDA kernels run in parallel to the CPU, so after triggering your `ntt` method if you need to wait for the result you must synchronize your stream. This can be done easily with `stream.synchronize().unwrap();` your CPU thread will now wait for all CUDA kernels to resolve. | ||
|
||
To retrieve the result you must copy the result from device to host. | ||
|
||
``` | ||
... | ||
ntt_results.copy_to_host(&mut host_bn254_results[..]).unwrap(); | ||
... | ||
``` | ||
|
||
Finally to clean up just destroy the stream you have been using. | ||
|
||
This example covers the basic usage of the ICICLE Rust bindings. |
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.
Its pretty typical for a short example to have the full code and then go line by line explaining whats going on. I know its a lot more to write out but it reads much better and is something anyone would be able to follow
No description provided.