Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cleanup using C++17 features #7931

Merged
merged 2 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines +58 to +59
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not minmax as mentioned in the comment?

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);
codereport marked this conversation as resolved.
Show resolved Hide resolved
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());
codereport marked this conversation as resolved.
Show resolved Hide resolved
Expand Down