Repository navigation
Add non-template ref-to-value converting constructor to __basic_any #8320
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
Changes from all commits
713ab18
3818b25
1074754
69b44f5
de03818
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,4 +348,83 @@ TEST_CASE("regression test for NVIDIA/cccl#8037", "[container][resource]") | |
| { | ||
| STATIC_REQUIRE(cuda::std::move_constructible<my_resource_wrapper>); | ||
| } | ||
|
|
||
| // Minimal proxy that wraps a value and provides operator T&(), mimicking | ||
| // Cython's __Pyx_FakeReference<T> which wraps intermediate expression results. | ||
| template <typename T> | ||
| struct value_proxy | ||
| { | ||
| T value; | ||
|
|
||
| template <typename... Args> | ||
| explicit value_proxy(Args&&... args) | ||
| : value(std::forward<Args>(args)...) | ||
| {} | ||
|
|
||
| operator T&() | ||
| { | ||
| return value; | ||
| } | ||
| }; | ||
|
|
||
| // See https://github.com/NVIDIA/cccl/issues/8316 | ||
| TEST_CASE("any_resource from proxy-wrapped resource_ref", "[container][resource]") | ||
| { | ||
| host_device_resource mr; | ||
| cuda::mr::resource_ref<cuda::mr::host_accessible> ref{mr}; | ||
|
|
||
| SECTION("direct construction from resource_ref") | ||
| { | ||
| cuda::mr::any_resource<cuda::mr::host_accessible> any{ref}; | ||
| // Extra parens prevent Catch2's expression decomposition, which triggers | ||
| // an nvcc bug with auto NTTP deduction in __satisfies during ADL. | ||
| CHECK((any == ref)); | ||
|
ericniebler marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| # if !_CCCL_CUDA_COMPILER(NVCC, <, 12, 9) | ||
| // nvcc before CTK 12.9 has a bug where auto NTTP deduction failures in | ||
| // __satisfies are hard errors instead of SFINAE during overload resolution. | ||
|
Comment on lines
+384
to
+386
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just raising a flag here. It seems like CUDA 12.0 didn't work with these changes. I wasn't able to come to a good workaround, but maybe someone else will have ideas. This is the MRE (sadly not very minimal): https://gist.github.com/bdice/0704486a9d32bceb782acd931c823123 I can't give a Godbolt reproducer link because it requires the changes from this PR...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems reasonable to exclude the tests that trigger a since-fixed compiler bug. particularly one that is hard to work around, like this one. EDIT: i wonder if it is the same issue that i worked around here: https://github.com/NVIDIA/cccl/blob/main/libcudacxx/include/cuda/__utility/__basic_any/basic_any_value.h#L254-L255 |
||
| SECTION("construction from lvalue proxy-wrapped resource_ref") | ||
| { | ||
| value_proxy<cuda::mr::resource_ref<cuda::mr::host_accessible>> proxy{mr}; | ||
| cuda::mr::any_resource<cuda::mr::host_accessible> any{proxy}; | ||
| CHECK((any == ref)); | ||
| } | ||
|
|
||
| SECTION("construction from rvalue proxy-wrapped resource_ref") | ||
| { | ||
| cuda::mr::any_resource<cuda::mr::host_accessible> any{ | ||
| value_proxy<cuda::mr::resource_ref<cuda::mr::host_accessible>>{mr}}; | ||
| CHECK((any == ref)); | ||
| } | ||
| # endif // !_CCCL_CUDA_COMPILER(NVCC, <, 12, 9) | ||
| } | ||
|
|
||
| TEST_CASE("any_synchronous_resource from proxy-wrapped synchronous_resource_ref", "[container][resource]") | ||
| { | ||
| host_device_resource mr; | ||
| cuda::mr::synchronous_resource_ref<cuda::mr::host_accessible> ref{mr}; | ||
|
|
||
| SECTION("direct construction from synchronous_resource_ref") | ||
| { | ||
| cuda::mr::any_synchronous_resource<cuda::mr::host_accessible> any{ref}; | ||
| CHECK((any == ref)); | ||
| } | ||
|
|
||
| # if !_CCCL_CUDA_COMPILER(NVCC, <, 12, 9) | ||
| SECTION("construction from lvalue proxy-wrapped synchronous_resource_ref") | ||
| { | ||
| value_proxy<cuda::mr::synchronous_resource_ref<cuda::mr::host_accessible>> proxy{mr}; | ||
| cuda::mr::any_synchronous_resource<cuda::mr::host_accessible> any{proxy}; | ||
| CHECK((any == ref)); | ||
| } | ||
|
|
||
| SECTION("construction from rvalue proxy-wrapped synchronous_resource_ref") | ||
| { | ||
| cuda::mr::any_synchronous_resource<cuda::mr::host_accessible> any{ | ||
| value_proxy<cuda::mr::synchronous_resource_ref<cuda::mr::host_accessible>>{mr}}; | ||
| CHECK((any == ref)); | ||
| } | ||
| # endif // !_CCCL_CUDA_COMPILER(NVCC, <, 12, 9) | ||
| } | ||
| #endif // __CUDA_ARCH__ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be _CCCL_REQUIRES?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this was intentional. The
__basic_anyclass uses rawenable_if_tinstead of_CCCL_TEMPLATE/_CCCL_REQUIRESto maintain ABI compatibility across C++17 and C++20. The_CCCL_REQUIRESmacro expands to arequires-clause in C++20 but to additional SFINAE template parameters in C++17, which produces different mangled names depending on the dialect. This caused runtime failures (vtable cast assertions) whenany_resourcewas used across DSO boundaries compiled with different-std=flags. See #7397 for the original bug report and #7401 / #7405 for the fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only needed to use
enable_iffor the functions whose ptrs actually end up in the pseudo-vtable (the ones marked_CCCL_PUBLIC_API). for these constructors,_CCCL_REQUIRESwould not cause the ABI issue described in #7397, and it would be consistent with the other constructors in this class.