Skip to content

Commit ea0ff25

Browse files
authored
Enable reporting peak memory usage for gtests (#18599)
Enables libcudf gtests to report peak memory usage after the tests complete. The memory peak uses the `rmm::mr::statistics_resource_adaptor` and is triggered with the environment variable `GTEST_CUDF_MEMORY_PEAK` Working on this uncovered that most of the `STREAM_` based tests were not using the `CUDF_TEST_PROGRAM_MAIN()` and so did not support custom parameters. Also, at least one test failed the stream check after this was corrected. The PR includes a shell script to run each test and report the peak memory for each to stdout in CSV format. Authors: - David Wendt (https://github.com/davidwendt) Approvers: - Bradley Dice (https://github.com/bdice) - Shruti Shivakumar (https://github.com/shrshi) URL: #18599
1 parent 2cb7be3 commit ea0ff25

38 files changed

+182
-41
lines changed

cpp/include/cudf_test/testing_main.hpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,9 @@
3333
#include <rmm/mr/device/managed_memory_resource.hpp>
3434
#include <rmm/mr/device/owning_wrapper.hpp>
3535
#include <rmm/mr/device/pool_memory_resource.hpp>
36+
#include <rmm/mr/device/statistics_resource_adaptor.hpp>
37+
38+
#include <iostream>
3639

3740
namespace CUDF_EXPORT cudf {
3841
namespace test {
@@ -226,10 +229,19 @@ inline void init_cudf_test(int argc, char** argv, cudf::test::config const& conf
226229
* This `main` function is a wrapper around the google test generated `main`,
227230
* maintaining the original functionality.
228231
*/
229-
#define CUDF_TEST_PROGRAM_MAIN() \
230-
int main(int argc, char** argv) \
231-
{ \
232-
::testing::InitGoogleTest(&argc, argv); \
233-
init_cudf_test(argc, argv); \
234-
return RUN_ALL_TESTS(); \
232+
#define CUDF_TEST_PROGRAM_MAIN() \
233+
int main(int argc, char** argv) \
234+
{ \
235+
::testing::InitGoogleTest(&argc, argv); \
236+
init_cudf_test(argc, argv); \
237+
if (std::getenv("GTEST_CUDF_MEMORY_PEAK")) { \
238+
auto mr = rmm::mr::statistics_resource_adaptor<rmm::mr::device_memory_resource>( \
239+
cudf::get_current_device_resource()); \
240+
cudf::set_current_device_resource(&mr); \
241+
auto rc = RUN_ALL_TESTS(); \
242+
std::cout << "Peak memory usage " << mr.get_bytes_counter().peak << " bytes" << std::endl; \
243+
return rc; \
244+
} else { \
245+
return RUN_ALL_TESTS(); \
246+
} \
235247
}

cpp/scripts/gtest_memory_usage.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Copyright (c) 2025, NVIDIA CORPORATION.
3+
4+
export GTEST_CUDF_RMM_MODE=cuda
5+
export GTEST_CUDF_MEMORY_PEAK=1
6+
export GTEST_BRIEF=1
7+
for gt in gtests/*_TEST ; do
8+
test_name=$(basename "${gt}")
9+
echo -n "$test_name"
10+
# dependent on the string output from testing_main.hpp
11+
bytes=$(${gt} 2>/dev/null | grep Peak | cut -d' ' -f4)
12+
echo ",${bytes}"
13+
done
14+
unset GTEST_BRIEF
15+
unset GTEST_CUDF_RMM_MODE
16+
unset GTEST_CUDF_MEMORY_PEAK

cpp/tests/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,22 +700,24 @@ ConfigureTest(STREAM_BINARYOP_TEST streams/binaryop_test.cpp STREAM_MODE testing
700700
ConfigureTest(STREAM_COLUMN_VIEW_TEST streams/column_view_test.cpp STREAM_MODE testing)
701701
ConfigureTest(STREAM_CONCATENATE_TEST streams/concatenate_test.cpp STREAM_MODE testing)
702702
ConfigureTest(STREAM_COPYING_TEST streams/copying_test.cpp STREAM_MODE testing)
703-
ConfigureTest(STREAM_CSVIO_TEST streams/io/csv_test.cpp STREAM_MODE testing)
704703
ConfigureTest(STREAM_DATETIME_TEST streams/datetime_test.cpp STREAM_MODE testing)
705704
ConfigureTest(STREAM_DICTIONARY_TEST streams/dictionary_test.cpp STREAM_MODE testing)
706705
ConfigureTest(STREAM_FILLING_TEST streams/filling_test.cpp STREAM_MODE testing)
707706
ConfigureTest(STREAM_GROUPBY_TEST streams/groupby_test.cpp STREAM_MODE testing)
708707
ConfigureTest(STREAM_HASHING_TEST streams/hash_test.cpp STREAM_MODE testing)
709708
ConfigureTest(STREAM_INTEROP streams/interop_test.cpp STREAM_MODE testing)
709+
ConfigureTest(STREAM_IO_CSV_TEST streams/io/csv_test.cpp STREAM_MODE testing)
710+
ConfigureTest(STREAM_IO_JSON_TEST streams/io/json_test.cpp STREAM_MODE testing)
711+
ConfigureTest(
712+
STREAM_IO_MULTIBYTE_SPLIT_TEST streams/io/multibyte_split_test.cpp STREAM_MODE testing
713+
)
714+
ConfigureTest(STREAM_IO_ORC_TEST streams/io/orc_test.cpp STREAM_MODE testing)
715+
ConfigureTest(STREAM_IO_PARQUET_TEST streams/io/parquet_test.cpp STREAM_MODE testing)
710716
ConfigureTest(STREAM_JOIN_TEST streams/join_test.cpp STREAM_MODE testing)
711-
ConfigureTest(STREAM_JSONIO_TEST streams/io/json_test.cpp STREAM_MODE testing)
712717
ConfigureTest(STREAM_LABELING_BINS_TEST streams/labeling_bins_test.cpp STREAM_MODE testing)
713718
ConfigureTest(STREAM_LISTS_TEST streams/lists_test.cpp STREAM_MODE testing)
714719
ConfigureTest(STREAM_MERGE_TEST streams/merge_test.cpp STREAM_MODE testing)
715-
ConfigureTest(STREAM_MULTIBYTE_SPLIT_TEST streams/io/multibyte_split_test.cpp STREAM_MODE testing)
716720
ConfigureTest(STREAM_NULL_MASK_TEST streams/null_mask_test.cpp STREAM_MODE testing)
717-
ConfigureTest(STREAM_ORCIO_TEST streams/io/orc_test.cpp STREAM_MODE testing)
718-
ConfigureTest(STREAM_PARQUETIO_TEST streams/io/parquet_test.cpp STREAM_MODE testing)
719721
ConfigureTest(STREAM_PARTITIONING_TEST streams/partitioning_test.cpp STREAM_MODE testing)
720722
ConfigureTest(STREAM_POOL_TEST streams/pool_test.cu STREAM_MODE testing)
721723
ConfigureTest(STREAM_QUANTILE_TEST streams/quantile_test.cpp STREAM_MODE testing)

cpp/tests/large_strings/large_strings_fixture.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -127,5 +127,13 @@ int main(int argc, char** argv)
127127
// create object to automatically be destroyed at the end of main()
128128
auto lsd = cudf::test::StringsLargeTest::get_ls_data();
129129

130+
if (std::getenv("GTEST_CUDF_MEMORY_PEAK")) {
131+
auto mr = rmm::mr::statistics_resource_adaptor<rmm::mr::device_memory_resource>(
132+
cudf::get_current_device_resource());
133+
cudf::set_current_device_resource(&mr);
134+
auto rc = RUN_ALL_TESTS();
135+
std::cout << "Peak memory usage " << mr.get_bytes_counter().peak << " bytes" << std::endl;
136+
return rc;
137+
}
130138
return RUN_ALL_TESTS();
131139
}

cpp/tests/streams/binaryop_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

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

123124
cudf::binary_operation(
124125
lhs, rhs, ptx, cudf::data_type(cudf::type_to_id<int32_t>()), cudf::test::get_default_stream());
125-
cudf::binary_operation(lhs, rhs, ptx, cudf::data_type(cudf::type_to_id<int64_t>()));
126+
cudf::binary_operation(
127+
lhs, rhs, ptx, cudf::data_type(cudf::type_to_id<int64_t>()), cudf::test::get_default_stream());
126128
}
129+
130+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/concatenate_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/concatenate.hpp>
2223

@@ -49,3 +50,5 @@ TEST_F(ConcatenateTest, Masks)
4950
std::vector<cudf::column_view> views{input1, input2};
5051
auto result = cudf::concatenate_masks(views, cudf::test::get_default_stream());
5152
}
53+
54+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/copying_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
2020
#include <cudf_test/iterator_utilities.hpp>
21+
#include <cudf_test/testing_main.hpp>
2122
#include <cudf_test/type_lists.hpp>
2223

2324
#include <cudf/contiguous_split.hpp>
@@ -360,3 +361,5 @@ TEST_F(CopyingTest, ContiguousSplit)
360361
cudf::table_view tbl({col, col2});
361362
auto result = cudf::contiguous_split(tbl, splits, cudf::test::get_default_stream());
362363
}
364+
365+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/datetime_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/datetime.hpp>
2223
#include <cudf/scalar/scalar_factories.hpp>
@@ -147,3 +148,5 @@ TEST_F(DatetimeTest, RoundDatetimes)
147148
cudf::datetime::round_datetimes(
148149
timestamps, cudf::datetime::rounding_frequency::HOUR, cudf::test::get_default_stream());
149150
}
151+
152+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/dictionary_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/dictionary/dictionary_column_view.hpp>
2223
#include <cudf/dictionary/dictionary_factories.hpp>
@@ -149,3 +150,5 @@ TEST_F(DictionaryTest, MatchDictionaries)
149150
cudf::test::fixed_width_column_wrapper<int> keys_col({2, 6});
150151
cudf::dictionary::match_dictionaries(dicts, cudf::test::get_default_stream());
151152
}
153+
154+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/filling_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

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

7576
cudf::calendrical_month_sequence(10, init, 2, cudf::test::get_default_stream());
7677
}
78+
79+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/groupby_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
#include <cudf_test/base_fixture.hpp>
2020
#include <cudf_test/column_wrapper.hpp>
21+
#include <cudf_test/testing_main.hpp>
2122
#include <cudf_test/type_lists.hpp>
2223

2324
#include <cudf/detail/aggregation/aggregation.hpp>
@@ -120,3 +121,5 @@ TEST_F(GroupbyTest, ReplaceNullsTest)
120121
auto p =
121122
gb_obj.replace_nulls(cudf::table_view({val}), policies, cudf::test::get_default_stream());
122123
}
124+
125+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/hash_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/hashing.hpp>
2223

@@ -52,3 +53,5 @@ TEST_F(HashTest, MultiValue)
5253
auto const output1 = cudf::hashing::murmurhash3_x86_32(
5354
input1, cudf::DEFAULT_HASH_SEED, cudf::test::get_default_stream());
5455
}
56+
57+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/interop_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/interop.hpp>
2223
#include <cudf/table/table_view.hpp>
@@ -46,3 +47,5 @@ TEST_F(DLPackTest, FromDLPack)
4647
unique_managed_tensor tensor(cudf::to_dlpack(input, cudf::test::get_default_stream()));
4748
auto result = cudf::from_dlpack(tensor.get(), cudf::test::get_default_stream());
4849
}
50+
51+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/io/csv_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/io/csv.hpp>
2223
#include <cudf/table/table_view.hpp>
@@ -90,3 +91,5 @@ TEST_F(CSVTest, CSVReader)
9091
cudf::io::csv_reader_options::builder(cudf::io::source_info{filepath}).build();
9192
cudf::io::read_csv(r_options, cudf::test::get_default_stream());
9293
}
94+
95+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/io/json_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
2020
#include <cudf_test/iterator_utilities.hpp>
21+
#include <cudf_test/testing_main.hpp>
2122

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

6263
cudf::io::write_json(options_builder.build(), cudf::test::get_default_stream());
6364
}
65+
66+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/io/multibyte_split_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/default_stream.hpp>
19+
#include <cudf_test/testing_main.hpp>
1920

2021
#include <cudf/io/text/data_chunk_source_factories.hpp>
2122
#include <cudf/io/text/multibyte_split.hpp>
@@ -33,3 +34,5 @@ TEST_F(MultibyteSplitTest, Reader)
3334
auto result =
3435
cudf::io::text::multibyte_split(*source, delimiter, options, cudf::test::get_default_stream());
3536
}
37+
38+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/io/orc_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/io/orc.hpp>
2223
#include <cudf/io/orc_metadata.hpp>
@@ -115,3 +116,5 @@ TEST_F(ORCTest, ORCReader)
115116
auto meta = read_orc_metadata(cudf::io::source_info{filepath});
116117
auto const stats = cudf::io::read_parsed_orc_statistics(cudf::io::source_info{filepath});
117118
}
119+
120+
CUDF_TEST_PROGRAM_MAIN()

cpp/tests/streams/io/parquet_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
#include <cudf_test/base_fixture.hpp>
1818
#include <cudf_test/column_wrapper.hpp>
1919
#include <cudf_test/default_stream.hpp>
20+
#include <cudf_test/testing_main.hpp>
2021

2122
#include <cudf/io/parquet.hpp>
2223
#include <cudf/table/table.hpp>
@@ -122,3 +123,5 @@ TEST_F(ParquetTest, ChunkedOperations)
122123
auto chunk = reader.read_chunk();
123124
}
124125
}
126+
127+
CUDF_TEST_PROGRAM_MAIN()

0 commit comments

Comments
 (0)