Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

rust examples #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

rust examples #28

wants to merge 2 commits into from

Conversation

ImmanuelSegol
Copy link
Contributor

No description provided.

fn main() {
let size = 1 << 23;
let scalars = ScalarCfg::generate_random(size);
let mut ntt_results: DeviceSlice<'_, ScalarField> = DeviceSlice::cuda_malloc(size).unwrap();
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@jeremyfelder jeremyfelder Jan 29, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh ok thanks

Comment on lines +69 to +88
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.
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants