Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
sham::USMPtrHolder< target > Class Template Reference

Class for holding a USM pointer. More...

#include <shambackends/include/shambackends/USMPtrHolder.hpp>

Public Member Functions

void free_ptr ()
 Free the held pointer.
 
 ~USMPtrHolder ()
 USM pointer holder destructor.
 
 USMPtrHolder (const USMPtrHolder &other)=delete
 Deleted copy constructor.
 
 USMPtrHolder (USMPtrHolder &&other) noexcept
 Move constructor.
 
USMPtrHolderoperator= (const USMPtrHolder &other)=delete
 Deleted copy assignment operator.
 
USMPtrHolderoperator= (USMPtrHolder &&other) noexcept
 Move assignment operator.
 
template<class T >
T * ptr_cast () const
 Cast the USM pointer to the given type.
 
void * get_raw_ptr () const
 Get the raw pointer of the USM allocation.
 
size_t get_bytesize () const
 Get the size of the USM allocation (in byte)
 
DeviceSchedulerget_dev_scheduler () const
 Get the SYCL context used for allocation/freeing the USM buffer.
 
std::shared_ptr< DeviceScheduler > & get_dev_scheduler_ptr ()
 Get the SYCL context used for allocation/freeing the USM buffer.
 
const std::shared_ptr< DeviceScheduler > & get_dev_scheduler_ptr () const
 Get the SYCL context used for allocation/freeing the USM buffer.
 

Static Public Member Functions

static USMPtrHolder create (size_t sz, std::shared_ptr< DeviceScheduler > dev_sched, std::optional< size_t > alignment=std::nullopt)
 Create a USM pointer holder.
 
static USMPtrHolder create_nullptr (std::shared_ptr< DeviceScheduler > dev_sched)
 

Detailed Description

template<USMKindTarget target>
class sham::USMPtrHolder< target >

Class for holding a USM pointer.

This class is a simple RAII wrapper around a USM (Unified Shared Memory) pointer. It is a move-only class that manages the lifetime of the USM buffer.

The USM buffer can be either a device, shared or host buffer, depending on the template parameter target.

The move constructor and move assignment operator are deleted to prevent accidental copies of the class.

Definition at line 59 of file USMPtrHolder.hpp.

Constructor & Destructor Documentation

◆ ~USMPtrHolder()

template<USMKindTarget target>
sham::USMPtrHolder< target >::~USMPtrHolder ( )

USM pointer holder destructor.

Frees the USM pointer if not equall to nullptr

Definition at line 55 of file USMPtrHolder.cpp.

◆ USMPtrHolder()

template<USMKindTarget target>
sham::USMPtrHolder< target >::USMPtrHolder ( USMPtrHolder< target > &&  other)
inlinenoexcept

Move constructor.

Moves the contents of the other USMPtrHolder into this one, leaving the other one with a nullptr USM pointer, which disable the destructor.

Parameters
otherThe USMPtrHolder to be moved from

Definition at line 112 of file USMPtrHolder.hpp.

Member Function Documentation

◆ create()

template<USMKindTarget target>
USMPtrHolder< target > sham::USMPtrHolder< target >::create ( size_t  sz,
std::shared_ptr< DeviceScheduler dev_sched,
std::optional< size_t >  alignment = std::nullopt 
)
static

Create a USM pointer holder.

Allocate a USM buffer of the given size using the provided SYCL queue. The USM buffer can be either a device, shared or host buffer, depending on the template parameter target.

Parameters
szThe size of the USM buffer to be allocated
dev_schedThe Device Scheduler used to allocate/free the USM buffer
alignmentThe alignment of the USM buffer (optional)
Returns
A USMPtrHolder instance wrapping the allocated USM buffer

Definition at line 25 of file USMPtrHolder.cpp.

◆ create_nullptr()

template<USMKindTarget target>
USMPtrHolder< target > sham::USMPtrHolder< target >::create_nullptr ( std::shared_ptr< DeviceScheduler dev_sched)
static

Definition at line 36 of file USMPtrHolder.cpp.

◆ free_ptr()

template<USMKindTarget target>
void sham::USMPtrHolder< target >::free_ptr ( )

Free the held pointer.

Definition at line 47 of file USMPtrHolder.cpp.

◆ get_bytesize()

template<USMKindTarget target>
size_t sham::USMPtrHolder< target >::get_bytesize ( ) const
inline

Get the size of the USM allocation (in byte)

Returns
The size of the USM allocation (in byte)

Definition at line 167 of file USMPtrHolder.hpp.

◆ get_dev_scheduler()

template<USMKindTarget target>
DeviceScheduler & sham::USMPtrHolder< target >::get_dev_scheduler ( ) const
inline

Get the SYCL context used for allocation/freeing the USM buffer.

Returns
The SYCL context used for allocation/freeing the USM buffer

Definition at line 174 of file USMPtrHolder.hpp.

◆ get_dev_scheduler_ptr() [1/2]

template<USMKindTarget target>
std::shared_ptr< DeviceScheduler > & sham::USMPtrHolder< target >::get_dev_scheduler_ptr ( )
inline

Get the SYCL context used for allocation/freeing the USM buffer.

Returns
The SYCL context used for allocation/freeing the USM buffer

Definition at line 181 of file USMPtrHolder.hpp.

◆ get_dev_scheduler_ptr() [2/2]

template<USMKindTarget target>
const std::shared_ptr< DeviceScheduler > & sham::USMPtrHolder< target >::get_dev_scheduler_ptr ( ) const
inline

Get the SYCL context used for allocation/freeing the USM buffer.

Returns
The SYCL context used for allocation/freeing the USM buffer

Definition at line 190 of file USMPtrHolder.hpp.

◆ get_raw_ptr()

template<USMKindTarget target>
void * sham::USMPtrHolder< target >::get_raw_ptr ( ) const
inline

Get the raw pointer of the USM allocation.

This method returns the raw pointer to the USM allocation. The caller must be careful with the type and the usage of the returned pointer.

Returns
The raw pointer of the USM allocation

Definition at line 160 of file USMPtrHolder.hpp.

◆ operator=()

template<USMKindTarget target>
USMPtrHolder & sham::USMPtrHolder< target >::operator= ( USMPtrHolder< target > &&  other)
inlinenoexcept

Move assignment operator.

Moves the contents of the other USMPtrHolder into this one, leaving the other one in a valid but unspecified state. The other USMPtrHolder will not free the USM buffer on destruction.

Parameters
otherThe USMPtrHolder to be moved from

Definition at line 130 of file USMPtrHolder.hpp.

◆ ptr_cast()

template<USMKindTarget target>
template<class T >
T * sham::USMPtrHolder< target >::ptr_cast ( ) const
inline

Cast the USM pointer to the given type.

Template Parameters
TThe type to cast the USM buffer pointer to
Returns
The casted USM pointer

Definition at line 144 of file USMPtrHolder.hpp.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: