From 47856feece775d51cc1fef26fcf1f853177390fb Mon Sep 17 00:00:00 2001 From: batzor <32958247+batzor@users.noreply.github.com> Date: Thu, 15 Aug 2024 10:34:37 +0900 Subject: [PATCH] refac(benchmark): change integer types for consistency --- benchmark/ec/ec_config.cc | 2 +- benchmark/ec/ec_config.h | 4 ++-- benchmark/ec/ec_double_benchmark_gpu.cc | 16 ++++++++-------- benchmark/fft/fft_benchmark.cc | 22 +++++++++++----------- benchmark/fft/fft_config.cc | 9 +++++---- benchmark/fft/fft_config.h | 6 +++--- benchmark/fft/fft_runner.h | 8 ++++---- benchmark/msm/msm_benchmark.cc | 6 +++--- benchmark/msm/msm_config.cc | 6 +++--- benchmark/msm/msm_config.h | 8 ++++---- benchmark/msm/msm_runner.h | 4 ++-- 11 files changed, 46 insertions(+), 45 deletions(-) diff --git a/benchmark/ec/ec_config.cc b/benchmark/ec/ec_config.cc index 9b6797d48..c05e1f5e5 100644 --- a/benchmark/ec/ec_config.cc +++ b/benchmark/ec/ec_config.cc @@ -10,7 +10,7 @@ namespace tachyon::benchmark { bool ECConfig::Parse(int argc, char** argv) { base::FlagParser parser; - parser.AddFlag>>(&point_nums_) + parser.AddFlag>>(&point_nums_) .set_short_name("-n") .set_required() .set_help("The number of points to test"); diff --git a/benchmark/ec/ec_config.h b/benchmark/ec/ec_config.h index 97b8a2302..d8eec8d77 100644 --- a/benchmark/ec/ec_config.h +++ b/benchmark/ec/ec_config.h @@ -17,12 +17,12 @@ class ECConfig : public Config { ECConfig(const ECConfig& other) = delete; ECConfig& operator=(const ECConfig& other) = delete; - const std::vector& point_nums() const { return point_nums_; } + const std::vector& point_nums() const { return point_nums_; } bool Parse(int argc, char** argv); private: - std::vector point_nums_; + std::vector point_nums_; }; } // namespace tachyon::benchmark diff --git a/benchmark/ec/ec_double_benchmark_gpu.cc b/benchmark/ec/ec_double_benchmark_gpu.cc index b89cf3a72..0a830cbed 100644 --- a/benchmark/ec/ec_double_benchmark_gpu.cc +++ b/benchmark/ec/ec_double_benchmark_gpu.cc @@ -23,14 +23,14 @@ namespace { // TODO(chokobole): Use openmp. void TestDoubleOnCPU(const std::vector& bases, std::vector& results, - uint64_t nums) { - for (uint64_t i = 0; i < nums; ++i) { + size_t nums) { + for (size_t i = 0; i < nums; ++i) { results[i] = bases[i].Double(); } } gpuError_t LaunchDouble(const math::bn254::G1AffinePointGpu* x, - math::bn254::G1JacobianPointGpu* y, uint64_t count) { + math::bn254::G1JacobianPointGpu* y, size_t count) { math::kernels::Double<<<(count - 1) / 32 + 1, 32>>>(x, y, count); gpuError_t error = LOG_IF_GPU_LAST_ERROR("Failed Double()"); return error == gpuSuccess ? LOG_IF_GPU_ERROR(gpuDeviceSynchronize(), @@ -41,8 +41,8 @@ gpuError_t LaunchDouble(const math::bn254::G1AffinePointGpu* x, void TestDoubleOnGPU(math::bn254::G1AffinePointGpu* bases_cuda, math::bn254::G1JacobianPointGpu* results_cuda, const std::vector& bases, - uint64_t nums) { - for (uint64_t i = 0; i < nums; ++i) { + size_t nums) { + for (size_t i = 0; i < nums; ++i) { bases_cuda[i] = ConvertPoint(bases[i]); } @@ -60,15 +60,15 @@ int RealMain(int argc, char** argv) { math::bn254::G1Curve::Init(); math::bn254::G1CurveGpu::Init(); - const std::vector& point_nums = config.point_nums(); + const std::vector& point_nums = config.point_nums(); SimpleReporter reporter("EC double benchmark"); reporter.SetXLabel("# of points"); reporter.SetColumnLabels(base::Map( - point_nums, [](uint64_t num) { return base::NumberToString(num); })); + point_nums, [](size_t num) { return base::NumberToString(num); })); std::cout << "Generating random points..." << std::endl; - uint64_t max_point_num = point_nums.back(); + size_t max_point_num = point_nums.back(); std::vector bases = CreatePseudoRandomPoints(max_point_num); std::vector scalars = base::CreateVectorParallel( diff --git a/benchmark/fft/fft_benchmark.cc b/benchmark/fft/fft_benchmark.cc index 4db2e4224..324ed38a6 100644 --- a/benchmark/fft/fft_benchmark.cc +++ b/benchmark/fft/fft_benchmark.cc @@ -22,35 +22,35 @@ namespace tachyon::benchmark { using namespace math; extern "C" tachyon_bn254_fr* run_fft_arkworks(const tachyon_bn254_fr* coeffs, - size_t n, + uint32_t n, const tachyon_bn254_fr* omega, uint32_t k, uint64_t* duration_in_us); extern "C" tachyon_bn254_fr* run_ifft_arkworks( - const tachyon_bn254_fr* coeffs, size_t n, const tachyon_bn254_fr* omega_inv, - uint32_t k, uint64_t* duration_in_us); + const tachyon_bn254_fr* coeffs, uint32_t n, + const tachyon_bn254_fr* omega_inv, uint32_t k, uint64_t* duration_in_us); extern "C" tachyon_bn254_fr* run_fft_bellman(const tachyon_bn254_fr* coeffs, - size_t n, + uint32_t n, const tachyon_bn254_fr* omega, uint32_t k, uint64_t* duration_in_us); extern "C" tachyon_bn254_fr* run_ifft_bellman(const tachyon_bn254_fr* coeffs, - size_t n, + uint32_t n, const tachyon_bn254_fr* omega_inv, uint32_t k, uint64_t* duration_in_us); extern "C" tachyon_bn254_fr* run_fft_halo2(const tachyon_bn254_fr* coeffs, - size_t n, + uint32_t n, const tachyon_bn254_fr* omega, uint32_t k, uint64_t* duration_in_us); extern "C" tachyon_bn254_fr* run_ifft_halo2(const tachyon_bn254_fr* coeffs, - size_t n, + uint32_t n, const tachyon_bn254_fr* omega_inv, uint32_t k, uint64_t* duration_in_us); @@ -81,23 +81,23 @@ void Run(const FFTConfig& config) { return base::NumberToString(exponent); })); - std::vector degrees = config.GetDegrees(); + std::vector degrees = config.GetDegrees(); std::cout << "Generating evaluation domain and random polys..." << std::endl; std::vector> domains = base::Map( - degrees, [](size_t degree) { return Domain::Create(degree + 1); }); + degrees, [](uint32_t degree) { return Domain::Create(degree + 1); }); std::vector> halo2_domains; for (const Vendor vendor : config.vendors()) { if (vendor.value() == Vendor::kBellman || vendor.value() == Vendor::kScrollHalo2) { math::halo2::ScopedSubgroupGeneratorOverrider scoped_overrider; halo2_domains = base::Map( - degrees, [](size_t degree) { return Domain::Create(degree + 1); }); + degrees, [](uint32_t degree) { return Domain::Create(degree + 1); }); break; } } std::vector polys = base::Map( - degrees, [](size_t degree) { return PolyOrEvals::Random(degree); }); + degrees, [](uint32_t degree) { return PolyOrEvals::Random(degree); }); std::cout << "Generation completed" << std::endl; FFTRunner runner(reporter); diff --git a/benchmark/fft/fft_config.cc b/benchmark/fft/fft_config.cc index b641f4187..08d5ad33e 100644 --- a/benchmark/fft/fft_config.cc +++ b/benchmark/fft/fft_config.cc @@ -12,7 +12,7 @@ namespace tachyon::benchmark { bool FFTConfig::Parse(int argc, char** argv, const Options& options) { base::FlagParser parser; // clang-format off - parser.AddFlag>>(&exponents_) + parser.AddFlag>>(&exponents_) .set_short_name("-k") .set_required() .set_help("Specify the exponent 'k's where the degree of poly to test is 2ᵏ."); @@ -42,9 +42,10 @@ bool FFTConfig::Parse(int argc, char** argv, const Options& options) { return true; } -std::vector FFTConfig::GetDegrees() const { - return base::Map(exponents_, - [](size_t exponent) { return (size_t{1} << exponent) - 1; }); +std::vector FFTConfig::GetDegrees() const { + return base::Map(exponents_, [](uint32_t exponent) { + return (uint32_t{1} << exponent) - 1; + }); } } // namespace tachyon::benchmark diff --git a/benchmark/fft/fft_config.h b/benchmark/fft/fft_config.h index 56cb721df..f01a2970e 100644 --- a/benchmark/fft/fft_config.h +++ b/benchmark/fft/fft_config.h @@ -18,15 +18,15 @@ class FFTConfig : public Config { FFTConfig(const FFTConfig& other) = delete; FFTConfig& operator=(const FFTConfig& other) = delete; - const std::vector& exponents() const { return exponents_; } + const std::vector& exponents() const { return exponents_; } bool run_ifft() const { return run_ifft_; } bool Parse(int argc, char** argv, const Options& options); - std::vector GetDegrees() const; + std::vector GetDegrees() const; private: - std::vector exponents_; + std::vector exponents_; bool run_ifft_ = false; }; diff --git a/benchmark/fft/fft_runner.h b/benchmark/fft/fft_runner.h index 6178bf190..0c5b39193 100644 --- a/benchmark/fft/fft_runner.h +++ b/benchmark/fft/fft_runner.h @@ -32,7 +32,7 @@ class FFTRunner { public: using F = typename Domain::Field; typedef tachyon_bn254_fr* (*FFTExternalFn)( - const tachyon_bn254_fr* coeffs, size_t n, + const tachyon_bn254_fr* coeffs, uint32_t n, const tachyon_bn254_fr* omega_or_omega_inv, uint32_t k, uint64_t* duration_in_us); @@ -61,7 +61,7 @@ class FFTRunner { std::is_same_v, tachyon_bn254_univariate_evaluations, tachyon_bn254_univariate_dense_polynomial>> - void Run(Vendor vendor, Fn fn, const std::vector& degrees, + void Run(Vendor vendor, Fn fn, const std::vector& degrees, std::vector& results, bool should_record) { if (should_record) { reporter_.AddVendor(vendor); @@ -83,7 +83,7 @@ class FFTRunner { template void RunExternal(Vendor vendor, FFTExternalFn fn, - const std::vector& exponents, + const std::vector& exponents, std::vector& results) const { reporter_.AddVendor(vendor); @@ -91,7 +91,7 @@ class FFTRunner { results.reserve(exponents.size()); for (size_t i = 0; i < exponents.size(); ++i) { uint64_t duration_in_us; - size_t n = size_t{1} << exponents[i]; + uint32_t n = uint32_t{1} << exponents[i]; std::unique_ptr ret; if constexpr (std::is_same_v) { diff --git a/benchmark/msm/msm_benchmark.cc b/benchmark/msm/msm_benchmark.cc index a13803b97..87d584bd5 100644 --- a/benchmark/msm/msm_benchmark.cc +++ b/benchmark/msm/msm_benchmark.cc @@ -45,18 +45,18 @@ int RealMain(int argc, char** argv) { SimpleReporter reporter("MSM Benchmark"); reporter.SetXLabel("Degree (2ˣ)"); - reporter.SetColumnLabels(base::Map(config.exponents(), [](uint64_t exponent) { + reporter.SetColumnLabels(base::Map(config.exponents(), [](uint32_t exponent) { return base::NumberToString(exponent); })); - std::vector point_nums = config.GetPointNums(); + std::vector point_nums = config.GetPointNums(); tachyon_bn254_g1_init(); tachyon_bn254_g1_msm_ptr msm = tachyon_bn254_g1_create_msm(config.exponents().back()); std::cout << "Generating random points..." << std::endl; - uint64_t max_point_num = point_nums.back(); + uint32_t max_point_num = point_nums.back(); VariableBaseMSMTestSet test_set; CHECK(config.GenerateTestSet(max_point_num, &test_set)); std::cout << "Generation completed" << std::endl; diff --git a/benchmark/msm/msm_config.cc b/benchmark/msm/msm_config.cc index 268e17a9d..ac4eb463c 100644 --- a/benchmark/msm/msm_config.cc +++ b/benchmark/msm/msm_config.cc @@ -38,7 +38,7 @@ bool MSMConfig::Parse(int argc, char** argv, const MSMConfig::Options& options) { base::FlagParser parser; // clang-format off - parser.AddFlag>>(&exponents_) + parser.AddFlag>>(&exponents_) .set_short_name("-k") .set_required() .set_help("Specify the exponent 'k' where the number of points to test is 2ᵏ."); @@ -70,9 +70,9 @@ bool MSMConfig::Parse(int argc, char** argv, return true; } -std::vector MSMConfig::GetPointNums() const { +std::vector MSMConfig::GetPointNums() const { return base::Map(exponents_, - [](uint64_t exponent) { return uint64_t{1} << exponent; }); + [](uint32_t exponent) { return uint32_t{1} << exponent; }); } } // namespace tachyon diff --git a/benchmark/msm/msm_config.h b/benchmark/msm/msm_config.h index a4a9f47a4..9783bcdc5 100644 --- a/benchmark/msm/msm_config.h +++ b/benchmark/msm/msm_config.h @@ -24,14 +24,14 @@ class MSMConfig : public Config { MSMConfig(const MSMConfig& other) = delete; MSMConfig& operator=(const MSMConfig& other) = delete; - const std::vector& exponents() const { return exponents_; } + const std::vector& exponents() const { return exponents_; } bool Parse(int argc, char** argv, const Options& options); - std::vector GetPointNums() const; + std::vector GetPointNums() const; template - bool GenerateTestSet(uint64_t size, + bool GenerateTestSet(uint32_t size, math::VariableBaseMSMTestSet* out) const { switch (test_set_) { case TestSet::kRandom: @@ -47,7 +47,7 @@ class MSMConfig : public Config { } private: - std::vector exponents_; + std::vector exponents_; TestSet test_set_ = TestSet::kRandom; }; diff --git a/benchmark/msm/msm_runner.h b/benchmark/msm/msm_runner.h index 4d956670b..5617678d1 100644 --- a/benchmark/msm/msm_runner.h +++ b/benchmark/msm/msm_runner.h @@ -44,7 +44,7 @@ class MSMRunner { template void Run(Vendor vendor, Fn fn, MSMPtr msm, - const std::vector& point_nums, + const std::vector& point_nums, std::vector& results) { reporter_.AddVendor(vendor); @@ -61,7 +61,7 @@ class MSMRunner { } void RunExternal(Vendor vendor, MSMAffineExternalFn fn, - const std::vector& point_nums, + const std::vector& point_nums, std::vector& results) const { reporter_.AddVendor(vendor);