diff --git a/libcudacxx/include/cuda/__memory_resource/device_memory_resource.h b/libcudacxx/include/cuda/__memory_resource/device_memory_resource.h index 16a69522657..e79c93dd5bf 100644 --- a/libcudacxx/include/cuda/__memory_resource/device_memory_resource.h +++ b/libcudacxx/include/cuda/__memory_resource/device_memory_resource.h @@ -31,9 +31,10 @@ # include <cuda/__memory_resource/properties.h> # include <cuda/__memory_resource/resource.h> # include <cuda/__memory_resource/resource_ref.h> +# include <cuda/std/__concepts/__concept_macros.h> # include <cuda/std/__cuda/api_wrapper.h> # include <cuda/std/__cuda/ensure_current_device.h> -# include <cuda/std/__new/bad_alloc.h> +# include <cuda/std/detail/libcxx/include/stdexcept> # if _CCCL_STD_VER >= 2014 @@ -59,14 +60,14 @@ class device_memory_resource //! @brief Allocate device memory of size at least \p __bytes. //! @param __bytes The size in bytes of the allocation. //! @param __alignment The requested alignment of the allocation. - //! @throw std::bad_alloc in case of invalid alignment or \c cuda::cuda_error of the returned error code. + //! @throw std::invalid_argument in case of invalid alignment or \c cuda::cuda_error of the returned error code. //! @return Pointer to the newly allocated memory _CCCL_NODISCARD void* allocate(const size_t __bytes, const size_t __alignment = default_cuda_malloc_alignment) const { // We need to ensure that the provided alignment matches the minimal provided alignment if (!__is_valid_alignment(__alignment)) { - _CUDA_VSTD::__throw_bad_alloc(); + _CUDA_VSTD::__throw_invalid_argument("Invalid alignment passed to device_memory_resource::allocate."); } // We need to ensure that we allocate on the right device as `cudaMalloc` always uses the current device diff --git a/libcudacxx/include/cuda/__memory_resource/managed_memory_resource.h b/libcudacxx/include/cuda/__memory_resource/managed_memory_resource.h index 47f74864baa..8c4cf5a8f93 100644 --- a/libcudacxx/include/cuda/__memory_resource/managed_memory_resource.h +++ b/libcudacxx/include/cuda/__memory_resource/managed_memory_resource.h @@ -31,8 +31,9 @@ # include <cuda/__memory_resource/properties.h> # include <cuda/__memory_resource/resource.h> # include <cuda/__memory_resource/resource_ref.h> +# include <cuda/std/__concepts/__concept_macros.h> # include <cuda/std/__cuda/api_wrapper.h> -# include <cuda/std/__new/bad_alloc.h> +# include <cuda/std/detail/libcxx/include/stdexcept> # if _CCCL_STD_VER >= 2014 @@ -56,14 +57,14 @@ class managed_memory_resource //! @brief Allocate CUDA unified memory of size at least \p __bytes. //! @param __bytes The size in bytes of the allocation. //! @param __alignment The requested alignment of the allocation. - //! @throw cuda::cuda_error of the returned error code + //! @throw std::invalid_argument in case of invalid alignment or \c cuda::cuda_error of the returned error code. //! @return Pointer to the newly allocated memory _CCCL_NODISCARD void* allocate(const size_t __bytes, const size_t __alignment = default_cuda_malloc_alignment) const { // We need to ensure that the provided alignment matches the minimal provided alignment if (!__is_valid_alignment(__alignment)) { - _CUDA_VSTD::__throw_bad_alloc(); + _CUDA_VSTD::__throw_invalid_argument("Invalid alignment passed to managed_memory_resource::allocate."); } void* __ptr{nullptr}; @@ -73,7 +74,7 @@ class managed_memory_resource } //! @brief Deallocate memory pointed to by \p __ptr. - //! @param __ptr Pointer to be deallocated. Must have been allocated through a call to `allocate` + //! @param __ptr Pointer to be deallocated. Must have been allocated through a call to `allocate`. //! @param __bytes The number of bytes that was passed to the `allocate` call that returned \p __ptr. //! @param __alignment The alignment that was passed to the `allocate` call that returned \p __ptr. void deallocate(void* __ptr, const size_t, const size_t __alignment = default_cuda_malloc_alignment) const noexcept @@ -85,26 +86,26 @@ class managed_memory_resource (void) __alignment; } - //! @brief Equality comparison with another \c managed_memory_resource - //! @param __other The other \c managed_memory_resource - //! @return Whether both \c managed_memory_resource were constructed with the same flags + //! @brief Equality comparison with another \c managed_memory_resource. + //! @param __other The other \c managed_memory_resource. + //! @return Whether both \c managed_memory_resource were constructed with the same flags. _CCCL_NODISCARD constexpr bool operator==(managed_memory_resource const& __other) const noexcept { return __flags_ == __other.__flags_; } # if _CCCL_STD_VER <= 2017 - //! @brief Inequality comparison with another \c managed_memory_resource - //! @param __other The other \c managed_memory_resource - //! @return Whether both \c managed_memory_resource were constructed with different flags + //! @brief Inequality comparison with another \c managed_memory_resource. + //! @param __other The other \c managed_memory_resource. + //! @return Whether both \c managed_memory_resource were constructed with different flags. _CCCL_NODISCARD constexpr bool operator!=(managed_memory_resource const& __other) const noexcept { return __flags_ != __other.__flags_; } # endif // _CCCL_STD_VER <= 2017 - //! @brief Equality comparison between a \c managed_memory_resource and another resource - //! @param __lhs The \c managed_memory_resource - //! @param __rhs The resource to compare to + //! @brief Equality comparison between a \c managed_memory_resource and another resource. + //! @param __lhs The \c managed_memory_resource. + //! @param __rhs The resource to compare to. //! @return If the underlying types are equality comparable, returns the result of equality comparison of both //! resources. Otherwise, returns false. template <class _Resource> diff --git a/libcudacxx/include/cuda/__memory_resource/pinned_memory_resource.h b/libcudacxx/include/cuda/__memory_resource/pinned_memory_resource.h index 6ec2b0c1186..a551785dcd3 100644 --- a/libcudacxx/include/cuda/__memory_resource/pinned_memory_resource.h +++ b/libcudacxx/include/cuda/__memory_resource/pinned_memory_resource.h @@ -32,8 +32,9 @@ # include <cuda/__memory_resource/properties.h> # include <cuda/__memory_resource/resource.h> # include <cuda/__memory_resource/resource_ref.h> +# include <cuda/std/__concepts/__concept_macros.h> # include <cuda/std/__cuda/api_wrapper.h> -# include <cuda/std/__new/bad_alloc.h> +# include <cuda/std/detail/libcxx/include/stdexcept> # if _CCCL_STD_VER >= 2014 @@ -58,7 +59,7 @@ class pinned_memory_resource //! @brief Allocate host memory of size at least \p __bytes. //! @param __bytes The size in bytes of the allocation. //! @param __alignment The requested alignment of the allocation. - //! @throw cuda::cuda_error if allocation fails with a CUDA error. + //! @throw std::invalid_argument in case of invalid alignment or \c cuda::cuda_error of the returned error code. //! @return Pointer to the newly allocated memory _CCCL_NODISCARD void* allocate(const size_t __bytes, const size_t __alignment = default_cuda_malloc_host_alignment) const @@ -66,7 +67,7 @@ class pinned_memory_resource // We need to ensure that the provided alignment matches the minimal provided alignment if (!__is_valid_alignment(__alignment)) { - _CUDA_VSTD::__throw_bad_alloc(); + _CUDA_VSTD::__throw_invalid_argument("Invalid alignment passed to pinned_memory_resource::allocate."); } void* __ptr{nullptr}; @@ -75,7 +76,7 @@ class pinned_memory_resource } //! @brief Deallocate memory pointed to by \p __ptr. - //! @param __ptr Pointer to be deallocated. Must have been allocated through a call to `allocate` + //! @param __ptr Pointer to be deallocated. Must have been allocated through a call to `allocate`. //! @param __bytes The number of bytes that was passed to the `allocate` call that returned \p __ptr. //! @param __alignment The alignment that was passed to the `allocate` call that returned \p __ptr. void @@ -88,26 +89,26 @@ class pinned_memory_resource (void) __alignment; } - //! @brief Equality comparison with another \c pinned_memory_resource - //! @param __other The other \c pinned_memory_resource - //! @return Whether both \c pinned_memory_resource were constructed with the same flags + //! @brief Equality comparison with another \c pinned_memory_resource. + //! @param __other The other \c pinned_memory_resource. + //! @return Whether both \c pinned_memory_resource were constructed with the same flags. _CCCL_NODISCARD constexpr bool operator==(pinned_memory_resource const& __other) const noexcept { return __flags_ == __other.__flags_; } # if _CCCL_STD_VER <= 2017 - //! @brief Equality comparison with another \c pinned_memory_resource - //! @param __other The other \c pinned_memory_resource - //! @return Whether both \c pinned_memory_resource were constructed with different flags + //! @brief Equality comparison with another \c pinned_memory_resource. + //! @param __other The other \c pinned_memory_resource. + //! @return Whether both \c pinned_memory_resource were constructed with different flags. _CCCL_NODISCARD constexpr bool operator!=(pinned_memory_resource const& __other) const noexcept { return __flags_ != __other.__flags_; } # endif // _CCCL_STD_VER <= 2017 - //! @brief Equality comparison between a \c pinned_memory_resource and another resource - //! @param __lhs The \c pinned_memory_resource - //! @param __rhs The resource to compare to + //! @brief Equality comparison between a \c pinned_memory_resource and another resource. + //! @param __lhs The \c pinned_memory_resource. + //! @param __rhs The resource to compare to. //! @return If the underlying types are equality comparable, returns the result of equality comparison of both //! resources. Otherwise, returns false. template <class _Resource> diff --git a/libcudacxx/include/cuda/__memory_resource/resource.h b/libcudacxx/include/cuda/__memory_resource/resource.h index 0692269b80b..fd2fa58d603 100644 --- a/libcudacxx/include/cuda/__memory_resource/resource.h +++ b/libcudacxx/include/cuda/__memory_resource/resource.h @@ -24,6 +24,7 @@ #if !defined(_CCCL_COMPILER_MSVC_2017) && defined(LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE) # include <cuda/__memory_resource/get_property.h> +# include <cuda/std/__concepts/__concept_macros.h> # include <cuda/std/__concepts/all_of.h> # include <cuda/std/__concepts/convertible_to.h> # include <cuda/std/__concepts/equality_comparable.h> diff --git a/libcudacxx/test/libcudacxx/cuda/memory_resource/device_memory_resource/allocate.pass.cpp b/libcudacxx/test/libcudacxx/cuda/memory_resource/device_memory_resource/allocate.pass.cpp index 51c4a5e830f..fe983aa93de 100644 --- a/libcudacxx/test/libcudacxx/cuda/memory_resource/device_memory_resource/allocate.pass.cpp +++ b/libcudacxx/test/libcudacxx/cuda/memory_resource/device_memory_resource/allocate.pass.cpp @@ -62,7 +62,7 @@ void test() auto* ptr = res.allocate(5, 42); unused(ptr); } - catch (const std::bad_alloc&) + catch (const std::invalid_argument&) { break; } @@ -78,7 +78,7 @@ void test() auto* ptr = res.allocate(5, 1337); unused(ptr); } - catch (const std::bad_alloc&) + catch (const std::invalid_argument&) { break; } diff --git a/libcudacxx/test/libcudacxx/cuda/memory_resource/managed_memory_resource/allocate.pass.cpp b/libcudacxx/test/libcudacxx/cuda/memory_resource/managed_memory_resource/allocate.pass.cpp index df0652d5a1d..f32093a1582 100644 --- a/libcudacxx/test/libcudacxx/cuda/memory_resource/managed_memory_resource/allocate.pass.cpp +++ b/libcudacxx/test/libcudacxx/cuda/memory_resource/managed_memory_resource/allocate.pass.cpp @@ -57,7 +57,7 @@ void test(const unsigned int flag) auto* ptr = res.allocate(5, 42); unused(ptr); } - catch (const std::bad_alloc&) + catch (const std::invalid_argument&) { break; } @@ -73,7 +73,7 @@ void test(const unsigned int flag) auto* ptr = res.allocate(5, 1337); unused(ptr); } - catch (const std::bad_alloc&) + catch (const std::invalid_argument&) { break; } diff --git a/libcudacxx/test/libcudacxx/cuda/memory_resource/pinned_memory_resource/allocate.pass.cpp b/libcudacxx/test/libcudacxx/cuda/memory_resource/pinned_memory_resource/allocate.pass.cpp index 3ad0ae106b2..a8fff25ffa6 100644 --- a/libcudacxx/test/libcudacxx/cuda/memory_resource/pinned_memory_resource/allocate.pass.cpp +++ b/libcudacxx/test/libcudacxx/cuda/memory_resource/pinned_memory_resource/allocate.pass.cpp @@ -57,7 +57,7 @@ void test(const unsigned int flag) auto* ptr = res.allocate(5, 42); unused(ptr); } - catch (const std::bad_alloc&) + catch (const std::invalid_argument&) { break; } @@ -73,7 +73,7 @@ void test(const unsigned int flag) auto* ptr = res.allocate(5, 1337); unused(ptr); } - catch (const std::bad_alloc&) + catch (const std::invalid_argument&) { break; }