alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment > Struct Template Reference

Life time managed buffer with contiguous data. More...

#include <SharedBuffer.hpp>

Inheritance diagram for alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >:

Public Member Functions

 SharedBuffer (SharedBuffer &&)=default
 SharedBuffer (SharedBuffer const &)=default
template<typename T_Type_Other>
 SharedBuffer (SharedBuffer< T_Api, T_Type_Other, T_Extents, T_MemAlignment > &&other)
template<typename T_Type_Other>
 SharedBuffer (SharedBuffer< T_Api, T_Type_Other, T_Extents, T_MemAlignment > const &other)
template<alpaka::concepts::HasApi T_Any, alpaka::concepts::Vector T_UserExtents, alpaka::concepts::Vector T_UserPitches>
 SharedBuffer (T_Any const &any, T_Type *data, T_UserExtents const &extents, T_UserPitches const &pitches, std::invocable<> auto deleter, T_MemAlignment const memAlignment=Alignment{})
void addDestructorAction (std::function< void()> &&action)
 Adds a destructor action to the shared buffer.
void destructorWaitFor (auto const &any)
 Add an action to be executed when the shared_ptr is destroyed.
auto getConstSharedBuffer () const
 create a read shared buffer view
auto getSubSharedBuffer (alpaka::concepts::VectorOrScalar auto const &extents)
auto getSubSharedBuffer (alpaka::concepts::VectorOrScalar auto const &extents) const
 Creates a buffer pointing to a part of the memory.
auto getSubSharedBuffer (alpaka::concepts::VectorOrScalar auto const &offsets, alpaka::concepts::VectorOrScalar auto const &extents)
auto getSubSharedBuffer (alpaka::concepts::VectorOrScalar auto const &offsets, alpaka::concepts::VectorOrScalar auto const &extents) const
 Creates a shared sub-buffer view to a part of the memory.
constexpr long getUseCount () const noexcept
 Return the number of SharedBuffers which points to the same memory.
auto getView ()
auto getView () const
void keepAlive (auto &queue)
 Keep the buffer alive until at least the current spot in the queue, even if it runs out of scope.
constexpr operator bool () const noexcept
 True if SharedBuffer is pointing to valid memory.
SharedBufferoperator= (SharedBuffer &&)=default
SharedBufferoperator= (SharedBuffer const &otherSharedBuffer)=default
 Assignment operator keeping const-ness.
Public Member Functions inherited from alpaka::View< T_Api, T_Type, T_Extents, Alignment<> >
constexpr View (T_Any const &any, T_Type *data, T_UserExtents const &extents, T_UserPitches const &pitches, T_MemAlignment const memAlignment=T_MemAlignment{})
 Creates a view.
constexpr auto getConstView () const
 create a read only view
constexpr alpaka::concepts::IMdSpan auto getMdSpan () const
constexpr Viewoperator= (View const &)=default
 Assignment operator keeping const-ness.
constexpr auto getSubView (alpaka::concepts::VectorOrScalar auto const &extents) const
 Creates a sub view to a part of the memory.
Public Member Functions inherited from alpaka::MdSpan< T_Type, T_Extents::UniVec, T_Extents::UniVec, T_MemAlignment >
constexpr MdSpan ()=default
constexpr auto begin () const
constexpr auto cbegin () const
constexpr auto cend () const
constexpr const_pointer data () const
 get origin pointer
constexpr auto end () const
constexpr auto getConstMdSpan () const
constexpr auto getExtents () const
constexpr T_Pitches getPitches () const
constexpr operator bool () const noexcept
 True if MdSpan is pointing to valid memory.
constexpr const_reference operator* () const
 return value the origin pointer is pointing to
constexpr MdSpanoperator= (MdSpan const &)=default
 Assignment operator keeping const-ness.
constexpr const_reference operator[] (concepts::IndexVec< index_type, alpaka::trait::GetDim< T_Extents >::value > auto const &idx) const
 get value at the given index

Private Types

using BaseView = View<T_Api, T_Type, T_Extents, T_MemAlignment>
template<alpaka::concepts::Pointer T>
using ConstPtr_t = std::add_pointer_t<std::add_const_t<std::remove_pointer_t<T>>>

Private Member Functions

 SharedBuffer (T_Api const api, T_Type *data, T_Extents const &extents, T_Extents const &pitches, std::shared_ptr< internal::ManagedDealloc > managedDeleter, T_MemAlignment const memAlignment)
 Constructor with existing managed deleter.

Private Attributes

std::shared_ptr< internal::ManagedDeallocm_deleter

Friends

