From 5a2976eb6bc6d7a230cbca7f627e379dde153384 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 10 Oct 2024 23:59:15 +0000 Subject: [PATCH 1/8] add `_LIBCUDACXX_REQUIRES_EXPR` to the concepts emulation macros --- .../include/cuda/__memory_resource/resource.h | 29 +++---- .../cuda/std/__concepts/__concept_macros.h | 85 +++++++++++++++++++ 2 files changed, 96 insertions(+), 18 deletions(-) diff --git a/libcudacxx/include/cuda/__memory_resource/resource.h b/libcudacxx/include/cuda/__memory_resource/resource.h index 2e9f72a63b..ed621f1966 100644 --- a/libcudacxx/include/cuda/__memory_resource/resource.h +++ b/libcudacxx/include/cuda/__memory_resource/resource.h @@ -36,14 +36,6 @@ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_MR -template -_LIBCUDACXX_CONCEPT_FRAGMENT( - __resource_, - requires(_Resource& __res, void* __ptr, size_t __bytes, size_t __alignment)( - requires(_CUDA_VSTD::same_as), - requires(_CUDA_VSTD::same_as), - requires(_CUDA_VSTD::equality_comparable<_Resource>))); - //! @brief The \c resource concept verifies that a type Resource satisfies the basic requirements of a memory //! resource //! @rst @@ -57,15 +49,11 @@ _LIBCUDACXX_CONCEPT_FRAGMENT( //! @endrst //! @tparam _Resource The type that should implement the resource concept template -_LIBCUDACXX_CONCEPT resource = _LIBCUDACXX_FRAGMENT(__resource_, _Resource); - -template -_LIBCUDACXX_CONCEPT_FRAGMENT( - __async_resource_, - requires(_Resource& __res, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)( - requires(resource<_Resource>), - requires(_CUDA_VSTD::same_as), - requires(_CUDA_VSTD::same_as))); +_LIBCUDACXX_CONCEPT resource = + _CUDA_VSTD::equality_comparable<_Resource> + && _LIBCUDACXX_REQUIRES_EXPR((_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment)( + _Same_as(void*) __res.allocate(__bytes, __alignment), // + _Same_as(void) __res.deallocate(__ptr, __bytes, __alignment)); //! @brief The \c async_resource concept verifies that a type Resource satisfies the basic requirements of a //! memory resource and additionally supports stream ordered allocations @@ -83,7 +71,12 @@ _LIBCUDACXX_CONCEPT_FRAGMENT( //! @endrst //! @tparam _Resource The type that should implement the async resource concept template -_LIBCUDACXX_CONCEPT async_resource = _LIBCUDACXX_FRAGMENT(__async_resource_, _Resource); +_LIBCUDACXX_CONCEPT async_resource = + resource<_Resource> + && _LIBCUDACXX_REQUIRES_EXPR( + (_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)( + _Same_as(void*) __res.allocate_async(__bytes, __alignment, __stream), + _Same_as(void) __res.deallocate_async(__ptr, __bytes, __alignment, __stream)); //! @brief The \c resource_with concept verifies that a type Resource satisfies the `resource` concept and //! also satisfies all the provided Properties diff --git a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h index a7cef351c2..d0b8f42478 100644 --- a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h +++ b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h @@ -171,6 +171,7 @@ # define _LIBCUDACXX_PP_IIF_1(_TRUE, ...) _TRUE # define _LIBCUDACXX_PP_LPAREN ( +# define _LIBCUDACXX_PP_RPAREN ) # define _LIBCUDACXX_PP_NOT(_BIT) _LIBCUDACXX_PP_CAT_(_LIBCUDACXX_PP_NOT_, _BIT) # define _LIBCUDACXX_PP_NOT_0 1 @@ -220,11 +221,13 @@ # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_requires _LIBCUDACXX_PP_PROBE_N(~, 1) # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_noexcept _LIBCUDACXX_PP_PROBE_N(~, 2) # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE_typename _LIBCUDACXX_PP_PROBE_N(~, 3) +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_PROBE__Same_as _LIBCUDACXX_PP_PROBE_N(~, 4) # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_0 _LIBCUDACXX_PP_EXPAND # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_1 _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_2 _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_3 _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SELECT_4 _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_OR_NOEXCEPT(_REQ) \ _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_, _REQ) # define _LIBCUDACXX_PP_EAT_TYPENAME_PROBE_typename _LIBCUDACXX_PP_PROBE(~) @@ -255,6 +258,14 @@ { \ __VA_ARGS__ \ } noexcept +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS(_REQ) \ + { \ + _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_PP_EAT_SAME_AS_, _REQ) \ + } -> _LIBCUDACXX_PP_EVAL(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_AUX, \ + _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_, _REQ)) +# define _LIBCUDACXX_PP_EAT_SAME_AS__Same_as(...) +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_AUX(_TYPE, ...) _CUDA_VSTD::same_as<_LIBCUDACXX_PP_EXPAND _TYPE> +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS__Same_as(...) (__VA_ARGS__), # define _LIBCUDACXX_FRAGMENT(_NAME, ...) _NAME<__VA_ARGS__> @@ -294,6 +305,10 @@ # else # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_REQUIRES_noexcept(...) _Concept::_Requires # endif +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS(_REQ) \ + _Concept::_Requires<_CUDA_VSTD::same_as<_LIBCUDACXX_PP_CAT4( \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_, _REQ) _LIBCUDACXX_PP_RPAREN>> +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS__Same_as(...) __VA_ARGS__, decltype _LIBCUDACXX_PP_LPAREN # define _LIBCUDACXX_FRAGMENT(_NAME, ...) \ (1u == sizeof(_NAME##_LIBCUDACXX_CONCEPT_FRAGMENT_(static_cast<_Concept::_Tag<__VA_ARGS__>*>(nullptr), nullptr))) @@ -323,6 +338,72 @@ # define _LIBCUDACXX_TRAILING_REQUIRES(...) ->_Concept::_Requires_t < __VA_ARGS__ _LIBCUDACXX_TRAILING_REQUIRES_AUX_ # endif +//////////////////////////////////////////////////////////////////////////////// +// _LIBCUDACXX_REQUIRES_EXPR +// Usage: +// template +// _LIBCUDACXX_CONCEPT equality_comparable = +// _LIBCUDACXX_REQUIRES_EXPR((T), T const& lhs, T const& rhs) ( +// lhs == rhs, +// lhs != rhs +// ); +// +// Can only be used as the last requirement in a concept definition. +# if defined(__cpp_concepts) && _CCCL_STD_VER >= 2020 +# define _LIBCUDACXX_REQUIRES_EXPR(_TY, ...) requires(__VA_ARGS__) _LIBCUDACXX_REQUIRES_EXPR_2 +# define _LIBCUDACXX_REQUIRES_EXPR_2(...) {_LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__)} +# else +# define _LIBCUDACXX_REQUIRES_EXPR_TPARAM_PROBE_variadic _LIBCUDACXX_PP_PROBE(~) +# define _LIBCUDACXX_REQUIRES_EXPR_TPARAM_variadic + +# define _LIBCUDACXX_REQUIRES_EXPR_DEF_TPARAM(_TY) \ + , _LIBCUDACXX_PP_CAT(_LIBCUDACXX_REQUIRES_EXPR_DEF_TPARAM_, \ + _LIBCUDACXX_PP_EVAL(_LIBCUDACXX_PP_CHECK, \ + _LIBCUDACXX_PP_CAT(_LIBCUDACXX_REQUIRES_EXPR_TPARAM_PROBE_, _TY)))(_TY) +# define _LIBCUDACXX_REQUIRES_EXPR_DEF_TPARAM_0(_TY) class _TY +# define _LIBCUDACXX_REQUIRES_EXPR_DEF_TPARAM_1(_TY) \ + class... _LIBCUDACXX_PP_CAT(_LIBCUDACXX_REQUIRES_EXPR_TPARAM_, _TY) + +# define _LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAM(_TY) \ + , _LIBCUDACXX_PP_CAT(_LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAM_, \ + _LIBCUDACXX_PP_EVAL(_LIBCUDACXX_PP_CHECK, \ + _LIBCUDACXX_PP_CAT(_LIBCUDACXX_REQUIRES_EXPR_TPARAM_PROBE_, _TY)))(_TY) +# define _LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAM_0(_TY) _TY +# define _LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAM_1(_TY) _LIBCUDACXX_PP_CAT(_LIBCUDACXX_REQUIRES_EXPR_TPARAM_, _TY)... + +# define _LIBCUDACXX_REQUIRES_EXPR_TPARAMS(...) \ + _LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_REQUIRES_EXPR_DEF_TPARAM, __VA_ARGS__) + +# define _LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAMS(...) \ + _LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAM, __VA_ARGS__) + +# define _LIBCUDACXX_REQUIRES_EXPR(_TY, ...) \ + decltype(_Concept::_Make_dependent( \ + (struct _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__)*) nullptr, \ + (_Concept::_Tag*) nullptr)):: \ + _Is_satisfied((_Concept::_Tag*) nullptr, \ + (void (*)(__VA_ARGS__)) nullptr); \ + struct _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__) \ + { \ + using _Self_t = _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__); \ + template \ + static auto _Well_formed(__VA_ARGS__) _LIBCUDACXX_REQUIRES_EXPR_2 + +# define _LIBCUDACXX_REQUIRES_EXPR_2(...) \ + ->decltype(_LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void()) {} \ + template \ + static constexpr auto _Is_satisfied(_Concept::_Tag*, Sig*) /* */ \ + -> decltype(!static_cast(&_Self_t::_Well_formed)) \ + { \ + return true; \ + } \ + static constexpr auto _Is_satisfied(void*, ...) -> bool \ + { \ + return false; \ + } \ + } +# endif + namespace _Concept { template @@ -344,6 +425,7 @@ using _Requires_t = typename _Select<_Bp>::template type<_Tp>; template struct _Tag; + template _LIBCUDACXX_HIDE_FROM_ABI constexpr bool _Is_true() { @@ -358,6 +440,9 @@ _LIBCUDACXX_HIDE_FROM_ABI _Concept::_Enable_if_t<_Bp> _Requires() template = 0> _LIBCUDACXX_INLINE_VAR constexpr int _Requires = 0; # endif + +template +auto _Make_dependent(_Tp*, _Tag<_Args...>*) -> _Tp; } // namespace _Concept #endif // _CCCL_STD_VER > 2011 From 74227c364faf9b71b6de43b2d9db859ee6700271 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 11 Oct 2024 01:37:35 +0000 Subject: [PATCH 2/8] work around nvcc pre-12.2 bug and molify nvrtc --- .../cuda/std/__concepts/__concept_macros.h | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h index d0b8f42478..2dfb9e2b89 100644 --- a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h +++ b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h @@ -258,13 +258,14 @@ { \ __VA_ARGS__ \ } noexcept -# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS(_REQ) \ - { \ - _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_PP_EAT_SAME_AS_, _REQ) \ - } -> _LIBCUDACXX_PP_EVAL(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_AUX, \ - _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_, _REQ)) +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS(_REQ) \ + { \ + _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_PP_EAT_SAME_AS_, _REQ) \ + } -> _LIBCUDACXX_CONCEPT_VSTD::same_as<_LIBCUDACXX_PP_EVAL( \ + _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_AUX, \ + _LIBCUDACXX_PP_CAT4(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_, _REQ))> # define _LIBCUDACXX_PP_EAT_SAME_AS__Same_as(...) -# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_AUX(_TYPE, ...) _CUDA_VSTD::same_as<_LIBCUDACXX_PP_EXPAND _TYPE> +# define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS_AUX(_TYPE, ...) _LIBCUDACXX_PP_EXPAND _TYPE # define _LIBCUDACXX_CONCEPT_FRAGMENT_REQS_SAME_AS__Same_as(...) (__VA_ARGS__), # define _LIBCUDACXX_FRAGMENT(_NAME, ...) _NAME<__VA_ARGS__> @@ -404,6 +405,10 @@ } # endif +// So that we can refer to the ::cuda::std namespace below +_LIBCUDACXX_BEGIN_NAMESPACE_STD +_LIBCUDACXX_END_NAMESPACE_STD + namespace _Concept { template @@ -442,7 +447,22 @@ _LIBCUDACXX_INLINE_VAR constexpr int _Requires = 0; # endif template -auto _Make_dependent(_Tp*, _Tag<_Args...>*) -> _Tp; +_LIBCUDACXX_HIDE_FROM_ABI auto _Make_dependent(_Tp*, _Tag<_Args...>*) -> _Tp; + +// We put an alias for _CUDA_VSTD here because of a bug in nvcc <12.2 +// where a requirement such as: +// +// { expression } -> ::concept +// +// where ::concept is a fully qualified name, would not compile. The +// _CUDA_VSTD macro is fully qualified. +namespace _Vstd = _CUDA_VSTD; // NOLINT(misc-unused-alias-decls) + +# if defined(_CCCL_CUDACC_BELOW_12_2) +# define _LIBCUDACXX_CONCEPT_VSTD _Concept::_Vstd // must not be fully qualified +# else +# define _LIBCUDACXX_CONCEPT_VSTD _CUDA_VSTD +# endif } // namespace _Concept #endif // _CCCL_STD_VER > 2011 From de08f1c4f7775b6442c0e6167e315338452bc9d2 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 11 Oct 2024 02:10:04 +0000 Subject: [PATCH 3/8] silence warning about an always true condition --- .../cuda/std/__concepts/__concept_macros.h | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h index 2dfb9e2b89..4e406f1d18 100644 --- a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h +++ b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h @@ -390,18 +390,17 @@ template \ static auto _Well_formed(__VA_ARGS__) _LIBCUDACXX_REQUIRES_EXPR_2 -# define _LIBCUDACXX_REQUIRES_EXPR_2(...) \ - ->decltype(_LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void()) {} \ - template \ - static constexpr auto _Is_satisfied(_Concept::_Tag*, Sig*) /* */ \ - -> decltype(!static_cast(&_Self_t::_Well_formed)) \ - { \ - return true; \ - } \ - static constexpr auto _Is_satisfied(void*, ...) -> bool \ - { \ - return false; \ - } \ +# define _LIBCUDACXX_REQUIRES_EXPR_2(...) \ + ->decltype(_LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void()) {} \ + template (&_Self_t::_Well_formed))> \ + static constexpr bool _Is_satisfied(_Concept::_Tag*, Sig*) \ + { \ + return true; \ + } \ + static constexpr bool _Is_satisfied(void*, ...) \ + { \ + return false; \ + } \ } # endif From d4756fdf3475f2d3e613068ab054caba894619a1 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Sat, 12 Oct 2024 01:02:29 +0000 Subject: [PATCH 4/8] simplify macro substitution with the help of an alias template --- .../cuda/std/__concepts/__concept_macros.h | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h index 4e406f1d18..7c3c156c8d 100644 --- a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h +++ b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h @@ -378,16 +378,15 @@ # define _LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAMS(...) \ _LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAM, __VA_ARGS__) -# define _LIBCUDACXX_REQUIRES_EXPR(_TY, ...) \ - decltype(_Concept::_Make_dependent( \ - (struct _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__)*) nullptr, \ - (_Concept::_Tag*) nullptr)):: \ - _Is_satisfied((_Concept::_Tag*) nullptr, \ - (void (*)(__VA_ARGS__)) nullptr); \ - struct _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__) \ - { \ - using _Self_t = _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__); \ - template \ +# define _LIBCUDACXX_REQUIRES_EXPR(_TY, ...) \ + _Concept::_Requires_expr_impl:: \ + _Is_satisfied((_Concept::_Tag*) nullptr, \ + (void (*)(__VA_ARGS__)) nullptr); \ + struct _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__) \ + { \ + using _Self_t = _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__); \ + template \ static auto _Well_formed(__VA_ARGS__) _LIBCUDACXX_REQUIRES_EXPR_2 # define _LIBCUDACXX_REQUIRES_EXPR_2(...) \ @@ -448,6 +447,10 @@ _LIBCUDACXX_INLINE_VAR constexpr int _Requires = 0; template _LIBCUDACXX_HIDE_FROM_ABI auto _Make_dependent(_Tp*, _Tag<_Args...>*) -> _Tp; +template +using _Requires_expr_impl = // + decltype(_Concept::_Make_dependent((_Impl*) nullptr, (_Tag*) nullptr)); + // We put an alias for _CUDA_VSTD here because of a bug in nvcc <12.2 // where a requirement such as: // From 3d72604fcef5604cbbb28a0dc5caab0d03d053f4 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 14 Oct 2024 15:44:21 +0000 Subject: [PATCH 5/8] fix the short-circuiting behavior of the `async_resource` concept pre-c++20 --- libcudacxx/include/cuda/__memory_resource/resource.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libcudacxx/include/cuda/__memory_resource/resource.h b/libcudacxx/include/cuda/__memory_resource/resource.h index ed621f1966..ea343341db 100644 --- a/libcudacxx/include/cuda/__memory_resource/resource.h +++ b/libcudacxx/include/cuda/__memory_resource/resource.h @@ -71,12 +71,11 @@ _LIBCUDACXX_CONCEPT resource = //! @endrst //! @tparam _Resource The type that should implement the async resource concept template -_LIBCUDACXX_CONCEPT async_resource = - resource<_Resource> - && _LIBCUDACXX_REQUIRES_EXPR( - (_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)( - _Same_as(void*) __res.allocate_async(__bytes, __alignment, __stream), - _Same_as(void) __res.deallocate_async(__ptr, __bytes, __alignment, __stream)); +_LIBCUDACXX_CONCEPT async_resource = _LIBCUDACXX_REQUIRES_EXPR( + (_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)( + requires(resource<_Resource>), + _Same_as(void*) __res.allocate_async(__bytes, __alignment, __stream), + _Same_as(void) __res.deallocate_async(__ptr, __bytes, __alignment, __stream)); //! @brief The \c resource_with concept verifies that a type Resource satisfies the `resource` concept and //! also satisfies all the provided Properties From edccc7542a07a97b5c9a9fba3b5fdfe1eaad6cf3 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 14 Oct 2024 15:51:25 +0000 Subject: [PATCH 6/8] replace C-style casts with C++-style `static_cast`s --- .../cuda/std/__concepts/__concept_macros.h | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h index 7c3c156c8d..427f8cec67 100644 --- a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h +++ b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h @@ -378,15 +378,15 @@ # define _LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAMS(...) \ _LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_REQUIRES_EXPR_EXPAND_TPARAM, __VA_ARGS__) -# define _LIBCUDACXX_REQUIRES_EXPR(_TY, ...) \ - _Concept::_Requires_expr_impl:: \ - _Is_satisfied((_Concept::_Tag*) nullptr, \ - (void (*)(__VA_ARGS__)) nullptr); \ - struct _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__) \ - { \ - using _Self_t = _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__); \ - template \ +# define _LIBCUDACXX_REQUIRES_EXPR(_TY, ...) \ + _Concept::_Requires_expr_impl:: \ + _Is_satisfied(static_cast<_Concept::_Tag*>(nullptr), \ + static_cast(nullptr)); \ + struct _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__) \ + { \ + using _Self_t = _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__); \ + template \ static auto _Well_formed(__VA_ARGS__) _LIBCUDACXX_REQUIRES_EXPR_2 # define _LIBCUDACXX_REQUIRES_EXPR_2(...) \ @@ -449,7 +449,7 @@ _LIBCUDACXX_HIDE_FROM_ABI auto _Make_dependent(_Tp*, _Tag<_Args...>*) -> _Tp; template using _Requires_expr_impl = // - decltype(_Concept::_Make_dependent((_Impl*) nullptr, (_Tag*) nullptr)); + decltype(_Concept::_Make_dependent(static_cast<_Impl*>(nullptr), static_cast<_Tag*>(nullptr))); // We put an alias for _CUDA_VSTD here because of a bug in nvcc <12.2 // where a requirement such as: From d8e22996fdaeec3a84de508ff963decd7d3095b1 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 14 Oct 2024 16:00:49 +0000 Subject: [PATCH 7/8] add missing `_LIBCUDACXX_HIDE_FROM_ABI` function annotations --- libcudacxx/include/cuda/std/__concepts/__concept_macros.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h index 427f8cec67..5345a5b1d6 100644 --- a/libcudacxx/include/cuda/std/__concepts/__concept_macros.h +++ b/libcudacxx/include/cuda/std/__concepts/__concept_macros.h @@ -387,16 +387,16 @@ { \ using _Self_t = _LIBCUDACXX_PP_CAT(_Libcudacxx_requires_expr_detail_, __LINE__); \ template \ - static auto _Well_formed(__VA_ARGS__) _LIBCUDACXX_REQUIRES_EXPR_2 + _LIBCUDACXX_HIDE_FROM_ABI static auto _Well_formed(__VA_ARGS__) _LIBCUDACXX_REQUIRES_EXPR_2 # define _LIBCUDACXX_REQUIRES_EXPR_2(...) \ ->decltype(_LIBCUDACXX_PP_FOR_EACH(_LIBCUDACXX_CONCEPT_FRAGMENT_REQS_M, __VA_ARGS__) void()) {} \ template (&_Self_t::_Well_formed))> \ - static constexpr bool _Is_satisfied(_Concept::_Tag*, Sig*) \ + _LIBCUDACXX_HIDE_FROM_ABI static constexpr bool _Is_satisfied(_Concept::_Tag*, Sig*) \ { \ return true; \ } \ - static constexpr bool _Is_satisfied(void*, ...) \ + _LIBCUDACXX_HIDE_FROM_ABI static constexpr bool _Is_satisfied(void*, ...) \ { \ return false; \ } \ From 6fb8805389e7da5e9f29d47cbe69d8dcc8a9c185 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Tue, 15 Oct 2024 20:41:24 +0000 Subject: [PATCH 8/8] restore short-circuiting in the `resource` concept --- libcudacxx/include/cuda/__memory_resource/resource.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcudacxx/include/cuda/__memory_resource/resource.h b/libcudacxx/include/cuda/__memory_resource/resource.h index ea343341db..d6085fa0d0 100644 --- a/libcudacxx/include/cuda/__memory_resource/resource.h +++ b/libcudacxx/include/cuda/__memory_resource/resource.h @@ -50,8 +50,8 @@ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_MR //! @tparam _Resource The type that should implement the resource concept template _LIBCUDACXX_CONCEPT resource = - _CUDA_VSTD::equality_comparable<_Resource> - && _LIBCUDACXX_REQUIRES_EXPR((_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment)( + _LIBCUDACXX_REQUIRES_EXPR((_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment)( + requires(_CUDA_VSTD::equality_comparable<_Resource>), _Same_as(void*) __res.allocate(__bytes, __alignment), // _Same_as(void) __res.deallocate(__ptr, __bytes, __alignment));