6#include <batchlas/export.hh>
21template <
typename T, std::
size_t N>
44 inline constexpr Span() : data_(nullptr), size_(0) {}
55 inline constexpr Span(
const Span<T>& other,
size_t offset) : data_(other.data_ + offset), size_(other.size_ - offset) { assert(offset <= other.size_); }
58 inline constexpr Span(
Span<T>&& other,
size_t offset) : data_(other.data_ + offset), size_(other.size_ - offset) { assert(offset <= other.size_); }
66 inline constexpr explicit Span(T& value) : data_(&value), size_(1) {}
82 return Span<U>(
reinterpret_cast<U*
>(data_), (
sizeof(T) * size_ /
sizeof(U)) );
86 inline constexpr Span<T> subspan(
size_t offset)
const { assert(offset <= size_);
return Span<T>(data_ + offset, size_ - offset); }
88 inline constexpr Span<T> subspan(
size_t offset,
size_t count)
const { assert(offset + count <= size_);
return Span<T>(data_ + offset, count); }
90 inline constexpr Span<T>& operator= (
const Span<T> &other) { data_ = other.data_; size_ = other.size_;
return *
this; }
92 inline constexpr Span<T>& operator= (
Span<T> &&other) {
return *
this = other; }
102 inline constexpr T &
operator[](
size_t index)
const {assert(index < size_); assert(data_);
return data_[index];}
104 inline constexpr T &
at(
size_t index)
const{assert(index < size_); assert(data_);
return data_[index];}
105 inline constexpr T *
data()
const {
return data_; }
106 inline constexpr size_t size()
const {
return size_; }
107 inline constexpr bool empty()
const {
return size_ == 0; }
109 inline constexpr size_t size_bytes()
const {
return size_ *
sizeof(T); }
110 inline constexpr T *
begin()
const {
return data_; }
111 inline constexpr T *
end()
const {
return data_ + size_; }
112 inline constexpr T &
front()
const {
return data_[0]; }
113 inline constexpr T &
back()
const {
return data_[size_ - 1]; }
115 template <
typename U>
144#ifndef BATCHLAS_NO_GLOBAL_NAMES
Completion handle of enqueued work, returned by every entry point.
Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.
Non-owning view of size() contiguous elements of type T.
std::size_t size_t
Size and index type.
T value_type
Element type.
constexpr size_t size_bytes() const
size() * sizeof(T).
constexpr Span< T > subspan(size_t offset) const
Elements [offset, size()).
constexpr Span(T *data, size_t size)
Views size elements starting at data.
Event set_access_device(const Queue &ctx=Queue()) const
Map for access by the device of ctx.
bool operator==(const Span< T > other) const
Element-wise comparison on the host.
constexpr Span(T *begin, T *end)
Views the range [begin, end).
constexpr T & back() const
Last element.
constexpr T * begin() const
Iterator to the first element.
constexpr bool empty() const
True when size() == 0.
constexpr Span()
An empty span (null data, size 0).
constexpr T & operator[](size_t index) const
Element index.
friend std::ostream & operator<<(std::ostream &os, const Span< U > &vec)
Prints the elements on the host as [a, b, c].
constexpr Span(Span< T > &&other)=default
Same as the copy constructor.
constexpr size_t size() const
Number of elements.
constexpr T & front() const
First element.
constexpr Span< U > as_span() const
Reinterprets the bytes as elements of type U; the size is size_bytes() / sizeof(U).
constexpr T * end() const
Iterator one past the last element.
constexpr T * data() const
Pointer to the first element (may be null).
Event set_preferred_location(const Queue &ctx=Queue()) const
Prefer residence on the device of ctx.
constexpr Span(Span< T > &&other, size_t offset)
Views other with its first offset elements dropped.
constexpr Span< T > subspan(size_t offset, size_t count) const
Elements [offset, offset + count).
constexpr Span(T &value)
A one-element span over value.
Event prefetch(const Queue &ctx=Queue()) const
Migrate to the device of ctx.
T * pointer
Pointer to an element.
constexpr T & at(size_t index) const
Element index.
constexpr Span(const Span< T > &other)=default
Copies the pointer and size; the elements are not copied.
constexpr Span(const Span< T > &other, size_t offset)
Views other with its first offset elements dropped.
True for std::array<T, N>, false otherwise.
batchlas::Device, batchlas::Event and batchlas::Queue: where work runs and how it is ordered.