From f655602ecd8f254dfcee5eb0c790bd3336e83d7c Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 11 Jun 2024 15:59:20 -0700 Subject: [PATCH 1/9] Fix Cython typo preventing proper inheritance (#15978) #15831 added new inheritance patterns to the Parquet options classes, but mirroring them perfectly in Cython proved problematic due to what appeared to be issues with Cython parsing of CRTP and inheritance. A deeper investigation revealed that the underlying issue was https://github.com/cython/cython/issues/6238. This PR applies the appropriate fix. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Thomas Li (https://github.com/lithomas1) - Bradley Dice (https://github.com/bdice) URL: https://github.com/rapidsai/cudf/pull/15978 --- .../_lib/pylibcudf/libcudf/io/parquet.pxd | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/python/cudf/cudf/_lib/pylibcudf/libcudf/io/parquet.pxd b/python/cudf/cudf/_lib/pylibcudf/libcudf/io/parquet.pxd index 36654457995..0ef6553db56 100644 --- a/python/cudf/cudf/_lib/pylibcudf/libcudf/io/parquet.pxd +++ b/python/cudf/cudf/_lib/pylibcudf/libcudf/io/parquet.pxd @@ -123,7 +123,7 @@ cdef extern from "cudf/io/parquet.hpp" namespace "cudf::io" nogil: ) except + cdef cppclass parquet_writer_options_builder_base[BuilderT, OptionsT]: - parquet_writer_options_builder() except + + parquet_writer_options_builder_base() except + BuilderT& metadata( cudf_io_types.table_input_metadata m @@ -164,22 +164,6 @@ cdef extern from "cudf/io/parquet.hpp" namespace "cudf::io" nogil: BuilderT& dictionary_policy( cudf_io_types.dictionary_policy val ) except + - # FIXME: the following two functions actually belong in - # parquet_writer_options_builder, but placing them there yields a - # "'parquet_writer_options_builder' is not a type identifier" error. - # This is probably a bug in cython since a simpler CRTP example that - # has methods returning references to a child class seem to work. - # Calling these from the chunked options builder will fail at compile - # time, so this should be safe. - # NOTE: these two are never actually called from libcudf. Instead these - # properties are set in the options after calling build(), so perhaps - # they can be removed. - BuilderT& partitions( - vector[cudf_io_types.partition_info] partitions - ) except + - BuilderT& column_chunks_file_paths( - vector[string] column_chunks_file_paths - ) except + OptionsT build() except + cdef cppclass parquet_writer_options_builder( @@ -190,6 +174,12 @@ cdef extern from "cudf/io/parquet.hpp" namespace "cudf::io" nogil: cudf_io_types.sink_info sink_, cudf_table_view.table_view table_ ) except + + parquet_writer_options_builder& partitions( + vector[cudf_io_types.partition_info] partitions + ) except + + parquet_writer_options_builder& column_chunks_file_paths( + vector[string] column_chunks_file_paths + ) except + cdef unique_ptr[vector[uint8_t]] write_parquet( parquet_writer_options args From 49e2a565ffb85479589406f622c74116d7f891c7 Mon Sep 17 00:00:00 2001 From: David Wendt <45795991+davidwendt@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:27:54 -0400 Subject: [PATCH 2/9] Support large strings in cudf::io::text::multibyte_split (#15947) Replaces int32 type used for building offsets in `cudf::io::text::multibyte_split()` to use the offsetalator instead. This allows creating large strings columns from input text files. Authors: - David Wendt (https://github.com/davidwendt) Approvers: - Mark Harris (https://github.com/harrism) - Bradley Dice (https://github.com/bdice) - Karthikeyan (https://github.com/karthikeyann) URL: https://github.com/rapidsai/cudf/pull/15947 --- cpp/src/io/text/multibyte_split.cu | 38 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/cpp/src/io/text/multibyte_split.cu b/cpp/src/io/text/multibyte_split.cu index 976d735e010..9c406369068 100644 --- a/cpp/src/io/text/multibyte_split.cu +++ b/cpp/src/io/text/multibyte_split.cu @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include @@ -518,32 +520,37 @@ std::unique_ptr multibyte_split(cudf::io::text::data_chunk_source bool const insert_end = not(last_row_offset.has_value() or (global_offsets.size() > 0 and global_offsets.back_element(stream) == chunk_offset)); - rmm::device_uvector offsets{ - global_offsets.size() + insert_begin + insert_end, stream, mr}; - if (insert_begin) { offsets.set_element_to_zero_async(0, stream); } - if (insert_end) { - offsets.set_element(offsets.size() - 1, chunk_offset - *first_row_offset, stream); - } + auto const chars_bytes = chunk_offset - *first_row_offset; + auto offsets = cudf::strings::detail::create_offsets_child_column( + chars_bytes, global_offsets.size() + insert_begin + insert_end, stream, mr); + auto offsets_itr = + cudf::detail::offsetalator_factory::make_output_iterator(offsets->mutable_view()); + auto set_offset_value = [offsets_itr, stream](size_type index, int64_t value) { + cudf::detail::device_single_thread( + [offsets_itr, index, value] __device__() mutable { offsets_itr[index] = value; }, stream); + }; + if (insert_begin) { set_offset_value(0, 0); } + if (insert_end) { set_offset_value(offsets->size() - 1, chars_bytes); } thrust::transform(rmm::exec_policy(stream), global_offsets.begin(), global_offsets.end(), - offsets.begin() + insert_begin, - cuda::proclaim_return_type( + offsets_itr + insert_begin, + cuda::proclaim_return_type( [baseline = *first_row_offset] __device__(byte_offset global_offset) { - return static_cast(global_offset - baseline); + return (global_offset - baseline); })); - auto string_count = offsets.size() - 1; + auto string_count = offsets->size() - 1; if (strip_delimiters) { auto it = cudf::detail::make_counting_transform_iterator( 0, cuda::proclaim_return_type>( - [ofs = offsets.data(), + [ofs = cudf::detail::offsetalator_factory::make_input_iterator(offsets->view()), chars = chars.data(), delim_size = static_cast(delimiter.size()), last_row = static_cast(string_count) - 1, insert_end] __device__(size_type row) { auto const begin = ofs[row]; - auto const len = ofs[row + 1] - begin; + auto const len = static_cast(ofs[row + 1] - begin); if (row == last_row && insert_end) { return thrust::make_pair(chars + begin, len); } else { @@ -552,12 +559,7 @@ std::unique_ptr multibyte_split(cudf::io::text::data_chunk_source })); return cudf::strings::detail::make_strings_column(it, it + string_count, stream, mr); } else { - return cudf::make_strings_column( - string_count, - std::make_unique(std::move(offsets), rmm::device_buffer{}, 0), - chars.release(), - 0, - {}); + return cudf::make_strings_column(string_count, std::move(offsets), chars.release(), 0, {}); } } From d2cd1d4411e1a16f5c989efff07643ca3411f8ab Mon Sep 17 00:00:00 2001 From: Matthew Murray <41342305+Matt711@users.noreply.github.com> Date: Tue, 11 Jun 2024 20:28:40 -0400 Subject: [PATCH 3/9] Migrate lists/combine to pylibcudf (#15928) Part of #15162. concatenate_rows, concatenate_list_elements Authors: - Matthew Murray (https://github.com/Matt711) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) - Thomas Li (https://github.com/lithomas1) URL: https://github.com/rapidsai/cudf/pull/15928 --- python/cudf/cudf/_lib/lists.pyx | 46 ++++---------- python/cudf/cudf/_lib/pylibcudf/lists.pxd | 7 +++ python/cudf/cudf/_lib/pylibcudf/lists.pyx | 61 +++++++++++++++++++ .../cudf/cudf/pylibcudf_tests/test_lists.py | 46 ++++++++++++++ 4 files changed, 127 insertions(+), 33 deletions(-) create mode 100644 python/cudf/cudf/pylibcudf_tests/test_lists.py diff --git a/python/cudf/cudf/_lib/lists.pyx b/python/cudf/cudf/_lib/lists.pyx index 656d92c1a4b..5d406f5c85f 100644 --- a/python/cudf/cudf/_lib/lists.pyx +++ b/python/cudf/cudf/_lib/lists.pyx @@ -9,11 +9,6 @@ from libcpp.utility cimport move from cudf._lib.column cimport Column from cudf._lib.pylibcudf.libcudf.column.column cimport column from cudf._lib.pylibcudf.libcudf.column.column_view cimport column_view -from cudf._lib.pylibcudf.libcudf.lists.combine cimport ( - concatenate_list_elements as cpp_concatenate_list_elements, - concatenate_null_policy, - concatenate_rows as cpp_concatenate_rows, -) from cudf._lib.pylibcudf.libcudf.lists.contains cimport ( contains, index_of as cpp_index_of, @@ -32,7 +27,6 @@ from cudf._lib.pylibcudf.libcudf.lists.stream_compaction cimport ( distinct as cpp_distinct, ) from cudf._lib.pylibcudf.libcudf.scalar.scalar cimport scalar -from cudf._lib.pylibcudf.libcudf.table.table_view cimport table_view from cudf._lib.pylibcudf.libcudf.types cimport ( nan_equality, null_equality, @@ -41,10 +35,7 @@ from cudf._lib.pylibcudf.libcudf.types cimport ( size_type, ) from cudf._lib.scalar cimport DeviceScalar -from cudf._lib.utils cimport ( - columns_from_pylibcudf_table, - table_view_from_columns, -) +from cudf._lib.utils cimport columns_from_pylibcudf_table from cudf._lib import pylibcudf @@ -223,31 +214,20 @@ def index_of_column(Column col, Column search_keys): @acquire_spill_lock() def concatenate_rows(list source_columns): - cdef unique_ptr[column] c_result - - cdef table_view c_table_view = table_view_from_columns(source_columns) - - with nogil: - c_result = move(cpp_concatenate_rows( - c_table_view, - )) - - return Column.from_unique_ptr(move(c_result)) + return Column.from_pylibcudf( + pylibcudf.lists.concatenate_rows( + pylibcudf.Table([ + c.to_pylibcudf(mode="read") for c in source_columns + ]) + ) + ) @acquire_spill_lock() def concatenate_list_elements(Column input_column, dropna=False): - cdef concatenate_null_policy policy = ( - concatenate_null_policy.IGNORE if dropna - else concatenate_null_policy.NULLIFY_OUTPUT_ROW + return Column.from_pylibcudf( + pylibcudf.lists.concatenate_list_elements( + input_column.to_pylibcudf(mode="read"), + dropna, + ) ) - cdef column_view c_input = input_column.view() - cdef unique_ptr[column] c_result - - with nogil: - c_result = move(cpp_concatenate_list_elements( - c_input, - policy - )) - - return Column.from_unique_ptr(move(c_result)) diff --git a/python/cudf/cudf/_lib/pylibcudf/lists.pxd b/python/cudf/cudf/_lib/pylibcudf/lists.pxd index b780d299977..2d2a5b2a9ea 100644 --- a/python/cudf/cudf/_lib/pylibcudf/lists.pxd +++ b/python/cudf/cudf/_lib/pylibcudf/lists.pxd @@ -1,8 +1,15 @@ # Copyright (c) 2024, NVIDIA CORPORATION. +from libcpp cimport bool + from cudf._lib.pylibcudf.libcudf.types cimport size_type +from .column cimport Column from .table cimport Table cpdef Table explode_outer(Table, size_type explode_column_idx) + +cpdef Column concatenate_rows(Table) + +cpdef Column concatenate_list_elements(Column, bool dropna) diff --git a/python/cudf/cudf/_lib/pylibcudf/lists.pyx b/python/cudf/cudf/_lib/pylibcudf/lists.pyx index 654f39742b6..069c9da31c2 100644 --- a/python/cudf/cudf/_lib/pylibcudf/lists.pyx +++ b/python/cudf/cudf/_lib/pylibcudf/lists.pyx @@ -1,12 +1,20 @@ # Copyright (c) 2024, NVIDIA CORPORATION. +from libcpp cimport bool from libcpp.memory cimport unique_ptr from libcpp.utility cimport move +from cudf._lib.pylibcudf.libcudf.column.column cimport column from cudf._lib.pylibcudf.libcudf.lists cimport explode as cpp_explode +from cudf._lib.pylibcudf.libcudf.lists.combine cimport ( + concatenate_list_elements as cpp_concatenate_list_elements, + concatenate_null_policy, + concatenate_rows as cpp_concatenate_rows, +) from cudf._lib.pylibcudf.libcudf.table.table cimport table from cudf._lib.pylibcudf.libcudf.types cimport size_type +from .column cimport Column from .table cimport Table @@ -33,3 +41,56 @@ cpdef Table explode_outer(Table input, size_type explode_column_idx): c_result = move(cpp_explode.explode_outer(input.view(), explode_column_idx)) return Table.from_libcudf(move(c_result)) + + +cpdef Column concatenate_rows(Table input): + """Concatenate multiple lists columns into a single lists column row-wise. + + Parameters + ---------- + input : Table + The input table + + Returns + ------- + Table + A new Column of concatenated rows + """ + cdef unique_ptr[column] c_result + + with nogil: + c_result = move(cpp_concatenate_rows(input.view())) + + return Column.from_libcudf(move(c_result)) + + +cpdef Column concatenate_list_elements(Column input, bool dropna): + """Concatenate multiple lists on the same row into a single list. + + Parameters + ---------- + input : Column + The input column + + Returns + ------- + Column + A new Column of concatenated list elements + dropna : bool + If true, null list elements will be ignored + from concatenation. Otherwise any input null values will result in + the corresponding output row being set to null. + """ + cdef concatenate_null_policy null_policy = ( + concatenate_null_policy.IGNORE if dropna + else concatenate_null_policy.NULLIFY_OUTPUT_ROW + ) + cdef unique_ptr[column] c_result + + with nogil: + c_result = move(cpp_concatenate_list_elements( + input.view(), + null_policy, + )) + + return Column.from_libcudf(move(c_result)) diff --git a/python/cudf/cudf/pylibcudf_tests/test_lists.py b/python/cudf/cudf/pylibcudf_tests/test_lists.py new file mode 100644 index 00000000000..b21af8ea11c --- /dev/null +++ b/python/cudf/cudf/pylibcudf_tests/test_lists.py @@ -0,0 +1,46 @@ +# Copyright (c) 2024, NVIDIA CORPORATION. + +import pyarrow as pa +import pytest +from utils import assert_column_eq + +from cudf._lib import pylibcudf as plc + + +def test_concatenate_rows(): + test_data = [[[0, 1], [2], [5], [6, 7]], [[8], [9], [], [13, 14, 15]]] + + arrow_tbl = pa.Table.from_arrays(test_data, names=["a", "b"]) + plc_tbl = plc.interop.from_arrow(arrow_tbl) + + res = plc.lists.concatenate_rows(plc_tbl) + + expect = pa.array([pair[0] + pair[1] for pair in zip(*test_data)]) + + assert_column_eq(expect, res) + + +@pytest.mark.parametrize( + "test_data, dropna, expected", + [ + ( + [[[1, 2], [3, 4], [5]], [[6], None, [7, 8, 9]]], + False, + [[1, 2, 3, 4, 5], None], + ), + ( + [[[1, 2], [3, 4], [5, None]], [[6], [None], [7, 8, 9]]], + True, + [[1, 2, 3, 4, 5, None], [6, None, 7, 8, 9]], + ), + ], +) +def test_concatenate_list_elements(test_data, dropna, expected): + arr = pa.array(test_data) + plc_column = plc.interop.from_arrow(arr) + + res = plc.lists.concatenate_list_elements(plc_column, dropna) + + expect = pa.array(expected) + + assert_column_eq(expect, res) From f7ba6ab47ac994e6a1363119c01eee5dd6304181 Mon Sep 17 00:00:00 2001 From: Vukasin Milovanovic Date: Tue, 11 Jun 2024 17:47:19 -0700 Subject: [PATCH 4/9] Pinned vector factory that uses the global pool (#15895) closes https://github.com/rapidsai/cudf/issues/15612 Expanded the set of vector factories to cover pinned vectors. The functions return `cudf::detail::host_vector`, which use a type-erased allocator, allowing us to utilize the runtime configurable global pinned (previously host) resource. The `pinned_host_vector` type has been removed as it can only support the non-pooled pinned allocations. Its use is not replaced with `cudf::detail::host_vector`. Moved the global host (now pinned) resource out of cuIO and changed the type to host_device. User-specified resources are now required to allocate device-accessible memory. The name has been changed to pinned to reflect the new requirement. Authors: - Vukasin Milovanovic (https://github.com/vuule) Approvers: - Alessandro Bellina (https://github.com/abellina) - Yunsong Wang (https://github.com/PointKernel) - Mark Harris (https://github.com/harrism) - David Wendt (https://github.com/davidwendt) URL: https://github.com/rapidsai/cudf/pull/15895 --- cpp/CMakeLists.txt | 1 + cpp/benchmarks/fixture/nvbench_fixture.hpp | 13 +- cpp/benchmarks/io/cuio_common.cpp | 12 + cpp/benchmarks/io/cuio_common.hpp | 4 +- .../io/parquet/parquet_reader_multithread.cpp | 2 +- cpp/benchmarks/io/text/multibyte_split.cpp | 10 +- .../{rmm_host_vector.hpp => host_vector.hpp} | 18 +- .../detail/utilities/pinned_host_vector.hpp | 216 ------------------ .../detail/utilities/vector_factories.hpp | 38 ++- cpp/include/cudf/io/memory_resource.hpp | 65 ------ cpp/include/cudf/utilities/pinned_memory.hpp | 58 +++++ cpp/src/io/csv/reader_impl.cu | 1 + cpp/src/io/orc/reader_impl_chunking.cu | 1 + cpp/src/io/orc/writer_impl.cu | 5 +- cpp/src/io/parquet/reader_impl_helpers.cpp | 2 + cpp/src/io/parquet/writer_impl.cu | 3 +- cpp/src/io/text/bgzip_data_chunk_source.cu | 16 +- .../io/text/data_chunk_source_factories.cpp | 51 ++--- cpp/src/io/utilities/config_utils.cpp | 214 +---------------- cpp/src/io/utilities/hostdevice_vector.hpp | 9 +- cpp/src/utilities/pinned_memory.cpp | 216 ++++++++++++++++++ cpp/tests/CMakeLists.txt | 5 +- cpp/tests/io/json_test.cpp | 6 +- .../utilities_tests/io_utilities_tests.cpp | 45 ---- .../utilities_tests/pinned_memory_tests.cpp | 65 ++++++ .../java/ai/rapids/cudf/PinnedMemoryPool.java | 12 +- java/src/main/java/ai/rapids/cudf/Rmm.java | 2 +- java/src/main/native/src/RmmJni.cpp | 34 +-- 28 files changed, 487 insertions(+), 637 deletions(-) rename cpp/include/cudf/detail/utilities/{rmm_host_vector.hpp => host_vector.hpp} (93%) delete mode 100644 cpp/include/cudf/detail/utilities/pinned_host_vector.hpp delete mode 100644 cpp/include/cudf/io/memory_resource.hpp create mode 100644 cpp/include/cudf/utilities/pinned_memory.hpp create mode 100644 cpp/src/utilities/pinned_memory.cpp create mode 100644 cpp/tests/utilities_tests/pinned_memory_tests.cpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index ca85996b990..aab0a9b2d49 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -664,6 +664,7 @@ add_library( src/utilities/default_stream.cpp src/utilities/linked_column.cpp src/utilities/logger.cpp + src/utilities/pinned_memory.cpp src/utilities/stacktrace.cpp src/utilities/stream_pool.cpp src/utilities/traits.cpp diff --git a/cpp/benchmarks/fixture/nvbench_fixture.hpp b/cpp/benchmarks/fixture/nvbench_fixture.hpp index ebcbcb17e98..df1492690bb 100644 --- a/cpp/benchmarks/fixture/nvbench_fixture.hpp +++ b/cpp/benchmarks/fixture/nvbench_fixture.hpp @@ -15,8 +15,8 @@ */ #pragma once -#include #include +#include #include #include @@ -81,17 +81,18 @@ struct nvbench_base_fixture { "\nExpecting: cuda, pool, async, arena, managed, or managed_pool"); } - inline rmm::host_async_resource_ref make_cuio_host_pinned() + inline rmm::host_device_async_resource_ref make_cuio_host_pinned() { static std::shared_ptr mr = std::make_shared(); return *mr; } - inline rmm::host_async_resource_ref create_cuio_host_memory_resource(std::string const& mode) + inline rmm::host_device_async_resource_ref create_cuio_host_memory_resource( + std::string const& mode) { if (mode == "pinned") return make_cuio_host_pinned(); - if (mode == "pinned_pool") return cudf::io::get_host_memory_resource(); + if (mode == "pinned_pool") return cudf::get_pinned_memory_resource(); CUDF_FAIL("Unknown cuio_host_mem parameter: " + mode + "\nExpecting: pinned or pinned_pool"); } @@ -112,14 +113,14 @@ struct nvbench_base_fixture { rmm::mr::set_current_device_resource(mr.get()); std::cout << "RMM memory resource = " << rmm_mode << "\n"; - cudf::io::set_host_memory_resource(create_cuio_host_memory_resource(cuio_host_mode)); + cudf::set_pinned_memory_resource(create_cuio_host_memory_resource(cuio_host_mode)); std::cout << "CUIO host memory resource = " << cuio_host_mode << "\n"; } ~nvbench_base_fixture() { // Ensure the the pool is freed before the CUDA context is destroyed: - cudf::io::set_host_memory_resource(this->make_cuio_host_pinned()); + cudf::set_pinned_memory_resource(this->make_cuio_host_pinned()); } std::shared_ptr mr; diff --git a/cpp/benchmarks/io/cuio_common.cpp b/cpp/benchmarks/io/cuio_common.cpp index 37ced8ea703..645994f3f0d 100644 --- a/cpp/benchmarks/io/cuio_common.cpp +++ b/cpp/benchmarks/io/cuio_common.cpp @@ -19,6 +19,9 @@ #include #include +#include +#include + #include #include @@ -28,6 +31,14 @@ temp_directory const cuio_source_sink_pair::tmpdir{"cudf_gbench"}; +// Don't use cudf's pinned pool for the source data +rmm::host_async_resource_ref pinned_memory_resource() +{ + static rmm::mr::pinned_host_memory_resource mr = rmm::mr::pinned_host_memory_resource{}; + + return mr; +} + std::string random_file_in_dir(std::string const& dir_path) { // `mkstemp` modifies the template in place @@ -41,6 +52,7 @@ std::string random_file_in_dir(std::string const& dir_path) cuio_source_sink_pair::cuio_source_sink_pair(io_type type) : type{type}, + pinned_buffer({pinned_memory_resource(), cudf::get_default_stream()}), d_buffer{0, cudf::get_default_stream()}, file_name{random_file_in_dir(tmpdir.path())}, void_sink{cudf::io::data_sink::create()} diff --git a/cpp/benchmarks/io/cuio_common.hpp b/cpp/benchmarks/io/cuio_common.hpp index d4f39a5f243..64d6021cf50 100644 --- a/cpp/benchmarks/io/cuio_common.hpp +++ b/cpp/benchmarks/io/cuio_common.hpp @@ -18,7 +18,7 @@ #include -#include +#include #include #include @@ -79,7 +79,7 @@ class cuio_source_sink_pair { io_type const type; std::vector h_buffer; - cudf::detail::pinned_host_vector pinned_buffer; + cudf::detail::host_vector pinned_buffer; rmm::device_uvector d_buffer; std::string const file_name; std::unique_ptr void_sink; diff --git a/cpp/benchmarks/io/parquet/parquet_reader_multithread.cpp b/cpp/benchmarks/io/parquet/parquet_reader_multithread.cpp index a67d1932951..b4c8ed78ed8 100644 --- a/cpp/benchmarks/io/parquet/parquet_reader_multithread.cpp +++ b/cpp/benchmarks/io/parquet/parquet_reader_multithread.cpp @@ -20,9 +20,9 @@ #include #include -#include #include #include +#include #include #include diff --git a/cpp/benchmarks/io/text/multibyte_split.cpp b/cpp/benchmarks/io/text/multibyte_split.cpp index b5d855d8881..67705863d41 100644 --- a/cpp/benchmarks/io/text/multibyte_split.cpp +++ b/cpp/benchmarks/io/text/multibyte_split.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -132,9 +131,10 @@ static void bench_multibyte_split(nvbench::state& state, auto const delim_factor = static_cast(delim_percent) / 100; std::unique_ptr datasource; - auto device_input = create_random_input(file_size_approx, delim_factor, 0.05, delim); - auto host_input = std::vector{}; - auto host_pinned_input = cudf::detail::pinned_host_vector{}; + auto device_input = create_random_input(file_size_approx, delim_factor, 0.05, delim); + auto host_input = std::vector{}; + auto host_pinned_input = + cudf::detail::make_pinned_vector_async(0, cudf::get_default_stream()); if (source_type != data_chunk_source_type::device && source_type != data_chunk_source_type::host_pinned) { diff --git a/cpp/include/cudf/detail/utilities/rmm_host_vector.hpp b/cpp/include/cudf/detail/utilities/host_vector.hpp similarity index 93% rename from cpp/include/cudf/detail/utilities/rmm_host_vector.hpp rename to cpp/include/cudf/detail/utilities/host_vector.hpp index 6901a19473e..6a115177ab5 100644 --- a/cpp/include/cudf/detail/utilities/rmm_host_vector.hpp +++ b/cpp/include/cudf/detail/utilities/host_vector.hpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -32,8 +33,6 @@ namespace cudf::detail { /*! \p rmm_host_allocator is a CUDA-specific host memory allocator * that employs \c a `rmm::host_async_resource_ref` for allocation. * - * This implementation is ported from pinned_host_vector in cudf. - * * \see https://en.cppreference.com/w/cpp/memory/allocator */ template @@ -42,8 +41,6 @@ class rmm_host_allocator; /*! \p rmm_host_allocator is a CUDA-specific host memory allocator * that employs \c an `cudf::host_async_resource_ref` for allocation. * - * This implementation is ported from pinned_host_vector in cudf. - * * \see https://en.cppreference.com/w/cpp/memory/allocator */ template <> @@ -70,8 +67,7 @@ class rmm_host_allocator { * The \p rmm_host_allocator provides an interface for host memory allocation through the user * provided \c `rmm::host_async_resource_ref`. The \p rmm_host_allocator does not take ownership of * this reference and therefore it is the user's responsibility to ensure its lifetime for the - * duration of the lifetime of the \p rmm_host_allocator. This implementation is ported from - * pinned_host_vector in cudf. + * duration of the lifetime of the \p rmm_host_allocator. * * \see https://en.cppreference.com/w/cpp/memory/allocator */ @@ -121,8 +117,12 @@ class rmm_host_allocator { inline pointer allocate(size_type cnt) { if (cnt > this->max_size()) { throw std::bad_alloc(); } // end if - return static_cast( - mr.allocate_async(cnt * sizeof(value_type), rmm::RMM_DEFAULT_HOST_ALIGNMENT, stream)); + auto const result = + mr.allocate_async(cnt * sizeof(value_type), rmm::RMM_DEFAULT_HOST_ALIGNMENT, stream); + // Synchronize to ensure the memory is allocated before thrust::host_vector initialization + // TODO: replace thrust::host_vector with a type that does not require synchronization + stream.synchronize(); + return static_cast(result); } /** @@ -182,6 +182,6 @@ class rmm_host_allocator { * @brief A vector class with rmm host memory allocator */ template -using rmm_host_vector = thrust::host_vector>; +using host_vector = thrust::host_vector>; } // namespace cudf::detail diff --git a/cpp/include/cudf/detail/utilities/pinned_host_vector.hpp b/cpp/include/cudf/detail/utilities/pinned_host_vector.hpp deleted file mode 100644 index c22b6a6ba15..00000000000 --- a/cpp/include/cudf/detail/utilities/pinned_host_vector.hpp +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2008-2024, NVIDIA CORPORATION - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include - -#include -#include -#include // for bad_alloc - -namespace cudf::detail { - -/*! \p pinned_allocator is a CUDA-specific host memory allocator - * that employs \c cudaMallocHost for allocation. - * - * This implementation is ported from the experimental/pinned_allocator - * that Thrust used to provide. - * - * \see https://en.cppreference.com/w/cpp/memory/allocator - */ -template -class pinned_allocator; - -/*! \p pinned_allocator is a CUDA-specific host memory allocator - * that employs \c cudaMallocHost for allocation. - * - * This implementation is ported from the experimental/pinned_allocator - * that Thrust used to provide. - * - * \see https://en.cppreference.com/w/cpp/memory/allocator - */ -template <> -class pinned_allocator { - public: - using value_type = void; ///< The type of the elements in the allocator - using pointer = void*; ///< The type returned by address() / allocate() - using const_pointer = void const*; ///< The type returned by address() - using size_type = std::size_t; ///< The type used for the size of the allocation - using difference_type = std::ptrdiff_t; ///< The type of the distance between two pointers - - /** - * @brief converts a `pinned_allocator` to `pinned_allocator` - */ - template - struct rebind { - using other = pinned_allocator; ///< The rebound type - }; -}; - -/*! \p pinned_allocator is a CUDA-specific host memory allocator - * that employs \c cudaMallocHost for allocation. - * - * This implementation is ported from the experimental/pinned_allocator - * that Thrust used to provide. - * - * \see https://en.cppreference.com/w/cpp/memory/allocator - */ -template -class pinned_allocator { - public: - using value_type = T; ///< The type of the elements in the allocator - using pointer = T*; ///< The type returned by address() / allocate() - using const_pointer = T const*; ///< The type returned by address() - using reference = T&; ///< The parameter type for address() - using const_reference = T const&; ///< The parameter type for address() - using size_type = std::size_t; ///< The type used for the size of the allocation - using difference_type = std::ptrdiff_t; ///< The type of the distance between two pointers - - /** - * @brief converts a `pinned_allocator` to `pinned_allocator` - */ - template - struct rebind { - using other = pinned_allocator; ///< The rebound type - }; - - /** - * @brief pinned_allocator's null constructor does nothing. - */ - __host__ __device__ inline pinned_allocator() {} - - /** - * @brief pinned_allocator's null destructor does nothing. - */ - __host__ __device__ inline ~pinned_allocator() {} - - /** - * @brief pinned_allocator's copy constructor does nothing. - */ - __host__ __device__ inline pinned_allocator(pinned_allocator const&) {} - - /** - * @brief pinned_allocator's copy constructor does nothing. - * - * This version of pinned_allocator's copy constructor - * is templated on the \c value_type of the pinned_allocator - * to copy from. It is provided merely for convenience; it - * does nothing. - */ - template - __host__ __device__ inline pinned_allocator(pinned_allocator const&) - { - } - - /** - * @brief This method returns the address of a \c reference of - * interest. - * - * @param r The \c reference of interest. - * @return \c r's address. - */ - __host__ __device__ inline pointer address(reference r) { return &r; } - - /** - * @brief This method returns the address of a \c const_reference - * of interest. - * - * @param r The \c const_reference of interest. - * @return \c r's address. - */ - __host__ __device__ inline const_pointer address(const_reference r) { return &r; } - - /** - * @brief This method allocates storage for objects in pinned host - * memory. - * - * @param cnt The number of objects to allocate. - * @return a \c pointer to the newly allocated objects. - * @note The second parameter to this function is meant as a - * hint pointer to a nearby memory location, but is - * not used by this allocator. - * @note This method does not invoke \p value_type's constructor. - * It is the responsibility of the caller to initialize the - * objects at the returned \c pointer. - */ - __host__ inline pointer allocate(size_type cnt, const_pointer /*hint*/ = 0) - { - if (cnt > this->max_size()) { throw std::bad_alloc(); } // end if - - pointer result(0); - CUDF_CUDA_TRY(cudaMallocHost(reinterpret_cast(&result), cnt * sizeof(value_type))); - return result; - } - - /** - * @brief This method deallocates pinned host memory previously allocated - * with this \c pinned_allocator. - * - * @param p A \c pointer to the previously allocated memory. - * @note The second parameter is the number of objects previously allocated - * but is ignored by this allocator. - * @note This method does not invoke \p value_type's destructor. - * It is the responsibility of the caller to destroy - * the objects stored at \p p. - */ - __host__ inline void deallocate(pointer p, size_type /*cnt*/) - { - auto dealloc_worked = cudaFreeHost(p); - (void)dealloc_worked; - assert(dealloc_worked == cudaSuccess); - } - - /** - * @brief This method returns the maximum size of the \c cnt parameter - * accepted by the \p allocate() method. - * - * @return The maximum number of objects that may be allocated - * by a single call to \p allocate(). - */ - inline size_type max_size() const { return (std::numeric_limits::max)() / sizeof(T); } - - /** - * @brief This method tests this \p pinned_allocator for equality to - * another. - * - * @param x The other \p pinned_allocator of interest. - * @return This method always returns \c true. - */ - __host__ __device__ inline bool operator==(pinned_allocator const& x) const { return true; } - - /** - * @brief This method tests this \p pinned_allocator for inequality - * to another. - * - * @param x The other \p pinned_allocator of interest. - * @return This method always returns \c false. - */ - __host__ __device__ inline bool operator!=(pinned_allocator const& x) const - { - return !operator==(x); - } -}; - -/** - * @brief A vector class with pinned host memory allocator - */ -template -using pinned_host_vector = thrust::host_vector>; - -} // namespace cudf::detail diff --git a/cpp/include/cudf/detail/utilities/vector_factories.hpp b/cpp/include/cudf/detail/utilities/vector_factories.hpp index 293a4096c57..20cb55bb1c7 100644 --- a/cpp/include/cudf/detail/utilities/vector_factories.hpp +++ b/cpp/include/cudf/detail/utilities/vector_factories.hpp @@ -21,8 +21,10 @@ * @file vector_factories.hpp */ +#include #include #include +#include #include #include @@ -380,7 +382,7 @@ thrust::host_vector make_host_vector_async(device_span v, rmm::cuda_ * @brief Asynchronously construct a `std::vector` containing a copy of data from a device * container * - * @note This function synchronizes `stream`. + * @note This function does not synchronize `stream`. * * @tparam Container The type of the container to copy from * @tparam T The type of the data to copy @@ -439,6 +441,40 @@ thrust::host_vector make_host_vector_sync( return make_host_vector_sync(device_span{c}, stream); } +/** + * @brief Asynchronously construct a pinned `cudf::detail::host_vector` of the given size + * + * @note This function may not synchronize `stream`. + * + * @tparam T The type of the vector data + * @param size The number of elements in the created vector + * @param stream The stream on which to allocate memory + * @return A host_vector of the given size + */ +template +host_vector make_pinned_vector_async(size_t size, rmm::cuda_stream_view stream) +{ + return host_vector(size, {cudf::get_pinned_memory_resource(), stream}); +} + +/** + * @brief Synchronously construct a pinned `cudf::detail::host_vector` of the given size + * + * @note This function synchronizes `stream`. + * + * @tparam T The type of the vector data + * @param size The number of elements in the created vector + * @param stream The stream on which to allocate memory + * @return A host_vector of the given size + */ +template +host_vector make_pinned_vector_sync(size_t size, rmm::cuda_stream_view stream) +{ + auto result = make_pinned_vector_async(size, stream); + stream.synchronize(); + return result; +} + } // namespace detail } // namespace cudf diff --git a/cpp/include/cudf/io/memory_resource.hpp b/cpp/include/cudf/io/memory_resource.hpp deleted file mode 100644 index a36e220ae7b..00000000000 --- a/cpp/include/cudf/io/memory_resource.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2024, NVIDIA CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include - -namespace cudf::io { - -/** - * @brief Set the rmm resource to be used for host memory allocations by - * cudf::detail::hostdevice_vector - * - * hostdevice_vector is a utility class that uses a pair of host and device-side buffers for - * bouncing state between the cpu and the gpu. The resource set with this function (typically a - * pinned memory allocator) is what it uses to allocate space for it's host-side buffer. - * - * @param mr The rmm resource to be used for host-side allocations - * @return The previous resource that was in use - */ -rmm::host_async_resource_ref set_host_memory_resource(rmm::host_async_resource_ref mr); - -/** - * @brief Get the rmm resource being used for host memory allocations by - * cudf::detail::hostdevice_vector - * - * @return The rmm resource used for host-side allocations - */ -rmm::host_async_resource_ref get_host_memory_resource(); - -/** - * @brief Options to configure the default host memory resource - */ -struct host_mr_options { - std::optional pool_size; ///< The size of the pool to use for the default host memory - ///< resource. If not set, the default pool size is used. -}; - -/** - * @brief Configure the size of the default host memory resource. - * - * @throws cudf::logic_error if called after the default host memory resource has been created - * - * @param opts Options to configure the default host memory resource - * @return True if this call successfully configured the host memory resource, false if a - * a resource was already configured. - */ -bool config_default_host_memory_resource(host_mr_options const& opts); - -} // namespace cudf::io diff --git a/cpp/include/cudf/utilities/pinned_memory.hpp b/cpp/include/cudf/utilities/pinned_memory.hpp new file mode 100644 index 00000000000..b423eab6d38 --- /dev/null +++ b/cpp/include/cudf/utilities/pinned_memory.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include + +namespace cudf { + +/** + * @brief Set the rmm resource to be used for pinned memory allocations. + * + * @param mr The rmm resource to be used for pinned allocations + * @return The previous resource that was in use + */ +rmm::host_device_async_resource_ref set_pinned_memory_resource( + rmm::host_device_async_resource_ref mr); + +/** + * @brief Get the rmm resource being used for pinned memory allocations. + * + * @return The rmm resource used for pinned allocations + */ +rmm::host_device_async_resource_ref get_pinned_memory_resource(); + +/** + * @brief Options to configure the default pinned memory resource + */ +struct pinned_mr_options { + std::optional pool_size; ///< The size of the pool to use for the default pinned memory + ///< resource. If not set, the default pool size is used. +}; + +/** + * @brief Configure the size of the default pinned memory resource. + * + * @param opts Options to configure the default pinned memory resource + * @return True if this call successfully configured the pinned memory resource, false if a + * a resource was already configured. + */ +bool config_default_pinned_memory_resource(pinned_mr_options const& opts); + +} // namespace cudf diff --git a/cpp/src/io/csv/reader_impl.cu b/cpp/src/io/csv/reader_impl.cu index 5dee0c17a33..05faded651d 100644 --- a/cpp/src/io/csv/reader_impl.cu +++ b/cpp/src/io/csv/reader_impl.cu @@ -27,6 +27,7 @@ #include "io/utilities/parsing_utils.cuh" #include +#include #include #include #include diff --git a/cpp/src/io/orc/reader_impl_chunking.cu b/cpp/src/io/orc/reader_impl_chunking.cu index 5034aa14a95..43301826003 100644 --- a/cpp/src/io/orc/reader_impl_chunking.cu +++ b/cpp/src/io/orc/reader_impl_chunking.cu @@ -22,6 +22,7 @@ #include #include +#include #include #include diff --git a/cpp/src/io/orc/writer_impl.cu b/cpp/src/io/orc/writer_impl.cu index 344e216cdc8..e9e031a407a 100644 --- a/cpp/src/io/orc/writer_impl.cu +++ b/cpp/src/io/orc/writer_impl.cu @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -2339,7 +2338,7 @@ auto convert_table_to_orc_data(table_view const& input, std::move(streams), std::move(stripes), std::move(stripe_dicts.views), - cudf::detail::pinned_host_vector()}; + cudf::detail::make_pinned_vector_async(0, stream)}; } // Allocate intermediate output stream buffer @@ -2407,7 +2406,7 @@ auto convert_table_to_orc_data(table_view const& input, return max_stream_size; }(); - cudf::detail::pinned_host_vector bounce_buffer(max_out_stream_size); + auto bounce_buffer = cudf::detail::make_pinned_vector_async(max_out_stream_size, stream); auto intermediate_stats = gather_statistic_blobs(stats_freq, orc_table, segmentation, stream); diff --git a/cpp/src/io/parquet/reader_impl_helpers.cpp b/cpp/src/io/parquet/reader_impl_helpers.cpp index eb653c6b9ac..9de8a9e2719 100644 --- a/cpp/src/io/parquet/reader_impl_helpers.cpp +++ b/cpp/src/io/parquet/reader_impl_helpers.cpp @@ -23,6 +23,8 @@ #include "ipc/Message_generated.h" #include "ipc/Schema_generated.h" +#include + #include #include diff --git a/cpp/src/io/parquet/writer_impl.cu b/cpp/src/io/parquet/writer_impl.cu index 1dfced94f5b..6d466748c17 100644 --- a/cpp/src/io/parquet/writer_impl.cu +++ b/cpp/src/io/parquet/writer_impl.cu @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -2278,7 +2277,7 @@ auto convert_table_to_parquet_data(table_input_metadata& table_meta, } auto bounce_buffer = - cudf::detail::pinned_host_vector(all_device_write ? 0 : max_write_size); + cudf::detail::make_pinned_vector_async(all_device_write ? 0 : max_write_size, stream); return std::tuple{std::move(agg_meta), std::move(pages), diff --git a/cpp/src/io/text/bgzip_data_chunk_source.cu b/cpp/src/io/text/bgzip_data_chunk_source.cu index faa09e586ab..0e3ce779089 100644 --- a/cpp/src/io/text/bgzip_data_chunk_source.cu +++ b/cpp/src/io/text/bgzip_data_chunk_source.cu @@ -19,8 +19,9 @@ #include "io/utilities/config_utils.hpp" #include +#include #include -#include +#include #include #include #include @@ -66,7 +67,7 @@ struct bgzip_nvcomp_transform_functor { class bgzip_data_chunk_reader : public data_chunk_reader { private: template - static void copy_to_device(cudf::detail::pinned_host_vector const& host, + static void copy_to_device(cudf::detail::host_vector const& host, rmm::device_uvector& device, rmm::cuda_stream_view stream) { @@ -84,9 +85,9 @@ class bgzip_data_chunk_reader : public data_chunk_reader { 1 << 16; // 64k offset allocation, resized on demand cudaEvent_t event; - cudf::detail::pinned_host_vector h_compressed_blocks; - cudf::detail::pinned_host_vector h_compressed_offsets; - cudf::detail::pinned_host_vector h_decompressed_offsets; + cudf::detail::host_vector h_compressed_blocks; + cudf::detail::host_vector h_compressed_offsets; + cudf::detail::host_vector h_decompressed_offsets; rmm::device_uvector d_compressed_blocks; rmm::device_uvector d_decompressed_blocks; rmm::device_uvector d_compressed_offsets; @@ -103,7 +104,10 @@ class bgzip_data_chunk_reader : public data_chunk_reader { bool is_decompressed{}; decompression_blocks(rmm::cuda_stream_view init_stream) - : d_compressed_blocks(0, init_stream), + : h_compressed_blocks{cudf::detail::make_pinned_vector_async(0, init_stream)}, + h_compressed_offsets{cudf::detail::make_pinned_vector_async(0, init_stream)}, + h_decompressed_offsets{cudf::detail::make_pinned_vector_async(0, init_stream)}, + d_compressed_blocks(0, init_stream), d_decompressed_blocks(0, init_stream), d_compressed_offsets(0, init_stream), d_decompressed_offsets(0, init_stream), diff --git a/cpp/src/io/text/data_chunk_source_factories.cpp b/cpp/src/io/text/data_chunk_source_factories.cpp index 9d1d0498ace..596ca3458c8 100644 --- a/cpp/src/io/text/data_chunk_source_factories.cpp +++ b/cpp/src/io/text/data_chunk_source_factories.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,12 @@ * limitations under the License. */ +#include "cudf/utilities/default_stream.hpp" #include "io/text/device_data_chunks.hpp" #include -#include +#include +#include #include #include @@ -31,8 +33,15 @@ namespace cudf::io::text { namespace { struct host_ticket { - cudaEvent_t event; - cudf::detail::pinned_host_vector buffer; + cudaEvent_t event{}; // tracks the completion of the last device-to-host copy. + cudf::detail::host_vector buffer; + + host_ticket() : buffer{cudf::detail::make_pinned_vector_sync(0, cudf::get_default_stream())} + { + cudaEventCreate(&event); + } + + ~host_ticket() { cudaEventDestroy(event); } }; /** @@ -43,20 +52,7 @@ class datasource_chunk_reader : public data_chunk_reader { constexpr static int num_tickets = 2; public: - datasource_chunk_reader(datasource* source) : _source(source) - { - // create an event to track the completion of the last device-to-host copy. - for (auto& ticket : _tickets) { - CUDF_CUDA_TRY(cudaEventCreate(&(ticket.event))); - } - } - - ~datasource_chunk_reader() override - { - for (auto& ticket : _tickets) { - CUDF_CUDA_TRY(cudaEventDestroy(ticket.event)); - } - } + datasource_chunk_reader(datasource* source) : _source(source) {} void skip_bytes(std::size_t size) override { @@ -84,7 +80,9 @@ class datasource_chunk_reader : public data_chunk_reader { CUDF_CUDA_TRY(cudaEventSynchronize(h_ticket.event)); // resize the host buffer as necessary to contain the requested number of bytes - if (h_ticket.buffer.size() < read_size) { h_ticket.buffer.resize(read_size); } + if (h_ticket.buffer.size() < read_size) { + h_ticket.buffer = cudf::detail::make_pinned_vector_sync(read_size, stream); + } _source->host_read(_offset, read_size, reinterpret_cast(h_ticket.buffer.data())); @@ -120,17 +118,6 @@ class istream_data_chunk_reader : public data_chunk_reader { istream_data_chunk_reader(std::unique_ptr datastream) : _datastream(std::move(datastream)) { - // create an event to track the completion of the last device-to-host copy. - for (auto& ticket : _tickets) { - CUDF_CUDA_TRY(cudaEventCreate(&(ticket.event))); - } - } - - ~istream_data_chunk_reader() override - { - for (auto& ticket : _tickets) { - CUDF_CUDA_TRY(cudaEventDestroy(ticket.event)); - } } void skip_bytes(std::size_t size) override { _datastream->ignore(size); }; @@ -148,7 +135,9 @@ class istream_data_chunk_reader : public data_chunk_reader { CUDF_CUDA_TRY(cudaEventSynchronize(h_ticket.event)); // resize the host buffer as necessary to contain the requested number of bytes - if (h_ticket.buffer.size() < read_size) { h_ticket.buffer.resize(read_size); } + if (h_ticket.buffer.size() < read_size) { + h_ticket.buffer = cudf::detail::make_pinned_vector_sync(read_size, stream); + } // read data from the host istream in to the pinned host memory buffer _datastream->read(h_ticket.buffer.data(), read_size); diff --git a/cpp/src/io/utilities/config_utils.cpp b/cpp/src/io/utilities/config_utils.cpp index dad1135e766..20ac89b4d53 100644 --- a/cpp/src/io/utilities/config_utils.cpp +++ b/cpp/src/io/utilities/config_utils.cpp @@ -16,22 +16,12 @@ #include "config_utils.hpp" -#include -#include #include -#include - -#include -#include -#include -#include #include #include -namespace cudf::io { - -namespace detail { +namespace cudf::io::detail { namespace cufile_integration { @@ -90,204 +80,4 @@ bool is_stable_enabled() { return is_all_enabled() or get_env_policy() == usage_ } // namespace nvcomp_integration -} // namespace detail - -namespace { -class fixed_pinned_pool_memory_resource { - using upstream_mr = rmm::mr::pinned_host_memory_resource; - using host_pooled_mr = rmm::mr::pool_memory_resource; - - private: - upstream_mr upstream_mr_{}; - size_t pool_size_{0}; - // Raw pointer to avoid a segfault when the pool is destroyed on exit - host_pooled_mr* pool_{nullptr}; - void* pool_begin_{nullptr}; - void* pool_end_{nullptr}; - cuda::stream_ref stream_{cudf::detail::global_cuda_stream_pool().get_stream().value()}; - - public: - fixed_pinned_pool_memory_resource(size_t size) - : pool_size_{size}, pool_{new host_pooled_mr(upstream_mr_, size, size)} - { - if (pool_size_ == 0) { return; } - - // Allocate full size from the pinned pool to figure out the beginning and end address - pool_begin_ = pool_->allocate_async(pool_size_, stream_); - pool_end_ = static_cast(static_cast(pool_begin_) + pool_size_); - pool_->deallocate_async(pool_begin_, pool_size_, stream_); - } - - void* do_allocate_async(std::size_t bytes, std::size_t alignment, cuda::stream_ref stream) - { - if (bytes <= pool_size_) { - try { - return pool_->allocate_async(bytes, alignment, stream); - } catch (...) { - // If the pool is exhausted, fall back to the upstream memory resource - } - } - - return upstream_mr_.allocate_async(bytes, alignment, stream); - } - - void do_deallocate_async(void* ptr, - std::size_t bytes, - std::size_t alignment, - cuda::stream_ref stream) noexcept - { - if (bytes <= pool_size_ && ptr >= pool_begin_ && ptr <= pool_end_) { - pool_->deallocate_async(ptr, bytes, alignment, stream); - } else { - upstream_mr_.deallocate_async(ptr, bytes, alignment, stream); - } - } - - void* allocate_async(std::size_t bytes, cuda::stream_ref stream) - { - return do_allocate_async(bytes, rmm::RMM_DEFAULT_HOST_ALIGNMENT, stream); - } - - void* allocate_async(std::size_t bytes, std::size_t alignment, cuda::stream_ref stream) - { - return do_allocate_async(bytes, alignment, stream); - } - - void* allocate(std::size_t bytes, std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) - { - auto const result = do_allocate_async(bytes, alignment, stream_); - stream_.wait(); - return result; - } - - void deallocate_async(void* ptr, std::size_t bytes, cuda::stream_ref stream) noexcept - { - return do_deallocate_async(ptr, bytes, rmm::RMM_DEFAULT_HOST_ALIGNMENT, stream); - } - - void deallocate_async(void* ptr, - std::size_t bytes, - std::size_t alignment, - cuda::stream_ref stream) noexcept - { - return do_deallocate_async(ptr, bytes, alignment, stream); - } - - void deallocate(void* ptr, - std::size_t bytes, - std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) noexcept - { - deallocate_async(ptr, bytes, alignment, stream_); - stream_.wait(); - } - - bool operator==(fixed_pinned_pool_memory_resource const& other) const - { - return pool_ == other.pool_ and stream_ == other.stream_; - } - - bool operator!=(fixed_pinned_pool_memory_resource const& other) const - { - return !operator==(other); - } - - [[maybe_unused]] friend void get_property(fixed_pinned_pool_memory_resource const&, - cuda::mr::device_accessible) noexcept - { - } - - [[maybe_unused]] friend void get_property(fixed_pinned_pool_memory_resource const&, - cuda::mr::host_accessible) noexcept - { - } -}; - -static_assert(cuda::mr::resource_with, - ""); - -} // namespace - -CUDF_EXPORT rmm::host_async_resource_ref& make_default_pinned_mr(std::optional config_size) -{ - static fixed_pinned_pool_memory_resource mr = [config_size]() { - auto const size = [&config_size]() -> size_t { - if (auto const env_val = getenv("LIBCUDF_PINNED_POOL_SIZE"); env_val != nullptr) { - return std::atol(env_val); - } - - if (config_size.has_value()) { return *config_size; } - - size_t free{}, total{}; - CUDF_CUDA_TRY(cudaMemGetInfo(&free, &total)); - // 0.5% of the total device memory, capped at 100MB - return std::min(total / 200, size_t{100} * 1024 * 1024); - }(); - - // rmm requires the pool size to be a multiple of 256 bytes - auto const aligned_size = (size + 255) & ~255; - CUDF_LOG_INFO("Pinned pool size = {}", aligned_size); - - // make the pool with max size equal to the initial size - return fixed_pinned_pool_memory_resource{aligned_size}; - }(); - - static rmm::host_async_resource_ref mr_ref{mr}; - return mr_ref; -} - -CUDF_EXPORT std::mutex& host_mr_mutex() -{ - static std::mutex map_lock; - return map_lock; -} - -// Must be called with the host_mr_mutex mutex held -CUDF_EXPORT rmm::host_async_resource_ref& make_host_mr(std::optional const& opts, - bool* did_configure = nullptr) -{ - static rmm::host_async_resource_ref* mr_ref = nullptr; - bool configured = false; - if (mr_ref == nullptr) { - configured = true; - mr_ref = &make_default_pinned_mr(opts ? opts->pool_size : std::nullopt); - } - - // If the user passed an out param to detect whether this call configured a resource - // set the result - if (did_configure != nullptr) { *did_configure = configured; } - - return *mr_ref; -} - -// Must be called with the host_mr_mutex mutex held -CUDF_EXPORT rmm::host_async_resource_ref& host_mr() -{ - static rmm::host_async_resource_ref mr_ref = make_host_mr(std::nullopt); - return mr_ref; -} - -rmm::host_async_resource_ref set_host_memory_resource(rmm::host_async_resource_ref mr) -{ - std::scoped_lock lock{host_mr_mutex()}; - auto last_mr = host_mr(); - host_mr() = mr; - return last_mr; -} - -rmm::host_async_resource_ref get_host_memory_resource() -{ - std::scoped_lock lock{host_mr_mutex()}; - return host_mr(); -} - -bool config_default_host_memory_resource(host_mr_options const& opts) -{ - std::scoped_lock lock{host_mr_mutex()}; - auto did_configure = false; - make_host_mr(opts, &did_configure); - return did_configure; -} - -} // namespace cudf::io +} // namespace cudf::io::detail diff --git a/cpp/src/io/utilities/hostdevice_vector.hpp b/cpp/src/io/utilities/hostdevice_vector.hpp index 0883ac3609f..1ae27a2f4ae 100644 --- a/cpp/src/io/utilities/hostdevice_vector.hpp +++ b/cpp/src/io/utilities/hostdevice_vector.hpp @@ -16,11 +16,10 @@ #pragma once -#include "config_utils.hpp" #include "hostdevice_span.hpp" -#include -#include +#include +#include #include #include #include @@ -53,7 +52,7 @@ class hostdevice_vector { } explicit hostdevice_vector(size_t initial_size, size_t max_size, rmm::cuda_stream_view stream) - : h_data({cudf::io::get_host_memory_resource(), stream}), d_data(max_size, stream) + : h_data{make_pinned_vector_async(0, stream)}, d_data(max_size, stream) { CUDF_EXPECTS(initial_size <= max_size, "initial_size cannot be larger than max_size"); @@ -173,7 +172,7 @@ class hostdevice_vector { } private: - cudf::detail::rmm_host_vector h_data; + cudf::detail::host_vector h_data; rmm::device_uvector d_data; }; diff --git a/cpp/src/utilities/pinned_memory.cpp b/cpp/src/utilities/pinned_memory.cpp new file mode 100644 index 00000000000..5d2e3ac332a --- /dev/null +++ b/cpp/src/utilities/pinned_memory.cpp @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace cudf { + +namespace { +class fixed_pinned_pool_memory_resource { + using upstream_mr = rmm::mr::pinned_host_memory_resource; + using host_pooled_mr = rmm::mr::pool_memory_resource; + + private: + upstream_mr upstream_mr_{}; + size_t pool_size_{0}; + // Raw pointer to avoid a segfault when the pool is destroyed on exit + host_pooled_mr* pool_{nullptr}; + void* pool_begin_{nullptr}; + void* pool_end_{nullptr}; + cuda::stream_ref stream_{cudf::detail::global_cuda_stream_pool().get_stream().value()}; + + public: + fixed_pinned_pool_memory_resource(size_t size) + : pool_size_{size}, pool_{new host_pooled_mr(upstream_mr_, size, size)} + { + if (pool_size_ == 0) { return; } + + // Allocate full size from the pinned pool to figure out the beginning and end address + pool_begin_ = pool_->allocate_async(pool_size_, stream_); + pool_end_ = static_cast(static_cast(pool_begin_) + pool_size_); + pool_->deallocate_async(pool_begin_, pool_size_, stream_); + } + + void* allocate_async(std::size_t bytes, std::size_t alignment, cuda::stream_ref stream) + { + if (bytes <= pool_size_) { + try { + return pool_->allocate_async(bytes, alignment, stream); + } catch (...) { + // If the pool is exhausted, fall back to the upstream memory resource + } + } + + return upstream_mr_.allocate_async(bytes, alignment, stream); + } + + void* allocate_async(std::size_t bytes, cuda::stream_ref stream) + { + return allocate_async(bytes, rmm::RMM_DEFAULT_HOST_ALIGNMENT, stream); + } + + void* allocate(std::size_t bytes, std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) + { + auto const result = allocate_async(bytes, alignment, stream_); + stream_.wait(); + return result; + } + + void deallocate_async(void* ptr, + std::size_t bytes, + std::size_t alignment, + cuda::stream_ref stream) noexcept + { + if (bytes <= pool_size_ && ptr >= pool_begin_ && ptr < pool_end_) { + pool_->deallocate_async(ptr, bytes, alignment, stream); + } else { + upstream_mr_.deallocate_async(ptr, bytes, alignment, stream); + } + } + + void deallocate_async(void* ptr, std::size_t bytes, cuda::stream_ref stream) noexcept + { + return deallocate_async(ptr, bytes, rmm::RMM_DEFAULT_HOST_ALIGNMENT, stream); + } + + void deallocate(void* ptr, + std::size_t bytes, + std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) noexcept + { + deallocate_async(ptr, bytes, alignment, stream_); + stream_.wait(); + } + + bool operator==(fixed_pinned_pool_memory_resource const& other) const + { + return pool_ == other.pool_ and stream_ == other.stream_; + } + + bool operator!=(fixed_pinned_pool_memory_resource const& other) const + { + return !operator==(other); + } + + friend void get_property(fixed_pinned_pool_memory_resource const&, + cuda::mr::device_accessible) noexcept + { + } + + friend void get_property(fixed_pinned_pool_memory_resource const&, + cuda::mr::host_accessible) noexcept + { + } +}; + +static_assert(cuda::mr::resource_with, + "Pinned pool mr must be accessible from both host and device"); + +CUDF_EXPORT rmm::host_device_async_resource_ref& make_default_pinned_mr( + std::optional config_size) +{ + static fixed_pinned_pool_memory_resource mr = [config_size]() { + auto const size = [&config_size]() -> size_t { + if (auto const env_val = getenv("LIBCUDF_PINNED_POOL_SIZE"); env_val != nullptr) { + return std::atol(env_val); + } + + if (config_size.has_value()) { return *config_size; } + + auto const total = rmm::available_device_memory().second; + // 0.5% of the total device memory, capped at 100MB + return std::min(total / 200, size_t{100} * 1024 * 1024); + }(); + + // rmm requires the pool size to be a multiple of 256 bytes + auto const aligned_size = rmm::align_up(size, rmm::RMM_DEFAULT_HOST_ALIGNMENT); + CUDF_LOG_INFO("Pinned pool size = {}", aligned_size); + + // make the pool with max size equal to the initial size + return fixed_pinned_pool_memory_resource{aligned_size}; + }(); + + static rmm::host_device_async_resource_ref mr_ref{mr}; + return mr_ref; +} + +CUDF_EXPORT std::mutex& host_mr_mutex() +{ + static std::mutex map_lock; + return map_lock; +} + +// Must be called with the host_mr_mutex mutex held +CUDF_EXPORT rmm::host_device_async_resource_ref& make_host_mr( + std::optional const& opts, bool* did_configure = nullptr) +{ + static rmm::host_device_async_resource_ref* mr_ref = nullptr; + bool configured = false; + if (mr_ref == nullptr) { + configured = true; + mr_ref = &make_default_pinned_mr(opts ? opts->pool_size : std::nullopt); + } + + // If the user passed an out param to detect whether this call configured a resource + // set the result + if (did_configure != nullptr) { *did_configure = configured; } + + return *mr_ref; +} + +// Must be called with the host_mr_mutex mutex held +CUDF_EXPORT rmm::host_device_async_resource_ref& host_mr() +{ + static rmm::host_device_async_resource_ref mr_ref = make_host_mr(std::nullopt); + return mr_ref; +} + +} // namespace + +rmm::host_device_async_resource_ref set_pinned_memory_resource( + rmm::host_device_async_resource_ref mr) +{ + std::scoped_lock lock{host_mr_mutex()}; + auto last_mr = host_mr(); + host_mr() = mr; + return last_mr; +} + +rmm::host_device_async_resource_ref get_pinned_memory_resource() +{ + std::scoped_lock lock{host_mr_mutex()}; + return host_mr(); +} + +bool config_default_pinned_memory_resource(pinned_mr_options const& opts) +{ + std::scoped_lock lock{host_mr_mutex()}; + auto did_configure = false; + make_host_mr(opts, &did_configure); + return did_configure; +} + +} // namespace cudf diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 826f879ddc0..f6d762cc2ec 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -380,15 +380,16 @@ ConfigureTest( # * utilities tests ------------------------------------------------------------------------------- ConfigureTest( UTILITIES_TEST - utilities_tests/type_list_tests.cpp utilities_tests/column_debug_tests.cpp utilities_tests/column_utilities_tests.cpp utilities_tests/column_wrapper_tests.cpp + utilities_tests/default_stream_tests.cpp utilities_tests/io_utilities_tests.cpp utilities_tests/lists_column_wrapper_tests.cpp utilities_tests/logger_tests.cpp - utilities_tests/default_stream_tests.cpp + utilities_tests/pinned_memory_tests.cpp utilities_tests/type_check_tests.cpp + utilities_tests/type_list_tests.cpp ) # ################################################################################################## diff --git a/cpp/tests/io/json_test.cpp b/cpp/tests/io/json_test.cpp index 57aa2721756..4c01a1fb87b 100644 --- a/cpp/tests/io/json_test.cpp +++ b/cpp/tests/io/json_test.cpp @@ -28,13 +28,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include @@ -2068,7 +2068,7 @@ TEST_F(JsonReaderTest, JSONLinesRecoveringSync) size_t{128} * 1024 * 1024}; // Set new resource - auto last_mr = cudf::io::set_host_memory_resource(mr); + auto last_mr = cudf::set_pinned_memory_resource(mr); /** * @brief Spark has the specific need to ignore extra characters that come after the first record @@ -2158,7 +2158,7 @@ TEST_F(JsonReaderTest, JSONLinesRecoveringSync) float64_wrapper{c_data.cbegin(), c_data.cend(), c_validity.cbegin()}); // Restore original memory source - cudf::io::set_host_memory_resource(last_mr); + cudf::set_pinned_memory_resource(last_mr); } TEST_F(JsonReaderTest, MixedTypes) diff --git a/cpp/tests/utilities_tests/io_utilities_tests.cpp b/cpp/tests/utilities_tests/io_utilities_tests.cpp index e5a153bf781..9ed8f18f5cc 100644 --- a/cpp/tests/utilities_tests/io_utilities_tests.cpp +++ b/cpp/tests/utilities_tests/io_utilities_tests.cpp @@ -16,14 +16,6 @@ #include #include -#include - -#include -#include - -#include -#include -#include #include @@ -32,43 +24,6 @@ using cudf::io::detail::base64_encode; class IoUtilitiesTest : public cudf::test::BaseFixture {}; -TEST(IoUtilitiesTest, HostMemoryGetAndSet) -{ - // Global environment for temporary files - auto const temp_env = static_cast( - ::testing::AddGlobalTestEnvironment(new cudf::test::TempDirTestEnvironment)); - - // pinned/pooled host memory resource - using host_pooled_mr = rmm::mr::pool_memory_resource; - host_pooled_mr mr(std::make_shared().get(), - size_t{128} * 1024 * 1024); - - // set new resource - auto last_mr = cudf::io::get_host_memory_resource(); - cudf::io::set_host_memory_resource(mr); - - constexpr int num_rows = 32 * 1024; - auto valids = - cudf::detail::make_counting_transform_iterator(0, [&](int index) { return index % 2; }); - auto values = thrust::make_counting_iterator(0); - - cudf::test::fixed_width_column_wrapper col(values, values + num_rows, valids); - - cudf::table_view expected({col}); - auto filepath = temp_env->get_temp_filepath("IoUtilsMemTest.parquet"); - cudf::io::parquet_writer_options out_args = - cudf::io::parquet_writer_options::builder(cudf::io::sink_info{filepath}, expected); - cudf::io::write_parquet(out_args); - - cudf::io::parquet_reader_options const read_opts = - cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}); - auto const result = cudf::io::read_parquet(read_opts); - CUDF_TEST_EXPECT_TABLES_EQUAL(*result.tbl, expected); - - // reset memory resource back - cudf::io::set_host_memory_resource(last_mr); -} - TEST(IoUtilitiesTest, Base64EncodeAndDecode) { // a vector of lorem ipsum strings diff --git a/cpp/tests/utilities_tests/pinned_memory_tests.cpp b/cpp/tests/utilities_tests/pinned_memory_tests.cpp new file mode 100644 index 00000000000..df9103640f4 --- /dev/null +++ b/cpp/tests/utilities_tests/pinned_memory_tests.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +class PinnedMemoryTest : public cudf::test::BaseFixture {}; + +TEST(PinnedMemoryTest, MemoryResourceGetAndSet) +{ + // Global environment for temporary files + auto const temp_env = static_cast( + ::testing::AddGlobalTestEnvironment(new cudf::test::TempDirTestEnvironment)); + + // pinned/pooled host memory resource + using host_pooled_mr = rmm::mr::pool_memory_resource; + host_pooled_mr mr(std::make_shared().get(), + 4 * 1024 * 1024); + + // set new resource + auto last_mr = cudf::get_pinned_memory_resource(); + cudf::set_pinned_memory_resource(mr); + + constexpr int num_rows = 32 * 1024; + auto valids = + cudf::detail::make_counting_transform_iterator(0, [&](int index) { return index % 2; }); + auto values = thrust::make_counting_iterator(0); + + cudf::test::fixed_width_column_wrapper col(values, values + num_rows, valids); + + cudf::table_view expected({col}); + auto filepath = temp_env->get_temp_filepath("MemoryResourceGetAndSetTest.parquet"); + cudf::io::parquet_writer_options out_args = + cudf::io::parquet_writer_options::builder(cudf::io::sink_info{filepath}, expected); + cudf::io::write_parquet(out_args); + + cudf::io::parquet_reader_options const read_opts = + cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}); + auto const result = cudf::io::read_parquet(read_opts); + CUDF_TEST_EXPECT_TABLES_EQUAL(*result.tbl, expected); + + // reset memory resource back + cudf::set_pinned_memory_resource(last_mr); +} diff --git a/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java b/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java index 83b801db7fb..df0d9dc7c3e 100644 --- a/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java +++ b/java/src/main/java/ai/rapids/cudf/PinnedMemoryPool.java @@ -128,9 +128,9 @@ public static synchronized void initialize(long poolSize, int gpuId) { * * @param poolSize size of the pool to initialize. * @param gpuId gpu id to set to get memory pool from, -1 means to use default - * @param setCuioHostMemoryResource true if this pinned pool should be used by cuIO for host memory + * @param setCudfPinnedPoolMemoryResource true if this pinned pool should be used by cuDF for pinned memory */ - public static synchronized void initialize(long poolSize, int gpuId, boolean setCuioHostMemoryResource) { + public static synchronized void initialize(long poolSize, int gpuId, boolean setCudfPinnedPoolMemoryResource) { if (isInitialized()) { throw new IllegalStateException("Can only initialize the pool once."); } @@ -139,7 +139,7 @@ public static synchronized void initialize(long poolSize, int gpuId, boolean set t.setDaemon(true); return t; }); - initFuture = initService.submit(() -> new PinnedMemoryPool(poolSize, gpuId, setCuioHostMemoryResource)); + initFuture = initService.submit(() -> new PinnedMemoryPool(poolSize, gpuId, setCudfPinnedPoolMemoryResource)); initService.shutdown(); } @@ -216,15 +216,15 @@ public static long getTotalPoolSizeBytes() { return 0; } - private PinnedMemoryPool(long poolSize, int gpuId, boolean setCuioHostMemoryResource) { + private PinnedMemoryPool(long poolSize, int gpuId, boolean setCudfPinnedPoolMemoryResource) { if (gpuId > -1) { // set the gpu device to use Cuda.setDevice(gpuId); Cuda.freeZero(); } this.poolHandle = Rmm.newPinnedPoolMemoryResource(poolSize, poolSize); - if (setCuioHostMemoryResource) { - Rmm.setCuioPinnedPoolMemoryResource(this.poolHandle); + if (setCudfPinnedPoolMemoryResource) { + Rmm.setCudfPinnedPoolMemoryResource(this.poolHandle); } this.poolSize = poolSize; } diff --git a/java/src/main/java/ai/rapids/cudf/Rmm.java b/java/src/main/java/ai/rapids/cudf/Rmm.java index 4dee1b7aa24..ed029c918e4 100755 --- a/java/src/main/java/ai/rapids/cudf/Rmm.java +++ b/java/src/main/java/ai/rapids/cudf/Rmm.java @@ -597,7 +597,7 @@ static native long newEventHandlerResourceAdaptor(long handle, long trackerHandl public static native long newPinnedPoolMemoryResource(long initSize, long maxSize); - public static native long setCuioPinnedPoolMemoryResource(long poolPtr); + public static native long setCudfPinnedPoolMemoryResource(long poolPtr); public static native void releasePinnedPoolMemoryResource(long poolPtr); diff --git a/java/src/main/native/src/RmmJni.cpp b/java/src/main/native/src/RmmJni.cpp index fa78f6ca4e2..8bd0f7793b4 100644 --- a/java/src/main/native/src/RmmJni.cpp +++ b/java/src/main/native/src/RmmJni.cpp @@ -16,7 +16,7 @@ #include "cudf_jni_apis.hpp" -#include +#include #include #include @@ -395,15 +395,17 @@ class java_debug_event_handler_memory_resource final : public java_event_handler } }; -inline auto& prior_cuio_host_mr() +inline auto& prior_cudf_pinned_mr() { - static rmm::host_async_resource_ref _prior_cuio_host_mr = cudf::io::get_host_memory_resource(); - return _prior_cuio_host_mr; + static rmm::host_device_async_resource_ref _prior_cudf_pinned_mr = + cudf::get_pinned_memory_resource(); + return _prior_cudf_pinned_mr; } /** * This is a pinned fallback memory resource that will try to allocate `pool` - * and if that fails, attempt to allocate from the prior resource used by cuIO `prior_cuio_host_mr`. + * and if that fails, attempt to allocate from the prior resource used by cuDF + * `prior_cudf_pinned_mr`. * * We detect whether a pointer to free is inside of the pool by checking its address (see * constructor) @@ -433,7 +435,7 @@ class pinned_fallback_host_memory_resource { /** * @brief Allocates pinned host memory of size at least \p bytes bytes from either the - * _pool argument provided, or prior_cuio_host_mr. + * _pool argument provided, or prior_cudf_pinned_mr. * * @throws rmm::bad_alloc if the requested allocation could not be fulfilled due to any other * reason. @@ -450,7 +452,7 @@ class pinned_fallback_host_memory_resource { return _pool->allocate(bytes, alignment); } catch (const std::exception& unused) { // try to allocate using the underlying pinned resource - return prior_cuio_host_mr().allocate(bytes, alignment); + return prior_cudf_pinned_mr().allocate(bytes, alignment); } // we should not reached here return nullptr; @@ -459,7 +461,7 @@ class pinned_fallback_host_memory_resource { /** * @brief Deallocate memory pointed to by \p ptr of size \p bytes bytes. We attempt * to deallocate from _pool, if ptr is detected to be in the pool address range, - * otherwise we deallocate from `prior_cuio_host_mr`. + * otherwise we deallocate from `prior_cudf_pinned_mr`. * * @param ptr Pointer to be deallocated. * @param bytes Size of the allocation. @@ -472,7 +474,7 @@ class pinned_fallback_host_memory_resource { if (ptr >= pool_begin_ && ptr <= pool_end_) { _pool->deallocate(ptr, bytes, alignment); } else { - prior_cuio_host_mr().deallocate(ptr, bytes, alignment); + prior_cudf_pinned_mr().deallocate(ptr, bytes, alignment); } } @@ -1025,7 +1027,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_newPinnedPoolMemoryResource(JNIE CATCH_STD(env, 0) } -JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCuioPinnedPoolMemoryResource(JNIEnv* env, +JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCudfPinnedPoolMemoryResource(JNIEnv* env, jclass clazz, jlong pool_ptr) { @@ -1035,7 +1037,7 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_setCuioPinnedPoolMemoryResource(J // create a pinned fallback pool that will allocate pinned memory // if the regular pinned pool is exhausted pinned_fallback_mr.reset(new pinned_fallback_host_memory_resource(pool)); - prior_cuio_host_mr() = cudf::io::set_host_memory_resource(*pinned_fallback_mr); + prior_cudf_pinned_mr() = cudf::set_pinned_memory_resource(*pinned_fallback_mr); } CATCH_STD(env, ) } @@ -1047,8 +1049,8 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_releasePinnedPoolMemoryResource(J try { cudf::jni::auto_set_device(env); // set the cuio host memory resource to what it was before, or the same - // if we didn't overwrite it with setCuioPinnedPoolMemoryResource - cudf::io::set_host_memory_resource(prior_cuio_host_mr()); + // if we didn't overwrite it with setCudfPinnedPoolMemoryResource + cudf::set_pinned_memory_resource(prior_cudf_pinned_mr()); pinned_fallback_mr.reset(); delete reinterpret_cast(pool_ptr); } @@ -1088,7 +1090,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Rmm_allocFromFallbackPinnedPool(JNIE jlong size) { cudf::jni::auto_set_device(env); - void* ret = cudf::io::get_host_memory_resource().allocate(size); + void* ret = cudf::get_pinned_memory_resource().allocate(size); return reinterpret_cast(ret); } @@ -1101,7 +1103,7 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_Rmm_freeFromFallbackPinnedPool(JNIEnv try { cudf::jni::auto_set_device(env); void* cptr = reinterpret_cast(ptr); - cudf::io::get_host_memory_resource().deallocate(cptr, size); + cudf::get_pinned_memory_resource().deallocate(cptr, size); } CATCH_STD(env, ) } @@ -1112,7 +1114,7 @@ JNIEXPORT jboolean JNICALL Java_ai_rapids_cudf_Rmm_configureDefaultCudfPinnedPoo { try { cudf::jni::auto_set_device(env); - return cudf::io::config_default_host_memory_resource(cudf::io::host_mr_options{size}); + return cudf::config_default_pinned_memory_resource(cudf::pinned_mr_options{size}); } CATCH_STD(env, false) } From 2b1029908af97b74304169631189dd57f382f072 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 12 Jun 2024 01:14:31 -0700 Subject: [PATCH 5/9] Apply clang-tidy autofixes (#15894) This changeset is large, but it's not very substantial. It's all the automated fixes produced by clang-tidy using our script. The bulk of the changes are either adding `[[nodiscard]]` to many functions or changing const ref args to pass by value and then move in cases where the parameter is only used to set a value. There are also some places where clang-tidy preferred either more or less namespacing of objects depending on the current namespace. The goal is to enable clang-tidy in CI, which we made progress towards in #9860 but stalled in #10064. This PR contains the first set of changes that will required for such a check to pass. I've marked this PR as breaking because some of the functions now marked as `[[nodiscard]]` are public APIs, so if consumers were ignoring the return values they will now see warnings, and if they are compiling with warnings as errors then the builds will break. Contributes to #584 Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Bradley Dice (https://github.com/bdice) - Nghia Truong (https://github.com/ttnghia) URL: https://github.com/rapidsai/cudf/pull/15894 --- .pre-commit-config.yaml | 8 + cpp/include/cudf/ast/expressions.hpp | 7 +- .../cudf/column/column_device_view.cuh | 10 +- .../cudf/detail/aggregation/aggregation.hpp | 27 +- cpp/include/cudf/detail/contiguous_split.hpp | 2 +- .../cudf/detail/normalizing_iterator.cuh | 8 +- cpp/include/cudf/detail/structs/utilities.hpp | 24 +- .../cudf/detail/utilities/host_vector.hpp | 4 +- .../cudf/detail/utilities/stream_pool.hpp | 2 +- cpp/include/cudf/fixed_point/fixed_point.hpp | 6 +- cpp/include/cudf/interop.hpp | 4 +- cpp/include/cudf/interop/detail/arrow.hpp | 7 +- cpp/include/cudf/io/arrow_io_source.hpp | 8 +- cpp/include/cudf/io/csv.hpp | 22 +- cpp/include/cudf/io/detail/parquet.hpp | 2 +- cpp/include/cudf/io/json.hpp | 42 +- cpp/include/cudf/io/orc.hpp | 26 +- cpp/include/cudf/io/parquet.hpp | 6 +- cpp/include/cudf/io/types.hpp | 5 +- cpp/include/cudf/join.hpp | 33 +- cpp/include/cudf/scalar/scalar.hpp | 19 +- .../cudf/strings/regex/regex_program.hpp | 14 +- cpp/include/cudf/strings/string_view.cuh | 8 +- cpp/include/cudf/table/table.hpp | 2 +- cpp/include/cudf/table/table_view.hpp | 4 +- cpp/include/cudf/utilities/error.hpp | 8 +- cpp/include/cudf/utilities/span.hpp | 24 +- cpp/include/cudf/utilities/thread_pool.hpp | 6 +- cpp/include/cudf/wrappers/dictionary.hpp | 2 +- cpp/include/cudf/wrappers/durations.hpp | 16 +- cpp/include/cudf/wrappers/timestamps.hpp | 16 +- cpp/include/cudf_test/base_fixture.hpp | 2 +- cpp/include/cudf_test/column_wrapper.hpp | 15 +- .../stream_checking_resource_adaptor.hpp | 2 +- cpp/src/binaryop/binaryop.cpp | 2 +- cpp/src/binaryop/compiled/operation.cuh | 8 +- cpp/src/binaryop/compiled/util.cpp | 4 +- cpp/src/copying/pack.cpp | 2 +- cpp/src/datetime/timezone.cpp | 2 +- cpp/src/interop/arrow_utilities.cpp | 2 +- cpp/src/interop/arrow_utilities.hpp | 2 +- cpp/src/interop/detail/arrow_allocator.cpp | 2 +- cpp/src/interop/from_arrow_host.cu | 4 +- cpp/src/io/avro/avro.cpp | 6 +- cpp/src/io/comp/uncomp.cpp | 8 +- cpp/src/io/functions.cpp | 8 +- cpp/src/io/json/nested_json_gpu.cu | 8 +- cpp/src/io/json/read_json.cu | 2 +- cpp/src/io/orc/orc.hpp | 2 +- cpp/src/io/orc/orc_field_writer.hpp | 6 +- cpp/src/io/orc/reader_impl_chunking.cu | 2 +- cpp/src/io/orc/reader_impl_decode.cu | 2 +- .../io/parquet/compact_protocol_reader.cpp | 2 +- .../io/parquet/compact_protocol_writer.hpp | 4 +- cpp/src/io/parquet/ipc/Schema_generated.h | 416 +++++++++--------- cpp/src/io/parquet/page_string_decode.cu | 10 +- cpp/src/io/parquet/page_string_utils.cuh | 4 +- cpp/src/io/parquet/parquet.hpp | 30 +- cpp/src/io/parquet/parquet_gpu.hpp | 33 +- cpp/src/io/parquet/predicate_pushdown.cpp | 4 +- cpp/src/io/parquet/reader_impl_chunking.cu | 2 +- cpp/src/io/parquet/reader_impl_helpers.cpp | 26 +- cpp/src/io/parquet/reader_impl_preprocess.cu | 8 +- cpp/src/io/statistics/byte_array_view.cuh | 6 +- cpp/src/io/utilities/arrow_io_source.cpp | 6 +- cpp/src/io/utilities/column_buffer.cpp | 20 +- cpp/src/io/utilities/column_buffer.hpp | 21 +- cpp/src/io/utilities/data_casting.cu | 4 +- cpp/src/io/utilities/data_sink.cpp | 8 +- cpp/src/io/utilities/datasource.cpp | 2 +- cpp/src/io/utilities/file_io_utilities.cpp | 8 +- cpp/src/io/utilities/hostdevice_span.hpp | 2 +- cpp/src/io/utilities/hostdevice_vector.hpp | 2 +- cpp/src/io/utilities/output_builder.cuh | 4 +- cpp/src/io/utilities/string_parsing.hpp | 6 +- cpp/src/io/utilities/type_inference.cu | 2 +- cpp/src/jit/cache.cpp | 4 +- cpp/src/jit/parser.cpp | 17 +- cpp/src/jit/parser.hpp | 8 +- cpp/src/reductions/reductions.cpp | 6 +- .../detail/optimized_unbounded_window.cpp | 2 +- cpp/src/strings/regex/regcomp.cpp | 26 +- cpp/src/strings/regex/regex.cuh | 45 +- cpp/src/strings/regex/regex.inl | 7 +- cpp/src/strings/regex/regexec.cpp | 14 +- cpp/src/transform/transform.cpp | 2 +- cpp/src/utilities/stream_pool.cpp | 4 +- .../binop-compiled-fixed_point-test.cpp | 8 +- cpp/tests/bitmask/is_element_valid_tests.cpp | 8 +- cpp/tests/column/column_view_shallow_test.cpp | 3 +- cpp/tests/copying/concatenate_tests.cpp | 79 ++-- cpp/tests/copying/copy_tests.cpp | 5 +- cpp/tests/copying/gather_str_tests.cpp | 27 +- cpp/tests/copying/gather_struct_tests.cpp | 4 +- cpp/tests/copying/get_value_tests.cpp | 12 +- cpp/tests/copying/pack_tests.cpp | 86 ++-- cpp/tests/copying/scatter_list_tests.cpp | 11 +- cpp/tests/copying/scatter_struct_tests.cpp | 9 +- cpp/tests/copying/scatter_tests.cpp | 47 +- cpp/tests/copying/shift_tests.cpp | 57 +-- cpp/tests/copying/slice_tests.cpp | 69 ++- cpp/tests/copying/split_tests.cpp | 123 ++++-- cpp/tests/dictionary/decode_test.cpp | 5 +- cpp/tests/dictionary/encode_test.cpp | 5 +- cpp/tests/dictionary/factories_test.cpp | 6 +- cpp/tests/dictionary/fill_test.cpp | 10 +- cpp/tests/dictionary/gather_test.cpp | 5 +- cpp/tests/dictionary/remove_keys_test.cpp | 14 +- cpp/tests/dictionary/scatter_test.cpp | 19 +- cpp/tests/dictionary/search_test.cpp | 6 +- cpp/tests/dictionary/set_keys_test.cpp | 12 +- cpp/tests/dictionary/slice_test.cpp | 15 +- cpp/tests/groupby/argmax_tests.cpp | 5 +- cpp/tests/groupby/argmin_tests.cpp | 7 +- cpp/tests/groupby/collect_set_tests.cpp | 4 +- cpp/tests/groupby/correlation_tests.cpp | 8 +- cpp/tests/groupby/count_scan_tests.cpp | 4 +- cpp/tests/groupby/count_tests.cpp | 7 +- cpp/tests/groupby/covariance_tests.cpp | 8 +- cpp/tests/groupby/groupby_test_util.cpp | 4 +- cpp/tests/groupby/groups_tests.cpp | 5 +- cpp/tests/groupby/keys_tests.cpp | 8 +- cpp/tests/groupby/m2_tests.cpp | 4 +- cpp/tests/groupby/max_scan_tests.cpp | 4 +- cpp/tests/groupby/max_tests.cpp | 25 +- cpp/tests/groupby/mean_tests.cpp | 7 +- cpp/tests/groupby/median_tests.cpp | 7 +- cpp/tests/groupby/merge_lists_tests.cpp | 4 +- cpp/tests/groupby/merge_m2_tests.cpp | 6 +- cpp/tests/groupby/merge_sets_tests.cpp | 4 +- cpp/tests/groupby/min_scan_tests.cpp | 4 +- cpp/tests/groupby/min_tests.cpp | 25 +- cpp/tests/groupby/nth_element_tests.cpp | 40 +- cpp/tests/groupby/nunique_tests.cpp | 19 +- cpp/tests/groupby/product_scan_tests.cpp | 2 +- cpp/tests/groupby/product_tests.cpp | 4 +- cpp/tests/groupby/quantile_tests.cpp | 7 +- cpp/tests/groupby/rank_scan_tests.cpp | 12 +- cpp/tests/groupby/replace_nulls_tests.cpp | 10 +- cpp/tests/groupby/shift_tests.cpp | 23 +- cpp/tests/groupby/std_tests.cpp | 12 +- cpp/tests/groupby/sum_of_squares_tests.cpp | 7 +- cpp/tests/groupby/sum_scan_tests.cpp | 4 +- cpp/tests/groupby/sum_tests.cpp | 5 +- cpp/tests/groupby/var_tests.cpp | 12 +- cpp/tests/hashing/md5_test.cpp | 32 +- cpp/tests/hashing/murmurhash3_x86_32_test.cpp | 106 ++++- cpp/tests/hashing/sha1_test.cpp | 8 +- cpp/tests/hashing/sha224_test.cpp | 8 +- cpp/tests/hashing/sha256_test.cpp | 8 +- cpp/tests/hashing/sha384_test.cpp | 8 +- cpp/tests/hashing/sha512_test.cpp | 8 +- cpp/tests/interop/dlpack_test.cpp | 2 +- cpp/tests/interop/from_arrow_device_test.cpp | 14 +- cpp/tests/interop/from_arrow_host_test.cpp | 6 +- cpp/tests/interop/from_arrow_test.cpp | 43 +- cpp/tests/interop/nanoarrow_utils.hpp | 14 +- cpp/tests/interop/to_arrow_device_test.cpp | 26 +- cpp/tests/io/csv_test.cpp | 4 +- cpp/tests/io/json_chunked_reader.cpp | 4 +- .../io/json_quote_normalization_test.cpp | 2 +- cpp/tests/io/json_test.cpp | 4 +- cpp/tests/io/json_tree.cpp | 8 +- cpp/tests/io/orc_chunked_reader_test.cu | 4 +- cpp/tests/io/orc_test.cpp | 8 +- cpp/tests/io/parquet_chunked_writer_test.cpp | 36 +- cpp/tests/io/parquet_reader_test.cpp | 54 ++- cpp/tests/io/parquet_v2_test.cpp | 79 ++-- cpp/tests/io/parquet_writer_test.cpp | 20 +- cpp/tests/join/distinct_join_tests.cpp | 76 ++-- cpp/tests/join/join_tests.cpp | 342 +++++++------- cpp/tests/join/semi_anti_join_tests.cpp | 43 +- cpp/tests/json/json_tests.cpp | 6 +- .../large_strings/large_strings_fixture.cpp | 9 +- cpp/tests/lists/contains_tests.cpp | 2 +- cpp/tests/lists/count_elements_tests.cpp | 10 +- cpp/tests/lists/explode_tests.cpp | 68 +-- cpp/tests/lists/sort_lists_tests.cpp | 8 +- cpp/tests/merge/merge_dictionary_test.cpp | 18 +- cpp/tests/merge/merge_string_test.cpp | 63 ++- .../partitioning/hash_partition_test.cpp | 2 +- cpp/tests/partitioning/round_robin_test.cpp | 73 +-- .../quantiles/percentile_approx_test.cpp | 11 +- cpp/tests/quantiles/quantile_test.cpp | 2 +- cpp/tests/quantiles/quantiles_test.cpp | 12 +- cpp/tests/reductions/collect_ops_tests.cpp | 47 +- cpp/tests/reductions/list_rank_test.cpp | 85 +++- cpp/tests/reductions/reduction_tests.cpp | 131 +++--- cpp/tests/reductions/scan_tests.cpp | 15 +- .../reductions/segmented_reduction_tests.cpp | 69 +-- cpp/tests/reshape/byte_cast_tests.cpp | 16 +- cpp/tests/rolling/collect_ops_test.cpp | 30 +- cpp/tests/rolling/grouped_rolling_test.cpp | 110 +++-- .../rolling/range_rolling_window_test.cpp | 24 +- cpp/tests/round/round_tests.cpp | 5 +- cpp/tests/scalar/scalar_test.cpp | 4 +- cpp/tests/search/search_dictionary_test.cpp | 30 +- cpp/tests/sort/is_sorted_tests.cpp | 8 +- cpp/tests/sort/rank_test.cpp | 91 ++-- cpp/tests/sort/stable_sort_tests.cpp | 8 +- .../distinct_count_tests.cpp | 37 +- .../stream_compaction/distinct_tests.cpp | 4 +- .../stream_compaction/drop_nans_tests.cpp | 38 +- .../stream_compaction/drop_nulls_tests.cpp | 67 +-- .../stable_distinct_tests.cpp | 4 +- cpp/tests/stream_compaction/unique_tests.cpp | 72 +-- cpp/tests/streams/interop_test.cpp | 1 + cpp/tests/streams/io/orc_test.cpp | 4 +- cpp/tests/streams/io/parquet_test.cpp | 4 +- cpp/tests/streams/lists_test.cpp | 5 +- cpp/tests/streams/reduction_test.cpp | 16 +- cpp/tests/streams/replace_test.cpp | 9 +- cpp/tests/streams/strings/filter_test.cpp | 4 +- cpp/tests/strings/case_tests.cpp | 50 ++- cpp/tests/strings/chars_types_tests.cpp | 51 ++- .../strings/combine/concatenate_tests.cpp | 11 +- .../strings/combine/join_strings_tests.cpp | 6 +- cpp/tests/strings/contains_tests.cpp | 16 +- cpp/tests/strings/datetime_tests.cpp | 6 +- cpp/tests/strings/extract_tests.cpp | 23 +- cpp/tests/strings/fill_tests.cpp | 6 +- cpp/tests/strings/find_multiple_tests.cpp | 2 +- cpp/tests/strings/find_tests.cpp | 102 +++-- cpp/tests/strings/findall_tests.cpp | 6 +- cpp/tests/strings/fixed_point_tests.cpp | 6 +- cpp/tests/strings/integers_tests.cpp | 24 +- cpp/tests/strings/ipv4_tests.cpp | 7 +- cpp/tests/strings/like_tests.cpp | 7 +- cpp/tests/strings/pad_tests.cpp | 5 +- cpp/tests/strings/replace_regex_tests.cpp | 6 +- cpp/tests/strings/replace_tests.cpp | 12 +- cpp/tests/strings/reverse_tests.cpp | 18 +- cpp/tests/strings/slice_tests.cpp | 8 +- cpp/tests/strings/split_tests.cpp | 42 +- cpp/tests/strings/strip_tests.cpp | 5 +- cpp/tests/strings/translate_tests.cpp | 4 +- cpp/tests/structs/structs_column_tests.cpp | 2 +- cpp/tests/structs/utilities_tests.cpp | 4 +- cpp/tests/table/row_operators_tests.cpp | 8 +- cpp/tests/text/bpe_tests.cpp | 2 +- cpp/tests/text/jaccard_tests.cpp | 15 +- cpp/tests/text/normalize_tests.cpp | 6 +- cpp/tests/text/replace_tests.cpp | 2 +- cpp/tests/text/stemmer_tests.cpp | 2 +- cpp/tests/text/subword_tests.cpp | 2 +- cpp/tests/text/tokenize_tests.cpp | 6 +- cpp/tests/transform/nans_to_null_test.cpp | 4 +- cpp/tests/transform/one_hot_encode_tests.cpp | 9 +- cpp/tests/unary/cast_tests.cpp | 15 +- cpp/tests/unary/math_ops_test.cpp | 3 +- cpp/tests/utilities/column_utilities.cu | 2 +- cpp/tests/utilities/identify_stream_usage.cpp | 2 +- cpp/tests/utilities_tests/logger_tests.cpp | 4 +- cpp/tests/utilities_tests/type_list_tests.cpp | 54 +-- java/src/main/native/include/jni_utils.hpp | 26 +- java/src/main/native/src/ColumnVectorJni.cpp | 14 +- java/src/main/native/src/ColumnViewJni.cpp | 44 +- java/src/main/native/src/RmmJni.cpp | 8 +- java/src/main/native/src/ScalarJni.cpp | 4 +- java/src/main/native/src/TableJni.cpp | 28 +- .../main/native/src/jni_writer_data_sink.hpp | 4 +- 261 files changed, 2911 insertions(+), 2151 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4cdcac88091..cc08b832e69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,12 +56,20 @@ repos: - id: clang-format types_or: [c, c++, cuda] args: ["-fallback-style=none", "-style=file", "-i"] + exclude: | + (?x)^( + ^cpp/src/io/parquet/ipc/Schema_generated.h| + ^cpp/src/io/parquet/ipc/Message_generated.h| + ^cpp/include/cudf_test/cxxopts.hpp| + ) - repo: https://github.com/sirosen/texthooks rev: 0.6.6 hooks: - id: fix-smartquotes exclude: | (?x)^( + ^cpp/src/io/parquet/ipc/Schema_generated.h| + ^cpp/src/io/parquet/ipc/Message_generated.h| ^cpp/include/cudf_test/cxxopts.hpp| ^python/cudf/cudf/tests/data/subword_tokenizer_data/.*| ^python/cudf/cudf/tests/text/test_text_methods.py diff --git a/cpp/include/cudf/ast/expressions.hpp b/cpp/include/cudf/ast/expressions.hpp index 26916e49012..918271e3e4f 100644 --- a/cpp/include/cudf/ast/expressions.hpp +++ b/cpp/include/cudf/ast/expressions.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -478,7 +478,10 @@ class operation : public expression { * * @return Vector of operands */ - std::vector> get_operands() const { return operands; } + [[nodiscard]] std::vector> get_operands() const + { + return operands; + } /** * @copydoc expression::accept diff --git a/cpp/include/cudf/column/column_device_view.cuh b/cpp/include/cudf/column/column_device_view.cuh index 19722d127cb..787e9c2c479 100644 --- a/cpp/include/cudf/column/column_device_view.cuh +++ b/cpp/include/cudf/column/column_device_view.cuh @@ -442,7 +442,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base { * @return string_view instance representing this element at this index */ template )> - __device__ T element(size_type element_index) const noexcept + __device__ [[nodiscard]] T element(size_type element_index) const noexcept { size_type index = element_index + offset(); // account for this view's _offset char const* d_strings = static_cast(_data); @@ -501,7 +501,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base { * @return dictionary32 instance representing this element at this index */ template )> - __device__ T element(size_type element_index) const noexcept + __device__ [[nodiscard]] T element(size_type element_index) const noexcept { size_type index = element_index + offset(); // account for this view's _offset auto const indices = d_children[0]; @@ -519,7 +519,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base { * @return numeric::fixed_point representing the element at this index */ template ())> - __device__ T element(size_type element_index) const noexcept + __device__ [[nodiscard]] T element(size_type element_index) const noexcept { using namespace numeric; using rep = typename T::rep; @@ -858,7 +858,7 @@ class alignas(16) column_device_view : public detail::column_device_view_base { */ [[nodiscard]] __device__ device_span children() const noexcept { - return device_span(d_children, _num_children); + return {d_children, static_cast(_num_children)}; } /** @@ -1032,7 +1032,7 @@ class alignas(16) mutable_column_device_view : public detail::column_device_view * @return Reference to the element at the specified index */ template ())> - __device__ T& element(size_type element_index) const noexcept + __device__ [[nodiscard]] T& element(size_type element_index) const noexcept { return data()[element_index]; } diff --git a/cpp/include/cudf/detail/aggregation/aggregation.hpp b/cpp/include/cudf/detail/aggregation/aggregation.hpp index 87c0f8ec7f1..edee83783b8 100644 --- a/cpp/include/cudf/detail/aggregation/aggregation.hpp +++ b/cpp/include/cudf/detail/aggregation/aggregation.hpp @@ -24,6 +24,7 @@ #include #include +#include namespace cudf { namespace detail { @@ -510,7 +511,7 @@ class quantile_aggregation final : public groupby_aggregation, public reduce_agg void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } private: - size_t hash_impl() const + [[nodiscard]] size_t hash_impl() const { return std::hash{}(static_cast(_interpolation)) ^ std::accumulate( @@ -596,7 +597,10 @@ class nunique_aggregation final : public groupby_aggregation, void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } private: - size_t hash_impl() const { return std::hash{}(static_cast(_null_handling)); } + [[nodiscard]] size_t hash_impl() const + { + return std::hash{}(static_cast(_null_handling)); + } }; /** @@ -638,7 +642,7 @@ class nth_element_aggregation final : public groupby_aggregation, void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } private: - size_t hash_impl() const + [[nodiscard]] size_t hash_impl() const { return std::hash{}(_n) ^ std::hash{}(static_cast(_null_handling)); } @@ -763,7 +767,10 @@ class collect_list_aggregation final : public rolling_aggregation, void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } private: - size_t hash_impl() const { return std::hash{}(static_cast(_null_handling)); } + [[nodiscard]] size_t hash_impl() const + { + return std::hash{}(static_cast(_null_handling)); + } }; /** @@ -813,7 +820,7 @@ class collect_set_aggregation final : public rolling_aggregation, void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } protected: - size_t hash_impl() const + [[nodiscard]] size_t hash_impl() const { return std::hash{}(static_cast(_null_handling) ^ static_cast(_nulls_equal) ^ static_cast(_nans_equal)); @@ -866,10 +873,10 @@ class lead_lag_aggregation final : public rolling_aggregation { class udf_aggregation final : public rolling_aggregation { public: udf_aggregation(aggregation::Kind type, - std::string const& user_defined_aggregator, + std::string user_defined_aggregator, data_type output_type) : aggregation{type}, - _source{user_defined_aggregator}, + _source{std::move(user_defined_aggregator)}, _operator_name{(type == aggregation::PTX) ? "rolling_udf_ptx" : "rolling_udf_cuda"}, _function_name{"rolling_udf"}, _output_type{output_type} @@ -973,7 +980,7 @@ class merge_sets_aggregation final : public groupby_aggregation, public reduce_a void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } protected: - size_t hash_impl() const + [[nodiscard]] size_t hash_impl() const { return std::hash{}(static_cast(_nulls_equal) ^ static_cast(_nans_equal)); } @@ -1046,7 +1053,7 @@ class covariance_aggregation final : public groupby_aggregation { void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } protected: - size_t hash_impl() const + [[nodiscard]] size_t hash_impl() const { return std::hash{}(_min_periods) ^ std::hash{}(_ddof); } @@ -1088,7 +1095,7 @@ class correlation_aggregation final : public groupby_aggregation { void finalize(aggregation_finalizer& finalizer) const override { finalizer.visit(*this); } protected: - size_t hash_impl() const + [[nodiscard]] size_t hash_impl() const { return std::hash{}(static_cast(_type)) ^ std::hash{}(_min_periods); } diff --git a/cpp/include/cudf/detail/contiguous_split.hpp b/cpp/include/cudf/detail/contiguous_split.hpp index de00b61cdca..1467ed1aa67 100644 --- a/cpp/include/cudf/detail/contiguous_split.hpp +++ b/cpp/include/cudf/detail/contiguous_split.hpp @@ -104,7 +104,7 @@ class metadata_builder { * * @returns A vector containing the serialized column metadata */ - std::vector build() const; + [[nodiscard]] std::vector build() const; /** * @brief Clear the internal buffer containing all added metadata. diff --git a/cpp/include/cudf/detail/normalizing_iterator.cuh b/cpp/include/cudf/detail/normalizing_iterator.cuh index 32df13104e0..308fd188b09 100644 --- a/cpp/include/cudf/detail/normalizing_iterator.cuh +++ b/cpp/include/cudf/detail/normalizing_iterator.cuh @@ -51,7 +51,7 @@ struct alignas(16) base_normalator { */ CUDF_HOST_DEVICE inline Derived& operator++() { - Derived& derived = static_cast(*this); + auto& derived = static_cast(*this); derived.p_ += width_; return derived; } @@ -71,7 +71,7 @@ struct alignas(16) base_normalator { */ CUDF_HOST_DEVICE inline Derived& operator--() { - Derived& derived = static_cast(*this); + auto& derived = static_cast(*this); derived.p_ -= width_; return derived; } @@ -91,7 +91,7 @@ struct alignas(16) base_normalator { */ CUDF_HOST_DEVICE inline Derived& operator+=(difference_type offset) { - Derived& derived = static_cast(*this); + auto& derived = static_cast(*this); derived.p_ += offset * width_; return derived; } @@ -121,7 +121,7 @@ struct alignas(16) base_normalator { */ CUDF_HOST_DEVICE inline Derived& operator-=(difference_type offset) { - Derived& derived = static_cast(*this); + auto& derived = static_cast(*this); derived.p_ -= offset * width_; return derived; } diff --git a/cpp/include/cudf/detail/structs/utilities.hpp b/cpp/include/cudf/detail/structs/utilities.hpp index e736514ac29..beedc009c84 100644 --- a/cpp/include/cudf/detail/structs/utilities.hpp +++ b/cpp/include/cudf/detail/structs/utilities.hpp @@ -25,6 +25,8 @@ #include #include +#include + namespace cudf::structs::detail { enum class column_nullability { @@ -112,12 +114,12 @@ class flattened_table { * @param columns_ Newly allocated columns to back the table_view * @param nullable_data_ Newly generated temporary data that needs to be kept alive */ - flattened_table(table_view const& flattened_columns_, + flattened_table(table_view flattened_columns_, std::vector const& orders_, std::vector const& null_orders_, std::vector>&& columns_, temporary_nullable_data&& nullable_data_) - : _flattened_columns{flattened_columns_}, + : _flattened_columns{std::move(flattened_columns_)}, _orders{orders_}, _null_orders{null_orders_}, _columns{std::move(columns_)}, @@ -170,11 +172,11 @@ class flattened_table { * orders, flattened null precedence, alongside the supporting columns and device_buffers * for the flattened table. */ -[[nodiscard]] std::unique_ptr flatten_nested_columns( +[[nodiscard]] std::unique_ptr flatten_nested_columns( table_view const& input, - std::vector const& column_order, - std::vector const& null_precedence, - column_nullability nullability, + std::vector const& column_order, + std::vector const& null_precedence, + cudf::structs::detail::column_nullability nullability, rmm::cuda_stream_view stream, rmm::device_async_resource_ref mr); @@ -194,11 +196,11 @@ class flattened_table { * @param mr Device memory resource used to allocate new device memory * @return A new column with potentially new null mask */ -[[nodiscard]] std::unique_ptr superimpose_nulls(bitmask_type const* null_mask, - size_type null_count, - std::unique_ptr&& input, - rmm::cuda_stream_view stream, - rmm::device_async_resource_ref mr); +[[nodiscard]] std::unique_ptr superimpose_nulls(bitmask_type const* null_mask, + cudf::size_type null_count, + std::unique_ptr&& input, + rmm::cuda_stream_view stream, + rmm::device_async_resource_ref mr); /** * @brief Push down nulls from the given input column into its children columns, using bitwise AND. diff --git a/cpp/include/cudf/detail/utilities/host_vector.hpp b/cpp/include/cudf/detail/utilities/host_vector.hpp index 6a115177ab5..2d14d0306cd 100644 --- a/cpp/include/cudf/detail/utilities/host_vector.hpp +++ b/cpp/include/cudf/detail/utilities/host_vector.hpp @@ -82,7 +82,7 @@ class rmm_host_allocator { using size_type = std::size_t; ///< The type used for the size of the allocation using difference_type = std::ptrdiff_t; ///< The type of the distance between two pointers - typedef cuda::std::true_type propagate_on_container_move_assignment; + using propagate_on_container_move_assignment = cuda::std::true_type; /** * @brief converts a `rmm_host_allocator` to `rmm_host_allocator` @@ -147,7 +147,7 @@ class rmm_host_allocator { * @return The maximum number of objects that may be allocated * by a single call to \p allocate(). */ - constexpr inline size_type max_size() const + [[nodiscard]] constexpr inline size_type max_size() const { return (std::numeric_limits::max)() / sizeof(T); } diff --git a/cpp/include/cudf/detail/utilities/stream_pool.hpp b/cpp/include/cudf/detail/utilities/stream_pool.hpp index e19cc3ec2f7..64c1d4ae514 100644 --- a/cpp/include/cudf/detail/utilities/stream_pool.hpp +++ b/cpp/include/cudf/detail/utilities/stream_pool.hpp @@ -73,7 +73,7 @@ class cuda_stream_pool { * * @return the number of stream objects in the pool */ - virtual std::size_t get_stream_pool_size() const = 0; + [[nodiscard]] virtual std::size_t get_stream_pool_size() const = 0; }; /** diff --git a/cpp/include/cudf/fixed_point/fixed_point.hpp b/cpp/include/cudf/fixed_point/fixed_point.hpp index e39d75757e8..6c3c3b4da07 100644 --- a/cpp/include/cudf/fixed_point/fixed_point.hpp +++ b/cpp/include/cudf/fixed_point/fixed_point.hpp @@ -291,14 +291,14 @@ class fixed_point { * * @return The underlying value of the `fixed_point` number */ - CUDF_HOST_DEVICE inline rep value() const { return _value; } + CUDF_HOST_DEVICE [[nodiscard]] inline rep value() const { return _value; } /** * @brief Method that returns the scale of the `fixed_point` number * * @return The scale of the `fixed_point` number */ - CUDF_HOST_DEVICE inline scale_type scale() const { return _scale; } + CUDF_HOST_DEVICE [[nodiscard]] inline scale_type scale() const { return _scale; } /** * @brief Explicit conversion operator to `bool` @@ -573,7 +573,7 @@ class fixed_point { * @param scale The `scale` of the returned `fixed_point` number * @return `fixed_point` number with a new `scale` */ - CUDF_HOST_DEVICE inline fixed_point rescaled(scale_type scale) const + CUDF_HOST_DEVICE [[nodiscard]] inline fixed_point rescaled(scale_type scale) const { if (scale == _scale) { return *this; } Rep const value = detail::shift(_value, scale_type{scale - _scale}); diff --git a/cpp/include/cudf/interop.hpp b/cpp/include/cudf/interop.hpp index f3ff0009d5c..56ec62fa6e1 100644 --- a/cpp/include/cudf/interop.hpp +++ b/cpp/include/cudf/interop.hpp @@ -40,6 +40,8 @@ #include +#include + struct DLManagedTensor; struct ArrowDeviceArray; @@ -121,7 +123,7 @@ struct column_metadata { * * @param _name Name of the column */ - column_metadata(std::string const& _name) : name(_name) {} + column_metadata(std::string _name) : name(std::move(_name)) {} column_metadata() = default; }; diff --git a/cpp/include/cudf/interop/detail/arrow.hpp b/cpp/include/cudf/interop/detail/arrow.hpp index 8043ecf5422..906d48f636b 100644 --- a/cpp/include/cudf/interop/detail/arrow.hpp +++ b/cpp/include/cudf/interop/detail/arrow.hpp @@ -24,8 +24,12 @@ #define ARROW_C_DEVICE_DATA_INTERFACE // Device type for the allocated memory -typedef int32_t ArrowDeviceType; +using ArrowDeviceType = int32_t; +// The Arrow spec specifies using macros rather than enums here to avoid being +// susceptible to changes in the underlying type chosen by the compiler, but +// clang-tidy doesn't like this. +// NOLINTBEGIN // CPU device, same as using ArrowArray directly #define ARROW_DEVICE_CPU 1 // CUDA GPU Device @@ -34,6 +38,7 @@ typedef int32_t ArrowDeviceType; #define ARROW_DEVICE_CUDA_HOST 3 // CUDA managed/unified memory allocated by cudaMallocManaged #define ARROW_DEVICE_CUDA_MANAGED 13 +// NOLINTEND struct ArrowDeviceArray { struct ArrowArray array; diff --git a/cpp/include/cudf/io/arrow_io_source.hpp b/cpp/include/cudf/io/arrow_io_source.hpp index 5f79f05c5a1..d7a48c34e12 100644 --- a/cpp/include/cudf/io/arrow_io_source.hpp +++ b/cpp/include/cudf/io/arrow_io_source.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include +#include namespace cudf::io { /** @@ -49,7 +50,10 @@ class arrow_io_source : public datasource { * * @param file The `arrow` object from which the data is read */ - explicit arrow_io_source(std::shared_ptr file) : arrow_file(file) {} + explicit arrow_io_source(std::shared_ptr file) + : arrow_file(std::move(file)) + { + } /** * @brief Returns a buffer with a subset of data from the `arrow` source. diff --git a/cpp/include/cudf/io/csv.hpp b/cpp/include/cudf/io/csv.hpp index a20f75cecd7..68bb7fba00e 100644 --- a/cpp/include/cudf/io/csv.hpp +++ b/cpp/include/cudf/io/csv.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -431,7 +432,8 @@ class csv_reader_options { * * @return Per-column types */ - std::variant, std::map> const& get_dtypes() const + [[nodiscard]] std::variant, std::map> const& + get_dtypes() const { return _dtypes; } @@ -441,49 +443,49 @@ class csv_reader_options { * * @return Additional values to recognize as boolean true values */ - std::vector const& get_true_values() const { return _true_values; } + [[nodiscard]] std::vector const& get_true_values() const { return _true_values; } /** * @brief Returns additional values to recognize as boolean false values. * * @return Additional values to recognize as boolean false values */ - std::vector const& get_false_values() const { return _false_values; } + [[nodiscard]] std::vector const& get_false_values() const { return _false_values; } /** * @brief Returns additional values to recognize as null values. * * @return Additional values to recognize as null values */ - std::vector const& get_na_values() const { return _na_values; } + [[nodiscard]] std::vector const& get_na_values() const { return _na_values; } /** * @brief Whether to keep the built-in default NA values. * * @return `true` if the built-in default NA values are kept */ - bool is_enabled_keep_default_na() const { return _keep_default_na; } + [[nodiscard]] bool is_enabled_keep_default_na() const { return _keep_default_na; } /** * @brief Whether to disable null filter. * * @return `true` if null filter is enabled */ - bool is_enabled_na_filter() const { return _na_filter; } + [[nodiscard]] bool is_enabled_na_filter() const { return _na_filter; } /** * @brief Whether to parse dates as DD/MM versus MM/DD. * * @return True if dates are parsed as DD/MM, false if MM/DD */ - bool is_enabled_dayfirst() const { return _dayfirst; } + [[nodiscard]] bool is_enabled_dayfirst() const { return _dayfirst; } /** * @brief Returns timestamp_type to which all timestamp columns will be cast. * * @return timestamp_type to which all timestamp columns will be cast */ - data_type get_timestamp_type() const { return _timestamp_type; } + [[nodiscard]] data_type get_timestamp_type() const { return _timestamp_type; } /** * @brief Sets compression format of the source. @@ -1399,8 +1401,8 @@ class csv_writer_options { * @param sink The sink used for writer output * @param table Table to be written to output */ - explicit csv_writer_options(sink_info const& sink, table_view const& table) - : _sink(sink), _table(table), _rows_per_chunk(table.num_rows()) + explicit csv_writer_options(sink_info sink, table_view const& table) + : _sink(std::move(sink)), _table(table), _rows_per_chunk(table.num_rows()) { } diff --git a/cpp/include/cudf/io/detail/parquet.hpp b/cpp/include/cudf/io/detail/parquet.hpp index 978216d971e..21c870cb75e 100644 --- a/cpp/include/cudf/io/detail/parquet.hpp +++ b/cpp/include/cudf/io/detail/parquet.hpp @@ -160,7 +160,7 @@ class chunked_reader : private reader { * destructor needs to be defined in a separate source file which can access to that object's * declaration. */ - ~chunked_reader(); + ~chunked_reader() override; /** * @copydoc cudf::io::chunked_parquet_reader::has_next diff --git a/cpp/include/cudf/io/json.hpp b/cpp/include/cudf/io/json.hpp index 65ba8f25577..8de690482f9 100644 --- a/cpp/include/cudf/io/json.hpp +++ b/cpp/include/cudf/io/json.hpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -166,9 +167,9 @@ class json_reader_options { * * @returns Data types of the columns */ - std::variant, - std::map, - std::map> const& + [[nodiscard]] std::variant, + std::map, + std::map> const& get_dtypes() const { return _dtypes; @@ -179,28 +180,28 @@ class json_reader_options { * * @return Compression format of the source */ - compression_type get_compression() const { return _compression; } + [[nodiscard]] compression_type get_compression() const { return _compression; } /** * @brief Returns number of bytes to skip from source start. * * @return Number of bytes to skip from source start */ - size_t get_byte_range_offset() const { return _byte_range_offset; } + [[nodiscard]] size_t get_byte_range_offset() const { return _byte_range_offset; } /** * @brief Returns number of bytes to read. * * @return Number of bytes to read */ - size_t get_byte_range_size() const { return _byte_range_size; } + [[nodiscard]] size_t get_byte_range_size() const { return _byte_range_size; } /** * @brief Returns number of bytes to read with padding. * * @return Number of bytes to read with padding */ - size_t get_byte_range_size_with_padding() const + [[nodiscard]] size_t get_byte_range_size_with_padding() const { if (_byte_range_size == 0) { return 0; @@ -214,7 +215,7 @@ class json_reader_options { * * @return Number of bytes to pad */ - size_t get_byte_range_padding() const + [[nodiscard]] size_t get_byte_range_padding() const { auto const num_columns = std::visit([](auto const& dtypes) { return dtypes.size(); }, _dtypes); @@ -236,67 +237,68 @@ class json_reader_options { * * @return Delimiter separating records in JSON lines */ - char get_delimiter() const { return _delimiter; } + [[nodiscard]] char get_delimiter() const { return _delimiter; } /** * @brief Whether to read the file as a json object per line. * * @return `true` if reading the file as a json object per line */ - bool is_enabled_lines() const { return _lines; } + [[nodiscard]] bool is_enabled_lines() const { return _lines; } /** * @brief Whether to parse mixed types as a string column. * * @return `true` if mixed types are parsed as a string column */ - bool is_enabled_mixed_types_as_string() const { return _mixed_types_as_string; } + [[nodiscard]] bool is_enabled_mixed_types_as_string() const { return _mixed_types_as_string; } /** * @brief Whether to prune columns on read, selected based on the @ref set_dtypes option. * * When set as true, if the reader options include @ref set_dtypes, then * the reader will only return those columns which are mentioned in @ref set_dtypes. - * If false, then all columns are returned, independent of the @ref set_dtypes setting. + * If false, then all columns are returned, independent of the @ref set_dtypes + * setting. * * @return True if column pruning is enabled */ - bool is_enabled_prune_columns() const { return _prune_columns; } + [[nodiscard]] bool is_enabled_prune_columns() const { return _prune_columns; } /** * @brief Whether to parse dates as DD/MM versus MM/DD. * * @returns true if dates are parsed as DD/MM, false if MM/DD */ - bool is_enabled_dayfirst() const { return _dayfirst; } + [[nodiscard]] bool is_enabled_dayfirst() const { return _dayfirst; } /** * @brief Whether the reader should keep quotes of string values. * * @returns true if the reader should keep quotes, false otherwise */ - bool is_enabled_keep_quotes() const { return _keep_quotes; } + [[nodiscard]] bool is_enabled_keep_quotes() const { return _keep_quotes; } /** * @brief Whether the reader should normalize single quotes around strings * * @returns true if the reader should normalize single quotes, false otherwise */ - bool is_enabled_normalize_single_quotes() const { return _normalize_single_quotes; } + [[nodiscard]] bool is_enabled_normalize_single_quotes() const { return _normalize_single_quotes; } /** * @brief Whether the reader should normalize unquoted whitespace characters * * @returns true if the reader should normalize whitespace, false otherwise */ - bool is_enabled_normalize_whitespace() const { return _normalize_whitespace; } + [[nodiscard]] bool is_enabled_normalize_whitespace() const { return _normalize_whitespace; } /** * @brief Queries the JSON reader's behavior on invalid JSON lines. * * @returns An enum that specifies the JSON reader's behavior on invalid JSON lines. */ - json_recovery_mode_t recovery_mode() const { return _recovery_mode; } + [[nodiscard]] json_recovery_mode_t recovery_mode() const { return _recovery_mode; } /** * @brief Set data types for columns to be read. @@ -717,8 +719,8 @@ class json_writer_options { * @param sink The sink used for writer output * @param table Table to be written to output */ - explicit json_writer_options(sink_info const& sink, table_view const& table) - : _sink(sink), _table(table), _rows_per_chunk(table.num_rows()) + explicit json_writer_options(sink_info sink, table_view table) + : _sink(std::move(sink)), _table(std::move(table)), _rows_per_chunk(table.num_rows()) { } diff --git a/cpp/include/cudf/io/orc.hpp b/cpp/include/cudf/io/orc.hpp index 8140f8897b7..623c1d9fc72 100644 --- a/cpp/include/cudf/io/orc.hpp +++ b/cpp/include/cudf/io/orc.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace cudf { @@ -125,7 +126,7 @@ class orc_reader_options { * * @return Number of rows to skip from the start */ - int64_t get_skip_rows() const { return _skip_rows; } + [[nodiscard]] int64_t get_skip_rows() const { return _skip_rows; } /** * @brief Returns number of row to read. @@ -133,35 +134,38 @@ class orc_reader_options { * @return Number of rows to read; `nullopt` if the option hasn't been set (in which case the file * is read until the end) */ - std::optional const& get_num_rows() const { return _num_rows; } + [[nodiscard]] std::optional const& get_num_rows() const { return _num_rows; } /** * @brief Whether to use row index to speed-up reading. * * @return `true` if row index is used to speed-up reading */ - bool is_enabled_use_index() const { return _use_index; } + [[nodiscard]] bool is_enabled_use_index() const { return _use_index; } /** * @brief Whether to use numpy-compatible dtypes. * * @return `true` if numpy-compatible dtypes are used */ - bool is_enabled_use_np_dtypes() const { return _use_np_dtypes; } + [[nodiscard]] bool is_enabled_use_np_dtypes() const { return _use_np_dtypes; } /** * @brief Returns timestamp type to which timestamp column will be cast. * * @return Timestamp type to which timestamp column will be cast */ - data_type get_timestamp_type() const { return _timestamp_type; } + [[nodiscard]] data_type get_timestamp_type() const { return _timestamp_type; } /** * @brief Returns fully qualified names of columns that should be read as 128-bit Decimal. * * @return Fully qualified names of columns that should be read as 128-bit Decimal */ - std::vector const& get_decimal128_columns() const { return _decimal128_columns; } + [[nodiscard]] std::vector const& get_decimal128_columns() const + { + return _decimal128_columns; + } // Setters @@ -603,8 +607,8 @@ class orc_writer_options { * @param sink The sink used for writer output * @param table Table to be written to output */ - explicit orc_writer_options(sink_info const& sink, table_view const& table) - : _sink(sink), _table(table) + explicit orc_writer_options(sink_info sink, table_view table) + : _sink(std::move(sink)), _table(std::move(table)) { } @@ -676,7 +680,7 @@ class orc_writer_options { * * @return Row index stride */ - auto get_row_index_stride() const + [[nodiscard]] auto get_row_index_stride() const { auto const unaligned_stride = std::min(_row_index_stride, get_stripe_size_rows()); return unaligned_stride - unaligned_stride % 8; @@ -1048,7 +1052,7 @@ class chunked_orc_writer_options { * * @param sink The sink used for writer output */ - chunked_orc_writer_options(sink_info const& sink) : _sink(sink) {} + chunked_orc_writer_options(sink_info sink) : _sink(std::move(sink)) {} public: /** @@ -1107,7 +1111,7 @@ class chunked_orc_writer_options { * * @return Row index stride */ - auto get_row_index_stride() const + [[nodiscard]] auto get_row_index_stride() const { auto const unaligned_stride = std::min(_row_index_stride, get_stripe_size_rows()); return unaligned_stride - unaligned_stride % 8; diff --git a/cpp/include/cudf/io/parquet.hpp b/cpp/include/cudf/io/parquet.hpp index 51eeed5b721..431f14af522 100644 --- a/cpp/include/cudf/io/parquet.hpp +++ b/cpp/include/cudf/io/parquet.hpp @@ -187,7 +187,7 @@ class parquet_reader_options { * * @return Timestamp type used to cast timestamp columns */ - data_type get_timestamp_type() const { return _timestamp_type; } + [[nodiscard]] data_type get_timestamp_type() const { return _timestamp_type; } /** * @brief Sets names of the columns to be read. @@ -626,7 +626,7 @@ class parquet_writer_options_base { * * @param sink The sink used for writer output */ - explicit parquet_writer_options_base(sink_info const& sink) : _sink(sink) {} + explicit parquet_writer_options_base(sink_info sink) : _sink(std::move(sink)) {} public: /** @@ -1287,7 +1287,7 @@ class chunked_parquet_writer_options : public parquet_writer_options_base { * * @param sink Sink used for writer output */ - explicit chunked_parquet_writer_options(sink_info const& sink); + explicit chunked_parquet_writer_options(sink_info sink); friend chunked_parquet_writer_options_builder; diff --git a/cpp/include/cudf/io/types.hpp b/cpp/include/cudf/io/types.hpp index 150e997f533..0dab1c606de 100644 --- a/cpp/include/cudf/io/types.hpp +++ b/cpp/include/cudf/io/types.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include namespace cudf { @@ -247,10 +248,10 @@ struct column_name_info { * @param _is_nullable True if column is nullable * @param _is_binary True if column is binary data */ - column_name_info(std::string const& _name, + column_name_info(std::string _name, std::optional _is_nullable = std::nullopt, std::optional _is_binary = std::nullopt) - : name(_name), is_nullable(_is_nullable), is_binary(_is_binary) + : name(std::move(_name)), is_nullable(_is_nullable), is_binary(_is_binary) { } diff --git a/cpp/include/cudf/join.hpp b/cpp/include/cudf/join.hpp index 825f758adbd..ba485bd6372 100644 --- a/cpp/include/cudf/join.hpp +++ b/cpp/include/cudf/join.hpp @@ -336,8 +336,8 @@ class hash_join { * the result of performing an inner join between two tables with `build` and `probe` * as the join keys . */ - std::pair>, - std::unique_ptr>> + [[nodiscard]] std::pair>, + std::unique_ptr>> inner_join(cudf::table_view const& probe, std::optional output_size = {}, rmm::cuda_stream_view stream = cudf::get_default_stream(), @@ -359,10 +359,10 @@ class hash_join { * * @return A pair of columns [`left_indices`, `right_indices`] that can be used to construct * the result of performing a left join between two tables with `build` and `probe` - * as the join keys . + * as the join keys. */ - std::pair>, - std::unique_ptr>> + [[nodiscard]] std::pair>, + std::unique_ptr>> left_join(cudf::table_view const& probe, std::optional output_size = {}, rmm::cuda_stream_view stream = cudf::get_default_stream(), @@ -386,8 +386,8 @@ class hash_join { * the result of performing a full join between two tables with `build` and `probe` * as the join keys . */ - std::pair>, - std::unique_ptr>> + [[nodiscard]] std::pair>, + std::unique_ptr>> full_join(cudf::table_view const& probe, std::optional output_size = {}, rmm::cuda_stream_view stream = cudf::get_default_stream(), @@ -440,7 +440,7 @@ class hash_join { * @return The exact number of output when performing a full join between two tables with `build` * and `probe` as the join keys . */ - std::size_t full_join_size( + [[nodiscard]] std::size_t full_join_size( cudf::table_view const& probe, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; @@ -492,12 +492,12 @@ class distinct_hash_join { * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned indices' device memory. * - * @return A pair of columns [`build_indices`, `probe_indices`] that can be used to construct - * the result of performing an inner join between two tables with `build` and `probe` - * as the join keys. + * @return A pair of columns [`build_indices`, `probe_indices`] that can be used to + * construct the result of performing an inner join between two tables + * with `build` and `probe` as the join keys. */ - std::pair>, - std::unique_ptr>> + [[nodiscard]] std::pair>, + std::unique_ptr>> inner_join(rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; @@ -512,10 +512,11 @@ class distinct_hash_join { * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned table and columns' device * memory. - * @return A `build_indices` column that can be used to construct the result of performing a left - * join between two tables with `build` and `probe` as the join keys. + * @return A `build_indices` column that can be used to construct the result of + * performing a left join between two tables with `build` and `probe` as the join + * keys. */ - std::unique_ptr> left_join( + [[nodiscard]] std::unique_ptr> left_join( rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource()) const; diff --git a/cpp/include/cudf/scalar/scalar.hpp b/cpp/include/cudf/scalar/scalar.hpp index da1d0d743a7..d78907b473a 100644 --- a/cpp/include/cudf/scalar/scalar.hpp +++ b/cpp/include/cudf/scalar/scalar.hpp @@ -187,7 +187,7 @@ class fixed_width_scalar : public scalar { * @param stream CUDA stream used for device memory operations. * @return Value of the scalar */ - T value(rmm::cuda_stream_view stream = cudf::get_default_stream()) const; + [[nodiscard]] T value(rmm::cuda_stream_view stream = cudf::get_default_stream()) const; /** * @brief Returns a raw pointer to the value in device memory. @@ -199,7 +199,7 @@ class fixed_width_scalar : public scalar { * @brief Returns a const raw pointer to the value in device memory. * @return A const raw pointer to the value in device memory */ - T const* data() const; + [[nodiscard]] T const* data() const; protected: rmm::device_scalar _data; ///< device memory containing the value @@ -245,8 +245,8 @@ class numeric_scalar : public detail::fixed_width_scalar { static_assert(is_numeric(), "Unexpected non-numeric type."); public: - numeric_scalar() = delete; - ~numeric_scalar() = default; + numeric_scalar() = delete; + ~numeric_scalar() override = default; /** * @brief Move constructor for numeric_scalar. @@ -393,7 +393,7 @@ class fixed_point_scalar : public scalar { * @param stream CUDA stream used for device memory operations. * @return The value of the scalar */ - rep_type value(rmm::cuda_stream_view stream = cudf::get_default_stream()) const; + [[nodiscard]] rep_type value(rmm::cuda_stream_view stream = cudf::get_default_stream()) const; /** * @brief Get the decimal32, decimal64 or decimal128. @@ -401,7 +401,8 @@ class fixed_point_scalar : public scalar { * @param stream CUDA stream used for device memory operations. * @return The decimal32, decimal64 or decimal128 value */ - T fixed_point_value(rmm::cuda_stream_view stream = cudf::get_default_stream()) const; + [[nodiscard]] T fixed_point_value( + rmm::cuda_stream_view stream = cudf::get_default_stream()) const; /** * @brief Explicit conversion operator to get the value of the scalar on the host. @@ -418,7 +419,7 @@ class fixed_point_scalar : public scalar { * @brief Returns a const raw pointer to the value in device memory. * @return a const raw pointer to the value in device memory */ - rep_type const* data() const; + [[nodiscard]] rep_type const* data() const; protected: rmm::device_scalar _data; ///< device memory containing the value @@ -565,8 +566,8 @@ class chrono_scalar : public detail::fixed_width_scalar { static_assert(is_chrono(), "Unexpected non-chrono type"); public: - chrono_scalar() = delete; - ~chrono_scalar() = default; + chrono_scalar() = delete; + ~chrono_scalar() override = default; /** * @brief Move constructor for chrono_scalar. diff --git a/cpp/include/cudf/strings/regex/regex_program.hpp b/cpp/include/cudf/strings/regex/regex_program.hpp index bdf541f455f..95c86ae0f8a 100644 --- a/cpp/include/cudf/strings/regex/regex_program.hpp +++ b/cpp/include/cudf/strings/regex/regex_program.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,35 +74,35 @@ struct regex_program { * * @return regex pattern as a string */ - std::string pattern() const; + [[nodiscard]] std::string pattern() const; /** * @brief Return the regex_flags used to create this instance * * @return regex flags setting */ - regex_flags flags() const; + [[nodiscard]] regex_flags flags() const; /** * @brief Return the capture_groups used to create this instance * * @return capture groups setting */ - capture_groups capture() const; + [[nodiscard]] capture_groups capture() const; /** * @brief Return the number of instructions in this instance * * @return Number of instructions */ - int32_t instructions_count() const; + [[nodiscard]] int32_t instructions_count() const; /** * @brief Return the number of capture groups in this instance * * @return Number of groups */ - int32_t groups_count() const; + [[nodiscard]] int32_t groups_count() const; /** * @brief Return the size of the working memory for the regex execution @@ -110,7 +110,7 @@ struct regex_program { * @param num_strings Number of strings for computation * @return Size of the working memory in bytes */ - std::size_t compute_working_memory_size(int32_t num_strings) const; + [[nodiscard]] std::size_t compute_working_memory_size(int32_t num_strings) const; ~regex_program(); diff --git a/cpp/include/cudf/strings/string_view.cuh b/cpp/include/cudf/strings/string_view.cuh index 74df1ea1887..93cc787683b 100644 --- a/cpp/include/cudf/strings/string_view.cuh +++ b/cpp/include/cudf/strings/string_view.cuh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,7 +110,7 @@ static __constant__ char max_string_sentinel[5]{"\xF7\xBF\xBF\xBF"}; * * @return An empty string */ -CUDF_HOST_DEVICE inline string_view string_view::min() { return string_view(); } +CUDF_HOST_DEVICE inline string_view string_view::min() { return {}; } /** * @brief Return maximum value associated with the string type @@ -130,7 +130,7 @@ CUDF_HOST_DEVICE inline string_view string_view::max() CUDF_CUDA_TRY( cudaGetSymbolAddress((void**)&psentinel, cudf::strings::detail::max_string_sentinel)); #endif - return string_view(psentinel, 4); + return {psentinel, 4}; } __device__ inline size_type string_view::length() const @@ -439,7 +439,7 @@ __device__ inline string_view string_view::substr(size_type pos, size_type count auto const itr = begin() + pos; auto const spos = itr.byte_offset(); auto const epos = count >= 0 ? (itr + count).byte_offset() : size_bytes(); - return string_view(data() + spos, epos - spos); + return {data() + spos, epos - spos}; } __device__ inline size_type string_view::character_offset(size_type bytepos) const diff --git a/cpp/include/cudf/table/table.hpp b/cpp/include/cudf/table/table.hpp index 8efe6eb8c72..c4f14af53fb 100644 --- a/cpp/include/cudf/table/table.hpp +++ b/cpp/include/cudf/table/table.hpp @@ -144,7 +144,7 @@ class table { */ template - table_view select(InputIterator begin, InputIterator end) const + [[nodiscard]] table_view select(InputIterator begin, InputIterator end) const { std::vector columns(std::distance(begin, end)); std::transform( diff --git a/cpp/include/cudf/table/table_view.hpp b/cpp/include/cudf/table/table_view.hpp index ad12b1eef4e..a71e0558dec 100644 --- a/cpp/include/cudf/table/table_view.hpp +++ b/cpp/include/cudf/table/table_view.hpp @@ -123,7 +123,7 @@ class table_view_base { * @param column_index The index of the desired column * @return A reference to the desired column */ - ColumnView const& column(size_type column_index) const; + [[nodiscard]] ColumnView const& column(size_type column_index) const; /** * @brief Returns the number of columns @@ -224,7 +224,7 @@ class table_view : public detail::table_view_base { * specified by the elements of `column_indices` */ template - table_view select(InputIterator begin, InputIterator end) const + [[nodiscard]] table_view select(InputIterator begin, InputIterator end) const { std::vector columns(std::distance(begin, end)); std::transform(begin, end, columns.begin(), [this](auto index) { return this->column(index); }); diff --git a/cpp/include/cudf/utilities/error.hpp b/cpp/include/cudf/utilities/error.hpp index 719d44a9ab3..f019f516b84 100644 --- a/cpp/include/cudf/utilities/error.hpp +++ b/cpp/include/cudf/utilities/error.hpp @@ -48,7 +48,7 @@ struct stacktrace_recorder { * * @return The pointer to a null-terminated string storing the output stacktrace */ - char const* stacktrace() const { return _stacktrace.c_str(); } + [[nodiscard]] char const* stacktrace() const { return _stacktrace.c_str(); } protected: std::string const _stacktrace; //!< The whole stacktrace stored as one string. @@ -78,7 +78,7 @@ struct logic_error : public std::logic_error, public stacktrace_recorder { // TODO Add an error code member? This would be useful for translating an // exception to an error code in a pure-C API - ~logic_error() + ~logic_error() override { // Needed so that the first instance of the implicit destructor for any TU isn't 'constructed' // from a host+device function marking the implicit version also as host+device @@ -106,7 +106,7 @@ struct cuda_error : public std::runtime_error, public stacktrace_recorder { * * @return CUDA error code */ - cudaError_t error_code() const { return _cudaError; } + [[nodiscard]] cudaError_t error_code() const { return _cudaError; } protected: cudaError_t _cudaError; //!< CUDA error code @@ -237,7 +237,7 @@ inline void throw_cuda_error(cudaError_t error, char const* file, unsigned int l // Calls cudaGetLastError to clear the error status. It is nearly certain that a fatal error // occurred if it still returns the same error after a cleanup. cudaGetLastError(); - auto const last = cudaFree(0); + auto const last = cudaFree(nullptr); auto const msg = std::string{"CUDA error encountered at: " + std::string{file} + ":" + std::to_string(line) + ": " + std::to_string(error) + " " + cudaGetErrorName(error) + " " + cudaGetErrorString(error)}; diff --git a/cpp/include/cudf/utilities/span.hpp b/cpp/include/cudf/utilities/span.hpp index 47e92d61a9f..3b35e60e034 100644 --- a/cpp/include/cudf/utilities/span.hpp +++ b/cpp/include/cudf/utilities/span.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ #include #include #include +#include namespace cudf { /** @@ -90,7 +91,7 @@ class span_base { * * @return Reference to the first element in the span */ - constexpr reference front() const { return _data[0]; } + [[nodiscard]] constexpr reference front() const { return _data[0]; } // not noexcept due to undefined behavior when size = 0 /** * @brief Returns a reference to the last element in the span. @@ -99,7 +100,7 @@ class span_base { * * @return Reference to the last element in the span */ - constexpr reference back() const { return _data[_size - 1]; } + [[nodiscard]] constexpr reference back() const { return _data[_size - 1]; } // not noexcept due to undefined behavior when idx < 0 || idx >= size /** * @brief Returns a reference to the idx-th element of the sequence. @@ -119,7 +120,7 @@ class span_base { * * @return An iterator to the first element of the span */ - constexpr iterator begin() const noexcept { return _data; } + [[nodiscard]] constexpr iterator begin() const noexcept { return _data; } /** * @brief Returns an iterator to the element following the last element of the span. * @@ -127,13 +128,13 @@ class span_base { * * @return An iterator to the element following the last element of the span */ - constexpr iterator end() const noexcept { return _data + _size; } + [[nodiscard]] constexpr iterator end() const noexcept { return _data + _size; } /** * @brief Returns a pointer to the beginning of the sequence. * * @return A pointer to the first element of the span */ - constexpr pointer data() const noexcept { return _data; } + [[nodiscard]] constexpr pointer data() const noexcept { return _data; } /** * @brief Returns the number of elements in the span. @@ -160,7 +161,10 @@ class span_base { * @param count Number of elements from the beginning of this span to put in the subspan. * @return A subspan of the first N elements of the sequence */ - constexpr Derived first(size_type count) const noexcept { return Derived(_data, count); } + [[nodiscard]] constexpr Derived first(size_type count) const noexcept + { + return Derived(_data, count); + } /** * @brief Obtains a subspan consisting of the last N elements of the sequence @@ -168,7 +172,7 @@ class span_base { * @param count Number of elements from the end of this span to put in the subspan * @return A subspan of the last N elements of the sequence */ - constexpr Derived last(size_type count) const noexcept + [[nodiscard]] constexpr Derived last(size_type count) const noexcept { return Derived(_data + _size - count, count); } @@ -180,7 +184,7 @@ class span_base { * @param count The number of elements in the subspan * @return A subspan of the sequence, of requested count and offset */ - constexpr Derived subspan(size_type offset, size_type count) const noexcept + [[nodiscard]] constexpr Derived subspan(size_type offset, size_type count) const noexcept { return Derived(_data + offset, count); } @@ -365,7 +369,7 @@ class base_2dspan { * @param data Pointer to the data * @param size Size of the 2D span as pair */ - base_2dspan(T* data, size_type size) noexcept : _data{data}, _size{size} {} + base_2dspan(T* data, size_type size) noexcept : _data{data}, _size{std::move(size)} {} /** * @brief Returns a pointer to the beginning of the sequence. diff --git a/cpp/include/cudf/utilities/thread_pool.hpp b/cpp/include/cudf/utilities/thread_pool.hpp index 74a2531710b..c8c3eb097c4 100644 --- a/cpp/include/cudf/utilities/thread_pool.hpp +++ b/cpp/include/cudf/utilities/thread_pool.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -201,8 +201,8 @@ class thread_pool { running = false; destroy_threads(); thread_count = _thread_count ? _thread_count : std::thread::hardware_concurrency(); - threads.reset(new std::thread[thread_count]); - paused = was_paused; + threads = std::make_unique(thread_count); + paused = was_paused; create_threads(); running = true; } diff --git a/cpp/include/cudf/wrappers/dictionary.hpp b/cpp/include/cudf/wrappers/dictionary.hpp index 37264c5a33c..95f4ac00a53 100644 --- a/cpp/include/cudf/wrappers/dictionary.hpp +++ b/cpp/include/cudf/wrappers/dictionary.hpp @@ -87,7 +87,7 @@ struct dictionary_wrapper { * * @return The value of this dictionary wrapper */ - CUDF_HOST_DEVICE inline value_type value() const { return _value; } + CUDF_HOST_DEVICE [[nodiscard]] inline value_type value() const { return _value; } /** * @brief Returns the maximum value of the value type. diff --git a/cpp/include/cudf/wrappers/durations.hpp b/cpp/include/cudf/wrappers/durations.hpp index 62aa22c2788..840dba4f4ba 100644 --- a/cpp/include/cudf/wrappers/durations.hpp +++ b/cpp/include/cudf/wrappers/durations.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,13 +56,13 @@ using duration_us = cuda::std::chrono::duration; -static_assert(sizeof(duration_D) == sizeof(typename duration_D::rep), ""); -static_assert(sizeof(duration_h) == sizeof(typename duration_h::rep), ""); -static_assert(sizeof(duration_m) == sizeof(typename duration_m::rep), ""); -static_assert(sizeof(duration_s) == sizeof(typename duration_s::rep), ""); -static_assert(sizeof(duration_ms) == sizeof(typename duration_ms::rep), ""); -static_assert(sizeof(duration_us) == sizeof(typename duration_us::rep), ""); -static_assert(sizeof(duration_ns) == sizeof(typename duration_ns::rep), ""); +static_assert(sizeof(duration_D) == sizeof(typename duration_D::rep)); +static_assert(sizeof(duration_h) == sizeof(typename duration_h::rep)); +static_assert(sizeof(duration_m) == sizeof(typename duration_m::rep)); +static_assert(sizeof(duration_s) == sizeof(typename duration_s::rep)); +static_assert(sizeof(duration_ms) == sizeof(typename duration_ms::rep)); +static_assert(sizeof(duration_us) == sizeof(typename duration_us::rep)); +static_assert(sizeof(duration_ns) == sizeof(typename duration_ns::rep)); /** @} */ // end of group } // namespace cudf diff --git a/cpp/include/cudf/wrappers/timestamps.hpp b/cpp/include/cudf/wrappers/timestamps.hpp index 0341ac6ede4..5194a3e8f96 100644 --- a/cpp/include/cudf/wrappers/timestamps.hpp +++ b/cpp/include/cudf/wrappers/timestamps.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,13 +73,13 @@ using timestamp_us = detail::timestamp; */ using timestamp_ns = detail::timestamp; -static_assert(sizeof(timestamp_D) == sizeof(typename timestamp_D::rep), ""); -static_assert(sizeof(timestamp_h) == sizeof(typename timestamp_h::rep), ""); -static_assert(sizeof(timestamp_m) == sizeof(typename timestamp_m::rep), ""); -static_assert(sizeof(timestamp_s) == sizeof(typename timestamp_s::rep), ""); -static_assert(sizeof(timestamp_ms) == sizeof(typename timestamp_ms::rep), ""); -static_assert(sizeof(timestamp_us) == sizeof(typename timestamp_us::rep), ""); -static_assert(sizeof(timestamp_ns) == sizeof(typename timestamp_ns::rep), ""); +static_assert(sizeof(timestamp_D) == sizeof(typename timestamp_D::rep)); +static_assert(sizeof(timestamp_h) == sizeof(typename timestamp_h::rep)); +static_assert(sizeof(timestamp_m) == sizeof(typename timestamp_m::rep)); +static_assert(sizeof(timestamp_s) == sizeof(typename timestamp_s::rep)); +static_assert(sizeof(timestamp_ms) == sizeof(typename timestamp_ms::rep)); +static_assert(sizeof(timestamp_us) == sizeof(typename timestamp_us::rep)); +static_assert(sizeof(timestamp_ns) == sizeof(typename timestamp_ns::rep)); /** @} */ // end of group } // namespace cudf diff --git a/cpp/include/cudf_test/base_fixture.hpp b/cpp/include/cudf_test/base_fixture.hpp index 18f75bbc842..0e35ff64af4 100644 --- a/cpp/include/cudf_test/base_fixture.hpp +++ b/cpp/include/cudf_test/base_fixture.hpp @@ -66,7 +66,7 @@ class BaseFixtureWithParam : public ::testing::TestWithParam { * all tests inheriting from this fixture * @return pointer to memory resource */ - rmm::device_async_resource_ref mr() const { return _mr; } + [[nodiscard]] rmm::device_async_resource_ref mr() const { return _mr; } }; /** diff --git a/cpp/include/cudf_test/column_wrapper.hpp b/cpp/include/cudf_test/column_wrapper.hpp index dc873658abf..47d17988775 100644 --- a/cpp/include/cudf_test/column_wrapper.hpp +++ b/cpp/include/cudf_test/column_wrapper.hpp @@ -1121,14 +1121,20 @@ class dictionary_column_wrapper : public detail::column_wrapper { * * @return column_view to keys column */ - column_view keys() const { return cudf::dictionary_column_view{wrapped->view()}.keys(); } + [[nodiscard]] column_view keys() const + { + return cudf::dictionary_column_view{wrapped->view()}.keys(); + } /** * @brief Access indices column view * * @return column_view to indices column */ - column_view indices() const { return cudf::dictionary_column_view{wrapped->view()}.indices(); } + [[nodiscard]] column_view indices() const + { + return cudf::dictionary_column_view{wrapped->view()}.indices(); + } /** * @brief Default constructor initializes an empty dictionary column of strings @@ -1792,7 +1798,10 @@ class lists_column_wrapper : public detail::column_wrapper { return {std::move(cols), std::move(stubs)}; } - column_view get_view() const { return root ? lists_column_view(*wrapped).child() : *wrapped; } + [[nodiscard]] column_view get_view() const + { + return root ? lists_column_view(*wrapped).child() : *wrapped; + } int depth = 0; bool root = false; diff --git a/cpp/include/cudf_test/stream_checking_resource_adaptor.hpp b/cpp/include/cudf_test/stream_checking_resource_adaptor.hpp index cafde6ca7d5..5a077e86a0f 100644 --- a/cpp/include/cudf_test/stream_checking_resource_adaptor.hpp +++ b/cpp/include/cudf_test/stream_checking_resource_adaptor.hpp @@ -110,7 +110,7 @@ class stream_checking_resource_adaptor final : public rmm::mr::device_memory_res * @param other The other resource to compare to * @return Whether or not the two resources are equivalent */ - bool do_is_equal(device_memory_resource const& other) const noexcept override + [[nodiscard]] bool do_is_equal(device_memory_resource const& other) const noexcept override { if (this == &other) { return true; } auto cast = dynamic_cast const*>(&other); diff --git a/cpp/src/binaryop/binaryop.cpp b/cpp/src/binaryop/binaryop.cpp index ac31f9045fe..8ac1491547d 100644 --- a/cpp/src/binaryop/binaryop.cpp +++ b/cpp/src/binaryop/binaryop.cpp @@ -153,7 +153,7 @@ void binary_operation(mutable_column_view& out, cudf::jit::get_program_cache(*binaryop_jit_kernel_cu_jit) .get_kernel(kernel_name, {}, {{"binaryop/jit/operation-udf.hpp", cuda_source}}, {"-arch=sm_."}) - ->configure_1d_max_occupancy(0, 0, 0, stream.value()) + ->configure_1d_max_occupancy(0, 0, nullptr, stream.value()) ->launch(out.size(), cudf::jit::get_data_ptr(out), cudf::jit::get_data_ptr(lhs), diff --git a/cpp/src/binaryop/compiled/operation.cuh b/cpp/src/binaryop/compiled/operation.cuh index 43b4bd232c4..57113785a29 100644 --- a/cpp/src/binaryop/compiled/operation.cuh +++ b/cpp/src/binaryop/compiled/operation.cuh @@ -173,8 +173,8 @@ struct PMod { __device__ inline auto operator()(TypeLhs x, TypeRhs y) { using common_t = std::common_type_t; - common_t xconv = static_cast(x); - common_t yconv = static_cast(y); + auto xconv = static_cast(x); + auto yconv = static_cast(y); auto rem = xconv % yconv; if constexpr (std::is_signed_v) if (rem < 0) rem = (rem + yconv) % yconv; @@ -188,8 +188,8 @@ struct PMod { __device__ inline auto operator()(TypeLhs x, TypeRhs y) { using common_t = std::common_type_t; - common_t xconv = static_cast(x); - common_t yconv = static_cast(y); + auto xconv = static_cast(x); + auto yconv = static_cast(y); auto rem = std::fmod(xconv, yconv); if (rem < 0) rem = std::fmod(rem + yconv, yconv); return rem; diff --git a/cpp/src/binaryop/compiled/util.cpp b/cpp/src/binaryop/compiled/util.cpp index 02f4e480ecb..2b6a4f58895 100644 --- a/cpp/src/binaryop/compiled/util.cpp +++ b/cpp/src/binaryop/compiled/util.cpp @@ -123,7 +123,7 @@ struct is_supported_operation_functor { template struct nested_support_functor { template - inline constexpr bool call(data_type out_type) const + [[nodiscard]] inline constexpr bool call(data_type out_type) const { return is_binary_operation_supported{}.template operator()( out_type); @@ -163,7 +163,7 @@ struct is_supported_operation_functor { }; template - inline constexpr bool bool_op(data_type out) const + [[nodiscard]] inline constexpr bool bool_op(data_type out) const { return out.id() == type_id::BOOL8 and is_binary_operation_supported{}.template operator()(); diff --git a/cpp/src/copying/pack.cpp b/cpp/src/copying/pack.cpp index b0208a58896..819ad593c0a 100644 --- a/cpp/src/copying/pack.cpp +++ b/cpp/src/copying/pack.cpp @@ -181,7 +181,7 @@ class metadata_builder_impl { col_type, col_size, col_null_count, data_offset, null_mask_offset, num_children); } - std::vector build() const + [[nodiscard]] std::vector build() const { auto output = std::vector(metadata.size() * sizeof(detail::serialized_column)); std::memcpy(output.data(), metadata.data(), output.size()); diff --git a/cpp/src/datetime/timezone.cpp b/cpp/src/datetime/timezone.cpp index a3471485293..1b0d201501b 100644 --- a/cpp/src/datetime/timezone.cpp +++ b/cpp/src/datetime/timezone.cpp @@ -221,7 +221,7 @@ class posix_parser { /** * @brief Returns the remaining number of characters in the input. */ - auto remaining_char_cnt() const { return end - cur; } + [[nodiscard]] auto remaining_char_cnt() const { return end - cur; } /** * @brief Returns the next character in the input. diff --git a/cpp/src/interop/arrow_utilities.cpp b/cpp/src/interop/arrow_utilities.cpp index 05beecfbf9b..dd9e9600a87 100644 --- a/cpp/src/interop/arrow_utilities.cpp +++ b/cpp/src/interop/arrow_utilities.cpp @@ -23,7 +23,7 @@ namespace cudf { namespace detail { -data_type arrow_to_cudf_type(const ArrowSchemaView* arrow_view) +data_type arrow_to_cudf_type(ArrowSchemaView const* arrow_view) { switch (arrow_view->type) { case NANOARROW_TYPE_NA: return data_type(type_id::EMPTY); diff --git a/cpp/src/interop/arrow_utilities.hpp b/cpp/src/interop/arrow_utilities.hpp index defddb4dc42..4e2628ab689 100644 --- a/cpp/src/interop/arrow_utilities.hpp +++ b/cpp/src/interop/arrow_utilities.hpp @@ -37,7 +37,7 @@ static constexpr int fixed_width_data_buffer_idx = 1; * @param arrow_view SchemaView to pull the logical and storage types from * @return Column type id */ -data_type arrow_to_cudf_type(const ArrowSchemaView* arrow_view); +data_type arrow_to_cudf_type(ArrowSchemaView const* arrow_view); /** * @brief Map cudf column type id to ArrowType id diff --git a/cpp/src/interop/detail/arrow_allocator.cpp b/cpp/src/interop/detail/arrow_allocator.cpp index 3e6a337457a..2a19a5360fe 100644 --- a/cpp/src/interop/detail/arrow_allocator.cpp +++ b/cpp/src/interop/detail/arrow_allocator.cpp @@ -38,7 +38,7 @@ T enable_hugepage(T&& buf) } #ifdef MADV_HUGEPAGE - const auto pagesize = sysconf(_SC_PAGESIZE); + auto const pagesize = sysconf(_SC_PAGESIZE); void* addr = const_cast(buf->data()); if (addr == nullptr) { return std::move(buf); } auto length{static_cast(buf->size())}; diff --git a/cpp/src/interop/from_arrow_host.cu b/cpp/src/interop/from_arrow_host.cu index 36bb35d9419..854a1d68fdc 100644 --- a/cpp/src/interop/from_arrow_host.cu +++ b/cpp/src/interop/from_arrow_host.cu @@ -140,7 +140,7 @@ std::unique_ptr dispatch_copy_from_arrow_host::operator()(ArrowSch bool skip_mask) { auto data_buffer = input->buffers[fixed_width_data_buffer_idx]; - const auto buffer_length = bitmask_allocation_size_bytes(input->length + input->offset); + auto const buffer_length = bitmask_allocation_size_bytes(input->length + input->offset); auto data = rmm::device_buffer(buffer_length, stream, mr); CUDF_CUDA_TRY(cudaMemcpyAsync(data.data(), @@ -322,7 +322,7 @@ template <> std::unique_ptr dispatch_copy_from_arrow_host::operator()( ArrowSchemaView* schema, ArrowArray const* input, data_type type, bool skip_mask) { - const void* offset_buffers[2] = {nullptr, input->buffers[fixed_width_data_buffer_idx]}; + void const* offset_buffers[2] = {nullptr, input->buffers[fixed_width_data_buffer_idx]}; ArrowArray offsets_array = { .length = input->offset + input->length + 1, .null_count = 0, diff --git a/cpp/src/io/avro/avro.cpp b/cpp/src/io/avro/avro.cpp index 221cdf93042..2041f03cd81 100644 --- a/cpp/src/io/avro/avro.cpp +++ b/cpp/src/io/avro/avro.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -485,8 +485,8 @@ std::string schema_parser::get_str() char const* cur = start; while (cur < m_end && *cur++ != '"') ; - int32_t len = static_cast(cur - start - 1); - m_cur = cur; + auto len = static_cast(cur - start - 1); + m_cur = cur; return s.assign(start, std::max(len, 0)); } diff --git a/cpp/src/io/comp/uncomp.cpp b/cpp/src/io/comp/uncomp.cpp index 3e5d966282d..ab516dd585d 100644 --- a/cpp/src/io/comp/uncomp.cpp +++ b/cpp/src/io/comp/uncomp.cpp @@ -305,7 +305,7 @@ std::vector decompress(compression_type compression, host_spannum_entries; i++) { - zip_cdfh_s const* cdfh = reinterpret_cast( + auto const* cdfh = reinterpret_cast( reinterpret_cast(za.cdfh) + cdfh_ofs); int cdfh_len = sizeof(zip_cdfh_s) + cdfh->fname_len + cdfh->extra_len + cdfh->comment_len; if (cdfh_ofs + cdfh_len > za.eocd->cdir_size || cdfh->sig != 0x0201'4b50) { @@ -314,8 +314,8 @@ std::vector decompress(compression_type compression, host_spancomp_method == 8 && cdfh->comp_size > 0 && cdfh->uncomp_size > 0) { - size_t lfh_ofs = cdfh->hdr_ofs; - zip_lfh_s const* lfh = reinterpret_cast(raw + lfh_ofs); + size_t lfh_ofs = cdfh->hdr_ofs; + auto const* lfh = reinterpret_cast(raw + lfh_ofs); if (lfh_ofs + sizeof(zip_lfh_s) <= src.size() && lfh->sig == 0x0403'4b50 && lfh_ofs + sizeof(zip_lfh_s) + lfh->fname_len + lfh->extra_len <= src.size()) { if (lfh->comp_method == 8 && lfh->comp_size > 0 && lfh->uncomp_size > 0) { @@ -340,7 +340,7 @@ std::vector decompress(compression_type compression, host_span 4) { - bz2_file_header_s const* fhdr = reinterpret_cast(raw); + auto const* fhdr = reinterpret_cast(raw); // Check for BZIP2 file signature "BZh1" to "BZh9" if (fhdr->sig[0] == 'B' && fhdr->sig[1] == 'Z' && fhdr->sig[2] == 'h' && fhdr->blksz >= '1' && fhdr->blksz <= '9') { diff --git a/cpp/src/io/functions.cpp b/cpp/src/io/functions.cpp index 1ed8ee5ce06..5daa55d4552 100644 --- a/cpp/src/io/functions.cpp +++ b/cpp/src/io/functions.cpp @@ -306,14 +306,14 @@ raw_orc_statistics read_raw_orc_statistics(source_info const& src_info, // Get file-level statistics, statistics of each column of file for (auto const& stats : metadata.ff.statistics) { - result.file_stats.push_back(std::string(stats.cbegin(), stats.cend())); + result.file_stats.emplace_back(stats.cbegin(), stats.cend()); } // Get stripe-level statistics for (auto const& stripes_stats : metadata.md.stripeStats) { result.stripes_stats.emplace_back(); for (auto const& stats : stripes_stats.colStats) { - result.stripes_stats.back().push_back(std::string(stats.cbegin(), stats.cend())); + result.stripes_stats.back().emplace_back(stats.cbegin(), stats.cend()); } } @@ -1026,8 +1026,8 @@ parquet_writer_options_builder& parquet_writer_options_builder::column_chunks_fi return *this; } -chunked_parquet_writer_options::chunked_parquet_writer_options(sink_info const& sink) - : parquet_writer_options_base(sink) +chunked_parquet_writer_options::chunked_parquet_writer_options(sink_info sink) + : parquet_writer_options_base(std::move(sink)) { } diff --git a/cpp/src/io/json/nested_json_gpu.cu b/cpp/src/io/json/nested_json_gpu.cu index b243e4ba006..031edfde4f6 100644 --- a/cpp/src/io/json/nested_json_gpu.cu +++ b/cpp/src/io/json/nested_json_gpu.cu @@ -245,7 +245,7 @@ struct TransduceToken { RelativeOffsetT const relative_offset, SymbolT const read_symbol) const { - const bool is_end_of_invalid_line = + bool const is_end_of_invalid_line = (state_id == static_cast(TT_INV) && match_id == static_cast(dfa_symbol_group_id::DELIMITER)); @@ -265,15 +265,15 @@ struct TransduceToken { // Number of tokens emitted on invalid lines constexpr int32_t num_inv_tokens = 2; - const bool is_delimiter = match_id == static_cast(dfa_symbol_group_id::DELIMITER); + bool const is_delimiter = match_id == static_cast(dfa_symbol_group_id::DELIMITER); // If state is either invalid or we're entering an invalid state, we discard tokens - const bool is_part_of_invalid_line = + bool const is_part_of_invalid_line = (match_id != static_cast(dfa_symbol_group_id::ERROR) && state_id == static_cast(TT_VLD)); // Indicates whether we transition from an invalid line to a potentially valid line - const bool is_end_of_invalid_line = (state_id == static_cast(TT_INV) && is_delimiter); + bool const is_end_of_invalid_line = (state_id == static_cast(TT_INV) && is_delimiter); int32_t const emit_count = is_end_of_invalid_line ? num_inv_tokens : (is_part_of_invalid_line && !is_delimiter ? 1 : 0); diff --git a/cpp/src/io/json/read_json.cu b/cpp/src/io/json/read_json.cu index df5c7bc21e1..e999be8f83a 100644 --- a/cpp/src/io/json/read_json.cu +++ b/cpp/src/io/json/read_json.cu @@ -85,7 +85,7 @@ device_span ingest_raw_input(device_span buffer, sources.end(), prefsum_source_sizes.begin(), std::plus{}, - [](const std::unique_ptr& s) { return s->size(); }); + [](std::unique_ptr const& s) { return s->size(); }); auto upper = std::upper_bound(prefsum_source_sizes.begin(), prefsum_source_sizes.end(), range_offset); size_t start_source = std::distance(prefsum_source_sizes.begin(), upper); diff --git a/cpp/src/io/orc/orc.hpp b/cpp/src/io/orc/orc.hpp index fd55cbb6846..e1403acd455 100644 --- a/cpp/src/io/orc/orc.hpp +++ b/cpp/src/io/orc/orc.hpp @@ -511,7 +511,7 @@ class ProtobufWriter { TypeKind kind, ColStatsBlob const* stats); - std::size_t size() const { return m_buff.size(); } + [[nodiscard]] std::size_t size() const { return m_buff.size(); } uint8_t const* data() { return m_buff.data(); } std::vector& buffer() { return m_buff; } diff --git a/cpp/src/io/orc/orc_field_writer.hpp b/cpp/src/io/orc/orc_field_writer.hpp index 4862562d526..731e9d7687e 100644 --- a/cpp/src/io/orc/orc_field_writer.hpp +++ b/cpp/src/io/orc/orc_field_writer.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,10 +31,10 @@ namespace io { namespace orc { struct ProtobufWriter::ProtobufFieldWriter { - int struct_size; + int struct_size{0}; ProtobufWriter* p; - ProtobufFieldWriter(ProtobufWriter* pbw) : struct_size(0), p(pbw) {} + ProtobufFieldWriter(ProtobufWriter* pbw) : p(pbw) {} /** * @brief Function to write a unsigned integer to the internal buffer diff --git a/cpp/src/io/orc/reader_impl_chunking.cu b/cpp/src/io/orc/reader_impl_chunking.cu index 43301826003..01ee5ad177d 100644 --- a/cpp/src/io/orc/reader_impl_chunking.cu +++ b/cpp/src/io/orc/reader_impl_chunking.cu @@ -537,7 +537,7 @@ void reader_impl::load_next_stripe_data(read_mode mode) _file_itm_data.selected_stripes.begin() + stripe_start, _file_itm_data.selected_stripes.begin() + stripe_start + stripe_count, std::size_t{0}, - [](std::size_t count, const auto& stripe) { return count + stripe.stripe_info->numberOfRows; }); + [](std::size_t count, auto const& stripe) { return count + stripe.stripe_info->numberOfRows; }); // Decoding range needs to be reset to start from the first position in `decode_stripe_ranges`. _chunk_read_data.curr_decode_stripe_range = 0; diff --git a/cpp/src/io/orc/reader_impl_decode.cu b/cpp/src/io/orc/reader_impl_decode.cu index da9fb802a0a..72eb41b1360 100644 --- a/cpp/src/io/orc/reader_impl_decode.cu +++ b/cpp/src/io/orc/reader_impl_decode.cu @@ -810,7 +810,7 @@ void reader_impl::decompress_and_decode_stripes(read_mode mode) cudf::detail::hostdevice_2dvector(stripe_count, num_lvl_columns, _stream); memset(chunks.base_host_ptr(), 0, chunks.size_bytes()); - const bool use_index = + bool const use_index = _options.use_index && // Do stripes have row group index _metadata.is_row_grp_idx_present() && diff --git a/cpp/src/io/parquet/compact_protocol_reader.cpp b/cpp/src/io/parquet/compact_protocol_reader.cpp index c9212334a96..192833507b0 100644 --- a/cpp/src/io/parquet/compact_protocol_reader.cpp +++ b/cpp/src/io/parquet/compact_protocol_reader.cpp @@ -42,7 +42,7 @@ class parquet_field { public: virtual ~parquet_field() = default; - int field() const { return _field_val; } + [[nodiscard]] int field() const { return _field_val; } }; std::string field_type_string(FieldType type) diff --git a/cpp/src/io/parquet/compact_protocol_writer.hpp b/cpp/src/io/parquet/compact_protocol_writer.hpp index c2e6178acbf..d4778b1ea15 100644 --- a/cpp/src/io/parquet/compact_protocol_writer.hpp +++ b/cpp/src/io/parquet/compact_protocol_writer.hpp @@ -64,11 +64,11 @@ class CompactProtocolWriter { class CompactProtocolFieldWriter { CompactProtocolWriter& writer; size_t struct_start_pos; - int current_field_value; + int current_field_value{0}; public: CompactProtocolFieldWriter(CompactProtocolWriter& caller) - : writer(caller), struct_start_pos(writer.m_buf.size()), current_field_value(0) + : writer(caller), struct_start_pos(writer.m_buf.size()) { } diff --git a/cpp/src/io/parquet/ipc/Schema_generated.h b/cpp/src/io/parquet/ipc/Schema_generated.h index 27141b4af31..c091204417a 100644 --- a/cpp/src/io/parquet/ipc/Schema_generated.h +++ b/cpp/src/io/parquet/ipc/Schema_generated.h @@ -139,13 +139,13 @@ inline const MetadataVersion (&EnumValuesMetadataVersion())[5] return values; } -inline const char* const* EnumNamesMetadataVersion() +inline char const* const* EnumNamesMetadataVersion() { - static const char* const names[6] = {"V1", "V2", "V3", "V4", "V5", nullptr}; + static char const* const names[6] = {"V1", "V2", "V3", "V4", "V5", nullptr}; return names; } -inline const char* EnumNameMetadataVersion(MetadataVersion e) +inline char const* EnumNameMetadataVersion(MetadataVersion e) { if (::flatbuffers::IsOutRange(e, MetadataVersion_V1, MetadataVersion_V5)) return ""; const size_t index = static_cast(e); @@ -190,14 +190,14 @@ inline const Feature (&EnumValuesFeature())[3] return values; } -inline const char* const* EnumNamesFeature() +inline char const* const* EnumNamesFeature() { - static const char* const names[4] = { + static char const* const names[4] = { "UNUSED", "DICTIONARY_REPLACEMENT", "COMPRESSED_BODY", nullptr}; return names; } -inline const char* EnumNameFeature(Feature e) +inline char const* EnumNameFeature(Feature e) { if (::flatbuffers::IsOutRange(e, Feature_UNUSED, Feature_COMPRESSED_BODY)) return ""; const size_t index = static_cast(e); @@ -217,13 +217,13 @@ inline const UnionMode (&EnumValuesUnionMode())[2] return values; } -inline const char* const* EnumNamesUnionMode() +inline char const* const* EnumNamesUnionMode() { - static const char* const names[3] = {"Sparse", "Dense", nullptr}; + static char const* const names[3] = {"Sparse", "Dense", nullptr}; return names; } -inline const char* EnumNameUnionMode(UnionMode e) +inline char const* EnumNameUnionMode(UnionMode e) { if (::flatbuffers::IsOutRange(e, UnionMode_Sparse, UnionMode_Dense)) return ""; const size_t index = static_cast(e); @@ -244,13 +244,13 @@ inline const Precision (&EnumValuesPrecision())[3] return values; } -inline const char* const* EnumNamesPrecision() +inline char const* const* EnumNamesPrecision() { - static const char* const names[4] = {"HALF", "SINGLE", "DOUBLE", nullptr}; + static char const* const names[4] = {"HALF", "SINGLE", "DOUBLE", nullptr}; return names; } -inline const char* EnumNamePrecision(Precision e) +inline char const* EnumNamePrecision(Precision e) { if (::flatbuffers::IsOutRange(e, Precision_HALF, Precision_DOUBLE)) return ""; const size_t index = static_cast(e); @@ -270,13 +270,13 @@ inline const DateUnit (&EnumValuesDateUnit())[2] return values; } -inline const char* const* EnumNamesDateUnit() +inline char const* const* EnumNamesDateUnit() { - static const char* const names[3] = {"DAY", "MILLISECOND", nullptr}; + static char const* const names[3] = {"DAY", "MILLISECOND", nullptr}; return names; } -inline const char* EnumNameDateUnit(DateUnit e) +inline char const* EnumNameDateUnit(DateUnit e) { if (::flatbuffers::IsOutRange(e, DateUnit_DAY, DateUnit_MILLISECOND)) return ""; const size_t index = static_cast(e); @@ -299,14 +299,14 @@ inline const TimeUnit (&EnumValuesTimeUnit())[4] return values; } -inline const char* const* EnumNamesTimeUnit() +inline char const* const* EnumNamesTimeUnit() { - static const char* const names[5] = { + static char const* const names[5] = { "SECOND", "MILLISECOND", "MICROSECOND", "NANOSECOND", nullptr}; return names; } -inline const char* EnumNameTimeUnit(TimeUnit e) +inline char const* EnumNameTimeUnit(TimeUnit e) { if (::flatbuffers::IsOutRange(e, TimeUnit_SECOND, TimeUnit_NANOSECOND)) return ""; const size_t index = static_cast(e); @@ -328,13 +328,13 @@ inline const IntervalUnit (&EnumValuesIntervalUnit())[3] return values; } -inline const char* const* EnumNamesIntervalUnit() +inline char const* const* EnumNamesIntervalUnit() { - static const char* const names[4] = {"YEAR_MONTH", "DAY_TIME", "MONTH_DAY_NANO", nullptr}; + static char const* const names[4] = {"YEAR_MONTH", "DAY_TIME", "MONTH_DAY_NANO", nullptr}; return names; } -inline const char* EnumNameIntervalUnit(IntervalUnit e) +inline char const* EnumNameIntervalUnit(IntervalUnit e) { if (::flatbuffers::IsOutRange(e, IntervalUnit_YEAR_MONTH, IntervalUnit_MONTH_DAY_NANO)) return ""; const size_t index = static_cast(e); @@ -389,9 +389,9 @@ inline const Type (&EnumValuesType())[27] return values; } -inline const char* const* EnumNamesType() +inline char const* const* EnumNamesType() { - static const char* const names[28] = { + static char const* const names[28] = { "NONE", "Null", "Int", "FloatingPoint", "Binary", "Utf8", "Bool", "Decimal", "Date", "Time", "Timestamp", "Interval", @@ -402,7 +402,7 @@ inline const char* const* EnumNamesType() return names; } -inline const char* EnumNameType(Type e) +inline char const* EnumNameType(Type e) { if (::flatbuffers::IsOutRange(e, Type_NONE, Type_LargeListView)) return ""; const size_t index = static_cast(e); @@ -544,10 +544,10 @@ struct TypeTraits { static const Type enum_value = Type_LargeListView; }; -bool VerifyType(::flatbuffers::Verifier& verifier, const void* obj, Type type); +bool VerifyType(::flatbuffers::Verifier& verifier, void const* obj, Type type); bool VerifyTypeVector(::flatbuffers::Verifier& verifier, - const ::flatbuffers::Vector<::flatbuffers::Offset>* values, - const ::flatbuffers::Vector* types); + ::flatbuffers::Vector<::flatbuffers::Offset> const* values, + ::flatbuffers::Vector const* types); /// ---------------------------------------------------------------------- /// Dictionary encoding metadata @@ -566,13 +566,13 @@ inline const DictionaryKind (&EnumValuesDictionaryKind())[1] return values; } -inline const char* const* EnumNamesDictionaryKind() +inline char const* const* EnumNamesDictionaryKind() { - static const char* const names[2] = {"DenseArray", nullptr}; + static char const* const names[2] = {"DenseArray", nullptr}; return names; } -inline const char* EnumNameDictionaryKind(DictionaryKind e) +inline char const* EnumNameDictionaryKind(DictionaryKind e) { if (::flatbuffers::IsOutRange(e, DictionaryKind_DenseArray, DictionaryKind_DenseArray)) return ""; const size_t index = static_cast(e); @@ -594,13 +594,13 @@ inline const Endianness (&EnumValuesEndianness())[2] return values; } -inline const char* const* EnumNamesEndianness() +inline char const* const* EnumNamesEndianness() { - static const char* const names[3] = {"Little", "Big", nullptr}; + static char const* const names[3] = {"Little", "Big", nullptr}; return names; } -inline const char* EnumNameEndianness(Endianness e) +inline char const* EnumNameEndianness(Endianness e) { if (::flatbuffers::IsOutRange(e, Endianness_Little, Endianness_Big)) return ""; const size_t index = static_cast(e); @@ -652,7 +652,7 @@ struct NullBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -685,7 +685,7 @@ struct Struct_Builder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -715,7 +715,7 @@ struct ListBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -747,7 +747,7 @@ struct LargeListBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -780,7 +780,7 @@ struct ListViewBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -812,7 +812,7 @@ struct LargeListViewBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -851,7 +851,7 @@ struct FixedSizeListBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -916,7 +916,7 @@ struct MapBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -941,9 +941,9 @@ struct Union FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { { return static_cast(GetField(VT_MODE, 0)); } - const ::flatbuffers::Vector* typeIds() const + ::flatbuffers::Vector const* typeIds() const { - return GetPointer*>(VT_TYPEIDS); + return GetPointer<::flatbuffers::Vector const*>(VT_TYPEIDS); } bool Verify(::flatbuffers::Verifier& verifier) const { @@ -971,7 +971,7 @@ struct UnionBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -991,7 +991,7 @@ inline ::flatbuffers::Offset CreateUnion( inline ::flatbuffers::Offset CreateUnionDirect( ::flatbuffers::FlatBufferBuilder& _fbb, cudf::io::parquet::flatbuf::UnionMode mode = cudf::io::parquet::flatbuf::UnionMode_Sparse, - const std::vector* typeIds = nullptr) + std::vector const* typeIds = nullptr) { auto typeIds__ = typeIds ? _fbb.CreateVector(*typeIds) : 0; return cudf::io::parquet::flatbuf::CreateUnion(_fbb, mode, typeIds__); @@ -1027,7 +1027,7 @@ struct IntBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1071,7 +1071,7 @@ struct FloatingPointBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1105,7 +1105,7 @@ struct Utf8Builder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1136,7 +1136,7 @@ struct BinaryBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1168,7 +1168,7 @@ struct LargeUtf8Builder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1200,7 +1200,7 @@ struct LargeBinaryBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1237,7 +1237,7 @@ struct Utf8ViewBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1274,7 +1274,7 @@ struct BinaryViewBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1312,7 +1312,7 @@ struct FixedSizeBinaryBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1344,7 +1344,7 @@ struct BoolBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1379,7 +1379,7 @@ struct RunEndEncodedBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1437,7 +1437,7 @@ struct DecimalBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1489,7 +1489,7 @@ struct DateBuilder { } ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); + auto const end = fbb_.EndTable(start_); auto o = ::flatbuffers::Offset(end); return o; } @@ -1548,7 +1548,7 @@ struct TimeBuilder { } ::flatbuffers::Offset