-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(benchmark): introduce
FFTBatch
and CosetLDEBatch
benchmark
- Loading branch information
Showing
17 changed files
with
580 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
load( | ||
"//bazel:tachyon_cc.bzl", | ||
"tachyon_cc_binary", | ||
"tachyon_cc_library", | ||
) | ||
|
||
tachyon_cc_library( | ||
name = "fft_batch_config", | ||
testonly = True, | ||
srcs = ["fft_batch_config.cc"], | ||
hdrs = ["fft_batch_config.h"], | ||
deps = [ | ||
"//benchmark:config", | ||
"//benchmark:field_type", | ||
"//tachyon/base/console", | ||
"//tachyon/base/containers:container_util", | ||
"//tachyon/base/flag:flag_parser", | ||
], | ||
) | ||
|
||
tachyon_cc_library( | ||
name = "fft_batch_runner", | ||
testonly = True, | ||
hdrs = ["fft_batch_runner.h"], | ||
deps = [ | ||
":fft_batch_config", | ||
"//benchmark:simple_reporter", | ||
"//tachyon/base/containers:container_util", | ||
"//tachyon/base/time", | ||
"//tachyon/c/math/matrix", | ||
"//tachyon/math/matrix:matrix_types", | ||
"//tachyon/math/polynomials/univariate:radix2_evaluation_domain", | ||
], | ||
) | ||
|
||
tachyon_cc_binary( | ||
name = "fft_batch_benchmark", | ||
testonly = True, | ||
srcs = ["fft_batch_benchmark.cc"], | ||
deps = [ | ||
":fft_batch_config", | ||
":fft_batch_runner", | ||
"//benchmark:simple_reporter", | ||
"//benchmark/fft_batch/plonky3", | ||
"//tachyon/c/math/finite_fields/baby_bear", | ||
"//tachyon/math/matrix:matrix_types", | ||
"//tachyon/math/polynomials/univariate:radix2_evaluation_domain", | ||
"@com_google_absl//absl/strings", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# FFTBatch/CosetLDEBatch Benchmark | ||
|
||
## CPU | ||
|
||
``` | ||
Run on 13th Gen Intel(R) Core(TM) i9-13900K (32 X 5500 MHz CPU s) | ||
CPU Caches: | ||
L1 Data 48 KiB (x16) | ||
L1 Instruction 32 KiB (x16) | ||
L2 Unified 2048 KiB (x16) | ||
L3 Unified 36864 KiB (x1) | ||
Run on Apple M3 Pro (12 X 4050 MHz) | ||
CPU Caches: | ||
L1 Data 64 KiB (x12) | ||
L1 Instruction 128 KiB (x12) | ||
L2 Unified 4096 KiB (x12) | ||
``` | ||
|
||
### FFTBatch | ||
|
||
```shell | ||
bazel run -c opt --//:has_openmp --//:has_rtti --//:has_matplotlib //benchmark/fft_batch:fft_batch_benchmark -- -k 16 -k 17 -k 18 -k 19 -k 20 -k 21 -k 22 -k 23 --vendor plonky3 -p baby_bear --check_results | ||
``` | ||
|
||
#### On Intel i9-13900K | ||
|
||
| Exponent | TachyonCPU | Plonky3 | | ||
| :------- | ------------ | ------------ | | ||
| 16 | **0.003543** | 0.005809 | | ||
| 17 | **0.007168** | 0.009239 | | ||
| 18 | 0.027791 | **0.023848** | | ||
| 19 | 0.063468 | **0.049085** | | ||
| 20 | 0.133178 | **0.102343** | | ||
| 21 | 0.238817 | **0.208557** | | ||
| 22 | 0.507061 | **0.427260** | | ||
| 23 | 1.11136 | **0.922439** | | ||
|
||
![image](/benchmark/fft_batch/fft_batch_benchmark_ubuntu_i9.png) | ||
|
||
#### On Mac M3 Pro | ||
|
||
| Exponent | TachyonCPU | Plonky3 | | ||
| :------- | ------------ | -------- | | ||
| 16 | **0.007926** | 0.01639 | | ||
| 17 | **0.016391** | 0.024321 | | ||
| 18 | **0.035098** | 0.085961 | | ||
| 19 | **0.076266** | 0.096928 | | ||
| 20 | **0.145975** | 0.151024 | | ||
| 21 | **0.309752** | 0.339549 | | ||
| 22 | **0.674991** | 2.66605 | | ||
| 23 | **1.727520** | 7.79002 | | ||
|
||
![image](/benchmark/fft_batch/fft_batch_benchmark_mac_m3.png) | ||
|
||
### CosetLDEBatch | ||
|
||
```shell | ||
bazel run -c opt --//:has_openmp --//:has_rtti --//:has_matplotlib //benchmark/fft_batch:fft_batch_benchmark -- -k 16 -k 17 -k 18 -k 19 -k 20 -k 21 -k 22 -k 23 --vendor plonky3 -p baby_bear --run_coset_lde --check_results | ||
``` | ||
|
||
#### On Intel i9-13900K | ||
|
||
| Exponent | TachyonCPU | Plonky3 | | ||
| :------- | ------------ | -------- | | ||
| 16 | **0.008384** | 0.018529 | | ||
| 17 | **0.017164** | 0.043266 | | ||
| 18 | **0.052999** | 0.093348 | | ||
| 19 | **0.128624** | 0.19531 | | ||
| 20 | **0.246412** | 0.418079 | | ||
| 21 | **0.508587** | 0.816136 | | ||
| 22 | **1.071360** | 1.63289 | | ||
| 23 | **2.225130** | 3.53348 | | ||
|
||
![image](/benchmark/fft_batch/coset_lde_batch_benchmark_ubuntu_i9.png) | ||
|
||
#### On Mac M3 Pro | ||
|
||
| Exponent | TachyonCPU | Plonky3 | | ||
| :------- | ------------ | ------------ | | ||
| 16 | **0.013503** | 0.020251 | | ||
| 17 | **0.028850** | 0.044731 | | ||
| 18 | 0.061675 | **0.055980** | | ||
| 19 | 0.132670 | **0.113062** | | ||
| 20 | **0.263582** | 0.300933 | | ||
| 21 | **0.548267** | 0.573641 | | ||
| 22 | **1.164400** | 1.19051 | | ||
| 23 | **2.818220** | 5.11368 | | ||
|
||
![image](/benchmark/fft_batch/coset_lde_batch_benchmark_mac_m3.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include <iostream> | ||
|
||
#include "absl/strings/substitute.h" | ||
|
||
// clang-format off | ||
#include "benchmark/fft_batch/fft_batch_config.h" | ||
#include "benchmark/fft_batch/fft_batch_runner.h" | ||
#include "benchmark/simple_reporter.h" | ||
// clang-format on | ||
#include "tachyon/base/console/iostream.h" | ||
#include "tachyon/c/math/finite_fields/baby_bear/baby_bear_type_traits.h" | ||
|
||
namespace tachyon::benchmark { | ||
|
||
extern "C" tachyon_baby_bear* run_fft_batch_plonky3_baby_bear( | ||
const tachyon_baby_bear* data, uint32_t n_log, size_t batch_size, | ||
uint64_t* duration); | ||
|
||
extern "C" tachyon_baby_bear* run_coset_lde_batch_plonky3_baby_bear( | ||
const tachyon_baby_bear* data, uint32_t n_log, size_t batch_size, | ||
uint64_t* duration); | ||
|
||
template <typename F> | ||
void CheckResults(bool check_results, | ||
const std::vector<math::RowMajorMatrix<F>>& results, | ||
const std::vector<math::RowMajorMatrix<F>>& results_vendor) { | ||
if (check_results) { | ||
CHECK(results == results_vendor) << "Results not matched"; | ||
} | ||
} | ||
|
||
template <typename F> | ||
int Run(const FFTBatchConfig& config) { | ||
using Domain = math::Radix2EvaluationDomain<F, SIZE_MAX - 1>; | ||
|
||
F::Init(); | ||
|
||
std::string name; | ||
if (config.run_coset_lde()) { | ||
name = absl::Substitute("CosetLDEBatch Benchmark (Batch Size: $0)", | ||
config.batch_size()); | ||
} else { | ||
name = absl::Substitute("FFTBatch Benchmark (Batch Size: $0)", | ||
config.batch_size()); | ||
} | ||
|
||
SimpleReporter reporter(name); | ||
|
||
reporter.SetXLabel("Degree (2ˣ)"); | ||
reporter.SetColumnLabels(base::Map(config.exponents(), [](uint32_t exponent) { | ||
return base::NumberToString(exponent); | ||
})); | ||
|
||
std::vector<size_t> degrees = config.GetDegrees(); | ||
|
||
std::cout << "Generating evaluation domain and random matrices..." | ||
<< std::endl; | ||
std::vector<std::unique_ptr<Domain>> domains = | ||
base::Map(degrees, [](size_t degree) { return Domain::Create(degree); }); | ||
std::vector<math::RowMajorMatrix<F>> inputs = | ||
base::Map(degrees, [&config](size_t degree) { | ||
math::RowMajorMatrix<F> matrix = | ||
math::RowMajorMatrix<F>::Random(degree, config.batch_size()); | ||
return matrix; | ||
}); | ||
|
||
FFTBatchRunner<Domain> runner(reporter, config); | ||
runner.set_domains(absl::MakeSpan(domains)); | ||
runner.set_inputs(absl::MakeSpan(inputs)); | ||
|
||
std::vector<math::RowMajorMatrix<F>> results; | ||
runner.Run(Vendor::TachyonCPU(), results, config.run_coset_lde()); | ||
for (Vendor vendor : config.vendors()) { | ||
std::vector<math::RowMajorMatrix<F>> results_vendor; | ||
if (vendor.value() == Vendor::kPlonky3) { | ||
if (config.run_coset_lde()) { | ||
runner.RunExternal(vendor, run_coset_lde_batch_plonky3_baby_bear, | ||
results_vendor); | ||
} else { | ||
runner.RunExternal(vendor, run_fft_batch_plonky3_baby_bear, | ||
results_vendor); | ||
} | ||
CheckResults(config.check_results(), results, results_vendor); | ||
} else { | ||
tachyon_cerr << "Unsupported vendor\n"; | ||
return 1; | ||
} | ||
} | ||
|
||
reporter.Show(); | ||
return 0; | ||
} | ||
|
||
int RealMain(int argc, char** argv) { | ||
FFTBatchConfig config; | ||
if (!config.Parse(argc, argv)) { | ||
return 1; | ||
} | ||
|
||
if (config.prime_field().value() == FieldType::kBabyBear) { | ||
return Run<math::BabyBear>(config); | ||
} else { | ||
tachyon_cerr << "Unsupported prime field\n"; | ||
return 1; | ||
} | ||
} | ||
|
||
} // namespace tachyon::benchmark | ||
|
||
int main(int argc, char** argv) { | ||
return tachyon::benchmark::RealMain(argc, argv); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.