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

Add parallel reads to GetFullProof #239

Merged
merged 1 commit into from
May 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/prover_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <algorithm> // std::min
#include <fstream>
#include <future>
#include <iostream>
#include <mutex>
#include <string>
Expand Down Expand Up @@ -218,7 +219,7 @@ class DiskProver {
}

// Gets the 64 leaf x values, concatenated together into a k*64 bit string.
std::vector<Bits> xs = GetInputs(disk_file, p7_entries[index], 6);
std::vector<Bits> xs = GetInputs(p7_entries[index], 6);

// Sorts them according to proof ordering, where
// f1(x0) m= f1(x1), f2(x0, x1) m= f2(x2, x3), etc. On disk, they are not stored in
Expand Down Expand Up @@ -634,8 +635,10 @@ class DiskProver {
// all of the leaves (x values). For example, for depth=5, it fetches the position-th
// entry in table 5, reading the two back pointers from the line point, and then
// recursively calling GetInputs for table 4.
std::vector<Bits> GetInputs(std::ifstream& disk_file, uint64_t position, uint8_t depth)
std::vector<Bits> GetInputs(uint64_t position, uint8_t depth)
{
// Create individual file handles to allow parallel processing
std::ifstream disk_file(filename, std::ios::in | std::ios::binary);
uint128_t line_point = ReadLinePoint(disk_file, depth, position);
std::pair<uint64_t, uint64_t> xy = Encoding::LinePointToSquare(line_point);

Expand All @@ -646,8 +649,10 @@ class DiskProver {
ret.emplace_back(xy.first, k); // x
return ret;
} else {
std::vector<Bits> left = GetInputs(disk_file, xy.second, depth - 1); // y
std::vector<Bits> right = GetInputs(disk_file, xy.first, depth - 1); // x
auto left_fut=std::async(std::launch::async, &DiskProver::GetInputs,this, (uint64_t)xy.second, (uint8_t)(depth - 1));
auto right_fut=std::async(std::launch::async, &DiskProver::GetInputs,this, (uint64_t)xy.first, (uint8_t)(depth - 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a good reason to cast the depth argument to a uint8_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler is very very picky about the data types during templating. If you don't cast it, it will throw an error that it can not find a matching template as it will consider the calculation an int - it does not do any implicit conversions and I didn't want to change the argument types.

std::vector<Bits> left = left_fut.get(); // y
std::vector<Bits> right = right_fut.get(); // x
left.insert(left.end(), right.begin(), right.end());
return left;
}
Expand Down