batchlas::VectorView< T > Class Template Reference

Overview

template<typename T>
class batchlas::VectorView< T >

Non-owning view of a batch of strided vectors: the vector argument type of the entry points.

Entry i of item b is at data_ptr()[b * stride() + i * inc()]; a stride of 0 means size * inc (items back to back). The memory must be USM the Queue's device can access and must outlive every use.

Trap
The positional constructors take (data, size, batch_size, inc, stride), the opposite order to Vector's (size, batch_size, Stride, Inc). Prefer the tagged overloads in new code.
See also
Matrix model: vectors, inc and stride

Definition at line 1754 of file matrix.hh.

#include <batchlas/blas/matrix.hh>

Inheritance diagram for batchlas::VectorView< T >:

Types

◆ value_type

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

Element type.

Definition at line 1756 of file matrix.hh.

◆ pointer

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

Pointer to an element.

Definition at line 1757 of file matrix.hh.

◆ reference

template<typename T>
using batchlas::VectorView< T >::reference = T&

Reference to an element.

Definition at line 1758 of file matrix.hh.

◆ const_reference

template<typename T>
using batchlas::VectorView< T >::const_reference = const T&

Const reference to an element.

Definition at line 1759 of file matrix.hh.

Constructors

◆ VectorView() [1/9]

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

An empty view with batch size 1.

Definition at line 1769 of file matrix.hh.