template<alpaka::concepts::Api T_OtherApi, typename T_OtherType, alpaka::concepts::Vector T_OtherExtents, alpaka::concepts::Alignment T_OtherMemAlignment2>
struct SharedBuffer
template<alpaka::concepts::Api T_OtherApi, typename T_OtherType, alpaka::concepts::Vector T_OtherExtents, alpaka::concepts::Alignment T_OtherMemAlignment2>
std::ostream & operator<< (std::ostream &s, SharedBuffer< T_OtherApi, T_OtherType, T_OtherExtents, T_OtherMemAlignment2 > const &buffer)

Additional Inherited Members

Public Types inherited from alpaka::MdSpan< T_Type, T_Extents::UniVec, T_Extents::UniVec, T_MemAlignment >
using const_pointer
using const_reference
using ConstThis
using index_type
using pointer
using reference
using value_type
Static Public Member Functions inherited from alpaka::View< T_Api, T_Type, T_Extents, Alignment<> >
static consteval T_Api getApi ()
Static Public Member Functions inherited from alpaka::MdSpan< T_Type, T_Extents::UniVec, T_Extents::UniVec, T_MemAlignment >
static consteval uint32_t dim ()
static constexpr auto getAlignment ()
Protected Member Functions inherited from alpaka::MdSpan< T_Type, T_Extents::UniVec, T_Extents::UniVec, T_MemAlignment >
constexpr auto ptr (concepts::Vector auto const &idx) const
 get the pointer of the value relative to the origin pointer m_ptr

Detailed Description

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
struct alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >

Life time managed buffer with contiguous data.

This buffer owns the data and will deallocate it when last copy is destroyed. Const-ness of the buffer instance is propagated to the data region. A copy of this instance will only perform a shallow copy, to perform a deep copy to duplicate the data you should use onHost::memcpy.

Definition at line 39 of file SharedBuffer.hpp.

Member Typedef Documentation

◆ BaseView

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
using alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::BaseView = View<T_Api, T_Type, T_Extents, T_MemAlignment>
private

Definition at line 42 of file SharedBuffer.hpp.

◆ ConstPtr_t

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
using alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::ConstPtr_t = std::add_pointer_t<std::add_const_t<std::remove_pointer_t<T>>>
private
Todo
move this to traits or somewhere else that it can be used everywhere

Definition at line 276 of file SharedBuffer.hpp.

Constructor & Destructor Documentation

◆ SharedBuffer() [1/6]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::SharedBuffer ( T_Api const api,
T_Type * data,
T_Extents const & extents,
T_Extents const & pitches,
std::shared_ptr< internal::ManagedDealloc > managedDeleter,
T_MemAlignment const memAlignment )
inlineprivate

Constructor with existing managed deleter.

Definition at line 45 of file SharedBuffer.hpp.

◆ SharedBuffer() [2/6]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
template<alpaka::concepts::HasApi T_Any, alpaka::concepts::Vector T_UserExtents, alpaka::concepts::Vector T_UserPitches>
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::SharedBuffer ( T_Any const & any,
T_Type * data,
T_UserExtents const & extents,
T_UserPitches const & pitches,
std::invocable<> auto deleter,
T_MemAlignment const memAlignment = Alignment{} )
inline

Definition at line 79 of file SharedBuffer.hpp.

◆ SharedBuffer() [3/6]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
template<typename T_Type_Other>
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::SharedBuffer ( SharedBuffer< T_Api, T_Type_Other, T_Extents, T_MemAlignment > const & other)
inline

Definition at line 96 of file SharedBuffer.hpp.

◆ SharedBuffer() [4/6]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::SharedBuffer ( SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment > const & )
default

◆ SharedBuffer() [5/6]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
template<typename T_Type_Other>
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::SharedBuffer ( SharedBuffer< T_Api, T_Type_Other, T_Extents, T_MemAlignment > && other)
inline

Definition at line 112 of file SharedBuffer.hpp.

◆ SharedBuffer() [6/6]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::SharedBuffer ( SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment > && )
default

Member Function Documentation

◆ addDestructorAction()

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
void alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::addDestructorAction ( std::function< void()> && action)
inline

Adds a destructor action to the shared buffer.

The action will be executed when the buffer is destroyed. This can be used to add additional cleanup actions e.g. waiting on a specific queue. Actions are executed in FIFO order.

Parameters
actioncallable to execute on destruction

Definition at line 226 of file SharedBuffer.hpp.

◆ destructorWaitFor()

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
void alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::destructorWaitFor ( auto const & any)
inline

Add an action to be executed when the shared_ptr is destroyed.

Parameters
actionCallable to execute on destruction.

Definition at line 235 of file SharedBuffer.hpp.

