Skip to content

Commit

Permalink
new type-erased memory resources (NVIDIA#2824)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler authored Dec 17, 2024
1 parent 7d057c4 commit 82cff38
Show file tree
Hide file tree
Showing 23 changed files with 1,293 additions and 450 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#endif // no system header

#include <cuda/__memory_resource/properties.h>
#include <cuda/__memory_resource/resource_ref.h>
#include <cuda/std/__memory/align.h>
#include <cuda/std/__new/launder.h>
#include <cuda/std/__type_traits/type_set.h>
Expand Down Expand Up @@ -118,7 +117,7 @@ private:
_CCCL_NODISCARD_FRIEND _CCCL_HIDE_FROM_ABI auto
__cudax_launch_transform(::cuda::stream_ref, uninitialized_async_buffer& __self) noexcept
_CCCL_TRAILING_REQUIRES(_CUDA_VSTD::span<_Tp>)(
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<mr::device_accessible, _Properties...>)
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<device_accessible, _Properties...>)
{
// TODO add auto synchronization
return {__self.__get_data(), __self.size()};
Expand All @@ -130,7 +129,7 @@ private:
_CCCL_NODISCARD_FRIEND _CCCL_HIDE_FROM_ABI auto
__cudax_launch_transform(::cuda::stream_ref, const uninitialized_async_buffer& __self) noexcept
_CCCL_TRAILING_REQUIRES(_CUDA_VSTD::span<const _Tp>)(
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<mr::device_accessible, _Properties...>)
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<device_accessible, _Properties...>)
{
// TODO add auto synchronization
return {__self.__get_data(), __self.size()};
Expand Down Expand Up @@ -287,15 +286,15 @@ public:
_CCCL_HIDE_FROM_ABI uninitialized_async_buffer __replace_allocation(const size_t __count)
{
// Create a new buffer with a reference to the stored memory resource and swap allocation information
uninitialized_async_buffer __ret{_CUDA_VMR::async_resource_ref<_Properties...>{__mr_}, __stream_, __count};
uninitialized_async_buffer __ret{async_resource_ref<_Properties...>{__mr_}, __stream_, __count};
_CUDA_VSTD::swap(__count_, __ret.__count_);
_CUDA_VSTD::swap(__buf_, __ret.__buf_);
return __ret;
}
};

template <class _Tp>
using uninitialized_async_device_buffer = uninitialized_async_buffer<_Tp, mr::device_accessible>;
using uninitialized_async_device_buffer = uninitialized_async_buffer<_Tp, device_accessible>;

} // namespace cuda::experimental

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#endif // no system header

#include <cuda/__memory_resource/properties.h>
#include <cuda/__memory_resource/resource_ref.h>
#include <cuda/std/__memory/align.h>
#include <cuda/std/__new/launder.h>
#include <cuda/std/__type_traits/type_set.h>
Expand Down Expand Up @@ -108,7 +107,7 @@ private:
_CCCL_NODISCARD_FRIEND _CCCL_HIDE_FROM_ABI auto
__cudax_launch_transform(::cuda::stream_ref, uninitialized_buffer& __self) noexcept
_CCCL_TRAILING_REQUIRES(_CUDA_VSTD::span<_Tp>)(
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<mr::device_accessible, _Properties...>)
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<device_accessible, _Properties...>)
{
return {__self.__get_data(), __self.size()};
}
Expand All @@ -119,7 +118,7 @@ private:
_CCCL_NODISCARD_FRIEND _CCCL_HIDE_FROM_ABI auto
__cudax_launch_transform(::cuda::stream_ref, const uninitialized_buffer& __self) noexcept
_CCCL_TRAILING_REQUIRES(_CUDA_VSTD::span<const _Tp>)(
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<mr::device_accessible, _Properties...>)
_CUDA_VSTD::same_as<_Tp, _Tp2>&& _CUDA_VSTD::__is_included_in_v<device_accessible, _Properties...>)
{
return {__self.__get_data(), __self.size()};
}
Expand Down Expand Up @@ -252,15 +251,15 @@ public:
_CCCL_HIDE_FROM_ABI uninitialized_buffer __replace_allocation(const size_t __count)
{
// Create a new buffer with a reference to the stored memory resource and swap allocation information
uninitialized_buffer __ret{_CUDA_VMR::resource_ref<_Properties...>{__mr_}, __count};
uninitialized_buffer __ret{resource_ref<_Properties...>{__mr_}, __count};
_CUDA_VSTD::swap(__count_, __ret.__count_);
_CUDA_VSTD::swap(__buf_, __ret.__buf_);
return __ret;
}
};

template <class _Tp>
using uninitialized_device_buffer = uninitialized_buffer<_Tp, mr::device_accessible>;
using uninitialized_device_buffer = uninitialized_buffer<_Tp, device_accessible>;

} // namespace cuda::experimental

Expand Down
Loading

0 comments on commit 82cff38

Please sign in to comment.