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

Merge dev-dumi into dev #4

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ git submodule update --init --recursive
- cuda NTT
```
cargo run --release -p plonky2_field --features=cuda --example fft
```
```

# Rust

To use a nightly toolchain for Plonky2 by default, you can run

```
rustup override set nightly
```
2 changes: 1 addition & 1 deletion depends/cryptography_cuda
11 changes: 7 additions & 4 deletions plonky2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ repository = "https://github.com/0xPolygonZero/plonky2"
keywords = ["cryptography", "SNARK", "PLONK", "FRI"]
categories = ["cryptography"]
edition = "2021"
build = "build.rs"

[features]
default = ["gate_testing", "parallel", "rand_chacha", "std", "timing"]
gate_testing = []
parallel = ["hashbrown/rayon", "plonky2_maybe_rayon/parallel"]
std = ["anyhow/std", "rand/std", "itertools/use_std"]
timing = ["std"]
cuda =["cryptography_cuda"]
cuda = ["cryptography_cuda"]
no_cuda = ["cryptography_cuda/no_cuda"]
batch =[]
batch = []
cuda_timing = []

[dependencies]
ahash = { version = "0.8.3", default-features = false, features = ["compile-time-rng"] } # NOTE: Be sure to keep this version the same as the dependency in `hashbrown`.
Expand All @@ -31,12 +33,13 @@ plonky2_maybe_rayon = { path = "../maybe_rayon", default-features = false }
num = { version = "0.4", default-features = false, features = ["rand"] }
plonky2_field = { path = "../field", default-features = false }
plonky2_util = { path = "../util", default-features = false }
rand = { version = "0.8.4", default-features = false }
rand = { version = "0.8.5", default-features = false, features = ["std", "std_rng"] }
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive", "rc"] }
serde_json = "1.0"
static_assertions = { version = "1.1.0", default-features = false }
unroll = { version = "0.1.5", default-features = false }
once_cell = { version = "1.18.0" }
cryptography_cuda ={path="../depends/cryptography_cuda", optional=true}

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
Expand All @@ -56,7 +59,7 @@ tynm = { version = "0.1.6", default-features = false }
jemallocator = "0.5.0"

[build-dependencies]
bindgen = "*"
bindgen = { version = "0.68.1" }

[[bin]]
name = "generate_constants"
Expand Down
44 changes: 44 additions & 0 deletions plonky2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,50 @@ Plonky2 is a SNARK implementation based on techniques from PLONK and FRI. It is

Plonky2 is built for speed, and features a highly efficient recursive circuit. On a Macbook Pro, recursive proofs can be generated in about 170 ms.

# Rust

To use a nightly toolchain for Plonky2 by default, you can run

```
rustup override set nightly
```

# Plonky2 on GPU

## Poseidon Hash on GPU (CUDA)

Build the shared library

```
cd cryptography_cuda/cuda/merkle
make lib
make libgpu
```

Run tests (in plonky2 folder)

```
export LD_LIBRARY_PATH=<path-to cryptography_cuda/cuda/merkle>
# CPU-only
cargo test -- --nocapture merkle_trees
# GPU
cargo test --features=cuda -- --nocapture merkle_trees
```

Run benchmarks
```
# CPU
cargo bench merkle
# GPU
cargo bench --features=cuda merkle
```

Run microbenchmarks

```
cd cryptography_cuda/cuda/merkle
./run-benchmark.sh
```

## License

Expand Down
42 changes: 42 additions & 0 deletions plonky2/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,45 @@ extern crate bindgen;
use std::env;
use std::path::{Path, PathBuf};

fn mtbindings() {
let pwd = env::current_dir().unwrap();
let libdir = pwd.parent().unwrap().join("depends/cryptography_cuda/cuda/merkle");
let header_file = libdir.join("merkle.h");

// Tell cargo to look for shared libraries in the specified directory
println!("cargo:rustc-link-search={}", libdir.to_str().unwrap());

// Tell cargo to tell rustc to link the system bzip2
// shared library.
println!("cargo:rustc-link-lib=merkle-gpu");

// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed={}", header_file.to_str().unwrap());

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header(header_file.to_str().unwrap())
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");

// Write the bindings to the $OUT_DIR/bindings.rs file.

let out_path = PathBuf::from("src");

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}

fn main() {
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();

Expand Down Expand Up @@ -78,7 +117,10 @@ fn main() {

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
println!("{}", out_path.to_str().unwrap());

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");

mtbindings();
}
Loading
Loading