Skip to content

Commit

Permalink
Almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
gevtushenko committed May 6, 2023
1 parent f8bc608 commit 9a38c1e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
7 changes: 4 additions & 3 deletions benchmarks/bench/select/flagged.cu
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ void select(nvbench::state &state, nvbench::type_list<T, OffsetT>)
thrust::device_vector<bool> flags(elements);
thrust::device_vector<offset_t> num_selected(1);

gen(seed_t{}, in);
gen(seed_t{1}, flags, entropy);

// TODO Extract into helper TU
const auto selected_elements = thrust::count(flags.cbegin(), flags.cend(), true);
thrust::device_vector<T> out(selected_elements);
Expand All @@ -43,8 +46,6 @@ void select(nvbench::state &state, nvbench::type_list<T, OffsetT>)
output_it_t d_out = thrust::raw_pointer_cast(out.data());
num_selected_it_t d_num_selected = thrust::raw_pointer_cast(num_selected.data());

gen(seed_t{}, in, entropy);

state.add_element_count(elements);
state.add_global_memory_reads<T>(elements);
state.add_global_memory_reads<bool>(elements);
Expand Down Expand Up @@ -84,4 +85,4 @@ NVBENCH_BENCH_TYPES(select, NVBENCH_TYPE_AXES(fundamental_types, offset_types))
.set_name("cub::DeviceSelect::Flagged")
.set_type_axes_names({"T{ct}", "OffsetT{ct}"})
.add_int64_power_of_two_axis("Elements{io}", nvbench::range(16, 28, 4))
.add_string_axis("Entropy", {"1.000", "0.544", "0.201"});
.add_string_axis("Entropy", {"1.000", "0.544", "0.000"});
51 changes: 51 additions & 0 deletions benchmarks/nvbench_helper/nvbench_helper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,55 @@ void generator_t::operator()(seed_t seed,
};
}

double entropy_to_probability(bit_entropy entropy)
{
switch (entropy)
{
case bit_entropy::_0_000: return 0.0;
case bit_entropy::_0_811: return 0.811;
case bit_entropy::_0_544: return 0.544;
case bit_entropy::_0_337: return 0.337;
case bit_entropy::_0_201: return 0.201;
case bit_entropy::_1_000: return 1.0;
default: return 0.0;
}
}

struct random_to_probability_t
{
double m_probability;

__host__ __device__ bool operator()(double random_value)
{
return random_value < m_probability;
}
};

template <>
void generator_t::operator()(seed_t seed,
thrust::device_vector<bool> &data,
bit_entropy entropy,
bool /* min */,
bool /* max */)
{
if (entropy == bit_entropy::_0_000)
{
thrust::fill(data.begin(), data.end(), false);
}
else if (entropy == bit_entropy::_1_000)
{
thrust::fill(data.begin(), data.end(), true);
}
else
{
prepare_random_generator(seed, data.size());
thrust::transform(m_distribution.begin(),
m_distribution.end(),
data.begin(),
random_to_probability_t{entropy_to_probability(entropy)});
}
}

template <typename T>
void gen(seed_t seed, thrust::device_vector<T> &data, bit_entropy entropy, T min, T max)
{
Expand All @@ -280,6 +329,8 @@ void gen(seed_t seed, thrust::device_vector<T> &data, bit_entropy entropy, T min

#define INSTANTIATE(TYPE) INSTANTIATE_RND(TYPE);

INSTANTIATE(bool);

INSTANTIATE(uint8_t);
INSTANTIATE(uint16_t);
INSTANTIATE(uint32_t);
Expand Down

0 comments on commit 9a38c1e

Please sign in to comment.