◆ VectorView() [2/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( Span< T > data,
int size,
int batch_size = 1,
int inc = 1,
int stride = 0 )
inline

Views data with the given layout.

Parameters
datastorage; must hold required_span_length() elements (debug-asserted)
sizeentries per item
batch_sizenumber of items
incelement distance between entries
strideelement distance between items; 0 means size * inc

Definition at line 1776 of file matrix.hh.

◆ VectorView() [3/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( UnifiedVector< T > & data,
int size,
int batch_size = 1,
int inc = 1,
int stride = 0 )
inline

Views a UnifiedVector's storage; parameters as the Span overload.

Definition at line 1782 of file matrix.hh.

◆ VectorView() [4/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( T * data,
int size,
int batch_size = 1,
int inc = 1,
int stride = 0 )
inline

Views raw memory; parameters as the Span overload (no length check).

Definition at line 1788 of file matrix.hh.

◆ VectorView() [5/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( Span< T > data,
int size,
int batch_size,
Inc inc,
Stride stride = Stride{0} )
inline

Views a Span; see the positional Span overload.

Definition at line 1797 of file matrix.hh.

◆ VectorView() [6/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( UnifiedVector< T > & data,
int size,
int batch_size,
Inc inc,
Stride stride = Stride{0} )
inline

Views a UnifiedVector's storage.

Definition at line 1800 of file matrix.hh.

◆ VectorView() [7/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( T * data,
int size,
int batch_size,
Inc inc,
Stride stride = Stride{0} )
inline

Views raw memory (no length check).

Definition at line 1803 of file matrix.hh.

◆ VectorView() [8/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( const VectorView< T > & )
default

◆ VectorView() [9/9]

template<typename T>
batchlas::VectorView< T >::VectorView ( VectorView< T > && )
defaultnoexcept

Functions

◆ required_span_length()

template<typename T>
constexpr std::size_t batchlas::VectorView< T >::required_span_length ( int size,
int inc,
int stride,
int batch_size )
inlinestaticconstexpr

Elements needed to hold the layout: (batch_size-1)*stride + (size-1)*inc + 1, or 0 when empty.

Definition at line 1762 of file matrix.hh.

◆ operator=() [1/2]

template<typename T>
VectorView & batchlas::VectorView< T >::operator= ( const VectorView< T > & )
default

◆ operator=() [2/2]

template<typename T>
VectorView & batchlas::VectorView< T >::operator= ( VectorView< T > && )
defaultnoexcept

◆ data()

template<typename T>
Span< T > batchlas::VectorView< T >::data ( ) const
inline

The viewed storage, from entry 0 of item 0 to the last entry of the last item.

Definition at line 1817 of file matrix.hh.

◆ set_access_device()

template<typename T>
Event batchlas::VectorView< T >::set_access_device ( const Queue & ctx) const
inline

Prefers residence of the viewed memory on the device of ctx.

Definition at line 1822 of file matrix.hh.

◆ set_preferred_location()

template<typename T>
Event batchlas::VectorView< T >::set_preferred_location ( const Queue & ctx) const
inline

Prefers residence of the viewed memory on the device of ctx.

Definition at line 1827 of file matrix.hh.

◆ prefetch()

template<typename T>
Event batchlas::VectorView< T >::prefetch ( const Queue & ctx) const
inline

Migrates the viewed memory to the device of ctx.

Definition at line 1832 of file matrix.hh.

◆ data_ptr()

template<typename T>
T * batchlas::VectorView< T >::data_ptr ( ) const
inline

Pointer to entry 0 of item 0.

Definition at line 1836 of file matrix.hh.

◆ size()

template<typename T>
int batchlas::VectorView< T >::size ( ) const
inline

Entries per item.

Definition at line 1837 of file matrix.hh.

◆ inc()

template<typename T>
int batchlas::VectorView< T >::inc ( ) const
inline

Element distance between entries.

Definition at line 1839 of file matrix.hh.

◆ stride()

template<typename T>
int batchlas::VectorView< T >::stride ( ) const
inline

Element distance between items.

Definition at line 1841 of file matrix.hh.

◆ batch_size()

template<typename T>
int batchlas::VectorView< T >::batch_size ( ) const
inline

Number of batch items.

Definition at line 1842 of file matrix.hh.

◆ all_items()

template<typename T>
std::vector< int > batchlas::VectorView< T >::all_items ( ) const
inline

Every item index, 0 .. batch_size() - 1.

Definition at line 1844 of file matrix.hh.

◆ default_items()

template<typename T>
std::vector< int > batchlas::VectorView< T >::default_items ( ) const
inline

{0, batch_size() / 2, batch_size() - 1}, sorted and de-duplicated ({} for batch 0): what a check reads by default, as MatrixView::default_items().

Definition at line 1852 of file matrix.hh.

◆ astype()

template<typename T>
template<typename U>
Vector< U > batchlas::VectorView< T >::astype ( ) const

Owning copy with every element converted by static_cast<U>, in this layout; host loop.

Definition at line 2146 of file matrix.hh.

◆ copy()

template<typename T>
Event batchlas::VectorView< T >::copy ( Queue & ctx,
const VectorView< T > & dest,
const VectorView< T > & src )
static

Enqueues dest := src on ctx, honouring each side's inc and stride.

Exceptions
batchlas::invalid_argumentif the sizes or batch sizes differ

◆ all_close()

template<typename T>
bool batchlas::VectorView< T >::all_close ( Queue & ctx,
const VectorView< T > & a,
const VectorView< T > & b,
float_t< T > tol = std::numeric_limits< float_t< T > >::epsilon() )
static

True when every entry of a and b agrees to relative tolerance tol; waits on ctx.

See also
MatrixView::all_close() for the comparison rule.

◆ at()

template<typename T>
T & batchlas::VectorView< T >::at ( int i,
int batch = 0 ) const
inline

Entry i of item batch; usable on the host and in a kernel.

Precondition
0 <= i < size(), 0 <= batch < batch_size() (asserted in debug builds)

Definition at line 1873 of file matrix.hh.

◆ operator[]()

template<typename T>
T & batchlas::VectorView< T >::operator[] ( int i) const
inline

Entry i of item 0.

Definition at line 1883 of file matrix.hh.

◆ operator()() [1/2]

template<typename T>
T & batchlas::VectorView< T >::operator() ( int i,
int batch = 0 ) const
inline

at(i, batch).

Definition at line 1886 of file matrix.hh.

◆ batch_item()

template<typename T>
VectorView< T > batchlas::VectorView< T >::batch_item ( int batch_index) const
inline

A batch-size-1 view of item batch_index.

Definition at line 1889 of file matrix.hh.

◆ operator()() [2/2]

template<typename T>
VectorView< T > batchlas::VectorView< T >::operator() ( Slice slice) const
inline

Entries slice of every item; keeps inc, stride and batch size.

Precondition
The slice is non-empty (asserted in debug builds)

Definition at line 1897 of file matrix.hh.

◆ stream_formatted_to()

template<typename T>
std::ostream & batchlas::VectorView< T >::stream_formatted_to ( std::ostream & os,
int max_elements = 10,
int max_cols_to_print = 10 ) const
inline

Prints the leading max_elements entries of each item in scientific notation.

Returns
os, with its format flags restored

Definition at line 1918 of file matrix.hh.

◆ print()

template<typename T>
void batchlas::VectorView< T >::print ( std::ostream & os = std::cout,
int max_elements = 10 ) const
inline

stream_formatted_to(os, max_elements).

Definition at line 1940 of file matrix.hh.

Variables

◆ data_

template<typename T>
Span<T> batchlas::VectorView< T >::data_
protected

Definition at line 1945 of file matrix.hh.

◆ size_

template<typename T>
int batchlas::VectorView< T >::size_ = 0
protected

Definition at line 1946 of file matrix.hh.

◆ inc_

template<typename T>
int batchlas::VectorView< T >::inc_ = 1
protected

Definition at line 1947 of file matrix.hh.

◆ stride_

template<typename T>
int batchlas::VectorView< T >::stride_ = 0
protected

Definition at line 1948 of file matrix.hh.

◆ batch_size_

template<typename T>
int batchlas::VectorView< T >::batch_size_ = 1
protected

Definition at line 1949 of file matrix.hh.