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

Fix memory error due to lambda return type deduction limitation #9778

Merged
merged 5 commits into from
Dec 1, 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
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>{}),
karthikeyann marked this conversation as resolved.
Show resolved Hide resolved
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