Skip to content

[STF] Move unstable_unique from STF to generic cudax utility#8190

Open
caugonnet wants to merge 5 commits intoNVIDIA:mainfrom
caugonnet:stf_unstable_unique_utility_move
Open

[STF] Move unstable_unique from STF to generic cudax utility#8190
caugonnet wants to merge 5 commits intoNVIDIA:mainfrom
caugonnet:stf_unstable_unique_utility_move

Conversation

@caugonnet
Copy link
Contributor

unstable_unique is a generic algorithm with no STF dependency. Move it to cuda::experimental namespace under __utility/, replace the STF UNITTEST with a Catch2 test, and update the sole STF consumer (event_types.cuh) to use the new location directly.

Description

closes

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

unstable_unique is a generic algorithm with no STF dependency.
Move it to cuda::experimental namespace under __utility/, replace
the STF UNITTEST with a Catch2 test, and update the sole STF
consumer (event_types.cuh) to use the new location directly.

Made-with: Cursor
@caugonnet caugonnet added the stf Sequential Task Flow programming model label Mar 26, 2026
@github-project-automation github-project-automation bot moved this to Todo in CCCL Mar 26, 2026
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Mar 26, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Progress in CCCL Mar 26, 2026
@caugonnet
Copy link
Contributor Author

/ok to test cb65d4f

@caugonnet caugonnet self-assigned this Mar 26, 2026
@github-actions
Copy link
Contributor

😬 CI Workflow Results

🟥 Finished in 44m 15s: Pass: 12%/48 | Total: 21h 49m | Max: 44m 09s | Hits: 87%/1282

See results here.

@caugonnet caugonnet marked this pull request as ready for review March 26, 2026 21:48
@caugonnet caugonnet requested review from a team as code owners March 26, 2026 21:48
@cccl-authenticator-app cccl-authenticator-app bot moved this from In Progress to In Review in CCCL Mar 26, 2026
Comment on lines +99 to +101
return ::cuda::experimental::unstable_unique(__first, __last, [](const auto& __a, const auto& __b) {
return __a == __b;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer ::cuda::std::equal_to<>{} here I think.

return __last;
}

++__first;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be moved into the first clause of the for-loop

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, though we lose the comment (which was lost already lol).

//!
//! @return Iterator to the new end of the range after duplicates have been removed.
template <class _Iterator, class _BinaryPredicate>
_CCCL_HOST_API _Iterator unstable_unique(_Iterator __first, _Iterator __last, _BinaryPredicate __pred)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this algorithm requires random access iterators. Consider static_assert()-ing (and documenting) that.

Note ++ and -- makes for bidirectional iterators, and I believe < means it needs random-access. If you can make the outer if condition if (; __first != __last; ++__first) and hide the asserts behind

if constexpr (/* is_random_access_iterator */)

then you could at least relax to bidirectional.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually it should work with bidir. Though improving the algo wasn't the primary purpose of this PR, we appreciate the review and take the opportunity to polish the code a lil.
I'll add specific suggestions to make the algo work with bidirectional iterators.


TEST_CASE("unstable_unique empty range", "[utility]")
{
std::vector<int> v;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding some tests with other iterator categories. For example std::list or std::set for bidirectional iterators.

++__first;
bool __first_is_known_duplicate = false;

for (; __first < __last; ++__first)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (; __first < __last; ++__first)
for (; __first != __last; ++__first)

to make it work with bidir

continue;
}
}
_CCCL_ASSERT(__first < __last, "unstable_unique: iterator out of range");
Copy link
Contributor

@andralex andralex Mar 27, 2026

Choose a reason for hiding this comment

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

Suggested change
_CCCL_ASSERT(__first < __last, "unstable_unique: iterator out of range");
_CCCL_ASSERT(__first != __last, "unstable_unique: iterator out of range");

also for bidir

{
return __first;
}
_CCCL_ASSERT(__first < __last, "unstable_unique: iterator out of range");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_CCCL_ASSERT(__first < __last, "unstable_unique: iterator out of range");
_CCCL_ASSERT(__first != __last, "unstable_unique: iterator out of range");

Comment on lines +99 to +101
return ::cuda::experimental::unstable_unique(__first, __last, [](const auto& __a, const auto& __b) {
return __a == __b;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return ::cuda::experimental::unstable_unique(__first, __last, [](const auto& __a, const auto& __b) {
return __a == __b;
});
return ::cuda::experimental::unstable_unique(__first, __last, ::cuda::std::equal_to<>{});

nice, thx @Jacobfaib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stf Sequential Task Flow programming model

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants