Skip to content

Commit

Permalink
Allocate less.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Jul 1, 2020
1 parent 7523cc3 commit 8d330b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
19 changes: 3 additions & 16 deletions filecoin-proofs/src/api/seal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fs::{self, metadata, File, OpenOptions};
use std::io::prelude::*;
use std::io::BufWriter;
use std::path::{Path, PathBuf};

use anyhow::{ensure, Context, Result};
Expand Down Expand Up @@ -780,32 +779,20 @@ pub fn fauxrep_aux<
cache_path: R,
out_path: S,
) -> Result<Commitment> {
let sector_bytes = PaddedBytesAmount::from(porep_config).0 as usize;
let sector_bytes = PaddedBytesAmount::from(porep_config).0;

{
// Create a sector full of null bytes at `out_path`.
let chunk_size = usize::min(sector_bytes, 1024);
let chunk = vec![0; chunk_size];
let chunk_count = sector_bytes / chunk_size;
assert_eq!(
0,
sector_bytes % chunk_size,
"sector size is not an even number of KiB"
);

let file = File::create(&out_path)?;
let mut buf = BufWriter::with_capacity(chunk.len(), file);
for _ in 0..chunk_count {
buf.write_all(&chunk)?;
}
file.set_len(sector_bytes)?;
}

let fake_comm_c = <Tree::Hasher as Hasher>::Domain::random(&mut rng);
let (comm_r, p_aux) = StackedDrg::<Tree, DefaultPieceHasher>::fake_replicate_phase2(
fake_comm_c,
out_path,
&cache_path,
sector_bytes,
sector_bytes as usize,
)?;

let p_aux_path = cache_path.as_ref().join(CacheKey::PAux.to_string());
Expand Down
7 changes: 4 additions & 3 deletions storage-proofs/porep/src/stacked/vanilla/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,17 +1194,18 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
)
.expect("failed to create TreeBuilder");

// Allocate zeros once and reuse.
let zero_leaves: Vec<Fr> = vec![Fr::zero(); max_gpu_tree_batch_size];
for (i, config) in configs.iter().enumerate() {
let mut consumed = 0;
while consumed < nodes_count {
let batch_size = usize::min(max_gpu_tree_batch_size, nodes_count - consumed);
let zero_leaves: Vec<Fr> = vec![Fr::zero(); batch_size];

consumed += batch_size;

if consumed != nodes_count {
tree_builder
.add_leaves(zero_leaves.as_slice())
.add_leaves(&zero_leaves[0..batch_size])
.expect("failed to add leaves");
continue;
};
Expand All @@ -1217,7 +1218,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
);

let (_, tree_data) = tree_builder
.add_final_leaves(&zero_leaves)
.add_final_leaves(&zero_leaves[0..batch_size])
.expect("failed to add final leaves");
let tree_data_len = tree_data.len();
let cache_size = get_merkle_tree_cache_size(
Expand Down

0 comments on commit 8d330b5

Please sign in to comment.