Skip to content

Commit

Permalink
Fix memory error due to lambda return type deduction limitation (#9778)
Browse files Browse the repository at this point in the history
Fixes #9703
replace device lambda with device functor with return type. (due to [14. extended-lambda-restrictions](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#extended-lambda-restrictions) )
~add `__host__` to lambda for nvcc return type deduction to work properly.~
~replaced `auto` (generic lambda) with `size_type`.~
fixes shared memory write error caused in #9703

Authors:
  - Karthikeyan (https://github.com/karthikeyann)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - David Wendt (https://github.com/davidwendt)
  - Jake Hemstad (https://github.com/jrhemstad)

URL: #9778
  • Loading branch information
karthikeyann authored Dec 1, 2021
1 parent 7d8a8e5 commit 5491cc7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cpp/src/sort/rank.cu
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ void rank_max(cudf::device_span<size_type const> group_keys,
stream);
}

// Returns index, count
template <typename T>
struct index_counter {
__device__ T operator()(size_type i) { return T{i, 1}; }
};

void rank_average(cudf::device_span<size_type const> group_keys,
column_view sorted_order_view,
mutable_column_view rank_mutable_view,
Expand All @@ -208,10 +214,9 @@ void rank_average(cudf::device_span<size_type const> group_keys,
using MinCount = thrust::pair<size_type, size_type>;
tie_break_ranks_transform<MinCount>(
group_keys,
cudf::detail::make_counting_transform_iterator(1,
[] __device__(auto i) {
return MinCount{i, 1};
}),
// Use device functor with return type. Cannot use device lambda due to limitation.
// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#extended-lambda-restrictions
cudf::detail::make_counting_transform_iterator(1, index_counter<MinCount>{}),
sorted_order_view,
rank_mutable_view.begin<double>(),
[] __device__(auto rank_count1, auto rank_count2) {
Expand Down
14 changes: 14 additions & 0 deletions cpp/tests/sort/rank_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,5 +410,19 @@ TYPED_TEST(Rank, min_desc_bottom_pct)
this->run_all_tests(rank_method::MIN, desc_bottom, col1_rank, col2_rank, col3_rank, true);
}

struct RankLarge : public BaseFixture {
};

TEST_F(RankLarge, average_large)
{
// testcase of https://github.com/rapidsai/cudf/issues/9703
auto iter = thrust::counting_iterator<int64_t>(0);
fixed_width_column_wrapper<int64_t> col1(iter, iter + 10558);
auto result =
cudf::rank(col1, rank_method::AVERAGE, {}, null_policy::EXCLUDE, null_order::AFTER, false);
fixed_width_column_wrapper<double, int> expected(iter + 1, iter + 10559);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(result->view(), expected);
}

} // namespace test
} // namespace cudf

0 comments on commit 5491cc7

Please sign in to comment.