Skip to content

Commit

Permalink
Replace gpu feature with gpu2 functionality (#1441)
Browse files Browse the repository at this point in the history
* feat: replace gpu feature with gpu2 functionality
* feat: update rust toolchain to 1.51.0
* fix: clean-up some warnings due to toolchain update
* feat: update clippy settings and remove some warnings
  • Loading branch information
cryptonemo authored Mar 31, 2021
1 parent 7d08e87 commit ec2ef88
Show file tree
Hide file tree
Showing 38 changed files with 114 additions and 227 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ jobs:
ulimit -n 20000
cd filecoin-proofs
~/.cargo/bin/cargo +<< pipeline.parameters.nightly-toolchain >> -Zpackage-features test --all --no-default-features --features gpu,blst --verbose --release lifecycle -- --ignored --nocapture
~/.cargo/bin/cargo +<< pipeline.parameters.nightly-toolchain >> -Zpackage-features test --all --no-default-features --features gpu2,blst --verbose --release lifecycle -- --ignored --nocapture
no_output_timeout: 30m
environment:
RUST_TEST_THREADS: 1
Expand Down
1 change: 0 additions & 1 deletion fil-proofs-param/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ heap-profile = ["gperftools/heap"]
simd = ["storage-proofs-core/simd"]
asm = ["storage-proofs-core/asm"]
gpu = ["storage-proofs-core/gpu", "storage-proofs-porep/gpu", "storage-proofs-post/gpu", "bellperson/gpu"]
gpu2 = ["storage-proofs-core/gpu2", "storage-proofs-porep/gpu2", "storage-proofs-post/gpu2", "bellperson/gpu"]
pairing = ["storage-proofs-core/pairing", "storage-proofs-porep/pairing", "storage-proofs-post/pairing", "bellperson/pairing"]
blst = ["storage-proofs-core/blst", "storage-proofs-porep/blst", "storage-proofs-post/blst", "bellperson/blst"]
8 changes: 0 additions & 8 deletions fil-proofs-tooling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ gpu = [
"bellperson/gpu",
"filecoin-hashers/gpu",
]
gpu2 = [
"storage-proofs-core/gpu2",
"storage-proofs-porep/gpu2",
"storage-proofs-post/gpu2",
"filecoin-proofs/gpu2",
"bellperson/gpu",
"filecoin-hashers/gpu2",
]
measurements = ["storage-proofs-core/measurements"]
profile = ["storage-proofs-core/profile", "measurements"]
pairing = [
Expand Down
1 change: 1 addition & 0 deletions fil-proofs-tooling/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)]
#![warn(clippy::unwrap_used)]
#![warn(clippy::needless_collect)]

pub mod measure;
pub mod metadata;
Expand Down
3 changes: 1 addition & 2 deletions filecoin-hashers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ hex = "0.4.2"
[features]
default = ["gpu", "pairing", "blake2s", "poseidon", "sha256"]

gpu = ["bellperson/gpu", "neptune/gpu"]
gpu2 = ["bellperson/gpu", "neptune/opencl"]
gpu = ["bellperson/gpu", "neptune/opencl"]

pairing = ["bellperson/pairing", "neptune/pairing", "bellperson/pairing-serde"]
blst = ["bellperson/blst", "neptune/blst", "bellperson/blst-serde"]
Expand Down
2 changes: 1 addition & 1 deletion filecoin-hashers/src/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl HashFunction<Blake2sDomain> for Blake2sFunction {
bits: &[Boolean],
) -> Result<AllocatedNum<Bls12>, SynthesisError> {
let personalization = vec![0u8; 8];
let alloc_bits = blake2s_circuit(cs.namespace(|| "hash"), &bits[..], &personalization)?;
let alloc_bits = blake2s_circuit(cs.namespace(|| "hash"), bits, &personalization)?;

multipack::pack_bits(cs.namespace(|| "pack"), &alloc_bits)
}
Expand Down
3 changes: 3 additions & 0 deletions filecoin-hashers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)]
#![allow(clippy::upper_case_acronyms)]
#![warn(clippy::unwrap_used)]
#![warn(clippy::from_over_into)]
#![warn(clippy::wrong_self_convention)]

