From 738d6a29cfedc9dae6f87930ce1042e8771a0ca8 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra <36027403+codereport@users.noreply.github.com> Date: Sat, 10 Apr 2021 02:22:32 -0400 Subject: [PATCH] Cleanup using C++17 features (#7931) Small cleanup PR Authors: - Conor Hoekstra (https://github.com/codereport) Approvers: - Nghia Truong (https://github.com/ttnghia) - MithunR (https://github.com/mythrocks) URL: https://github.com/rapidsai/cudf/pull/7931 --- cpp/include/cudf/ast/detail/transform.cuh | 4 +--- cpp/include/cudf/detail/utilities/cuda.cuh | 2 +- cpp/include/cudf_test/timestamp_utilities.cuh | 9 ++++----- cpp/src/copying/contiguous_split.cu | 5 +---- cpp/src/io/json/reader_impl.cu | 5 ++--- cpp/src/merge/merge.cu | 1 - cpp/tests/wrappers/timestamps_test.cu | 5 +---- 7 files changed, 10 insertions(+), 21 deletions(-) diff --git a/cpp/include/cudf/ast/detail/transform.cuh b/cpp/include/cudf/ast/detail/transform.cuh index da15ac07c63..f9d7426e2e4 100644 --- a/cpp/include/cudf/ast/detail/transform.cuh +++ b/cpp/include/cudf/ast/detail/transform.cuh @@ -364,9 +364,7 @@ struct ast_plan { std::vector get_offsets() const { auto offsets = std::vector(sizes.size()); - // When C++17, use std::exclusive_scan - offsets[0] = 0; - std::partial_sum(sizes.cbegin(), sizes.cend() - 1, offsets.begin() + 1); + thrust::exclusive_scan(sizes.cbegin(), sizes.cend(), offsets.begin(), 0); return offsets; } diff --git a/cpp/include/cudf/detail/utilities/cuda.cuh b/cpp/include/cudf/detail/utilities/cuda.cuh index 33c61414a1c..11dbba70c3f 100644 --- a/cpp/include/cudf/detail/utilities/cuda.cuh +++ b/cpp/include/cudf/detail/utilities/cuda.cuh @@ -134,7 +134,7 @@ cudf::size_type elements_per_thread(Kernel kernel, int num_sms = 0; CUDA_TRY(cudaDeviceGetAttribute(&num_sms, cudaDevAttrMultiProcessorCount, device)); int per_thread = total_size / (max_blocks * num_sms * block_size); - return std::max(1, std::min(per_thread, max_per_thread)); // switch to std::clamp with C++17 + return std::clamp(per_thread, 1, max_per_thread); } /** diff --git a/cpp/include/cudf_test/timestamp_utilities.cuh b/cpp/include/cudf_test/timestamp_utilities.cuh index 201b837e936..6cab8b92283 100644 --- a/cpp/include/cudf_test/timestamp_utilities.cuh +++ b/cpp/include/cudf_test/timestamp_utilities.cuh @@ -55,11 +55,10 @@ inline cudf::test::fixed_width_column_wrapper generate_timestamps(in auto lhs = start.time_since_epoch().count(); auto rhs = stop.time_since_epoch().count(); - // When C++17, auto [min, max] = std::minmax(lhs, rhs) - auto min = std::min(lhs, rhs); - auto max = std::max(lhs, rhs); - auto range = max - min; - auto iter = cudf::detail::make_counting_transform_iterator(0, [=](auto i) { + auto const min = std::min(lhs, rhs); + auto const max = std::max(lhs, rhs); + auto const range = max - min; + auto iter = cudf::detail::make_counting_transform_iterator(0, [=](auto i) { return cuda::std::chrono::floor( cuda::std::chrono::milliseconds(min + (range / count) * i)) .count(); diff --git a/cpp/src/copying/contiguous_split.cu b/cpp/src/copying/contiguous_split.cu index 9a2f0f26f74..1a840a6f39a 100644 --- a/cpp/src/copying/contiguous_split.cu +++ b/cpp/src/copying/contiguous_split.cu @@ -660,10 +660,7 @@ BufInfo build_output_columns(InputIter begin, { auto current_info = info_begin; std::transform(begin, end, out_begin, [¤t_info, base_ptr](column_view const& src) { - // Use C++17 structured bindings - bitmask_type const* bitmask_ptr; - size_type null_count; - std::tie(bitmask_ptr, null_count) = [&]() { + auto [bitmask_ptr, null_count] = [&]() { if (src.nullable()) { auto const ptr = current_info->num_elements == 0 diff --git a/cpp/src/io/json/reader_impl.cu b/cpp/src/io/json/reader_impl.cu index 1a1fa8d0602..90655d90972 100644 --- a/cpp/src/io/json/reader_impl.cu +++ b/cpp/src/io/json/reader_impl.cu @@ -492,9 +492,8 @@ void reader::impl::set_data_types(rmm::cuda_stream_view stream) std::cend(dtype), std::inserter(col_type_map, col_type_map.end()), [&](auto const &ts) -> std::pair { - // When C++17, use structured bindings: auto const& [col_name, type_str] = .. - auto split = split_on_colon(ts); - return {split.first, convert_string_to_dtype(split.second)}; + auto const &[col_name, type_str] = split_on_colon(ts); + return {col_name, convert_string_to_dtype(type_str)}; }); // Using the map here allows O(n log n) complexity diff --git a/cpp/src/merge/merge.cu b/cpp/src/merge/merge.cu index 24c0af12938..053f9401758 100644 --- a/cpp/src/merge/merge.cu +++ b/cpp/src/merge/merge.cu @@ -297,7 +297,6 @@ struct column_merger { row_order_.end(), merged_view.begin(), [d_lcol, d_rcol] __device__(index_type const& index_pair) { - // When C++17, use structure bindings auto side = thrust::get<0>(index_pair); auto index = thrust::get<1>(index_pair); return side == side::LEFT ? d_lcol[index] : d_rcol[index]; diff --git a/cpp/tests/wrappers/timestamps_test.cu b/cpp/tests/wrappers/timestamps_test.cu index 5088c3122bd..d1c0ad5d840 100644 --- a/cpp/tests/wrappers/timestamps_test.cu +++ b/cpp/tests/wrappers/timestamps_test.cu @@ -83,10 +83,7 @@ TYPED_TEST(ChronoColumnTest, ChronoDurationsMatchPrimitiveRepresentation) // round-trip through the host to copy `chrono_col` values // to a new fixed_width_column_wrapper `primitive_col` - // When C++17, use structured bindings - thrust::host_vector chrono_col_data; - std::vector chrono_col_mask; - std::tie(chrono_col_data, chrono_col_mask) = to_host(chrono_col); + auto const [chrono_col_data, chrono_col_mask] = to_host(chrono_col); auto primitive_col = fixed_width_column_wrapper(chrono_col_data.begin(), chrono_col_data.end());