Skip to content

Commit

Permalink
fix: use GPU tree builder only for Poseidon hashes (#1515)
Browse files Browse the repository at this point in the history
The GPU tree builder (Neptune) only supports Poseidon hashes. Switch
to the CPU tree builder if other hash algorithms are used (which isn't
the case in Filecoin at the moment).

Closes #1512.
  • Loading branch information
vmx authored Oct 5, 2021
1 parent d1155fe commit 0daa536
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions storage-proofs-porep/src/stacked/vanilla/proof.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::TypeId;
use std::fs;
use std::marker::PhantomData;
use std::panic::panic_any;
Expand All @@ -7,7 +8,7 @@ use std::sync::Mutex;
use anyhow::Context;
use bincode::deserialize;
use fdlimit::raise_fd_limit;
use filecoin_hashers::{Domain, HashFunction, Hasher, PoseidonArity};
use filecoin_hashers::{poseidon::PoseidonHasher, Domain, HashFunction, Hasher, PoseidonArity};
use generic_array::typenum::{Unsigned, U0, U11, U2, U8};
use lazy_static::lazy_static;
use log::{error, info, trace};
Expand Down Expand Up @@ -428,7 +429,9 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
ColumnArity: 'static + PoseidonArity,
TreeArity: PoseidonArity,
{
if SETTINGS.use_gpu_column_builder {
if SETTINGS.use_gpu_column_builder
&& TypeId::of::<Tree::Hasher>() == TypeId::of::<PoseidonHasher>()
{
Self::generate_tree_c_gpu::<ColumnArity, TreeArity>(
layers,
nodes_count,
Expand Down Expand Up @@ -806,7 +809,10 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
where
TreeArity: PoseidonArity,
{
if SETTINGS.use_gpu_tree_builder {
// The GPU tree builder only support Poseidon hashes.
if SETTINGS.use_gpu_tree_builder
&& TypeId::of::<Tree::Hasher>() == TypeId::of::<PoseidonHasher>()
{
Self::generate_tree_r_last_gpu::<TreeArity>(
data,
nodes_count,
Expand Down

0 comments on commit 0daa536

Please # to comment.