Skip to content

Commit

Permalink
refac(benchmark): change integer types for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
batzor committed Aug 15, 2024
1 parent 5f302d2 commit 47856fe
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion benchmark/ec/ec_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace tachyon::benchmark {

bool ECConfig::Parse(int argc, char** argv) {
base::FlagParser parser;
parser.AddFlag<base::Flag<std::vector<uint64_t>>>(&point_nums_)
parser.AddFlag<base::Flag<std::vector<size_t>>>(&point_nums_)
.set_short_name("-n")
.set_required()
.set_help("The number of points to test");
Expand Down
4 changes: 2 additions & 2 deletions benchmark/ec/ec_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class ECConfig : public Config {
ECConfig(const ECConfig& other) = delete;
ECConfig& operator=(const ECConfig& other) = delete;

const std::vector<uint64_t>& point_nums() const { return point_nums_; }
const std::vector<size_t>& point_nums() const { return point_nums_; }

bool Parse(int argc, char** argv);

private:
std::vector<uint64_t> point_nums_;
std::vector<size_t> point_nums_;
};

} // namespace tachyon::benchmark
Expand Down
16 changes: 8 additions & 8 deletions benchmark/ec/ec_double_benchmark_gpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ namespace {
// TODO(chokobole): Use openmp.
void TestDoubleOnCPU(const std::vector<math::bn254::G1AffinePoint>& bases,
std::vector<math::bn254::G1JacobianPoint>& 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(),
Expand All @@ -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<math::bn254::G1AffinePoint>& 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<math::bn254::G1AffinePointGpu>(bases[i]);
}

Expand All @@ -60,15 +60,15 @@ int RealMain(int argc, char** argv) {
math::bn254::G1Curve::Init();
math::bn254::G1CurveGpu::Init();

const std::vector<uint64_t>& point_nums = config.point_nums();
const std::vector<size_t>& 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<bn254::G1AffinePoint> bases =
CreatePseudoRandomPoints<bn254::G1AffinePoint>(max_point_num);
std::vector<bn254::Fr> scalars = base::CreateVectorParallel(
Expand Down
22 changes: 11 additions & 11 deletions benchmark/fft/fft_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -81,23 +81,23 @@ void Run(const FFTConfig& config) {
return base::NumberToString(exponent);
}));

std::vector<size_t> degrees = config.GetDegrees();
std::vector<uint32_t> degrees = config.GetDegrees();

std::cout << "Generating evaluation domain and random polys..." << std::endl;
std::vector<std::unique_ptr<Domain>> domains = base::Map(
degrees, [](size_t degree) { return Domain::Create(degree + 1); });
degrees, [](uint32_t degree) { return Domain::Create(degree + 1); });
std::vector<std::unique_ptr<Domain>> 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<PolyOrEvals> 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<Domain, PolyOrEvals> runner(reporter);
Expand Down
9 changes: 5 additions & 4 deletions benchmark/fft/fft_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<base::Flag<std::vector<size_t>>>(&exponents_)
parser.AddFlag<base::Flag<std::vector<uint32_t>>>(&exponents_)
.set_short_name("-k")
.set_required()
.set_help("Specify the exponent 'k's where the degree of poly to test is 2ᵏ.");
Expand Down Expand Up @@ -42,9 +42,10 @@ bool FFTConfig::Parse(int argc, char** argv, const Options& options) {
return true;
}

std::vector<size_t> FFTConfig::GetDegrees() const {
return base::Map(exponents_,
[](size_t exponent) { return (size_t{1} << exponent) - 1; });
std::vector<uint32_t> FFTConfig::GetDegrees() const {
return base::Map(exponents_, [](uint32_t exponent) {
return (uint32_t{1} << exponent) - 1;
});
}

} // namespace tachyon::benchmark
6 changes: 3 additions & 3 deletions benchmark/fft/fft_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class FFTConfig : public Config {
FFTConfig(const FFTConfig& other) = delete;
FFTConfig& operator=(const FFTConfig& other) = delete;

const std::vector<size_t>& exponents() const { return exponents_; }
const std::vector<uint32_t>& exponents() const { return exponents_; }
bool run_ifft() const { return run_ifft_; }

bool Parse(int argc, char** argv, const Options& options);

std::vector<size_t> GetDegrees() const;
std::vector<uint32_t> GetDegrees() const;

private:
std::vector<size_t> exponents_;
std::vector<uint32_t> exponents_;
bool run_ifft_ = false;
};

Expand Down
8 changes: 4 additions & 4 deletions benchmark/fft/fft_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -61,7 +61,7 @@ class FFTRunner {
std::is_same_v<RetPoly, typename Domain::Evals>,
tachyon_bn254_univariate_evaluations,
tachyon_bn254_univariate_dense_polynomial>>
void Run(Vendor vendor, Fn fn, const std::vector<size_t>& degrees,
void Run(Vendor vendor, Fn fn, const std::vector<uint32_t>& degrees,
std::vector<RetPoly>& results, bool should_record) {
if (should_record) {
reporter_.AddVendor(vendor);
Expand All @@ -83,15 +83,15 @@ class FFTRunner {

template <typename RetPoly>
void RunExternal(Vendor vendor, FFTExternalFn fn,
const std::vector<size_t>& exponents,
const std::vector<uint32_t>& exponents,
std::vector<RetPoly>& results) const {
reporter_.AddVendor(vendor);

results.clear();
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<F> ret;
if constexpr (std::is_same_v<PolyOrEvals, typename Domain::Evals>) {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/msm/msm_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t> point_nums = config.GetPointNums();
std::vector<uint32_t> 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<bn254::G1AffinePoint> test_set;
CHECK(config.GenerateTestSet(max_point_num, &test_set));
std::cout << "Generation completed" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions benchmark/msm/msm_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool MSMConfig::Parse(int argc, char** argv,
const MSMConfig::Options& options) {
base::FlagParser parser;
// clang-format off
parser.AddFlag<base::Flag<std::vector<uint64_t>>>(&exponents_)
parser.AddFlag<base::Flag<std::vector<uint32_t>>>(&exponents_)
.set_short_name("-k")
.set_required()
.set_help("Specify the exponent 'k' where the number of points to test is 2ᵏ.");
Expand Down Expand Up @@ -70,9 +70,9 @@ bool MSMConfig::Parse(int argc, char** argv,
return true;
}

std::vector<uint64_t> MSMConfig::GetPointNums() const {
std::vector<uint32_t> 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
8 changes: 4 additions & 4 deletions benchmark/msm/msm_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class MSMConfig : public Config {
MSMConfig(const MSMConfig& other) = delete;
MSMConfig& operator=(const MSMConfig& other) = delete;

const std::vector<uint64_t>& exponents() const { return exponents_; }
const std::vector<uint32_t>& exponents() const { return exponents_; }

bool Parse(int argc, char** argv, const Options& options);

std::vector<uint64_t> GetPointNums() const;
std::vector<uint32_t> GetPointNums() const;

template <typename Point, typename Bucket>
bool GenerateTestSet(uint64_t size,
bool GenerateTestSet(uint32_t size,
math::VariableBaseMSMTestSet<Point, Bucket>* out) const {
switch (test_set_) {
case TestSet::kRandom:
Expand All @@ -47,7 +47,7 @@ class MSMConfig : public Config {
}

private:
std::vector<uint64_t> exponents_;
std::vector<uint32_t> exponents_;
TestSet test_set_ = TestSet::kRandom;
};

Expand Down
4 changes: 2 additions & 2 deletions benchmark/msm/msm_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MSMRunner {

template <typename Fn, typename MSMPtr>
void Run(Vendor vendor, Fn fn, MSMPtr msm,
const std::vector<uint64_t>& point_nums,
const std::vector<uint32_t>& point_nums,
std::vector<RetPoint>& results) {
reporter_.AddVendor(vendor);

Expand All @@ -61,7 +61,7 @@ class MSMRunner {
}

void RunExternal(Vendor vendor, MSMAffineExternalFn fn,
const std::vector<uint64_t>& point_nums,
const std::vector<uint32_t>& point_nums,
std::vector<RetPoint>& results) const {
reporter_.AddVendor(vendor);

Expand Down

0 comments on commit 47856fe

Please sign in to comment.