3#include <batchlas/export.hh>
46 void resize(
size_t new_size, T value);
64 other.data_ =
nullptr;
68 if (
this == &other)
return *
this;
70 this->data_ = other.data_;
71 this->size_ = other.size_;
72 this->capacity_ = other.capacity_;
73 other.data_ =
nullptr;
89 inline constexpr T *
data()
const {
return data_; }
90 inline constexpr size_t size()
const {
return size_; }
91 inline constexpr size_t capacity()
const {
return capacity_; }
95 inline constexpr void clear() { size_ = 0; }
98 inline constexpr T &
operator[](
size_t index) {
if(index >= size_) printf(
"Index: %zu, Size: %zu\n", index, size_); assert (index < size_);
return data_[index]; }
100 inline constexpr const T &
operator[](
size_t index)
const {
if (index >= size_) printf(
"Index: %zu, Size: %zu\n", index, size_); assert (index < size_);
return data_[index]; }
103 inline constexpr T &
at(
size_t index) { assert(index < size_);
return data_[index]; }
105 inline constexpr const T &
at(
size_t index)
const { assert(index < size_);
return data_[index]; }
114 if(size_ == capacity_){
115 size_t new_capacity = capacity_ == 0 ? 1 : 2*capacity_;
118 data_[size_++] = value;
123 if(size_ == capacity_){
124 size_t new_capacity = capacity_ == 0 ? 1 : 2*capacity_;
127 data_[size_++] = std::move(value);
132 inline constexpr T
pop_back() { assert(size_ > 0);
return data_[--size_]; }
135 template <
typename U>
138 inline constexpr T *
begin()
const {
return data_; }
139 inline constexpr T *
end()
const {
return data_ + size_; }
141 inline constexpr T &
back()
const {
return data_[size_ - 1]; }
142 inline constexpr T &
front()
const {
return data_[0]; }
146 std::swap(data_, other.data_);
147 std::swap(size_, other.size_);
148 std::swap(capacity_, other.capacity_);
153 static T* alloc_shared(
size_t n);
172#ifndef BATCHLAS_NO_GLOBAL_NAMES
constexpr void swap(UnifiedVector< T > &lhs, UnifiedVector< T > &rhs)
Swaps the storage of two vectors without copying; found by ADL.
Non-owning view of size() contiguous elements of type T.
Owning, growable array of T in USM shared memory (sycl::malloc_shared).
constexpr Span< T > subspan(size_t offset, size_t count) const
A Span over elements [offset, offset + count); not bounds-checked.
constexpr T & front() const
First element.
constexpr Span< T > to_span() const
A Span over the first size() elements.
constexpr void clear()
Sets the size to 0 and keeps the allocation.
UnifiedVector< T > & operator=(UnifiedVector< T > &&other)
Frees this vector's allocation, takes other's and leaves other empty.
UnifiedVector< T > & operator=(const UnifiedVector< T > &other)
Deep copy of other's elements; reallocates only when this capacity is smaller.
T * pointer
Pointer to an element.
constexpr T & at(size_t index)
Element index.
void resize(size_t new_size)
Sets the size; reallocates (keeping the contents) only when new_size exceeds the capacity.
UnifiedVector()
An empty vector with no allocation.
constexpr T & back() const
Last element.
UnifiedVector(size_t size, T value)
Allocates size elements set to value (filled on the host).
void reserve(size_t new_capacity)
Ensures a capacity of at least new_capacity, keeping the contents and the size.
constexpr bool operator==(const UnifiedVector< T > &other) const
Element-wise comparison with Span::operator== semantics.
constexpr T & operator[](size_t index)
Element index; prints and asserts (debug build) when out of range.
friend std::ostream & operator<<(std::ostream &os, const UnifiedVector< U > &vec)
Prints the elements on the host as [a, b, c], like Span's operator<<.
UnifiedVector(const UnifiedVector< T > &other)
Deep copy of other's first size() elements into a new allocation.
constexpr void push_back(const T &value)
Appends value, doubling the capacity when full (which invalidates earlier Spans).
constexpr T * begin() const
Iterator to the first element.
constexpr void fill(T data)
Sets every element to data, on the host.
constexpr Span< T > subspan(size_t offset) const
A Span over elements [offset, size()).
void 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.
constexpr T pop_back()
Removes and returns the last element; keeps the capacity.
constexpr T * end() const
Iterator one past the last element.
void resize(size_t new_size, T value)
Grows to new_size, setting the new elements to value.
UnifiedVector(size_t size)
Allocates size uninitialised elements.
constexpr size_t capacity() const
Allocated elements.
constexpr size_t size() const
Number of elements.
T value_type
Element type.
UnifiedVector(UnifiedVector< T > &&other)
Takes other's allocation and leaves other empty.
constexpr void swap(UnifiedVector< T > &other)
Exchanges storage, size and capacity with other; no element is copied.
constexpr T * data() const
Pointer to the first element (null when never allocated).
constexpr const T & at(size_t index) const
Element index (const).
std::size_t size_t
Size and index type.
~UnifiedVector()
Frees the allocation; never throws, even if the runtime reports an earlier async error.
constexpr void push_back(T &&value)
Appends value by move; growth as for the copying overload.
constexpr const T & operator[](size_t index) const
Element index (const); same checks as the non-const overload.
batchlas::Device, batchlas::Event and batchlas::Queue: where work runs and how it is ordered.
batchlas::Span, the non-owning pointer + length every entry point takes for 1-D data.