Skip to content

Commit

Permalink
fix(gpu-explorations): add feature flags for root toml and modify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
moven0831 committed Apr 17, 2024
1 parent a279c1d commit fc0c972
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ exclude = ["mopro-cli-example"]
# See https://github.com/wasmerio/wasmer/commit/09c7070
wasmer = { git = "https://github.com/oskarth/wasmer.git", rev = "09c7070" }

# NOTE: For gpu exploration on zprize works
ark-bls12-377-3 = { git = 'https://github.com/arkworks-rs/curves.git', package = 'ark-bls12-377', tag = 'v0.3.0' }
ark-ec-3 = { git = 'https://github.com/arkworks-rs/algebra.git', package = 'ark-ec', tag = 'v0.3.0', features = ["parallel"] }
ark-ff-3 = { git = 'https://github.com/arkworks-rs/algebra.git', package = 'ark-ff', tag = 'v0.3.0', features = ["parallel"] }
ark-serialize-3 = { git = 'https://github.com/arkworks-rs/algebra.git', package = 'ark-serialize', tag = 'v0.3.0' }
ark-std-3 = { git = 'https://github.com/arkworks-rs/std.git', package = 'ark-std', tag = 'v0.3.0' }
# NOTE: For gpu exploration on zprize works, will only compile when `gpu-benchmarks` feature is enabled
ark-bls12-377-3 = { git = 'https://github.com/arkworks-rs/curves.git', package = 'ark-bls12-377', tag = 'v0.3.0', optional = true}
ark-ec-3 = { git = 'https://github.com/arkworks-rs/algebra.git', package = 'ark-ec', tag = 'v0.3.0', features = ["parallel"], optional = true }
ark-ff-3 = { git = 'https://github.com/arkworks-rs/algebra.git', package = 'ark-ff', tag = 'v0.3.0', features = ["parallel"], optional = true }
ark-serialize-3 = { git = 'https://github.com/arkworks-rs/algebra.git', package = 'ark-serialize', tag = 'v0.3.0', optional = true }
ark-std-3 = { git = 'https://github.com/arkworks-rs/std.git', package = 'ark-std', tag = 'v0.3.0', optional = true }
52 changes: 31 additions & 21 deletions mopro-core/gpu_explorations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,52 @@ There are currently 2 algorithms for benchmarking:

### mopro-core tests

To run the benchmarks for the benchmarking test in `mopro-core`:
`cargo test --release --features gpu-benchmarks --package mopro-core --lib -- middleware::gpu_explorations::<algorithm_you_want_to_test>::tests::test_run_multi_benchmarks --exact --nocapture`
To run the benchmarks of the instance size of $2^{16}$ on BLS12_377 curve in `mopro-core`, replace `<algorithm_you_want_to_test>` with the algorithm name listed above.

replace `<algorithm_you_want_to_test>` with the algorithm name listed above.
```bash
cargo test --release --features gpu-benchmarks --package mopro-core --lib -- middleware::gpu_explorations::<algorithm_you_want_to_test>::tests::test_run_benchmark --exact --nocapture
```

Run the benchmarks for multiple instance size. You can customize your own benchmark parameters on modular files in `mopro-core\src\middleware\gpu_explorations`
```bash
cargo test --release --features gpu-benchmarks --package mopro-core --lib -- middleware::gpu_explorations::<algorithm_you_want_to_test>::tests::test_run_multi_benchmarks --exact --nocapture
```

it would start generating `points` (on `bls12-377`) and `scalars` (32-bytes) under `mopro-core/src/middlware/gpu-explorations/utils/vectors/`. And after that it will begin to benchmark.
More context about the benchmark:
- It would generate instances size on BLS12_377 curve with scalar size of 32 bytes (i.e. can represent 0 to $2^{256}-1$ unsigned integer.) in `mopro-core/src/middlware/gpu-explorations/utils/vectors/`
- The instance size mean the amount of points and scalars.
- The msm time is linear to the size of instance.

The results are as below:

```bash
Vectors already generated
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 47.739041ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 48.719542ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 49.344042ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 48.545792ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 48.26825ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 48.587625ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 48.371541ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 49.861625ms
Average time to execute MSM with 4096 points and scalars in 1 iterations is: 48.5495ms
Done running benchmark.
12x5 result: BenchmarkResult {
instance_size: 12,
num_instance: 5,
avg_processing_time: 48.66521755555556,
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 195.635083ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 206.639791ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 205.1675ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 197.742167ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 207.147166ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 199.729459ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 203.080416ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 198.15875ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 201.636916ms
Average time to execute MSM with 65536 points and scalars in 1 iterations is: 210.273792ms
Done running benchmark. Check the result at: "../mopro-core/benchmarks/gpu_explorations"
16x10 result: BenchmarkResult {
instance_size: 16,
num_instance: 10,
avg_processing_time: 202.52110399999998,
}
...
```

### mopro-ios benchmarking

1. cd to the root dir.
1. cd to the `mopro/` directory.
2. run `./scripts/build_ios.sh config-example.toml` (remember to change your ios_device_type `simulator`/`device`) to build and update the bindings.
3. open `mopro-ios/MoproKit/Example/MoproKit.xcworkspace` in Xcode.
4. choose your simulator/mobile device and use `cmd + R` to build.
5. choose `MSMBenchmark` and choose the algorithms and click the button below you want to start benchmark
4. choose your simulator/mobile device and build the project (can also use `cmd + R` as hot key).
5. choose `MSMBenchmark` and choose the algorithms and click the button below you want to start benchmark.

### `ExampleGpuExploration` in templates

Expand Down
2 changes: 1 addition & 1 deletion mopro-ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ To test bindings in release mode without warning:

1. Comment `default=[]` and uncomment `default=["gpu-benchmarks"]` to enable `gpu-benchmarks` feature flag
2. run `RUSTFLAGS="-C opt-level=3" cargo test --test test_generated_bindings --release`
3. The report will be generated at `mopro-core/benchmarks/gpu_explorations/msm_bench_swift_laptop.csv`
3. The benchmark result will be shown in the console log

![msm benchmarks of time (rust vs. swift)](https://hackmd.io/_uploads/BkxRMMtca.png)

Expand Down
10 changes: 0 additions & 10 deletions mopro-ios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,3 @@ There are two ways to run tests for the example app:
```sh
xcodebuild -showdestinations -workspace MoproKit.xcworkspace -scheme MoproKit-Example
```

## Run MSM Benchmark

1. `cd mopro-ffi/` and convert `default=[]` into `default=["gpu-benchmarks"]` to enable `gpu-benchmarks` feature flag
2. run `make` to build the mopro-ffi library
3. `cd mopro/` and run `./scripts/build_ios.sh config-example.toml` to build IOS app and link
* remember to alter the `ios_device_type` in `config-example.toml`
* `simulator`: running on the simulator (default)
* `device`: running on a real IOS device
4. Open `MoproKit/Example/MoproKit.xcworkspace` in Xcode and `cmd + R` for building

0 comments on commit fc0c972

Please sign in to comment.