Skip to content

Enable reporting peak memory usage for gtests #18599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions cpp/include/cudf_test/testing_main.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
* Copyright (c) 2020-2025, 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 @@ -33,6 +33,9 @@
#include <rmm/mr/device/managed_memory_resource.hpp>
#include <rmm/mr/device/owning_wrapper.hpp>
#include <rmm/mr/device/pool_memory_resource.hpp>
#include <rmm/mr/device/statistics_resource_adaptor.hpp>

#include <iostream>

namespace CUDF_EXPORT cudf {
namespace test {
Expand Down Expand Up @@ -226,10 +229,19 @@ inline void init_cudf_test(int argc, char** argv, cudf::test::config const& conf
* This `main` function is a wrapper around the google test generated `main`,
* maintaining the original functionality.
*/
#define CUDF_TEST_PROGRAM_MAIN() \
int main(int argc, char** argv) \
{ \
::testing::InitGoogleTest(&argc, argv); \
init_cudf_test(argc, argv); \
return RUN_ALL_TESTS(); \
#define CUDF_TEST_PROGRAM_MAIN() \
int main(int argc, char** argv) \
{ \
::testing::InitGoogleTest(&argc, argv); \
init_cudf_test(argc, argv); \
if (std::getenv("GTEST_CUDF_MEMORY_PEAK")) { \
auto mr = rmm::mr::statistics_resource_adaptor<rmm::mr::device_memory_resource>( \
cudf::get_current_device_resource()); \
cudf::set_current_device_resource(&mr); \
auto rc = RUN_ALL_TESTS(); \
std::cout << "Peak memory usage " << mr.get_bytes_counter().peak << " bytes" << std::endl; \
return rc; \
} else { \
return RUN_ALL_TESTS(); \
} \
}
16 changes: 16 additions & 0 deletions cpp/scripts/gtest_memory_usage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Copyright (c) 2025, NVIDIA CORPORATION.

export GTEST_CUDF_RMM_MODE=cuda
export GTEST_CUDF_MEMORY_PEAK=1
export GTEST_BRIEF=1
for gt in gtests/*_TEST ; do
test_name=$(basename "${gt}")
echo -n "$test_name"
# dependent on the string output from testing_main.hpp
bytes=$(${gt} 2>/dev/null | grep Peak | cut -d' ' -f4)
echo ",${bytes}"
done
unset GTEST_BRIEF
unset GTEST_CUDF_RMM_MODE
unset GTEST_CUDF_MEMORY_PEAK
12 changes: 7 additions & 5 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -697,22 +697,24 @@ ConfigureTest(STREAM_BINARYOP_TEST streams/binaryop_test.cpp STREAM_MODE testing
ConfigureTest(STREAM_COLUMN_VIEW_TEST streams/column_view_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_CONCATENATE_TEST streams/concatenate_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_COPYING_TEST streams/copying_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_CSVIO_TEST streams/io/csv_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_DATETIME_TEST streams/datetime_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_DICTIONARY_TEST streams/dictionary_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_FILLING_TEST streams/filling_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_GROUPBY_TEST streams/groupby_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_HASHING_TEST streams/hash_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_INTEROP streams/interop_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_IO_CSV_TEST streams/io/csv_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_IO_JSON_TEST streams/io/json_test.cpp STREAM_MODE testing)
ConfigureTest(
STREAM_IO_MULTIBYTE_SPLIT_TEST streams/io/multibyte_split_test.cpp STREAM_MODE testing
)
ConfigureTest(STREAM_IO_ORC_TEST streams/io/orc_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_IO_PARQUET_TEST streams/io/parquet_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_JOIN_TEST streams/join_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_JSONIO_TEST streams/io/json_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_LABELING_BINS_TEST streams/labeling_bins_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_LISTS_TEST streams/lists_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_MERGE_TEST streams/merge_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_MULTIBYTE_SPLIT_TEST streams/io/multibyte_split_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_NULL_MASK_TEST streams/null_mask_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_ORCIO_TEST streams/io/orc_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_PARQUETIO_TEST streams/io/parquet_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_PARTITIONING_TEST streams/partitioning_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_POOL_TEST streams/pool_test.cu STREAM_MODE testing)
ConfigureTest(STREAM_QUANTILE_TEST streams/quantile_test.cpp STREAM_MODE testing)
Expand Down
6 changes: 5 additions & 1 deletion cpp/tests/streams/binaryop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/binaryop.hpp>
#include <cudf/jit/runtime_support.hpp>
Expand Down Expand Up @@ -122,5 +123,8 @@ TEST_F(BinaryopPTXTest, ColumnColumnPTX)

cudf::binary_operation(
lhs, rhs, ptx, cudf::data_type(cudf::type_to_id<int32_t>()), cudf::test::get_default_stream());
cudf::binary_operation(lhs, rhs, ptx, cudf::data_type(cudf::type_to_id<int64_t>()));
cudf::binary_operation(
lhs, rhs, ptx, cudf::data_type(cudf::type_to_id<int64_t>()), cudf::test::get_default_stream());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix! Not sure how the stream tests were passing earlier though 😕

}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/concatenate_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/concatenate.hpp>

Expand Down Expand Up @@ -49,3 +50,5 @@ TEST_F(ConcatenateTest, Masks)
std::vector<cudf::column_view> views{input1, input2};
auto result = cudf::concatenate_masks(views, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
3 changes: 3 additions & 0 deletions cpp/tests/streams/copying_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/testing_main.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/contiguous_split.hpp>
Expand Down Expand Up @@ -360,3 +361,5 @@ TEST_F(CopyingTest, ContiguousSplit)
cudf::table_view tbl({col, col2});
auto result = cudf::contiguous_split(tbl, splits, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/datetime_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/datetime.hpp>
#include <cudf/scalar/scalar_factories.hpp>
Expand Down Expand Up @@ -147,3 +148,5 @@ TEST_F(DatetimeTest, RoundDatetimes)
cudf::datetime::round_datetimes(
timestamps, cudf::datetime::rounding_frequency::HOUR, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/dictionary_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/dictionary/dictionary_column_view.hpp>
#include <cudf/dictionary/dictionary_factories.hpp>
Expand Down Expand Up @@ -149,3 +150,5 @@ TEST_F(DictionaryTest, MatchDictionaries)
cudf::test::fixed_width_column_wrapper<int> keys_col({2, 6});
cudf::dictionary::match_dictionaries(dicts, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/filling_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/column/column_view.hpp>
#include <cudf/filling.hpp>
Expand Down Expand Up @@ -74,3 +75,5 @@ TEST_F(FillingTest, CalendricalMonthSequence)

cudf::calendrical_month_sequence(10, init, 2, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/groupby_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/testing_main.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -120,3 +121,5 @@ TEST_F(GroupbyTest, ReplaceNullsTest)
auto p =
gb_obj.replace_nulls(cudf::table_view({val}), policies, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/hash_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/hashing.hpp>

Expand Down Expand Up @@ -52,3 +53,5 @@ TEST_F(HashTest, MultiValue)
auto const output1 = cudf::hashing::murmurhash3_x86_32(
input1, cudf::DEFAULT_HASH_SEED, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/interop_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/interop.hpp>
#include <cudf/table/table_view.hpp>
Expand Down Expand Up @@ -46,3 +47,5 @@ TEST_F(DLPackTest, FromDLPack)
unique_managed_tensor tensor(cudf::to_dlpack(input, cudf::test::get_default_stream()));
auto result = cudf::from_dlpack(tensor.get(), cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/io/csv_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/io/csv.hpp>
#include <cudf/table/table_view.hpp>
Expand Down Expand Up @@ -90,3 +91,5 @@ TEST_F(CSVTest, CSVReader)
cudf::io::csv_reader_options::builder(cudf::io::source_info{filepath}).build();
cudf::io::read_csv(r_options, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/io/json_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -18,6 +18,7 @@
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/io/json.hpp>
#include <cudf/table/table_view.hpp>
Expand Down Expand Up @@ -61,3 +62,5 @@ TEST_F(JSONTest, JSONwriter)

cudf::io::write_json(options_builder.build(), cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/io/multibyte_split_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, 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 @@ -16,6 +16,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/io/text/data_chunk_source_factories.hpp>
#include <cudf/io/text/multibyte_split.hpp>
Expand All @@ -33,3 +34,5 @@ TEST_F(MultibyteSplitTest, Reader)
auto result =
cudf::io::text::multibyte_split(*source, delimiter, options, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/io/orc_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/io/orc.hpp>
#include <cudf/io/orc_metadata.hpp>
Expand Down Expand Up @@ -115,3 +116,5 @@ TEST_F(ORCTest, ORCReader)
auto meta = read_orc_metadata(cudf::io::source_info{filepath});
auto const stats = cudf::io::read_parsed_orc_statistics(cudf::io::source_info{filepath});
}

CUDF_TEST_PROGRAM_MAIN()
5 changes: 4 additions & 1 deletion cpp/tests/streams/io/parquet_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
* Copyright (c) 2023-2025, 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 @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/io/parquet.hpp>
#include <cudf/table/table.hpp>
Expand Down Expand Up @@ -122,3 +123,5 @@ TEST_F(ParquetTest, ChunkedOperations)
auto chunk = reader.read_chunk();
}
}

CUDF_TEST_PROGRAM_MAIN()
3 changes: 3 additions & 0 deletions cpp/tests/streams/join_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/testing_main.hpp>

#include <cudf/ast/expressions.hpp>
#include <cudf/column/column.hpp>
Expand Down Expand Up @@ -218,3 +219,5 @@ TEST_F(JoinTest, ConditionalLeftAntiJoinSize)
cudf::conditional_left_anti_join_size(
table0, table1, left_zero_eq_right_zero, cudf::test::get_default_stream());
}

CUDF_TEST_PROGRAM_MAIN()
Loading