#[cfg(feature = "blake2s")]
pub mod blake2s;
Expand Down
2 changes: 1 addition & 1 deletion filecoin-hashers/src/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl HashFunction<Sha256Domain> for Sha256Function {
mut cs: CS,
bits: &[Boolean],
) -> Result<AllocatedNum<Bls12>, SynthesisError> {
let be_bits = sha256_circuit(cs.namespace(|| "hash"), &bits[..])?;
let be_bits = sha256_circuit(cs.namespace(|| "hash"), bits)?;
let le_bits = be_bits
.chunks(8)
.flat_map(|chunk| chunk.iter().rev())
Expand Down
8 changes: 0 additions & 8 deletions filecoin-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ gpu = [
"filecoin-hashers/gpu",
"fr32/gpu",
]
gpu2 = [
"storage-proofs-core/gpu2",
"storage-proofs-porep/gpu2",
"storage-proofs-post/gpu2",
"bellperson/gpu",
"filecoin-hashers/gpu2",
"fr32/gpu",
]
pairing = [
"storage-proofs-core/pairing",
"storage-proofs-porep/pairing",
Expand Down
4 changes: 2 additions & 2 deletions filecoin-proofs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ fn verify_store(config: &StoreConfig, arity: usize, required_configs: usize) ->
let path_str = cur_path.as_str();
let tree_names = vec!["tree-d", "tree-c", "tree-r-last"];
for name in tree_names {
if path_str.find(name).is_some() {
if path_str.contains(name) {
configs.push(StoreConfig::from_config(
config,
format!("{}-{}", name, i),
Expand Down Expand Up @@ -549,7 +549,7 @@ fn verify_level_cache_store<Tree: MerkleTreeTrait>(config: &StoreConfig) -> Resu
let path_str = cur_path.as_str();
let tree_names = vec!["tree-d", "tree-c", "tree-r-last"];
for name in tree_names {
if path_str.find(name).is_some() {
if path_str.contains(name) {
configs.push(StoreConfig::from_config(
config,
format!("{}-{}", name, i),
Expand Down
12 changes: 5 additions & 7 deletions filecoin-proofs/src/api/post_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ pub fn generate_fallback_sector_challenges<Tree: 'static + MerkleTreeTrait>(

let num_sectors_per_chunk = post_config.sector_count;
let partitions = match post_config.typ {
PoStType::Window => match get_partitions_for_window_post(pub_sectors.len(), &post_config) {
Some(x) => x,
None => 1,
},
PoStType::Window => {
get_partitions_for_window_post(pub_sectors.len(), &post_config).unwrap_or(1)
}
PoStType::Winning => 1,
};

Expand Down Expand Up @@ -148,12 +147,11 @@ pub fn generate_single_vanilla_proof<Tree: 'static + MerkleTreeTrait>(
let comm_c = replica.safe_comm_c();
let comm_r_last = replica.safe_comm_r_last();

let mut priv_sectors = Vec::with_capacity(1);
priv_sectors.push(fallback::PrivateSector {
let mut priv_sectors = vec![fallback::PrivateSector {
tree,
comm_c,
comm_r_last,
});
}];

let priv_inputs = fallback::PrivateInputs::<Tree> {
sectors: &priv_sectors,
Expand Down
11 changes: 4 additions & 7 deletions filecoin-proofs/src/api/window_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ pub fn generate_window_post_with_vanilla<Tree: 'static + MerkleTreeTrait>(
priority: post_config.priority,
};

let partitions = match partitions {
Some(x) => x,
None => 1,
};
let partitions = partitions.unwrap_or(1);

let pub_params: compound_proof::PublicParams<'_, FallbackPoSt<'_, Tree>> =
FallbackPoStCompound::setup(&setup_params)?;
Expand Down Expand Up @@ -92,7 +89,7 @@ pub fn generate_window_post_with_vanilla<Tree: 'static + MerkleTreeTrait>(

info!("generate_window_post_with_vanilla:finish");

Ok(proof.to_vec()?)
proof.to_vec()
}

/// Generates a Window proof-of-spacetime.
Expand Down Expand Up @@ -172,7 +169,7 @@ pub fn generate_window_post<Tree: 'static + MerkleTreeTrait>(

info!("generate_window_post:finish");

Ok(proof.to_vec()?)
proof.to_vec()
}

/// Verifies a window proof-of-spacetime.
Expand Down Expand Up @@ -226,7 +223,7 @@ pub fn verify_window_post<Tree: 'static + MerkleTreeTrait>(

let is_valid = {
let verifying_key = get_post_verifying_key::<Tree>(&post_config)?;
let multi_proof = MultiProof::new_from_reader(partitions, &proof[..], &verifying_key)?;
let multi_proof = MultiProof::new_from_reader(partitions, proof, &verifying_key)?;

FallbackPoStCompound::verify(
&pub_params,
Expand Down
7 changes: 2 additions & 5 deletions filecoin-proofs/src/api/winning_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ pub fn generate_winning_post_with_vanilla<Tree: 'static + MerkleTreeTrait>(
k: None,
};

let partitions = match pub_params.partitions {
Some(x) => x,
None => 1,
};
let partitions = pub_params.partitions.unwrap_or(1);
let partitioned_proofs = partition_vanilla_proofs(
&post_config,
&pub_params.vanilla_params,
Expand Down Expand Up @@ -282,7 +279,7 @@ pub fn verify_winning_post<Tree: 'static + MerkleTreeTrait>(
let is_valid = {
let verifying_key = get_post_verifying_key::<Tree>(&post_config)?;

let single_proof = MultiProof::new_from_reader(None, &proof[..], &verifying_key)?;
let single_proof = MultiProof::new_from_reader(None, proof, &verifying_key)?;
if single_proof.len() != 1 {
return Ok(false);
}
Expand Down
8 changes: 4 additions & 4 deletions filecoin-proofs/src/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ pub fn get_stacked_params<Tree: 'static + MerkleTreeTrait>(
.map_err(Into::into)
};

Ok(lookup_groth_params(
lookup_groth_params(
format!(
"STACKED[{}]",
usize::from(PaddedBytesAmount::from(porep_config))
),
parameters_generator,
)?)
)
}

pub fn get_post_params<Tree: 'static + MerkleTreeTrait>(
Expand Down Expand Up @@ -172,13 +172,13 @@ pub fn get_stacked_verifying_key<Tree: 'static + MerkleTreeTrait>(
Ok(prepare_verifying_key(&vk))
};

Ok(lookup_verifying_key(
lookup_verifying_key(
format!(
"STACKED[{}]",
usize::from(PaddedBytesAmount::from(porep_config))
),
vk_generator,
)?)
)
}

pub fn get_post_verifying_key<Tree: 'static + MerkleTreeTrait>(
Expand Down
26 changes: 10 additions & 16 deletions filecoin-proofs/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,25 @@ pub type SectorShape32KiB = SectorShapeTop2;
pub type SectorShape64GiB = SectorShapeTop2;

pub fn is_sector_shape_base(sector_size: u64) -> bool {
match sector_size {
SECTOR_SIZE_2_KIB | SECTOR_SIZE_8_MIB | SECTOR_SIZE_512_MIB => true,
_ => false,
}
matches!(
sector_size,
SECTOR_SIZE_2_KIB | SECTOR_SIZE_8_MIB | SECTOR_SIZE_512_MIB
)
}

pub fn is_sector_shape_sub2(sector_size: u64) -> bool {
match sector_size {
SECTOR_SIZE_4_KIB | SECTOR_SIZE_16_MIB | SECTOR_SIZE_1_GIB => true,
_ => false,
}
matches!(
sector_size,
SECTOR_SIZE_4_KIB | SECTOR_SIZE_16_MIB | SECTOR_SIZE_1_GIB
)
}

pub fn is_sector_shape_sub8(sector_size: u64) -> bool {
match sector_size {
SECTOR_SIZE_16_KIB | SECTOR_SIZE_32_GIB => true,
_ => false,
}
matches!(sector_size, SECTOR_SIZE_16_KIB | SECTOR_SIZE_32_GIB)
}

pub fn is_sector_shape_top2(sector_size: u64) -> bool {
match sector_size {
SECTOR_SIZE_32_KIB | SECTOR_SIZE_64_GIB => true,
_ => false,
}
matches!(sector_size, SECTOR_SIZE_32_KIB | SECTOR_SIZE_64_GIB)
}

/// Calls a function with the type hint of the sector shape matching the provided sector.
Expand Down
2 changes: 2 additions & 0 deletions filecoin-proofs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)]
#![warn(clippy::unwrap_used)]
#![warn(clippy::upper_case_acronyms)]
#![warn(clippy::unnecessary_wraps)]

pub mod constants;
pub mod param;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.46.0
1.51.0
3 changes: 1 addition & 2 deletions storage-proofs-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ big-sector-sizes-bench = []
measurements = ["cpu-time", "gperftools"]
profile = ["measurements"]

gpu = ["bellperson/gpu", "neptune/gpu", "filecoin-hashers/gpu", "fr32/gpu"]
gpu2 = ["bellperson/gpu", "neptune/opencl", "filecoin-hashers/gpu2", "fr32/gpu"]
gpu = ["bellperson/gpu", "neptune/opencl", "filecoin-hashers/gpu", "fr32/gpu"]
pairing = ["bellperson/pairing", "neptune/pairing", "bellperson/pairing-serde", "filecoin-hashers/pairing", "fr32/pairing"]
blst = ["bellperson/blst", "neptune/blst", "bellperson/blst-serde", "filecoin-hashers/blst", "fr32/blst"]

Expand Down
5 changes: 5 additions & 0 deletions storage-proofs-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
#![allow(clippy::many_single_char_names)]
#![allow(clippy::unreadable_literal)]
#![allow(clippy::type_repetition_in_bounds)]
#![allow(clippy::upper_case_acronyms)]
#![warn(clippy::unwrap_used)]
#![warn(clippy::unnecessary_wraps)]
#![warn(clippy::ptr_arg)]
#![warn(clippy::unnecessary_lazy_evaluations)]
#![warn(clippy::redundant_slicing)]

use std::convert::TryInto;

Expand Down
3 changes: 1 addition & 2 deletions storage-proofs-porep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ filecoin-hashers = { path = "../filecoin-hashers", version = "1.0.0", default-fe

[features]
default = ["pairing", "gpu"]
gpu = ["storage-proofs-core/gpu", "filecoin-hashers/gpu", "neptune/gpu", "bellperson/gpu", "fr32/gpu"]
gpu2 = ["storage-proofs-core/gpu2", "filecoin-hashers/gpu2", "neptune/opencl", "bellperson/gpu", "fr32/gpu"]
gpu = ["storage-proofs-core/gpu", "filecoin-hashers/gpu", "neptune/opencl", "bellperson/gpu", "fr32/gpu"]
pairing = ["storage-proofs-core/pairing", "bellperson/pairing", "neptune/pairing", "filecoin-hashers/pairing", "fr32/pairing"]
blst = ["storage-proofs-core/blst", "bellperson/blst", "neptune/blst", "filecoin-hashers/blst", "fr32/blst"]
single-threaded = []
Expand Down
11 changes: 4 additions & 7 deletions storage-proofs-porep/src/drg/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a, H: 'static + Hasher> Circuit<Bls12> for DrgPoRepCircuit<'a, H> {
assert_eq!(self.data_nodes_paths.len(), nodes);

let replica_node_num = AllocatedNum::alloc(cs.namespace(|| "replica_id_num"), || {
replica_id.ok_or_else(|| SynthesisError::AssignmentMissing)
replica_id.ok_or(SynthesisError::AssignmentMissing)
})?;

replica_node_num.inputize(cs.namespace(|| "replica_id"))?;
Expand Down Expand Up @@ -206,10 +206,7 @@ impl<'a, H: 'static + Hasher> Circuit<Bls12> for DrgPoRepCircuit<'a, H> {
.map(|(i, val)| {
let num = AllocatedNum::alloc(
cs.namespace(|| format!("parents_{}_num", i)),
|| {
val.map(Into::into)
.ok_or_else(|| SynthesisError::AssignmentMissing)
},
|| val.map(Into::into).ok_or(SynthesisError::AssignmentMissing),
)?;
Ok(reverse_bit_numbering(num.to_bits_le(
cs.namespace(|| format!("parents_{}_bits", i)),
Expand All @@ -228,15 +225,15 @@ impl<'a, H: 'static + Hasher> Circuit<Bls12> for DrgPoRepCircuit<'a, H> {

let replica_node_num =
AllocatedNum::alloc(cs.namespace(|| "replica_node"), || {
(*replica_node).ok_or_else(|| SynthesisError::AssignmentMissing)
(*replica_node).ok_or(SynthesisError::AssignmentMissing)
})?;

let decoded = encode::decode(cs.namespace(|| "decode"), &key, &replica_node_num)?;

// TODO this should not be here, instead, this should be the leaf Fr in the data_auth_path
// TODO also note that we need to change/makesurethat the leaves are the data, instead of hashes of the data
let expected = AllocatedNum::alloc(cs.namespace(|| "data node"), || {
data_node.ok_or_else(|| SynthesisError::AssignmentMissing)
data_node.ok_or(SynthesisError::AssignmentMissing)
})?;

// ensure the encrypted data and data_node match
Expand Down
3 changes: 1 addition & 2 deletions storage-proofs-porep/src/drg/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ where
private: pub_params.private,
};

let mut input: Vec<Fr> = Vec::new();
input.push(replica_id.into());
let mut input: Vec<Fr> = vec![replica_id.into()];

let mut parents = vec![0; pub_params.graph.degree()];
for challenge in challenges {
Expand Down
1 change: 1 addition & 0 deletions storage-proofs-porep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)]
#![warn(clippy::unwrap_used)]
#![cfg_attr(target_arch = "aarch64", feature(stdsimd))]
#![warn(clippy::unnecessary_wraps)]

use std::path::PathBuf;

Expand Down
2 changes: 1 addition & 1 deletion storage-proofs-porep/src/stacked/circuit/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Column {
.enumerate()
.map(|(i, val)| {
AllocatedNum::alloc(cs.namespace(|| format!("column_num_row_{}", i)), || {
val.ok_or_else(|| SynthesisError::AssignmentMissing)
val.ok_or(SynthesisError::AssignmentMissing)
})
})
.collect::<Result<Vec<_>, _>>()?;
Expand Down
2 changes: 1 addition & 1 deletion storage-proofs-porep/src/stacked/circuit/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<Tree: MerkleTreeTrait, G: 'static + Hasher> Proof<Tree, G> {

// PrivateInput: data_leaf
let data_leaf_num = AllocatedNum::alloc(cs.namespace(|| "data_leaf"), || {
data_leaf.ok_or_else(|| SynthesisError::AssignmentMissing)
data_leaf.ok_or(SynthesisError::AssignmentMissing)
})?;

// enforce inclusion of the data leaf in the tree D
Expand Down
Loading

0 comments on commit ec2ef88

Please sign in to comment.