Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Fix errors in atomic with small aggregates and enum classes #347

Merged
merged 6 commits into from
Jan 10, 2023

Conversation

wmaxey
Copy link
Member

@wmaxey wmaxey commented Jan 4, 2023

This PR fixes cases where enum classes and aggregates are assigned to rather than default constructed.

Not that it worked before, but small aggregate types are no longer constexpr with this patch.

@wmaxey wmaxey requested review from miscco and griwes and removed request for miscco January 4, 2023 20:48
Copy link
Collaborator

@miscco miscco left a comment

Choose a reason for hiding this comment

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

Some minor nits about internal helpers. (Allies throughout product code)

>::type;

// Arithmetic conversions to/from proxy types
template<class _Tp, _EnableIf<is_arithmetic<_Tp>::value, int> = 0>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto, we should move to

Suggested change
template<class _Tp, _EnableIf<is_arithmetic<_Tp>::value, int> = 0>
template<class _Tp, __enable_if_t<is_arithmetic<_Tp>::value, int> = 0>

Copy link
Member Author

Choose a reason for hiding this comment

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

I was under the impression that the meta base stuff was better to use internally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is correct, but my evil plan is to settle on __enable_if_t globally and then move that over to use the meta based implementation. I really do not like it that we have three different ways to do this.

So anything here is fine by me as that should be a separate PR anyway

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is really strange, do we build in C++03?

Copy link
Member Author

Choose a reason for hiding this comment

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

I rebased the branch, which I know is fairly aggressive, but now all the conditionals are using the __blah_t versions.


// Arithmetic conversions to/from proxy types
template<class _Tp, _EnableIf<is_arithmetic<_Tp>::value, int> = 0>
constexpr __host__ __device__ inline __cxx_atomic_small_to_32<_Tp> __cxx_small_to_32(_Tp __val) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this rather use _LIBCUDACXX_INLINE_VISIBILITY. Also I am not sure if we need the inline here,a s the function is already constexpr

Suggested change
constexpr __host__ __device__ inline __cxx_atomic_small_to_32<_Tp> __cxx_small_to_32(_Tp __val) {
_LIBCUDACXX_INLINE_VISIBILITY constexpr __cxx_atomic_small_to_32<_Tp> __cxx_small_to_32(_Tp __val) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@miscco
Copy link
Collaborator

miscco commented Jan 7, 2023

#if _LIBCUDACXX_STD_VER > 11
template <bool _Bp, class _IfRes, class _ElseRes>
using conditional_t = typename conditional<_Bp, _IfRes, _ElseRes>::type;
#endif
// Helper so we can use "conditional_t" in all language versions.
template <bool _Bp, class _If, class _Then> using __conditional_t = typename conditional<_Bp, _If, _Then>::type;
_LIBCUDACXX_END_NAMESPACE_STD

Why is it not there?

@wmaxey
Copy link
Member Author

wmaxey commented Jan 7, 2023

#if _LIBCUDACXX_STD_VER > 11
template <bool _Bp, class _IfRes, class _ElseRes>
using conditional_t = typename conditional<_Bp, _IfRes, _ElseRes>::type;
#endif
// Helper so we can use "conditional_t" in all language versions.
template <bool _Bp, class _If, class _Then> using __conditional_t = typename conditional<_Bp, _If, _Then>::type;
_LIBCUDACXX_END_NAMESPACE_STD

Why is it not there?

Perhaps I just need to update the branch it's based on. I'll do that today.

@wmaxey wmaxey force-pushed the bugfix/atomic_small_aggregate_and_enums branch from 933f51e to 4a97fc6 Compare January 9, 2023 22:56
@wmaxey wmaxey requested a review from miscco January 9, 2023 23:00
@wmaxey wmaxey merged commit 69f50e6 into main Jan 10, 2023
@wmaxey wmaxey deleted the bugfix/atomic_small_aggregate_and_enums branch January 10, 2023 18:22
wmaxey added a commit that referenced this pull request Jan 13, 2023
* Add tests and coverage for small enum classes and aggregates

* Fix regressions due to improper conversions in small atomic proxies

* Use `__conditional_t` alias instead of `conditional`

Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>

* /s/__host__ __device__/visibility macro

* _[_]conditional_t does not exist, but the metabase _If does

* After rebase, use type_trait helpers that provide c++14 backports rather than metabase classes

Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants