From 4414f3f201b35a074574b9846c45e483de7577a0 Mon Sep 17 00:00:00 2001 From: Karthikeyan Natarajan Date: Wed, 28 Jul 2021 00:37:01 +0530 Subject: [PATCH 1/2] replace auto with auto& ref for cast<&> --- cpp/include/cudf/detail/indexalator.cuh | 2 +- cpp/src/binaryop/compiled/binary_ops.cu | 6 +++--- cpp/src/column/column_factories.cu | 4 ++-- cpp/src/groupby/sort/aggregate.cpp | 16 ++++++++-------- cpp/src/reductions/simple.cuh | 2 +- cpp/src/replace/nulls.cu | 2 +- cpp/src/rolling/rolling_detail.cuh | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cpp/include/cudf/detail/indexalator.cuh b/cpp/include/cudf/detail/indexalator.cuh index 4a2b40e8be7..d56f34a5765 100644 --- a/cpp/include/cudf/detail/indexalator.cuh +++ b/cpp/include/cudf/detail/indexalator.cuh @@ -157,7 +157,7 @@ struct base_indexalator { */ CUDA_HOST_DEVICE_CALLABLE difference_type operator-(T const& rhs) const { - auto derived = static_cast(*this); + auto& derived = static_cast(*this); return (derived.p_ - rhs.p_) / width_; } diff --git a/cpp/src/binaryop/compiled/binary_ops.cu b/cpp/src/binaryop/compiled/binary_ops.cu index 0576606a58c..2b38224864a 100644 --- a/cpp/src/binaryop/compiled/binary_ops.cu +++ b/cpp/src/binaryop/compiled/binary_ops.cu @@ -45,7 +45,7 @@ struct scalar_as_column_device_view { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - auto h_scalar_type_view = static_cast&>(const_cast(s)); + auto& h_scalar_type_view = static_cast&>(const_cast(s)); auto col_v = column_view(s.type(), 1, h_scalar_type_view.data(), (bitmask_type const*)s.validity_data()); return std::pair{column_device_view::create(col_v, stream), std::unique_ptr(nullptr)}; @@ -63,8 +63,8 @@ scalar_as_column_device_view::operator()(scalar const& s, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - using T = cudf::string_view; - auto h_scalar_type_view = static_cast&>(const_cast(s)); + using T = cudf::string_view; + auto& h_scalar_type_view = static_cast&>(const_cast(s)); // build offsets column from the string size auto offsets_transformer_itr = diff --git a/cpp/src/column/column_factories.cu b/cpp/src/column/column_factories.cu index 4f1f5faffdd..ebe483f9725 100644 --- a/cpp/src/column/column_factories.cu +++ b/cpp/src/column/column_factories.cu @@ -63,7 +63,7 @@ std::unique_ptr column_from_scalar_dispatch::operator()(null_mask.data()), size}; - auto sv = static_cast const&>(value); + auto& sv = static_cast const&>(value); // fill the column with the scalar auto output = strings::detail::fill(strings_column_view(sc), 0, size, sv, stream, mr); output->set_null_mask(rmm::device_buffer{}, 0); // should be no nulls @@ -96,7 +96,7 @@ std::unique_ptr column_from_scalar_dispatch::operator() const&>(value); + auto& ss = static_cast const&>(value); auto iter = thrust::make_constant_iterator(0); auto children = diff --git a/cpp/src/groupby/sort/aggregate.cpp b/cpp/src/groupby/sort/aggregate.cpp index 4e60d8d3f7d..3c8afccb057 100644 --- a/cpp/src/groupby/sort/aggregate.cpp +++ b/cpp/src/groupby/sort/aggregate.cpp @@ -258,7 +258,7 @@ void aggregate_result_functor::operator()(aggregation con { if (cache.has_result(col_idx, agg)) return; - auto var_agg = dynamic_cast(agg); + auto& var_agg = dynamic_cast(agg); auto mean_agg = make_mean_aggregation(); auto count_agg = make_count_aggregation(); operator()(*mean_agg); @@ -281,8 +281,8 @@ void aggregate_result_functor::operator()(aggregation const& a { if (cache.has_result(col_idx, agg)) return; - auto std_agg = dynamic_cast(agg); - auto var_agg = make_variance_aggregation(std_agg._ddof); + auto& std_agg = dynamic_cast(agg); + auto var_agg = make_variance_aggregation(std_agg._ddof); operator()(*var_agg); column_view var_result = cache.get_result(col_idx, *var_agg); @@ -298,7 +298,7 @@ void aggregate_result_functor::operator()(aggregation con auto count_agg = make_count_aggregation(); operator()(*count_agg); column_view group_sizes = cache.get_result(col_idx, *count_agg); - auto quantile_agg = dynamic_cast(agg); + auto& quantile_agg = dynamic_cast(agg); auto result = detail::group_quantiles(get_sorted_values(), group_sizes, @@ -336,7 +336,7 @@ void aggregate_result_functor::operator()(aggregation cons { if (cache.has_result(col_idx, agg)) return; - auto nunique_agg = dynamic_cast(agg); + auto& nunique_agg = dynamic_cast(agg); auto result = detail::group_nunique(get_sorted_values(), helper.group_labels(stream), @@ -353,7 +353,7 @@ void aggregate_result_functor::operator()(aggregation { if (cache.has_result(col_idx, agg)) return; - auto nth_element_agg = dynamic_cast(agg); + auto& nth_element_agg = dynamic_cast(agg); auto count_agg = make_count_aggregation(nth_element_agg._null_handling); if (count_agg->kind == aggregation::COUNT_VALID) { @@ -474,12 +474,12 @@ void aggregate_result_functor::operator()(aggregation c { if (cache.has_result(col_idx, agg)) { return; } - auto const merged_result = detail::group_merge_lists(get_grouped_values(), + auto const merged_result = detail::group_merge_lists(get_grouped_values(), helper.group_offsets(stream), helper.num_groups(stream), stream, rmm::mr::get_current_device_resource()); - auto const merge_sets_agg = dynamic_cast(agg); + auto const& merge_sets_agg = dynamic_cast(agg); cache.add_result(col_idx, agg, lists::detail::drop_list_duplicates(lists_column_view(merged_result->view()), diff --git a/cpp/src/reductions/simple.cuh b/cpp/src/reductions/simple.cuh index 4bdad95dbfe..e0dc219b767 100644 --- a/cpp/src/reductions/simple.cuh +++ b/cpp/src/reductions/simple.cuh @@ -263,7 +263,7 @@ struct same_element_type_dispatcher { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - auto index = static_cast const&>(keys_index); + auto& index = static_cast const&>(keys_index); return cudf::detail::get_element(keys, index.value(stream), stream, mr); } diff --git a/cpp/src/replace/nulls.cu b/cpp/src/replace/nulls.cu index 9341d2f4097..a336de6fb49 100644 --- a/cpp/src/replace/nulls.cu +++ b/cpp/src/replace/nulls.cu @@ -312,7 +312,7 @@ struct replace_nulls_scalar_kernel_forwarder { auto output_view = output->mutable_view(); using ScalarType = cudf::scalar_type_t; - auto s1 = static_cast(replacement); + auto& s1 = static_cast(replacement); auto device_in = cudf::column_device_view::create(input); auto func = replace_nulls_functor{s1.data()}; diff --git a/cpp/src/rolling/rolling_detail.cuh b/cpp/src/rolling/rolling_detail.cuh index 51b002f67de..64395a3522c 100644 --- a/cpp/src/rolling/rolling_detail.cuh +++ b/cpp/src/rolling/rolling_detail.cuh @@ -1050,7 +1050,7 @@ std::unique_ptr rolling_window_udf(column_view const& input, min_periods = std::max(min_periods, 0); - auto udf_agg = dynamic_cast(agg); + auto& udf_agg = dynamic_cast(agg); std::string hash = "prog_rolling." + std::to_string(std::hash{}(udf_agg._source)); From b4deb5d9428e933c1490508ea923ded0cff48c03 Mon Sep 17 00:00:00 2001 From: Karthikeyan Natarajan Date: Wed, 28 Jul 2021 02:07:14 +0530 Subject: [PATCH 2/2] fix const ptr, remove temp variable --- cpp/include/cudf/detail/indexalator.cuh | 3 +-- cpp/src/replace/nulls.cu | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cpp/include/cudf/detail/indexalator.cuh b/cpp/include/cudf/detail/indexalator.cuh index d56f34a5765..d546162fc7a 100644 --- a/cpp/include/cudf/detail/indexalator.cuh +++ b/cpp/include/cudf/detail/indexalator.cuh @@ -157,8 +157,7 @@ struct base_indexalator { */ CUDA_HOST_DEVICE_CALLABLE difference_type operator-(T const& rhs) const { - auto& derived = static_cast(*this); - return (derived.p_ - rhs.p_) / width_; + return (static_cast(*this).p_ - rhs.p_) / width_; } /** diff --git a/cpp/src/replace/nulls.cu b/cpp/src/replace/nulls.cu index a336de6fb49..87e850e6676 100644 --- a/cpp/src/replace/nulls.cu +++ b/cpp/src/replace/nulls.cu @@ -289,8 +289,8 @@ std::unique_ptr replace_nulls_column_kernel_forwarder::operator()< template struct replace_nulls_functor { - T* value_it; - replace_nulls_functor(T* _value_it) : value_it(_value_it) {} + T const* value_it; + replace_nulls_functor(T const* _value_it) : value_it(_value_it) {} __device__ T operator()(T input, bool is_valid) { return is_valid ? input : *value_it; } };