![]() |
Shamrock 2025.10.0
Astrophysical Code
|
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. | |
| DeviceBuffer & | operator= (const DeviceBuffer &other)=delete |
| Deleted copy assignment operator. | |
| DeviceBuffer (DeviceBuffer &&other) noexcept | |
| Move constructor for DeviceBuffer. | |
| DeviceBuffer & | operator= (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. | |
| DeviceScheduler & | get_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. | |
| DeviceQueue & | get_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) |
| T | 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. | |
A buffer allocated in USM (Unified Shared Memory)
| T | The type of the buffer's elements |
| target | The USM target where the buffer is allocated (host, device, shared) |
Definition at line 106 of file DeviceBuffer.hpp.
|
inline |
Construct a new Device Buffer object with a given USM pointer.
| sz | The size of the buffer in number of elements |
| _hold | A 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.
|
inline |
Construct a new Device Buffer object.
| sz | The size of the buffer in number of elements |
| dev_sched | A 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.
|
inline |
Construct a new Device Buffer object from a SYCL buffer.
| syclbuf | The SYCL buffer to copy from |
| dev_sched | A 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:
|
inline |
Construct a new Device Buffer object from a SYCL buffer with a given size.
| syclbuf | The SYCL buffer to copy from |
| sz | The size of the buffer in number of elements |
| dev_sched | A 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:
|
inline |
Construct a new Device Buffer object by moving from a SYCL buffer.
| syclbuf | The SYCL buffer to move from |
| dev_sched | A 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.
|
inline |
Construct a new Device Buffer object by moving from a SYCL buffer with a given size.
| syclbuf | The SYCL buffer to move from |
| sz | The size of the buffer in number of elements |
| dev_sched | A 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.
|
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.
|
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:
|
inlinestatic |
Convert a size in number of elements to a size in bytes.
| sz | The size in number of elements |
Definition at line 147 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| other | The buffer from which to copy the data. |
Definition at line 1223 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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
| e | The SYCL event resulting of the queried access. |
Definition at line 385 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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
| e | The SYCL event resulting of the queried access. |
Definition at line 402 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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
| e | The SYCL event resulting of the queried access. |
Definition at line 368 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
Definition at line 913 of file DeviceBuffer.hpp.
|
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.
| other | The buffer from which to copy the data |
Definition at line 892 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| other | The buffer from which to copy the data |
| copy_size | The size of the copy |
Definition at line 859 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| vec | The std::vector to copy from |
Definition at line 666 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| vec | The std::vector to copy from |
| sz | The number of elements to copy |
Definition at line 696 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| buf | The SYCL buffer to copy from |
Definition at line 755 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| buf | The SYCL buffer to copy from |
| sz | The number of elements to copy |
Definition at line 788 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| begin | The starting index of the range to copy, inclusive. |
| end | The ending index of the range to copy, exclusive. |
| dest | The destination buffer to copy to. |
Definition at line 652 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| begin | The starting index of the range to copy, inclusive. |
| end | The ending index of the range to copy, exclusive. |
| dest | The destination buffer to copy to. |
Definition at line 583 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
Definition at line 830 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
Definition at line 510 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| begin | The starting index of the range to copy, inclusive. |
| end | The ending index of the range to copy, exclusive. |
| std::invalid_argument | if 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:
|
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.
Definition at line 726 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| add_sz | The number of elements to add to the buffer. |
Definition at line 1194 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| value | The value to fill the buffer with. |
Definition at line 997 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| value | The value to fill the buffer with |
| idx_count | The number of elements to fill |
Definition at line 986 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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().
| value | The value to fill the buffer with |
| idx_range | The 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:
|
inline |
Definition at line 1000 of file DeviceBuffer.hpp.
|
inline |
Alias for resize_discard_data(0).
Definition at line 1184 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
inlinestatic |
Get 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:
|
inline |
Gets the Device scheduler corresponding to the held allocation.
Definition at line 430 of file DeviceBuffer.hpp.
|
inline |
Gets the Device scheduler pointer corresponding to the held allocation.
Definition at line 439 of file DeviceBuffer.hpp.
|
inline |
Gets the Device scheduler pointer corresponding to the held allocation.
Definition at line 448 of file DeviceBuffer.hpp.
|
inline |
Definition at line 1080 of file DeviceBuffer.hpp.
|
inline |
Gets the amount of memory used by the buffer.
Definition at line 483 of file DeviceBuffer.hpp.
|
inline |
Gets the DeviceQueue associated with the held allocation.
Definition at line 457 of file DeviceBuffer.hpp.
|
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.
| depends_list | A vector of SYCL events to wait for before accessing the buffer. |
Definition at line 331 of file DeviceBuffer.hpp.
|
inline |
Gets the number of elements in the buffer.
Definition at line 476 of file DeviceBuffer.hpp.
|
inline |
Get the value at a given index in the buffer.
This function returns the value at the given index in the buffer.
| idx | The index of the value to retrieve |
Definition at line 1032 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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.
| depends_list | A vector of SYCL events to wait for before accessing the buffer. |
Definition at line 349 of file DeviceBuffer.hpp.
|
inline |
Check if the buffer is empty.
true if the buffer is empty, false otherwise Definition at line 490 of file DeviceBuffer.hpp.
|
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.
Definition at line 922 of file DeviceBuffer.hpp.
|
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.
|
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.
| add_sz | The number of elements to reserve space for. |
Definition at line 1263 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
inline |
Resizes the buffer to a given size.
| new_size | The new size of the buffer. |
| keep_data | If 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:
|
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:
|
inline |
Definition at line 1053 of file DeviceBuffer.hpp.
|
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.
| sub_sz | The number of elements to remove from the buffer. |
Definition at line 1204 of file DeviceBuffer.hpp.
Here is the call graph for this function:
|
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: