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

feat: integrate gpu into sdk #1301

Closed
wants to merge 18 commits into from
41 changes: 21 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"build",
"cli",
"core",
"cuda",
"derive",
"eval",
"helper",
Expand All @@ -15,7 +16,6 @@ members = [
"recursion/gnark-cli",
"recursion/gnark-ffi",
"recursion/program",
"server",
"sdk",
"zkvm/*",
]
Expand Down Expand Up @@ -46,6 +46,7 @@ sp1-build = { path = "build", version = "1.1.1" }
sp1-derive = { path = "derive", version = "1.1.1" }
sp1-core = { path = "core", version = "1.1.1" }
sp1-cli = { path = "cli", version = "1.1.1", default-features = false }
sp1-cuda = { path = "cuda", version = "1.1.1", default-features = false }
sp1-eval = { path = "eval", version = "1.1.0", default-features = false }
sp1-helper = { path = "helper", version = "1.1.1", default-features = false }
sp1-primitives = { path = "primitives", version = "1.1.1" }
Expand Down
5 changes: 4 additions & 1 deletion book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@
- [Usage](./generating-proofs/prover-network/usage.md)
- [Supported Versions](./generating-proofs/prover-network/versions.md)

- [FAQ](./generating-proofs/sp1-sdk-faq.md)
- [Hardware Acceleration](./generating-proofs/hardware-acceleration.md)
- [AVX](./generating-proofs/hardware-acceleration/avx.md)
- [CUDA](./generating-proofs/hardware-acceleration/cuda.md)

- [FAQ](./generating-proofs/sp1-sdk-faq.md)

# Onchain Verification

Expand Down
7 changes: 7 additions & 0 deletions book/generating-proofs/hardware-acceleration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Hardware Acceleration

SP1 supports hardware acceleration on the following platforms:
- [AVX256/AVX512](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions) on x86 CPUs
- [CUDA](https://en.wikipedia.org/wiki/CUDA) on Nvidia GPUs

To enable hardware acceleration, please refer to the platform specific instructions available in this section.
30 changes: 30 additions & 0 deletions book/generating-proofs/hardware-acceleration/avx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# AVX

SP1 supports both AVX256 and AVX512 acceleration on x86 CPUs due to support in [Plonky3](https://github.com/Plonky3/Plonky3).
Whenever possible, we recommend using AVX512 acceleration as it provides better performance.

## Checking for AVX

To check if your CPU supports AVX, you can run the following command:

`grep avx /proc/cpuinfo`

Look for the flags `avx2` and `avx512`.

## Enabling AVX256

To enable AVX256 acceleration, you can set the `RUSTFLAGS` environment variable to include the following flags:

```bash
RUSTFLAGS="-C target-cpu=native" cargo run --release
```

## Enabling AVX512

To enable AVX512 acceleration, you can set the `RUSTFLAGS` environment variable to include the following flags:

```bash
RUSTFLAGS="-C target-cpu=native -C target-feature=+avx512f" cargo run --release
```

Note that the `+avx512f` flag is required to enable AVX512 acceleration.
26 changes: 26 additions & 0 deletions book/generating-proofs/hardware-acceleration/cuda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# CUDA

<div class="warning">
WARNING: CUDA proving is still an experimental feature and may be buggy.
</div>


SP1 supports CUDA acceleration, which can provide dramatically better latency and cost performance
compared to using the CPU prover, even with AVX acceleration.

## Software Requirements

Please make sure you have the following installed before using the CUDA prover:

- [CUDA 12](https://developer.nvidia.com/cuda-12-0-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_local)
- [CUDA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)

## Hardware Requirements

- **CPU**: We recommend having at least 8 CPU cores with 32GB of RAM available to fully utilize the GPU.
- **GPU**: 24GB or more for core/compressed proofs, 40GB or more for shrink/wrap proofs

## Usage

To use the CUDA prover, you can compile the `sp1-sdk` crate with the `cuda` feature enabled. You
can use the normal methods on the `ProverClient` to generate proofs.
21 changes: 1 addition & 20 deletions book/generating-proofs/sp1-sdk-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,4 @@ Example of setting the logging level to `info` (other options are `debug`, `trac

```bash
RUST_LOG=info cargo run --release
```


## Optimize Local Proving with CPU Acceleration

SP1 supports CPU hardware acceleration using AVX256/512 and NEON SIMD instructions. To enable the acceleration, you can use the `RUSTFLAGS` environment variable to generate code that is optimized for your CPU.

**AVX2 / NEON**:
```bash
RUSTFLAGS='-C target-cpu=native' cargo run --release
```

**AVX512**:
```bash
RUSTFLAGS='-C target-cpu=native -C target_feature=+avx512ifma,+avx512vl' cargo run --release
```

## GPU Proving

Note that SP1 has a GPU prover that is currently in beta, but it is not yet supported in the `sp1-sdk` crate and has experimental support in the `sp1-prover` crate. Our prover network currently runs the SP1 GPU prover, so the recommended way to generate proofs with GPU is via the prover network.
```
1 change: 1 addition & 0 deletions core/src/utils/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn setup_logger() {
let default_filter = "off";
let env_filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new(default_filter))
.add_directive("hyper=off".parse().unwrap())
.add_directive("p3_keccak_air=off".parse().unwrap())
.add_directive("p3_fri=off".parse().unwrap())
.add_directive("p3_dft=off".parse().unwrap())
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion server/Cargo.toml → cuda/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "sp1-server"
name = "sp1-cuda"
description = "SP1 is a performant, 100% open-source, contributor-friendly zkVM."
readme = "../README.md"
version = { workspace = true }
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions cuda/proto/api.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";

package api;

service ProverService {
rpc Ready(ReadyRequest) returns (ReadyResponse) {}
rpc ProveCore(ProveCoreRequest) returns (ProveCoreResponse) {}
rpc Compress(CompressRequest) returns (CompressResponse) {}
rpc Shrink(ShrinkRequest) returns (ShrinkResponse) {}
rpc Wrap(WrapRequest) returns (WrapResponse) {}
}

message ReadyRequest {}

message ReadyResponse {
bool ready = 1;
}

message ProveCoreRequest {
bytes data = 1;
}

message ProveCoreResponse {
bytes result = 1;
}

message CompressRequest {
bytes data = 1;
}

message CompressResponse {
bytes result = 1;
}

message ShrinkRequest {
bytes data = 1;
}

message ShrinkResponse {
bytes result = 1;
}

message WrapRequest {
bytes data = 1;
}

message WrapResponse {
bytes result = 1;
}
Loading
Loading