◆ getConstSharedBuffer()

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
auto alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getConstSharedBuffer ( ) const
inline

create a read shared buffer view

Definition at line 134 of file SharedBuffer.hpp.

◆ getSubSharedBuffer() [1/4]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
auto alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getSubSharedBuffer ( alpaka::concepts::VectorOrScalar auto const & extents)
inline

Definition at line 164 of file SharedBuffer.hpp.

◆ getSubSharedBuffer() [2/4]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
auto alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getSubSharedBuffer ( alpaka::concepts::VectorOrScalar auto const & extents) const
inline

Creates a buffer pointing to a part of the memory.

Parameters
extentsnumber of elements for each dimension
Returns
shared buffer which is pointing only to a part of the original buffer.

Definition at line 151 of file SharedBuffer.hpp.

◆ getSubSharedBuffer() [3/4]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
auto alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getSubSharedBuffer ( alpaka::concepts::VectorOrScalar auto const & offsets,
alpaka::concepts::VectorOrScalar auto const & extents )
inline

Definition at line 201 of file SharedBuffer.hpp.

◆ getSubSharedBuffer() [4/4]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
auto alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getSubSharedBuffer ( alpaka::concepts::VectorOrScalar auto const & offsets,
alpaka::concepts::VectorOrScalar auto const & extents ) const
inline

Creates a shared sub-buffer view to a part of the memory.

Parameters
offsetsoffset in elements to the original buffer
extentsnumber of elements for each dimension
Returns
Buffer which is pointing only to a part of the original buffer with a shifted origin pointer. Buffer which pointThe alignment of the sub view is reduced to the element alignment.

Definition at line 184 of file SharedBuffer.hpp.

◆ getUseCount()

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
long alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getUseCount ( ) const
inlinenodiscardconstexprnoexcept

Return the number of SharedBuffers which points to the same memory.

Definition at line 262 of file SharedBuffer.hpp.

◆ getView() [1/2]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
auto alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getView ( )
inline

Definition at line 128 of file SharedBuffer.hpp.

◆ getView() [2/2]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
auto alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::getView ( ) const
inline

Definition at line 123 of file SharedBuffer.hpp.

◆ keepAlive()

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
void alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::keepAlive ( auto & queue)
inline

Keep the buffer alive until at least the current spot in the queue, even if it runs out of scope.

This ensures that the buffer is and stays valid in previously enqueued kernels. There is no guarantee that the buffer is deleted immediately when the last reference to it is deleted.

This differs from destructorWaitFor, because that function waits, while keepAlive does not block anything, it just extends lifetime.

Attention
Do not apply this function to a buffer allocated with alpaka::onHost::allocDeferred, see https://github.com/alpaka-group/alpaka3/issues/394
Parameters
queueThe queue to enqueue to.

Definition at line 252 of file SharedBuffer.hpp.

◆ operator bool()

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::operator bool ( ) const
inlineexplicitnodiscardconstexprnoexcept

True if SharedBuffer is pointing to valid memory.

Definition at line 268 of file SharedBuffer.hpp.

◆ operator=() [1/2]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
SharedBuffer & alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::operator= ( SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment > && )
default

◆ operator=() [2/2]

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
SharedBuffer & alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::operator= ( SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment > const & otherSharedBuffer)
default

Assignment operator keeping const-ness.

Attention
the assign operator is not removing inner const-ness because the type signature is not changed.

◆ SharedBuffer

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
template<alpaka::concepts::Api T_OtherApi, typename T_OtherType, alpaka::concepts::Vector T_OtherExtents, alpaka::concepts::Alignment T_OtherMemAlignment2>
friend struct SharedBuffer
friend

Definition at line 63 of file SharedBuffer.hpp.

◆ operator<<

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
template<alpaka::concepts::Api T_OtherApi, typename T_OtherType, alpaka::concepts::Vector T_OtherExtents, alpaka::concepts::Alignment T_OtherMemAlignment2>
std::ostream & operator<< ( std::ostream & s,
SharedBuffer< T_OtherApi, T_OtherType, T_OtherExtents, T_OtherMemAlignment2 > const & buffer )
friend

Member Data Documentation

◆ m_deleter

template<alpaka::concepts::Api T_Api, typename T_Type, alpaka::concepts::Vector T_Extents, alpaka::concepts::Alignment T_MemAlignment = Alignment<>>
std::shared_ptr<internal::ManagedDealloc> alpaka::onHost::SharedBuffer< T_Api, T_Type, T_Extents, T_MemAlignment >::m_deleter
private

Definition at line 278 of file SharedBuffer.hpp.


The documentation for this struct was generated from the following file: