batchlas::UnifiedVector< T > Struct Template Reference

Overview

template<typename T>
struct batchlas::UnifiedVector< T >

Owning, growable array of T in USM shared memory (sycl::malloc_shared).

The storage is allocated in the shared context of Device::default_device(), so it is readable and writable from the host and from that device. Copying deep-copies on the host; moving transfers ownership. Converts implicitly to Span<T>, which is how it is passed to entry points. Growth reallocates, so any Span or pointer taken earlier is invalidated.

Template Parameters
Telement type (trivially copyable: growth uses memcpy)

Definition at line 22 of file sycl-vector.hh.

#include <batchlas/util/sycl-vector.hh>

Types

◆ value_type

template<typename T>
using batchlas::UnifiedVector< T >::value_type = T

Element type.

Definition at line 24 of file sycl-vector.hh.

◆ pointer

template<typename T>
using batchlas::UnifiedVector< T >::pointer = T*

Pointer to an element.

Definition at line 25 of file sycl-vector.hh.

◆ size_t

template<typename T>
using batchlas::UnifiedVector< T >::size_t = std::size_t

Size and index type.

Definition at line 26 of file sycl-vector.hh.

Constructors

◆ UnifiedVector() [1/5]

template<typename T>
batchlas::UnifiedVector< T >::UnifiedVector ( size_t size)

Allocates size uninitialised elements.

Exceptions
std::bad_allocif the allocation fails

◆ UnifiedVector() [2/5]

template<typename T>
batchlas::UnifiedVector< T >::UnifiedVector ( size_t size,
T value )

Allocates size elements set to value (filled on the host).

◆ UnifiedVector() [3/5]

template<typename T>
batchlas::UnifiedVector< T >::UnifiedVector ( const UnifiedVector< T > & other)

Deep copy of other's first size() elements into a new allocation.

◆ ~UnifiedVector()

template<typename T>
batchlas::UnifiedVector< T >::~UnifiedVector ( )

Frees the allocation; never throws, even if the runtime reports an earlier async error.

◆ UnifiedVector() [4/5]

template<typename T>
batchlas::UnifiedVector< T >::UnifiedVector ( )
inline

An empty vector with no allocation.

Definition at line 59 of file sycl-vector.hh.

◆ UnifiedVector() [5/5]

template<typename T>
batchlas::UnifiedVector< T >::UnifiedVector ( UnifiedVector< T > && other)
inline

Takes other's allocation and leaves other empty.

Definition at line 61 of file sycl-vector.hh.

Functions

◆ operator=() [1/2]

template<typename T>
UnifiedVector< T > & batchlas::UnifiedVector< T >::operator= ( const UnifiedVector< T > & other)

Deep copy of other's elements; reallocates only when this capacity is smaller.

Trivially copyable T is copied with a device memcpy that is waited on.

◆ resize() [1/3]

template<typename T>
void batchlas::UnifiedVector< T >::resize ( size_t new_size)

Sets the size; reallocates (keeping the contents) only when new_size exceeds the capacity.

◆ resize() [2/3]

template<typename T>
void batchlas::UnifiedVector< T >::resize ( size_t new_size,
T value )

Grows to new_size, setting the new elements to value.

Note
A no-op unless new_size exceeds the capacity: it neither shrinks nor grows within the existing capacity (unlike the one-argument resize()).

◆ resize() [3/3]

template<typename T>
void batchlas::UnifiedVector< T >::resize ( size_t new_size,
size_t front,
size_t back,
size_t seg_size )

Grows a ring buffer to new_size, unrolling its live segment to the front.

The live data starts at front and ends with the seg_size elements at back, wrapping when back < front. After the call it is contiguous from index 0 and the rest is value-initialised. No-op unless new_size exceeds the capacity.

◆ reserve()

template<typename T>
void batchlas::UnifiedVector< T >::reserve ( size_t new_capacity)

Ensures a capacity of at least new_capacity, keeping the contents and the size.

◆ operator=() [2/2]

template<typename T>
UnifiedVector< T > & batchlas::UnifiedVector< T >::operator= ( UnifiedVector< T > && other)
inline

Frees this vector's allocation, takes other's and leaves other empty.

Definition at line 67 of file sycl-vector.hh.

◆ operator Span< T >()

template<typename T>
batchlas::UnifiedVector< T >::operator Span< T > ( ) const
inlineconstexpr

A Span over the first size() elements.

Definition at line 80 of file sycl-vector.hh.

◆ to_span()

template<typename T>
Span< T > batchlas::UnifiedVector< T >::to_span ( ) const
inlineconstexpr

A Span over the first size() elements.

Definition at line 82 of file sycl-vector.hh.

◆ subspan() [1/2]

template<typename T>
Span< T > batchlas::UnifiedVector< T >::subspan ( size_t offset,
size_t count ) const
inlineconstexpr

A Span over elements [offset, offset + count); not bounds-checked.

Definition at line 84 of file sycl-vector.hh.

◆ subspan() [2/2]

template<typename T>
Span< T > batchlas::UnifiedVector< T >::subspan ( size_t offset) const
inlineconstexpr

A Span over elements [offset, size()).

Definition at line 86 of file sycl-vector.hh.

◆ fill()

template<typename T>
void batchlas::UnifiedVector< T >::fill ( T data)
inlineconstexpr

Sets every element to data, on the host.

Definition at line 88 of file sycl-vector.hh.

◆ data()

template<typename T>
T * batchlas::UnifiedVector< T >::data ( ) const
inlineconstexpr

Pointer to the first element (null when never allocated).

Definition at line 89 of file sycl-vector.hh.

◆ size()

template<typename T>
size_t batchlas::UnifiedVector< T >::size ( ) const
inlineconstexpr

Number of elements.

Definition at line 90 of file sycl-vector.hh.

◆ capacity()

template<typename T>
size_t batchlas::UnifiedVector< T >::capacity ( ) const
inlineconstexpr

Allocated elements.

Definition at line 91 of file sycl-vector.hh.

◆ clear()

template<typename T>
void batchlas::UnifiedVector< T >::clear ( )
inlineconstexpr

Sets the size to 0 and keeps the allocation.

Definition at line 95 of file sycl-vector.hh.

◆ operator[]() [1/2]

template<typename T>
T & batchlas::UnifiedVector< T >::operator[] ( size_t index)
inlineconstexpr

Element index; prints and asserts (debug build) when out of range.

Definition at line 98 of file sycl-vector.hh.

◆ operator[]() [2/2]

template<typename T>
const T & batchlas::UnifiedVector< T >::operator[] ( size_t index) const
inlineconstexpr

Element index (const); same checks as the non-const overload.

Definition at line 100 of file sycl-vector.hh.

◆ at() [1/2]

template<typename T>
T & batchlas::UnifiedVector< T >::at ( size_t index)
inlineconstexpr

Element index.

Precondition
index < size() (asserted in debug builds, not thrown)

Definition at line 103 of file sycl-vector.hh.

◆ at() [2/2]

template<typename T>
const T & batchlas::UnifiedVector< T >::at ( size_t index) const
inlineconstexpr

Element index (const).

Precondition
index < size()

Definition at line 105 of file sycl-vector.hh.

◆ operator==()

template<typename T>
bool batchlas::UnifiedVector< T >::operator== ( const UnifiedVector< T > & other) const
inlineconstexpr

Element-wise comparison with Span::operator== semantics.

Definition at line 108 of file sycl-vector.hh.

◆ push_back() [1/2]

template<typename T>
void batchlas::UnifiedVector< T >::push_back ( const T & value)
inlineconstexpr

Appends value, doubling the capacity when full (which invalidates earlier Spans).

Definition at line 113 of file sycl-vector.hh.

◆ push_back() [2/2]

template<typename T>
void batchlas::UnifiedVector< T >::push_back ( T && value)
inlineconstexpr

Appends value by move; growth as for the copying overload.

Definition at line 122 of file sycl-vector.hh.

◆ pop_back()

template<typename T>
T batchlas::UnifiedVector< T >::pop_back ( )
inlineconstexpr

Removes and returns the last element; keeps the capacity.

Precondition
size() > 0

Definition at line 132 of file sycl-vector.hh.

◆ begin()

template<typename T>
T * batchlas::UnifiedVector< T >::begin ( ) const
inlineconstexpr

Iterator to the first element.

Definition at line 138 of file sycl-vector.hh.

◆ end()

template<typename T>
T * batchlas::UnifiedVector< T >::end ( ) const
inlineconstexpr

Iterator one past the last element.

Definition at line 139 of file sycl-vector.hh.

◆ back()

template<typename T>
T & batchlas::UnifiedVector< T >::back ( ) const
inlineconstexpr

Last element.

Precondition
size() > 0

Definition at line 141 of file sycl-vector.hh.

◆ front()

template<typename T>
T & batchlas::UnifiedVector< T >::front ( ) const
inlineconstexpr

First element.

Precondition
size() > 0

Definition at line 142 of file sycl-vector.hh.

◆ swap()

template<typename T>
void batchlas::UnifiedVector< T >::swap ( UnifiedVector< T > & other)
inlineconstexpr

Exchanges storage, size and capacity with other; no element is copied.

Definition at line 145 of file sycl-vector.hh.