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

Ensure that cuda::std::pair is potentially trivially copyable #1249

Merged
merged 9 commits into from
Jan 18, 2024

Conversation

miscco
Copy link
Collaborator

@miscco miscco commented Jan 5, 2024

trivially copyable is a requirement for memcpy. We want to ensure that our pair implementation satisfies that whenever possible.

This is especially important for thrust::pair as that is used in rmm extensively.

Fixes #1246

trivially copyable is a requirement for memcpy. We want to ensure that our pair implementation satisfies that whenever possible.

This is especially important for thrust::pair as that is used in rmm extensively.

Fixes NVIDIA#1246
@miscco miscco force-pushed the trivial_pair branch 3 times, most recently from 814e6b9 to be1dd81 Compare January 5, 2024 11:00
@miscco
Copy link
Collaborator Author

miscco commented Jan 8, 2024

I am currently investigating why gcc-12 segfaults. I believe this is because we now have a base class which should not have any effect but yeah

@miscco miscco requested a review from a team as a code owner January 11, 2024 10:49
@miscco miscco requested a review from elstehle January 11, 2024 10:49
@miscco miscco enabled auto-merge (squash) January 11, 2024 15:40
!__implicit_default_constructible && _LIBCUDACXX_TRAIT(is_default_constructible, _T1)
&& _LIBCUDACXX_TRAIT(is_default_constructible, _T2);

static constexpr bool __implicit_copy_constructible_from_T =
Copy link
Collaborator

Choose a reason for hiding this comment

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

So at first (just reading the traits) I thought that these 4 should have the _from_T suffix removed from their names, but seeing how they are used, I'd suggest something like __implicit_constructible_from_element_copies and so on; it might be longer, but since there's no T in scope here, even logically, I don't think the current names make much sense. (_from_Ts maybe, but I think that's still muddled in its meaning.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about _from_elements?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The thing I probably dislike the most about the current name is that it contains "copy_constructible". This has a meaning - this thing we are constructing is created using its copy constructor. But that's not what's happening here, hence my original suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah, we should just name that __{implicit,explicit}_constructible_from_elements

libcudacxx/test/support/archetypes.ipp Show resolved Hide resolved
// In that case _T1 would be copy assignable but _TestSynthesizeAssignment<_T1> would not
// This happens e.g for reference types
template <class _T1>
struct _TestSynthesizeAssignment
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: most types (including helpers) are in lower case. Could you share the motivation behind naming this one in camel calse?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The thought was that this is nothing that is intended to be ever used outside of that check but yeah that is not really convincing.

I am wondering whether we should just go with _CamelCase for classes and __snake_case for variables?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what's the convention in libcu++, in cub it's camel case for template parameters and snake case for everything else (in new style).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is what I try to do too, but the issue is that libc++ has a totally different style of everything snake case

I want to be able to see whether something is a type or a function / variable but at the same time I dont want to rewrite the world

_T1 first;
_T2 second;

template <class _Constraints = __pair_constraints<_T1, _T2>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: symbols are quite different now:

_ZN4cuda3std3__44pairI1AS3_EC2IS3_S3_NS1_18__pair_constraintsIS3_S3_E15__constructibleIS3_S3_EETnNS1_9enable_ifIXsrT1_24__implicit_constructibleEiE4typeELi0EEEOT_OT0_

vs

_ZN4cuda3std3__44pairI1AS3_EC2IS3_S3_TnPNS1_9enable_ifIXsr10_CheckArgs17__enable_implicitIT_T0_EE5valueEvE4typeELPv0EEEOS7_OS8_

Do we need to bump ABI version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dont think so, we do not change any behavior and worst case it is a link error

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think this is fine. Code that was compiled with the old version will have distinct mangled names from the new version, so they can easily coexist in the same program. As @miscco said, at worst this is a linker error forcing recompilation.

When we do a release, however, this should probably be spelled out as a change potentially requiring recompilation in the release notes.

@miscco
Copy link
Collaborator Author

miscco commented Jan 17, 2024

@griwes I have changed the name to __{implicit,explicit}_constructible_from_elements If there is nothing else we can merge this once you approve

@miscco miscco merged commit a4a3289 into NVIDIA:main Jan 18, 2024
537 checks passed
Copy link
Contributor

Backport failed for branch/2.3.x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin branch/2.3.x
git worktree add -d .worktree/backport-1249-to-branch/2.3.x origin/branch/2.3.x
cd .worktree/backport-1249-to-branch/2.3.x
git checkout -b backport-1249-to-branch/2.3.x
ancref=$(git merge-base 50ce545772844ce746134db602af4123cb9cc78e bff2a91eaaf194b59bc3ac7752f13707117f86c5)
git cherry-pick -x $ancref..bff2a91eaaf194b59bc3ac7752f13707117f86c5

@miscco miscco deleted the trivial_pair branch January 18, 2024 07:29
miscco added a commit to miscco/cccl that referenced this pull request Jan 18, 2024
…IA#1249)

trivially copyable is a requirement for memcpy. We want to ensure that our pair implementation satisfies that whenever possible.

This is especially important for thrust::pair as that is used in rmm extensively.

Fixes NVIDIA#1246

Co-authored-by: Georgy Evtushenko <[email protected]>
miscco added a commit to miscco/cccl that referenced this pull request Jan 18, 2024
…IA#1249)

trivially copyable is a requirement for memcpy. We want to ensure that our pair implementation satisfies that whenever possible.

This is especially important for thrust::pair as that is used in rmm extensively.

Fixes NVIDIA#1246

Co-authored-by: Georgy Evtushenko <[email protected]>
jrhemstad pushed a commit that referenced this pull request Jan 18, 2024
* Ensure that `cuda::std::pair` is potentially trivially copyable (#1249)

trivially copyable is a requirement for memcpy. We want to ensure that our pair implementation satisfies that whenever possible.

This is especially important for thrust::pair as that is used in rmm extensively.

Fixes #1246

Co-authored-by: Georgy Evtushenko <[email protected]>

* Mark test as passing

---------

Co-authored-by: Georgy Evtushenko <[email protected]>
rapids-bot bot pushed a commit to rapidsai/rapids-cmake that referenced this pull request Jan 18, 2024
Patch both CCCL and CUCO to have only internal linkage.

For cuco I am working on upstreaming these changes ( NVIDIA/cuCollections#422 ). Once that is accepted and we have validated that moving cuco is stable ( e.g. changes around `cuco::experimental::static_set` ) we can drop this patch set.

For cccl the long term fix is to move to CCCL 2.3+, but due to issues ( NVIDIA/cccl#1249, maybe others ) that isn't viable for the 24.02 timeframe.
Since the CCCL changes mean C++ and CUDA sources have non compatible ABI's, we need to specify `THRUST_DISABLE_ABI_NAMESPACE` and `THRUST_IGNORE_ABI_NAMESPACE_ERROR` so that we don't change ABI in rapids-cmake consumers since they expect 2.2 behavior.

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #523
@miscco miscco added backport done This PR has been backported to the relevant branch and removed backport branch/2.3.x For backporting to the 2.3.x release branch labels Jan 18, 2024
PointKernel pushed a commit to PointKernel/rapids-cmake that referenced this pull request Jan 23, 2024
Patch both CCCL and CUCO to have only internal linkage.

For cuco I am working on upstreaming these changes ( NVIDIA/cuCollections#422 ). Once that is accepted and we have validated that moving cuco is stable ( e.g. changes around `cuco::experimental::static_set` ) we can drop this patch set.

For cccl the long term fix is to move to CCCL 2.3+, but due to issues ( NVIDIA/cccl#1249, maybe others ) that isn't viable for the 24.02 timeframe.
Since the CCCL changes mean C++ and CUDA sources have non compatible ABI's, we need to specify `THRUST_DISABLE_ABI_NAMESPACE` and `THRUST_IGNORE_ABI_NAMESPACE_ERROR` so that we don't change ABI in rapids-cmake consumers since they expect 2.2 behavior.

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: rapidsai#523
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.3.2 Targeted for 2.3.2 patch release backport done This PR has been backported to the relevant branch
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG]: thrust::pair is not trivially copyable in CCCL branch/2.3.x
4 participants