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

A buffer allocated in USM (Unified Shared Memory) More...

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

Public Member Functions

 DeviceBuffer (size_t sz, USMPtrHolder< target > &&_hold)
 Construct a new Device Buffer object with a given USM pointer.
 
 DeviceBuffer (size_t sz, DeviceScheduler_ptr dev_sched)
 Construct a new Device Buffer object.
 
 DeviceBuffer (sycl::buffer< T > &syclbuf, std::shared_ptr< DeviceScheduler > dev_sched)
 Construct a new Device Buffer object from a SYCL buffer.
 
 DeviceBuffer (sycl::buffer< T > &syclbuf, size_t sz, std::shared_ptr< DeviceScheduler > dev_sched)
 Construct a new Device Buffer object from a SYCL buffer with a given size.
 
 DeviceBuffer (sycl::buffer< T > &&syclbuf, std::shared_ptr< DeviceScheduler > dev_sched)
 Construct a new Device Buffer object by moving from a SYCL buffer.
 
 DeviceBuffer (sycl::buffer< T > &&syclbuf, size_t sz, std::shared_ptr< DeviceScheduler > dev_sched)
 Construct a new Device Buffer object by moving from a SYCL buffer with a given size.
 
 DeviceBuffer (const DeviceBuffer &other)=delete
 Deleted copy constructor.
 
DeviceBufferoperator= (const DeviceBuffer &other)=delete
 Deleted copy assignment operator.
 
 DeviceBuffer (DeviceBuffer &&other) noexcept
 Move constructor for DeviceBuffer.
 
DeviceBufferoperator= (DeviceBuffer &&other) noexcept
 Move assignment operator for DeviceBuffer.
 
 ~DeviceBuffer ()
 Destructor for DeviceBuffer.
 
