Skip to content

Commit

Permalink
Cleanup using C++17 features (#7931)
Browse files Browse the repository at this point in the history
Small cleanup PR

Authors:
  - Conor Hoekstra (https://github.com/codereport)

Approvers:
  - Nghia Truong (https://github.com/ttnghia)
  - MithunR (https://github.com/mythrocks)

URL: #7931
  • Loading branch information
codereport authored Apr 10, 2021
1 parent 348ad4d commit 738d6a2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 21 deletions.
4 changes: 1 addition & 3 deletions cpp/include/cudf/ast/detail/transform.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ struct ast_plan {
std::vector<cudf::size_type> get_offsets() const
{
auto offsets = std::vector<int>(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;
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cudf/detail/utilities/cuda.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions cpp/include/cudf_test/timestamp_utilities.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ inline cudf::test::fixed_width_column_wrapper<T, int64_t> 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<ToDuration>(
cuda::std::chrono::milliseconds(min + (range / count) * i))
.count();
Expand Down
5 changes: 1 addition & 4 deletions cpp/src/copying/contiguous_split.cu
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,7 @@ BufInfo build_output_columns(InputIter begin,
{
auto current_info = info_begin;
std::transform(begin, end, out_begin, [&current_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
Expand Down
5 changes: 2 additions & 3 deletions cpp/src/io/json/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, data_type> {
// 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
Expand Down
1 change: 0 additions & 1 deletion cpp/src/merge/merge.cu
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ struct column_merger {
row_order_.end(),
merged_view.begin<Element>(),
[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];
Expand Down
5 changes: 1 addition & 4 deletions cpp/tests/wrappers/timestamps_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rep> chrono_col_data;
std::vector<cudf::bitmask_type> chrono_col_mask;
std::tie(chrono_col_data, chrono_col_mask) = to_host<Rep>(chrono_col);
auto const [chrono_col_data, chrono_col_mask] = to_host<Rep>(chrono_col);

auto primitive_col =
fixed_width_column_wrapper<Rep>(chrono_col_data.begin(), chrono_col_data.end());
Expand Down

0 comments on commit 738d6a2

Please sign in to comment.