Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions libcudacxx/include/cuda/__container/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -724,7 +724,7 @@ _CCCL_TEMPLATE(class _Tp,
_CCCL_REQUIRES(
::cuda::mr::synchronous_resource_with<::cuda::std::decay_t<_Resource>, _FirstProperty, _RestProperties...> _CCCL_AND
__buffer_compatible_env<_Env>)
buffer<_Tp, _FirstProperty, _RestProperties...> make_buffer(
_CCCL_HOST_API buffer<_Tp, _FirstProperty, _RestProperties...> make_buffer(
stream_ref __stream, _Resource&& __mr, const buffer<_Tp, _SourceProperties...>& __source, const _Env& __env = {})
{
buffer<_Tp, _FirstProperty, _RestProperties...> __res{
Expand All @@ -742,13 +742,13 @@ buffer<_Tp, _FirstProperty, _RestProperties...> make_buffer(
//! @param __env The environment providing additional configuration.
# ifdef _CCCL_DOXYGEN_INVOKED
template <class _Tp, class _Resource, class... _SourceProperties, class _Env = ::cuda::std::execution::env<>>
auto make_buffer(
_CCCL_HOST_API auto make_buffer(
stream_ref __stream, _Resource&& __mr, const buffer<_Tp, _SourceProperties...>& __source, const _Env& __env = {});
# else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv
_CCCL_TEMPLATE(class _Tp, class _Resource, class... _SourceProperties, class _Env = ::cuda::std::execution::env<>)
_CCCL_REQUIRES(::cuda::mr::synchronous_resource<::cuda::std::decay_t<_Resource>>
_CCCL_AND ::cuda::mr::__has_default_queries<::cuda::std::decay_t<_Resource>>)
auto make_buffer(
_CCCL_HOST_API auto make_buffer(
stream_ref __stream, _Resource&& __mr, const buffer<_Tp, _SourceProperties...>& __source, const _Env& __env = {})
{
using __buffer_type = __buffer_type_for_props<_Tp, typename ::cuda::std::decay_t<_Resource>::default_queries>;
Expand Down Expand Up @@ -778,13 +778,13 @@ make_buffer(stream_ref __stream, _Resource&& __mr, const _Env& __env = {})
//! @param __env The environment providing additional configuration.
# ifdef _CCCL_DOXYGEN_INVOKED
template <class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>>
auto make_buffer(stream_ref __stream, _Resource&& __mr, const _Env& __env = {});
_CCCL_HOST_API auto make_buffer(stream_ref __stream, _Resource&& __mr, const _Env& __env = {});
# else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv
_CCCL_TEMPLATE(class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>)
_CCCL_REQUIRES(::cuda::mr::synchronous_resource<::cuda::std::decay_t<_Resource>>
_CCCL_AND ::cuda::mr::__has_default_queries<::cuda::std::decay_t<_Resource>> _CCCL_AND
__buffer_compatible_env<_Env>)
auto make_buffer(stream_ref __stream, _Resource&& __mr, const _Env& __env = {})
_CCCL_HOST_API auto make_buffer(stream_ref __stream, _Resource&& __mr, const _Env& __env = {})
{
using __buffer_type = __buffer_type_for_props<_Tp, typename ::cuda::std::decay_t<_Resource>::default_queries>;
return __buffer_type{__stream, ::cuda::std::forward<_Resource>(__mr), __env};
Expand All @@ -799,7 +799,7 @@ _CCCL_TEMPLATE(
_CCCL_REQUIRES(
::cuda::mr::synchronous_resource_with<::cuda::std::decay_t<_Resource>, _FirstProperty, _RestProperties...> _CCCL_AND
__buffer_compatible_env<_Env>)
buffer<_Tp, _FirstProperty, _RestProperties...> make_buffer(
_CCCL_HOST_API buffer<_Tp, _FirstProperty, _RestProperties...> make_buffer(
stream_ref __stream, _Resource&& __mr, size_t __size, const _Tp& __value, [[maybe_unused]] const _Env& __env = {})
{
auto __res =
Expand All @@ -817,12 +817,13 @@ buffer<_Tp, _FirstProperty, _RestProperties...> make_buffer(
//! @param __env The environment providing additional configuration.
# ifdef _CCCL_DOXYGEN_INVOKED
template <class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>>
auto make_buffer(stream_ref __stream, _Resource&& __mr, size_t __size, const _Tp& __value, const _Env& __env = {});
_CCCL_HOST_API auto
make_buffer(stream_ref __stream, _Resource&& __mr, size_t __size, const _Tp& __value, const _Env& __env = {});
# else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv
_CCCL_TEMPLATE(class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>)
_CCCL_REQUIRES(::cuda::mr::synchronous_resource<::cuda::std::decay_t<_Resource>>
_CCCL_AND ::cuda::mr::__has_default_queries<::cuda::std::decay_t<_Resource>>)
auto make_buffer(
_CCCL_HOST_API auto make_buffer(
stream_ref __stream, _Resource&& __mr, size_t __size, const _Tp& __value, [[maybe_unused]] const _Env& __env = {})
{
using __default_queries = typename ::cuda::std::decay_t<_Resource>::default_queries;
Expand Down Expand Up @@ -856,12 +857,14 @@ make_buffer(stream_ref __stream, _Resource&& __mr, size_t __size, ::cuda::no_ini
//! @param __env The environment providing additional configuration.
# ifdef _CCCL_DOXYGEN_INVOKED
template <class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>>
auto make_buffer(stream_ref __stream, _Resource&& __mr, size_t __size, ::cuda::no_init_t, const _Env& __env = {});
_CCCL_HOST_API auto
make_buffer(stream_ref __stream, _Resource&& __mr, size_t __size, ::cuda::no_init_t, const _Env& __env = {});
# else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv
_CCCL_TEMPLATE(class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>)
_CCCL_REQUIRES(::cuda::mr::synchronous_resource<::cuda::std::decay_t<_Resource>>
_CCCL_AND ::cuda::mr::__has_default_queries<_Resource>)
auto make_buffer(stream_ref __stream, _Resource&& __mr, size_t __size, ::cuda::no_init_t, const _Env& __env = {})
_CCCL_HOST_API auto
make_buffer(stream_ref __stream, _Resource&& __mr, size_t __size, ::cuda::no_init_t, const _Env& __env = {})
{
using __buffer_type = __buffer_type_for_props<_Tp, typename ::cuda::std::decay_t<_Resource>::default_queries>;
return __buffer_type{__stream, ::cuda::std::forward<_Resource>(__mr), __size, ::cuda::no_init, __env};
Expand Down Expand Up @@ -893,13 +896,15 @@ make_buffer(stream_ref __stream, _Resource&& __mr, _Iter __first, _Iter __last,
//! @param __env The environment providing additional configuration.
# ifdef _CCCL_DOXYGEN_INVOKED
template <class _Tp, class _Resource, class _Iter, class _Env = ::cuda::std::execution::env<>>
auto make_buffer(stream_ref __stream, _Resource&& __mr, _Iter __first, _Iter __last, const _Env& __env = {});
_CCCL_HOST_API auto
make_buffer(stream_ref __stream, _Resource&& __mr, _Iter __first, _Iter __last, const _Env& __env = {});
# else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv
_CCCL_TEMPLATE(class _Tp, class _Resource, class _Iter, class _Env = ::cuda::std::execution::env<>)
_CCCL_REQUIRES(
::cuda::mr::synchronous_resource<::cuda::std::decay_t<_Resource>>
_CCCL_AND ::cuda::mr::__has_default_queries<_Resource> _CCCL_AND ::cuda::std::__has_forward_traversal<_Iter>)
auto make_buffer(stream_ref __stream, _Resource&& __mr, _Iter __first, _Iter __last, const _Env& __env = {})
_CCCL_HOST_API auto
make_buffer(stream_ref __stream, _Resource&& __mr, _Iter __first, _Iter __last, const _Env& __env = {})
{
using __buffer_type = __buffer_type_for_props<_Tp, typename ::cuda::std::decay_t<_Resource>::default_queries>;
return __buffer_type{__stream, ::cuda::std::forward<_Resource>(__mr), __first, __last, __env};
Expand All @@ -926,14 +931,14 @@ make_buffer(stream_ref __stream, _Resource&& __mr, ::cuda::std::initializer_list
//! @param __env The environment providing additional configuration.
# ifdef _CCCL_DOXYGEN_INVOKED
template <class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>>
auto make_buffer(
stream_ref __stream, _Resource&& __mr, ::cuda::std::initializer_list<_Tp> __ilist, const _Env& __env = {});
_CCCL_HOST_API auto
make_buffer(stream_ref __stream, _Resource&& __mr, ::cuda::std::initializer_list<_Tp> __ilist, const _Env& __env = {});
# else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv
_CCCL_TEMPLATE(class _Tp, class _Resource, class _Env = ::cuda::std::execution::env<>)
_CCCL_REQUIRES(::cuda::mr::synchronous_resource<::cuda::std::decay_t<_Resource>>
_CCCL_AND ::cuda::mr::__has_default_queries<::cuda::std::decay_t<_Resource>>)
auto make_buffer(
stream_ref __stream, _Resource&& __mr, ::cuda::std::initializer_list<_Tp> __ilist, const _Env& __env = {})
_CCCL_HOST_API auto
make_buffer(stream_ref __stream, _Resource&& __mr, ::cuda::std::initializer_list<_Tp> __ilist, const _Env& __env = {})
{
using __buffer_type = __buffer_type_for_props<_Tp, typename ::cuda::std::decay_t<_Resource>::default_queries>;
return __buffer_type{__stream, ::cuda::std::forward<_Resource>(__mr), __ilist, __env};
Expand Down Expand Up @@ -964,13 +969,13 @@ make_buffer(stream_ref __stream, _Resource&& __mr, _Range&& __range, const _Env&
//! @param __env The environment providing additional configuration.
# ifdef _CCCL_DOXYGEN_INVOKED
template <class _Tp, class _Resource, class _Range, class _Env = ::cuda::std::execution::env<>>
auto make_buffer(stream_ref __stream, _Resource&& __mr, _Range&& __range, const _Env& __env = {});
_CCCL_HOST_API auto make_buffer(stream_ref __stream, _Resource&& __mr, _Range&& __range, const _Env& __env = {});
# else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv
_CCCL_TEMPLATE(class _Tp, class _Resource, class _Range, class _Env = ::cuda::std::execution::env<>)
_CCCL_REQUIRES(
::cuda::mr::synchronous_resource<::cuda::std::decay_t<_Resource>> _CCCL_AND ::cuda::mr::__has_default_queries<
::cuda::std::decay_t<_Resource>> _CCCL_AND ::cuda::std::ranges::forward_range<_Range>)
auto make_buffer(stream_ref __stream, _Resource&& __mr, _Range&& __range, const _Env& __env = {})
_CCCL_HOST_API auto make_buffer(stream_ref __stream, _Resource&& __mr, _Range&& __range, const _Env& __env = {})
{
using __buffer_type = __buffer_type_for_props<_Tp, typename ::cuda::std::decay_t<_Resource>::default_queries>;
return __buffer_type{__stream, ::cuda::std::forward<_Resource>(__mr), ::cuda::std::forward<_Range>(__range), __env};
Expand Down
89 changes: 89 additions & 0 deletions libcudacxx/include/cuda/__container/make_buffer_with_pool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// Part of libcu++, the C++ Standard Library for your entire system,
// under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef _CUDA___CONTAINER_MAKE_BUFFER_WITH_POOL_H
#define _CUDA___CONTAINER_MAKE_BUFFER_WITH_POOL_H

#include <cuda/std/detail/__config>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

#if _CCCL_HAS_CTK()

# include <cuda/__container/buffer.h>
# include <cuda/__memory_pool/device_memory_pool.h>

# if _CCCL_CTK_AT_LEAST(12, 9)
# include <cuda/__memory_pool/pinned_memory_pool.h>
# endif // _CCCL_CTK_AT_LEAST(12, 9)

# if _CCCL_CTK_AT_LEAST(13, 0)
# include <cuda/__memory_pool/managed_memory_pool.h>
# endif // _CCCL_CTK_AT_LEAST(13, 0)

# include <cuda/std/__cccl/prologue.h>

_CCCL_BEGIN_NAMESPACE_CUDA

//! @brief Creates a buffer backed by the default device memory pool.
//! @param __stream The stream used for allocation.
//! @param __device The device whose default memory pool will be used.
//! @param __args Remaining arguments forwarded to `make_buffer`.
//! @see make_buffer for the full set of supported argument combinations.
template <class _Tp, class... _Args>
_CCCL_HOST_API auto make_device_buffer(stream_ref __stream, device_ref __device, _Args&&... __args)
{
return ::cuda::make_buffer<_Tp>(
__stream, ::cuda::device_default_memory_pool(__device), ::cuda::std::forward<_Args>(__args)...);
}

# if _CCCL_CTK_AT_LEAST(12, 9)

//! @brief Creates a buffer backed by the default pinned memory pool.
//! @param __stream The stream used for allocation.
//! @param __args Remaining arguments forwarded to `make_buffer`.
//! @see make_buffer for the full set of supported argument combinations.
template <class _Tp, class... _Args>
_CCCL_HOST_API auto make_pinned_buffer(stream_ref __stream, _Args&&... __args)
{
return ::cuda::make_buffer<_Tp>(
__stream, ::cuda::pinned_default_memory_pool(), ::cuda::std::forward<_Args>(__args)...);
}

# endif // _CCCL_CTK_AT_LEAST(12, 9)

# if _CCCL_CTK_AT_LEAST(13, 0)

//! @brief Creates a buffer backed by the default managed memory pool.
//! @param __stream The stream used for allocation.
//! @param __args Remaining arguments forwarded to `make_buffer`.
//! @see make_buffer for the full set of supported argument combinations.
template <class _Tp, class... _Args>
_CCCL_HOST_API auto make_managed_buffer(stream_ref __stream, _Args&&... __args)
{
return ::cuda::make_buffer<_Tp>(
__stream, ::cuda::managed_default_memory_pool(), ::cuda::std::forward<_Args>(__args)...);
}

# endif // _CCCL_CTK_AT_LEAST(13, 0)

_CCCL_END_NAMESPACE_CUDA

# include <cuda/std/__cccl/epilogue.h>

#endif // _CCCL_HAS_CTK()

#endif // _CUDA___CONTAINER_MAKE_BUFFER_WITH_POOL_H
3 changes: 2 additions & 1 deletion libcudacxx/include/cuda/buffer
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

Expand All @@ -23,5 +23,6 @@

#include <cuda/__container/buffer.h>
#include <cuda/__container/heterogeneous_iterator.h>
#include <cuda/__container/make_buffer_with_pool.h>

#endif // _CUDA_BUFFER
Loading
Loading