const T * get_read_access (sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
 Get a read-only pointer to the buffer's data.
 
T * get_write_access (sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
 Get a read-write pointer to the buffer's data.
 
void complete_event_state (sycl::event e) const
 Complete the event state of the buffer.
 
void complete_event_state (const std::vector< sycl::event > &e) const
 Complete the event state of the buffer.
 
void complete_event_state (sham::EventList &e) const
 Complete the event state of the buffer.
 
void synchronize () const
 Wait for all the events associated with the buffer to be completed.
 
DeviceSchedulerget_dev_scheduler () const
 Gets the Device scheduler corresponding to the held allocation.
 
std::shared_ptr< DeviceScheduler > & get_dev_scheduler_ptr ()
 Gets the Device scheduler pointer corresponding to the held allocation.
 
const std::shared_ptr< DeviceScheduler > & get_dev_scheduler_ptr () const
 Gets the Device scheduler pointer corresponding to the held allocation.
 
DeviceQueueget_queue () const
 Gets the DeviceQueue associated with the held allocation.
 
size_t get_size () const
 Gets the number of elements in the buffer.
 
size_t get_mem_usage () const
 Gets the amount of memory used by the buffer.
 
bool is_empty () const
 Check if the buffer is empty.
 
std::vector< T > copy_to_stdvec () const
 Copy the content of the buffer to a std::vector.
 
std::vector< T > copy_to_stdvec_idx_range (size_t begin, size_t end) const
 Copies a specified range of elements from the buffer to a std::vector.
 
template<USMKindTarget dest_target>
void copy_range_offset (size_t begin, size_t end, sham::DeviceBuffer< T, dest_target > &dest, size_t dest_offset) const
 Copy a range of elements from the buffer to another buffer.
 
template<USMKindTarget dest_target>
void copy_range (size_t begin, size_t end, sham::DeviceBuffer< T, dest_target > &dest) const
 Copy a range of elements from the buffer to another buffer.
 
void copy_from_stdvec (const std::vector< T > &vec)
 Copy the content of a std::vector into the buffer.
 
void copy_from_stdvec (const std::vector< T > &vec, size_t sz)
 Copy the content of a std::vector into the buffer.
 
sycl::buffer< T > copy_to_sycl_buffer () const
 Copy the content of the buffer to a new SYCL buffer.
 
void copy_from_sycl_buffer (sycl::buffer< T > &buf)
 Copy the content of a SYCL buffer into the buffer.
 
void copy_from_sycl_buffer (sycl::buffer< T > &buf, size_t sz)
 Copy the content of a SYCL buffer into the buffer.
 
template<USMKindTarget new_target>
DeviceBuffer< T, new_target > copy_to () const
 Copy the content of the buffer to a new buffer with a different USM target.
 
template<USMKindTarget new_target>
void copy_from (const DeviceBuffer< T, new_target > &other, size_t copy_size)
 Copies the content of another buffer to this one.
 
template<USMKindTarget new_target>
void copy_from (const DeviceBuffer< T, new_target > &other)
 Copies the data from another buffer to this one.
 
DeviceBuffer< T, target > copy () const
 Copy the current buffer.
 
template<USMKindTarget mirror_target>
BufferMirror< T, mirror_target, target > mirror_to ()
 Creates a new buffer that is a mirror of the current one. Upon destruction of the mirror the changes will be propagated to the original buffer.
 
void fill (T value, std::array< size_t, 2 > idx_range)
 Fill a subpart of the buffer with a given value.
 
void fill (T value, size_t idx_count)
 Fill the first idx_count elements of the buffer with a given value.
 
void fill (T value)
 Fill the buffer with a given value.
 
template<class Fct >
void fill_lambda (Fct &&fct)
 
get_val_at_idx (size_t idx) const
 Get the value at a given index in the buffer.
 
void set_val_at_idx (size_t idx, T val)
 
size_t get_max_alloc_size () const
 
void resize (size_t new_size, bool keep_data=true)
 Resizes the buffer to a given size.
 
void resize_discard_data (size_t new_size)
 same as resize but data will not be copied if reallocation is needed
 
void free_alloc ()
 Alias for resize_discard_data(0).
 
void expand (u32 add_sz)
 Expand the buffer by add_sz elements.
 
void shrink (u32 sub_sz)
 Shrink the buffer by sub_sz elements.
 
void append (const DeviceBuffer &other)
 Append the content of another buffer to this one.
 
void reserve (size_t add_sz)
 Reserves space in the buffer for add_sz elements, but doesn't change the buffer's size.
 

Static Public Member Functions

static std::optional< size_t > get_alignment (const DeviceScheduler_ptr &dev_sched)
 Get the memory alignment of the type T in bytes.
 
static size_t alloc_request_size_fct (size_t sz, const DeviceScheduler_ptr &dev_sched)
 Convert a size in number of elements to a size in bytes.
 

Detailed Description

template<class T, USMKindTarget target = device>
class sham::DeviceBuffer< T, target >

A buffer allocated in USM (Unified Shared Memory)

Template Parameters
TThe type of the buffer's elements
targetThe USM target where the buffer is allocated (host, device, shared)

Definition at line 106 of file DeviceBuffer.hpp.

Constructor & Destructor Documentation

◆ DeviceBuffer() [1/7]

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::DeviceBuffer ( size_t  sz,
USMPtrHolder< target > &&  _hold 
)
inline

Construct a new Device Buffer object with a given USM pointer.

Parameters
szThe size of the buffer in number of elements
_holdA USMPtrHolder holding the USM pointer

This constructor is used to create a Device Buffer object with a pre-allocated USM pointer. The size of the buffer is given by the sz parameter, and the USM pointer is given by the _hold parameter. The constructor forwards the _hold parameter to the USMPtrHolder constructor.

Definition at line 173 of file DeviceBuffer.hpp.

◆ DeviceBuffer() [2/7]

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::DeviceBuffer ( size_t  sz,
DeviceScheduler_ptr  dev_sched 
)
inline

Construct a new Device Buffer object.

Parameters
szThe size of the buffer in number of elements
dev_schedA shared pointer to the Device Scheduler

This constructor creates a new Device Buffer object with the given size. It allocates the buffer as USM memory and stores the USM pointer and the size in the respective member variables. The constructor also creates a BufferEventHandler object and stores it in the events_hndl member variable.

Definition at line 189 of file DeviceBuffer.hpp.

◆ DeviceBuffer() [3/7]

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::DeviceBuffer ( sycl::buffer< T > &  syclbuf,
std::shared_ptr< DeviceScheduler dev_sched 
)
inline

Construct a new Device Buffer object from a SYCL buffer.

Parameters
syclbufThe SYCL buffer to copy from
dev_schedA shared pointer to the Device Scheduler

This constructor creates a new Device Buffer object with the same size as the given SYCL buffer. It allocates the buffer as USM memory and stores the USM pointer and the size in the respective member variables. The constructor also copies the content of the SYCL buffer into the newly allocated USM buffer.

Definition at line 208 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ DeviceBuffer() [4/7]

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::DeviceBuffer ( sycl::buffer< T > &  syclbuf,
size_t  sz,
std::shared_ptr< DeviceScheduler dev_sched 
)
inline

Construct a new Device Buffer object from a SYCL buffer with a given size.

Parameters
syclbufThe SYCL buffer to copy from
szThe size of the buffer in number of elements
dev_schedA shared pointer to the Device Scheduler

This constructor creates a new Device Buffer object with the given size. It allocates the buffer as USM memory and stores the USM pointer and the size in the respective member variables. The constructor also copies the first sz elements of the SYCL buffer into the newly allocated USM buffer.

Definition at line 226 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ DeviceBuffer() [5/7]

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::DeviceBuffer ( sycl::buffer< T > &&  syclbuf,
std::shared_ptr< DeviceScheduler dev_sched 
)
inline

Construct a new Device Buffer object by moving from a SYCL buffer.

Parameters
syclbufThe SYCL buffer to move from
dev_schedA shared pointer to the Device Scheduler

This constructor moves a SYCL buffer into a new Device Buffer object. It forwards the SYCL buffer and the device scheduler to another constructor.

Definition at line 241 of file DeviceBuffer.hpp.

◆ DeviceBuffer() [6/7]

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::DeviceBuffer ( sycl::buffer< T > &&  syclbuf,
size_t  sz,
std::shared_ptr< DeviceScheduler dev_sched 
)
inline

Construct a new Device Buffer object by moving from a SYCL buffer with a given size.

Parameters
syclbufThe SYCL buffer to move from
szThe size of the buffer in number of elements
dev_schedA shared pointer to the Device Scheduler

This constructor moves a SYCL buffer into a new Device Buffer object. It forwards the SYCL buffer and the device scheduler to another constructor. The size of the buffer is also given as a parameter.

Definition at line 256 of file DeviceBuffer.hpp.

◆ DeviceBuffer() [7/7]

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::DeviceBuffer ( DeviceBuffer< T, target > &&  other)
inlinenoexcept

Move constructor for DeviceBuffer.

This move constructor moves the USM pointer and the event handler from the other object to this object.

Definition at line 276 of file DeviceBuffer.hpp.

◆ ~DeviceBuffer()

template<class T , USMKindTarget target = device>
sham::DeviceBuffer< T, target >::~DeviceBuffer ( )
inline

Destructor for DeviceBuffer.

This destructor releases the USM pointer and event handler by transfering them back to the memory handler

Definition at line 299 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ alloc_request_size_fct()

template<class T , USMKindTarget target = device>
static size_t sham::DeviceBuffer< T, target >::alloc_request_size_fct ( size_t  sz,
const DeviceScheduler_ptr &  dev_sched 
)
inlinestatic

Convert a size in number of elements to a size in bytes.

Parameters
szThe size in number of elements
Returns
The size in bytes

Definition at line 147 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ append()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::append ( const DeviceBuffer< T, target > &  other)
inline

Append the content of another buffer to this one.

This function appends the content of another buffer to this one. The content of the other buffer is copied into this buffer, and the size of this buffer is increased by the size of the other buffer.

Parameters
otherThe buffer from which to copy the data.

Definition at line 1223 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ complete_event_state() [1/3]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::complete_event_state ( const std::vector< sycl::event > &  e) const
inline

Complete the event state of the buffer.

This function complete the event state of the buffer by registering the event resulting of the last queried access

Note
This function is const compatible.
Warning
This function must be called on ALL accessed buffers after a kernel to ensure that the state of the event handlers are up to date.
Parameters
eThe SYCL event resulting of the queried access.

Definition at line 385 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ complete_event_state() [2/3]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::complete_event_state ( sham::EventList e) const
inline

Complete the event state of the buffer.

This function complete the event state of the buffer by registering the event resulting of the last queried access

Note
This function is const compatible.
Warning
This function must be called on ALL accessed buffers after a kernel to ensure that the state of the event handlers are up to date.
Parameters
eThe SYCL event resulting of the queried access.

Definition at line 402 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ complete_event_state() [3/3]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::complete_event_state ( sycl::event  e) const
inline

Complete the event state of the buffer.

This function complete the event state of the buffer by registering the event resulting of the last queried access

Note
This function is const compatible.
Warning
This function must be called on ALL accessed buffers after a kernel to ensure that the state of the event handlers are up to date.
Parameters
eThe SYCL event resulting of the queried access.

Definition at line 368 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy()

template<class T , USMKindTarget target = device>
DeviceBuffer< T, target > sham::DeviceBuffer< T, target >::copy ( ) const
inline

Copy the current buffer.

This function creates a new buffer of the same type and size as the current one, and copies the content of the current buffer to the new one.

Returns
The new buffer.

Definition at line 913 of file DeviceBuffer.hpp.

◆ copy_from() [1/2]

template<class T , USMKindTarget target = device>
template<USMKindTarget new_target>
void sham::DeviceBuffer< T, target >::copy_from ( const DeviceBuffer< T, new_target > &  other)
inline

Copies the data from another buffer to this one.

This function copies the data from another buffer to this one. The two buffers must have the same size.

Parameters
otherThe buffer from which to copy the data

Definition at line 892 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_from() [2/2]

template<class T , USMKindTarget target = device>
template<USMKindTarget new_target>
void sham::DeviceBuffer< T, target >::copy_from ( const DeviceBuffer< T, new_target > &  other,
size_t  copy_size 
)
inline

Copies the content of another buffer to this one.

This function copies the content of another buffer to this one. The two buffers must have the same size, and the size of the copy must be smaller than the size of the buffer involved.

Parameters
otherThe buffer from which to copy the data
copy_sizeThe size of the copy

Definition at line 859 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_from_stdvec() [1/2]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::copy_from_stdvec ( const std::vector< T > &  vec)
inline

Copy the content of a std::vector into the buffer.

This function copies the content of a given std::vector into the buffer. The size of the vector must be equal to the size of the buffer.

Parameters
vecThe std::vector to copy from

Definition at line 666 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_from_stdvec() [2/2]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::copy_from_stdvec ( const std::vector< T > &  vec,
size_t  sz 
)
inline

Copy the content of a std::vector into the buffer.

This function copies the content of a given std::vector into the buffer. The size of the vector must be equal to the size of the buffer.

Parameters
vecThe std::vector to copy from
szThe number of elements to copy

Definition at line 696 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_from_sycl_buffer() [1/2]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::copy_from_sycl_buffer ( sycl::buffer< T > &  buf)
inline

Copy the content of a SYCL buffer into the buffer.

This function copies the content of a given SYCL buffer into the buffer. The size of the SYCL buffer must be equal to the size of the buffer.

Parameters
bufThe SYCL buffer to copy from

Definition at line 755 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_from_sycl_buffer() [2/2]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::copy_from_sycl_buffer ( sycl::buffer< T > &  buf,
size_t  sz 
)
inline

Copy the content of a SYCL buffer into the buffer.

This function copies the content of a given SYCL buffer into the buffer. The size of the SYCL buffer must be equal to the size of the buffer.

Parameters
bufThe SYCL buffer to copy from
szThe number of elements to copy

Definition at line 788 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_range()

template<class T , USMKindTarget target = device>
template<USMKindTarget dest_target>
void sham::DeviceBuffer< T, target >::copy_range ( size_t  begin,
size_t  end,
sham::DeviceBuffer< T, dest_target > &  dest 
) const
inline

Copy a range of elements from the buffer to another buffer.

This function copies a range of elements from the buffer to another buffer. The range is specified by the begin and end indices.

Parameters
beginThe starting index of the range to copy, inclusive.
endThe ending index of the range to copy, exclusive.
destThe destination buffer to copy to.

Definition at line 652 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_range_offset()

template<class T , USMKindTarget target = device>
template<USMKindTarget dest_target>
void sham::DeviceBuffer< T, target >::copy_range_offset ( size_t  begin,
size_t  end,
sham::DeviceBuffer< T, dest_target > &  dest,
size_t  dest_offset 
) const
inline

Copy a range of elements from the buffer to another buffer.

This function copies a range of elements from the buffer to another buffer. The range is specified by the begin and end indices.

Parameters
beginThe starting index of the range to copy, inclusive.
endThe ending index of the range to copy, exclusive.
destThe destination buffer to copy to.

Definition at line 583 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_to()

template<class T , USMKindTarget target = device>
template<USMKindTarget new_target>
DeviceBuffer< T, new_target > sham::DeviceBuffer< T, target >::copy_to ( ) const
inline

Copy the content of the buffer to a new buffer with a different USM target.

This function creates a new buffer with the same size and content than the current one but with a different USM target. The new buffer is returned.

Returns
The new buffer

Definition at line 830 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_to_stdvec()

template<class T , USMKindTarget target = device>
std::vector< T > sham::DeviceBuffer< T, target >::copy_to_stdvec ( ) const
inline

Copy the content of the buffer to a std::vector.

This function creates a new std::vector with the same size and content than the current one and returns it.

Returns
The new std::vector

Definition at line 510 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_to_stdvec_idx_range()

template<class T , USMKindTarget target = device>
std::vector< T > sham::DeviceBuffer< T, target >::copy_to_stdvec_idx_range ( size_t  begin,
size_t  end 
) const
inline

Copies a specified range of elements from the buffer to a std::vector.

This function creates a new std::vector containing elements from the buffer within the specified index range [begin, end). The function ensures that the indices are valid and throws an exception if they are not.

Parameters
beginThe starting index of the range to copy, inclusive.
endThe ending index of the range to copy, exclusive.
Returns
A std::vector containing the elements from the specified range.
Exceptions
std::invalid_argumentif the end index is greater than the buffer size or if the begin index is greater than or equal to the end index.

Definition at line 540 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ copy_to_sycl_buffer()

template<class T , USMKindTarget target = device>
sycl::buffer< T > sham::DeviceBuffer< T, target >::copy_to_sycl_buffer ( ) const
inline

Copy the content of the buffer to a new SYCL buffer.

This function creates a new SYCL buffer with the same size and content than the current one and returns it.

Returns
The new SYCL buffer

Definition at line 726 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ expand()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::expand ( u32  add_sz)
inline

Expand the buffer by add_sz elements.

This functions reserves space in the buffer for add_sz elements, but doesn't change the buffer's size.

Parameters
add_szThe number of elements to add to the buffer.

Definition at line 1194 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ fill() [1/3]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::fill ( value)
inline

Fill the buffer with a given value.

This function fills the buffer with the given value. The function returns immediately, and the filling operation is executed asynchronously.

Parameters
valueThe value to fill the buffer with.

Definition at line 997 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ fill() [2/3]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::fill ( value,
size_t  idx_count 
)
inline

Fill the first idx_count elements of the buffer with a given value.

This function fills the first idx_count elements of the buffer with the given value. The function returns immediately, and the filling operation is executed asynchronously.

Parameters
valueThe value to fill the buffer with
idx_countThe number of elements to fill

Definition at line 986 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ fill() [3/3]

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::fill ( value,
std::array< size_t, 2 >  idx_range 
)
inline

Fill a subpart of the buffer with a given value.

This function fills a subpart of the buffer with a given value. The subpart is defined by a range of indices, given as a pair [start_index,idx_count]. The start index is the first index of the range, and the count is the number of elements to fill.

The function checks that the range of indices is valid, i.e. that start_index + idx_count <= get_size().

Parameters
valueThe value to fill the buffer with
idx_rangeThe range of indices to fill, given as a pair [start_index,idx_count].

Definition at line 951 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ fill_lambda()

template<class T , USMKindTarget target = device>
template<class Fct >
void sham::DeviceBuffer< T, target >::fill_lambda ( Fct &&  fct)
inline

Definition at line 1000 of file DeviceBuffer.hpp.

◆ free_alloc()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::free_alloc ( )
inline

Alias for resize_discard_data(0).

Definition at line 1184 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ get_alignment()

template<class T , USMKindTarget target = device>
static std::optional< size_t > sham::DeviceBuffer< T, target >::get_alignment ( const DeviceScheduler_ptr &  dev_sched)
inlinestatic

Get the memory alignment of the type T in bytes.

Returns
The memory alignment of the type T in bytes

Definition at line 130 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ get_dev_scheduler()

template<class T , USMKindTarget target = device>
DeviceScheduler & sham::DeviceBuffer< T, target >::get_dev_scheduler ( ) const
inline

Gets the Device scheduler corresponding to the held allocation.

Returns
The Device scheduler

Definition at line 430 of file DeviceBuffer.hpp.

◆ get_dev_scheduler_ptr() [1/2]

template<class T , USMKindTarget target = device>
std::shared_ptr< DeviceScheduler > & sham::DeviceBuffer< T, target >::get_dev_scheduler_ptr ( )
inline

Gets the Device scheduler pointer corresponding to the held allocation.

Returns
The Device scheduler pointer corresponding to the held allocation

Definition at line 439 of file DeviceBuffer.hpp.

◆ get_dev_scheduler_ptr() [2/2]

template<class T , USMKindTarget target = device>
const std::shared_ptr< DeviceScheduler > & sham::DeviceBuffer< T, target >::get_dev_scheduler_ptr ( ) const
inline

Gets the Device scheduler pointer corresponding to the held allocation.

Returns
The Device scheduler pointer corresponding to the held allocation

Definition at line 448 of file DeviceBuffer.hpp.

◆ get_max_alloc_size()

template<class T , USMKindTarget target = device>
size_t sham::DeviceBuffer< T, target >::get_max_alloc_size ( ) const
inline

Definition at line 1080 of file DeviceBuffer.hpp.

◆ get_mem_usage()

template<class T , USMKindTarget target = device>
size_t sham::DeviceBuffer< T, target >::get_mem_usage ( ) const
inline

Gets the amount of memory used by the buffer.

Returns
The amount of memory used by the buffer

Definition at line 483 of file DeviceBuffer.hpp.

◆ get_queue()

template<class T , USMKindTarget target = device>
DeviceQueue & sham::DeviceBuffer< T, target >::get_queue ( ) const
inline

Gets the DeviceQueue associated with the held allocation.

Returns
The DeviceQueue associated with the held allocation

Definition at line 457 of file DeviceBuffer.hpp.

◆ get_read_access()

template<class T , USMKindTarget target = device>
const T * sham::DeviceBuffer< T, target >::get_read_access ( sham::EventList depends_list,
SourceLocation  src_loc = SourceLocation{} 
) const
inline

Get a read-only pointer to the buffer's data.

This function returns a const pointer to the buffer's data. The pointer is locked for reading and the event handler is updated to reflect the read access.

Parameters
depends_listA vector of SYCL events to wait for before accessing the buffer.
Returns
A const pointer to the buffer's data.

Definition at line 331 of file DeviceBuffer.hpp.

◆ get_size()

template<class T , USMKindTarget target = device>
size_t sham::DeviceBuffer< T, target >::get_size ( ) const
inline

Gets the number of elements in the buffer.

Returns
The number of elements in the buffer

Definition at line 476 of file DeviceBuffer.hpp.

◆ get_val_at_idx()

template<class T , USMKindTarget target = device>
T sham::DeviceBuffer< T, target >::get_val_at_idx ( size_t  idx) const
inline

Get the value at a given index in the buffer.

This function returns the value at the given index in the buffer.

Parameters
idxThe index of the value to retrieve
Returns
The value at the given index

Definition at line 1032 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ get_write_access()

template<class T , USMKindTarget target = device>
T * sham::DeviceBuffer< T, target >::get_write_access ( sham::EventList depends_list,
SourceLocation  src_loc = SourceLocation{} 
)
inline

Get a read-write pointer to the buffer's data.

This function returns a pointer to the buffer's data. The event handler is updated to reflect the write access.

Todo:
should be made const also ???
Parameters
depends_listA vector of SYCL events to wait for before accessing the buffer.
Returns
A pointer to the buffer's data.

Definition at line 349 of file DeviceBuffer.hpp.

◆ is_empty()

template<class T , USMKindTarget target = device>
bool sham::DeviceBuffer< T, target >::is_empty ( ) const
inline

Check if the buffer is empty.

Returns
true if the buffer is empty, false otherwise

Definition at line 490 of file DeviceBuffer.hpp.

◆ mirror_to()

template<class T , USMKindTarget target = device>
template<USMKindTarget mirror_target>
BufferMirror< T, mirror_target, target > sham::DeviceBuffer< T, target >::mirror_to ( )
inline

Creates a new buffer that is a mirror of the current one. Upon destruction of the mirror the changes will be propagated to the original buffer.

Returns
The mirror buffer

Definition at line 922 of file DeviceBuffer.hpp.

◆ operator=()

template<class T , USMKindTarget target = device>
DeviceBuffer & sham::DeviceBuffer< T, target >::operator= ( DeviceBuffer< T, target > &&  other)
inlinenoexcept

Move assignment operator for DeviceBuffer.

This move assignment operator moves the USM pointer and the event handler from the other object to this object.

Definition at line 286 of file DeviceBuffer.hpp.

◆ reserve()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::reserve ( size_t  add_sz)
inline

Reserves space in the buffer for add_sz elements, but doesn't change the buffer's size.

This function is useful when you know you'll need to add add_sz elements to the buffer, but you don't want to resize the buffer just yet. After calling this function, you can add add_sz elements to the buffer without triggering a resize.

Parameters
add_szThe number of elements to reserve space for.

Definition at line 1263 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ resize()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::resize ( size_t  new_size,
bool  keep_data = true 
)
inline

Resizes the buffer to a given size.

Parameters
new_sizeThe new size of the buffer.
keep_dataIf true, the content of the buffer is preserved up to the minimum of the old and new sizes. If false, the content may be discarded if a reallocation occurs.

Definition at line 1103 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ resize_discard_data()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::resize_discard_data ( size_t  new_size)
inline

same as resize but data will not be copied if reallocation is needed

Definition at line 1179 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ set_val_at_idx()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::set_val_at_idx ( size_t  idx,
val 
)
inline

Definition at line 1053 of file DeviceBuffer.hpp.

◆ shrink()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::shrink ( u32  sub_sz)
inline

Shrink the buffer by sub_sz elements.

If sub_sz is greater than the current size of the buffer, this function will throw an std::invalid_argument.

Parameters
sub_szThe number of elements to remove from the buffer.

Definition at line 1204 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

◆ synchronize()

template<class T , USMKindTarget target = device>
void sham::DeviceBuffer< T, target >::synchronize ( ) const
inline

Wait for all the events associated with the buffer to be completed.

This function waits for all the events associated with the buffer to be completed. The events are associated with the buffer by calling complete_event_state.

Definition at line 413 of file DeviceBuffer.hpp.

+ Here is the call graph for this function:

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