Skip to content

Commit

Permalink
estimate_size() should take a column_view
Browse files Browse the repository at this point in the history
  • Loading branch information
jihoonson committed Jun 28, 2024
1 parent 2daeff5 commit 40804e2
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 29 deletions.
7 changes: 2 additions & 5 deletions cpp/benchmarks/common/table_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
#include <cudf/transform.hpp>
#include <cudf/reduction.hpp>

int64_t estimate_size(std::unique_ptr<cudf::column> column)
int64_t estimate_size(cudf::column_view const& col)
{
std::vector<std::unique_ptr<cudf::column>> columns;
columns.emplace_back(std::move(column));
cudf::table table{std::move(columns)};
return estimate_size(table.view());
return estimate_size( cudf::table_view( {col} ) );
}

int64_t estimate_size(cudf::table_view const& view)
Expand Down
6 changes: 3 additions & 3 deletions cpp/benchmarks/common/table_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
* and accumulates them, the returned estimate may be an inexact approximation in some
* cases. See cudf::row_bit_count() for more details.
*
* @param column The column to estimate its size
* @param view The column view to estimate its size
*/
int64_t estimate_size(std::unique_ptr<cudf::column> column);
int64_t estimate_size(cudf::column_view const& view);

/**
* @brief Estimates the table size in bytes.
Expand All @@ -36,6 +36,6 @@ int64_t estimate_size(std::unique_ptr<cudf::column> column);
* and accumulates them, the returned estimate may be an inexact approximation in some
* cases. See cudf::row_bit_count() for more details.
*
* @param view The view to estimate its size
* @param view The table view to estimate its size
*/
int64_t estimate_size(cudf::table_view const& view);
4 changes: 2 additions & 2 deletions cpp/benchmarks/reduction/anyall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void BM_reduction_anyall(benchmark::State& state,
auto const dtype = cudf::type_to_id<type>();
data_profile const profile = data_profile_builder().no_validity().distribution(
dtype, distribution_id::UNIFORM, 0, agg->kind == cudf::aggregation::ANY ? 0 : 100);
auto values = create_random_column(dtype, row_count{column_size}, profile);
auto const values = create_random_column(dtype, row_count{column_size}, profile);

cudf::data_type output_dtype{cudf::type_id::BOOL8};

Expand All @@ -47,7 +47,7 @@ void BM_reduction_anyall(benchmark::State& state,

// The benchmark takes a column and produces one scalar.
set_items_processed(state, column_size + 1);
set_bytes_processed(state, estimate_size(std::move(values)) + cudf::size_of(output_dtype));
set_bytes_processed(state, estimate_size(values->view()) + cudf::size_of(output_dtype));
}

#define concat(a, b, c) a##b##c
Expand Down
4 changes: 2 additions & 2 deletions cpp/benchmarks/reduction/minmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void BM_reduction(benchmark::State& state)
{
cudf::size_type const column_size{(cudf::size_type)state.range(0)};
auto const dtype_id = cudf::type_to_id<type>();
auto input_column =
auto const input_column =
create_random_column(dtype_id, row_count{column_size}, data_profile_builder().no_validity());

for (auto _ : state) {
Expand All @@ -42,7 +42,7 @@ void BM_reduction(benchmark::State& state)
// The benchmark takes a column and produces two scalars.
set_items_processed(state, column_size + 2);
cudf::data_type dtype = cudf::data_type{dtype_id};
set_bytes_processed(state, estimate_size(std::move(input_column)) + 2 * cudf::size_of(dtype));
set_bytes_processed(state, estimate_size(input_column->view()) + 2 * cudf::size_of(dtype));
}

#define concat(a, b, c) a##b##c
Expand Down
6 changes: 3 additions & 3 deletions cpp/benchmarks/reduction/rank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ static void nvbench_reduction_scan(nvbench::state& state, nvbench::type_list<typ
timer.stop();

// Estimating the result size will launch a kernel. Do not include it in measuring time.
result_size += estimate_size(std::move(result));
result_size += estimate_size(result->view());
});

state.add_element_count(new_tbl->num_rows());
state.add_global_memory_reads(estimate_size(new_tbl->view()));
state.add_element_count(input.size());
state.add_global_memory_reads(estimate_size(input));
state.add_global_memory_writes(result_size);

set_throughputs(state);
Expand Down
4 changes: 2 additions & 2 deletions cpp/benchmarks/reduction/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void BM_reduction(benchmark::State& state, std::unique_ptr<cudf::reduce_aggregat
auto const dtype = cudf::type_to_id<type>();
data_profile const profile =
data_profile_builder().no_validity().distribution(dtype, distribution_id::UNIFORM, 0, 100);
auto input_column = create_random_column(dtype, row_count{column_size}, profile);
auto const input_column = create_random_column(dtype, row_count{column_size}, profile);

cudf::data_type output_dtype =
(agg->kind == cudf::aggregation::MEAN || agg->kind == cudf::aggregation::VARIANCE ||
Expand All @@ -51,7 +51,7 @@ void BM_reduction(benchmark::State& state, std::unique_ptr<cudf::reduce_aggregat

// The benchmark takes a column and produces two scalars.
set_items_processed(state, column_size + 1);
set_bytes_processed(state, estimate_size(std::move(input_column)) + cudf::size_of(output_dtype));
set_bytes_processed(state, estimate_size(input_column->view()) + cudf::size_of(output_dtype));
}

#define concat(a, b, c) a##b##c
Expand Down
6 changes: 3 additions & 3 deletions cpp/benchmarks/reduction/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void BM_reduction_scan(benchmark::State& state, bool include_nulls)
{
cudf::size_type const n_rows{(cudf::size_type)state.range(0)};
auto const dtype = cudf::type_to_id<type>();
auto column = create_random_column(dtype, row_count{n_rows});
auto const column = create_random_column(dtype, row_count{n_rows});
if (!include_nulls) column->set_null_mask(rmm::device_buffer{}, 0);

int64_t result_size = 0;
Expand All @@ -44,12 +44,12 @@ static void BM_reduction_scan(benchmark::State& state, bool include_nulls)
result = cudf::scan(
*column, *cudf::make_min_aggregation<cudf::scan_aggregation>(), cudf::scan_type::INCLUSIVE);
}
result_size = estimate_size(std::move(result));
result_size = estimate_size(result->view());
}

// The benchmark takes a column and produces a new column of the same size as input.
set_items_processed(state, n_rows * 2);
set_bytes_processed(state, estimate_size(std::move(column)) + result_size);
set_bytes_processed(state, estimate_size(column->view()) + result_size);
}

#define SCAN_BENCHMARK_DEFINE(name, type, nulls) \
Expand Down
16 changes: 7 additions & 9 deletions cpp/benchmarks/reduction/scan_structs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ static void nvbench_structs_scan(nvbench::state& state)
row_count{size},
profile);
auto [null_mask, null_count] = create_random_null_mask(size, null_probability);
auto input = cudf::make_structs_column(
auto const input = cudf::make_structs_column(
size, std::move(data_table->release()), null_count, std::move(null_mask));
std::vector<std::unique_ptr<cudf::column>> columns;
columns.emplace_back(std::move(input));
cudf::table input_table{std::move(columns)};
auto input_view = input->view();

auto const agg = cudf::make_min_aggregation<cudf::scan_aggregation>();
auto const null_policy = static_cast<cudf::null_policy>(state.get_int64("null_policy"));
Expand All @@ -59,16 +57,16 @@ static void nvbench_structs_scan(nvbench::state& state)
int64_t result_size = 0;
state.exec(nvbench::exec_tag::sync | nvbench::exec_tag::timer, [&](nvbench::launch& launch, auto& timer) {
timer.start();
auto result = cudf::detail::scan_inclusive(
input_table.view().column(0), *agg, null_policy, stream, rmm::mr::get_current_device_resource());
auto const result = cudf::detail::scan_inclusive(
input_view, *agg, null_policy, stream, rmm::mr::get_current_device_resource());
timer.stop();

// Estimating the result size will launch a kernel. Do not include it in measuring time.
result_size += estimate_size(std::move(result));
result_size += estimate_size(result->view());
});

state.add_element_count(input_table.num_rows());
state.add_global_memory_reads(estimate_size(input_table.view()));
state.add_element_count(input_view.size());
state.add_global_memory_reads(estimate_size(input_view));
state.add_global_memory_writes(result_size);

set_throughputs(state);
Expand Down

0 comments on commit 40804e2

Please sign in to comment.