Skip to content

Commit

Permalink
Add peak memory usage tracking to cuIO benchmarks (#7770)
Browse files Browse the repository at this point in the history
Uses `rmm::mr::statistics_resource_adapter` to track peak memory usage in cuIO benchmarks.

Authors:
  - Devavret Makkar (https://github.com/devavret)

Approvers:
  - David Wendt (https://github.com/davidwendt)
  - Mark Harris (https://github.com/harrism)
  - Vukasin Milovanovic (https://github.com/vuule)

URL: #7770
  • Loading branch information
devavret authored Jul 19, 2021
1 parent 4d7ad4f commit fdf4901
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 7 deletions.
23 changes: 22 additions & 1 deletion cpp/benchmarks/fixture/benchmark_fixture.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2020, NVIDIA CORPORATION.
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,11 +14,14 @@
* limitations under the License.
*/

#pragma once

#include <benchmark/benchmark.h>
#include <rmm/mr/device/cuda_memory_resource.hpp>
#include <rmm/mr/device/owning_wrapper.hpp>
#include <rmm/mr/device/per_device_resource.hpp>
#include <rmm/mr/device/pool_memory_resource.hpp>
#include <rmm/mr/device/statistics_resource_adaptor.hpp>

namespace cudf {

Expand Down Expand Up @@ -88,4 +91,22 @@ class benchmark : public ::benchmark::Fixture {
std::shared_ptr<rmm::mr::device_memory_resource> mr;
};

class memory_stats_logger {
public:
memory_stats_logger()
: existing_mr(rmm::mr::get_current_device_resource()),
statistics_mr(rmm::mr::make_statistics_adaptor(existing_mr))
{
rmm::mr::set_current_device_resource(&statistics_mr);
}

~memory_stats_logger() { rmm::mr::set_current_device_resource(existing_mr); }

size_t peak_memory_usage() const noexcept { return statistics_mr.get_bytes_counter().peak; }

private:
rmm::mr::device_memory_resource* existing_mr;
rmm::mr::statistics_resource_adaptor<rmm::mr::device_memory_resource> statistics_mr;
};

} // namespace cudf
7 changes: 6 additions & 1 deletion cpp/benchmarks/io/csv/csv_reader_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,12 +51,14 @@ void BM_csv_read_varying_input(benchmark::State& state)
cudf_io::csv_reader_options const read_options =
cudf_io::csv_reader_options::builder(source_sink.make_source_info());

auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::read_csv(read_options);
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

void BM_csv_read_varying_options(benchmark::State& state)
Expand Down Expand Up @@ -94,6 +96,7 @@ void BM_csv_read_varying_options(benchmark::State& state)

size_t const chunk_size = csv_data.size() / num_chunks;
cudf::size_type const chunk_row_cnt = view.num_rows() / num_chunks;
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
for (int32_t chunk = 0; chunk < num_chunks; ++chunk) {
Expand Down Expand Up @@ -124,8 +127,10 @@ void BM_csv_read_varying_options(benchmark::State& state)
cudf_io::read_csv(read_options);
}
}

auto const data_processed = data_size * cols_to_read.size() / view.num_columns();
state.SetBytesProcessed(data_processed * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

#define CSV_RD_BM_INPUTS_DEFINE(name, type_or_group, src_type) \
Expand Down
6 changes: 5 additions & 1 deletion cpp/benchmarks/io/csv/csv_writer_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,7 @@ void BM_csv_write_varying_inout(benchmark::State& state)
auto const view = tbl->view();

cuio_source_sink_pair source_sink(sink_type);
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::csv_writer_options options =
Expand All @@ -52,6 +53,7 @@ void BM_csv_write_varying_inout(benchmark::State& state)
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

void BM_csv_write_varying_options(benchmark::State& state)
Expand All @@ -69,6 +71,7 @@ void BM_csv_write_varying_options(benchmark::State& state)

std::string const na_per(na_per_len, '#');
std::vector<char> csv_data;
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::csv_writer_options options =
Expand All @@ -80,6 +83,7 @@ void BM_csv_write_varying_options(benchmark::State& state)
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

#define CSV_WR_BM_INOUTS_DEFINE(name, type_or_group, sink_type) \
Expand Down
7 changes: 6 additions & 1 deletion cpp/benchmarks/io/orc/orc_reader_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,12 +58,14 @@ void BM_orc_read_varying_input(benchmark::State& state)
cudf_io::orc_reader_options read_opts =
cudf_io::orc_reader_options::builder(source_sink.make_source_info());

auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::read_orc(read_opts);
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

std::vector<std::string> get_col_names(std::vector<char> const& orc_data)
Expand Down Expand Up @@ -110,6 +112,7 @@ void BM_orc_read_varying_options(benchmark::State& state)

auto const num_stripes = data_size / (64 << 20);
cudf::size_type const chunk_row_cnt = view.num_rows() / num_chunks;
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0

Expand Down Expand Up @@ -139,8 +142,10 @@ void BM_orc_read_varying_options(benchmark::State& state)

CUDF_EXPECTS(rows_read == view.num_rows(), "Benchmark did not read the entire table");
}

auto const data_processed = data_size * cols_to_read.size() / view.num_columns();
state.SetBytesProcessed(data_processed * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

#define ORC_RD_BM_INPUTS_DEFINE(name, type_or_group, src_type) \
Expand Down
6 changes: 5 additions & 1 deletion cpp/benchmarks/io/orc/orc_writer_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,6 +50,7 @@ void BM_orc_write_varying_inout(benchmark::State& state)
auto const view = tbl->view();

cuio_source_sink_pair source_sink(sink_type);
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::orc_writer_options options =
Expand All @@ -59,6 +60,7 @@ void BM_orc_write_varying_inout(benchmark::State& state)
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

void BM_orc_write_varying_options(benchmark::State& state)
Expand All @@ -75,6 +77,7 @@ void BM_orc_write_varying_options(benchmark::State& state)
auto const view = tbl->view();

cuio_source_sink_pair source_sink(io_type::FILEPATH);
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::orc_writer_options const options =
Expand All @@ -85,6 +88,7 @@ void BM_orc_write_varying_options(benchmark::State& state)
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

#define ORC_WR_BM_INOUTS_DEFINE(name, type_or_group, sink_type) \
Expand Down
7 changes: 6 additions & 1 deletion cpp/benchmarks/io/parquet/parquet_reader_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,12 +58,14 @@ void BM_parq_read_varying_input(benchmark::State& state)
cudf_io::parquet_reader_options read_opts =
cudf_io::parquet_reader_options::builder(source_sink.make_source_info());

auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer const raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::read_parquet(read_opts);
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

std::vector<std::string> get_col_names(std::vector<char> const& parquet_data)
Expand Down Expand Up @@ -112,6 +114,7 @@ void BM_parq_read_varying_options(benchmark::State& state)

auto const num_row_groups = data_size / (128 << 20);
cudf::size_type const chunk_row_cnt = view.num_rows() / num_chunks;
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0

Expand Down Expand Up @@ -141,8 +144,10 @@ void BM_parq_read_varying_options(benchmark::State& state)

CUDF_EXPECTS(rows_read == view.num_rows(), "Benchmark did not read the entire table");
}

auto const data_processed = data_size * cols_to_read.size() / view.num_columns();
state.SetBytesProcessed(data_processed * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

#define PARQ_RD_BM_INPUTS_DEFINE(name, type_or_group, src_type) \
Expand Down
6 changes: 5 additions & 1 deletion cpp/benchmarks/io/parquet/parquet_writer_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,6 +50,7 @@ void BM_parq_write_varying_inout(benchmark::State& state)
auto const view = tbl->view();

cuio_source_sink_pair source_sink(sink_type);
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::parquet_writer_options opts =
Expand All @@ -59,6 +60,7 @@ void BM_parq_write_varying_inout(benchmark::State& state)
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

void BM_parq_write_varying_options(benchmark::State& state)
Expand All @@ -76,6 +78,7 @@ void BM_parq_write_varying_options(benchmark::State& state)
auto const view = tbl->view();

cuio_source_sink_pair source_sink(io_type::FILEPATH);
auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::parquet_writer_options const options =
Expand All @@ -87,6 +90,7 @@ void BM_parq_write_varying_options(benchmark::State& state)
}

state.SetBytesProcessed(data_size * state.iterations());
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

#define PARQ_WR_BM_INOUTS_DEFINE(name, type_or_group, sink_type) \
Expand Down
4 changes: 4 additions & 0 deletions cpp/benchmarks/io/parquet/parquet_writer_chunks_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void PQ_write(benchmark::State& state)
auto tbl = create_random_table({cudf::type_id::INT32}, num_cols, table_size_bytes{data_size});
cudf::table_view view = tbl->view();

auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::parquet_writer_options opts =
Expand All @@ -55,6 +56,7 @@ void PQ_write(benchmark::State& state)
}

state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) * state.range(0));
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

void PQ_write_chunked(benchmark::State& state)
Expand All @@ -68,6 +70,7 @@ void PQ_write_chunked(benchmark::State& state)
{cudf::type_id::INT32}, num_cols, table_size_bytes{size_t(data_size / num_tables)}));
}

auto mem_stats_logger = cudf::memory_stats_logger();
for (auto _ : state) {
cuda_event_timer raii(state, true); // flush_l2_cache = true, stream = 0
cudf_io::chunked_parquet_writer_options opts =
Expand All @@ -80,6 +83,7 @@ void PQ_write_chunked(benchmark::State& state)
}

state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) * state.range(0));
state.counters["peak_memory_usage"] = mem_stats_logger.peak_memory_usage();
}

#define PWBM_BENCHMARK_DEFINE(name, size, num_columns) \
Expand Down

0 comments on commit fdf4901

Please sign in to comment.