Speclib  0.1.2
The library for writing better CUDA libraries
sp::TensorView< TensorType, R > Class Template Reference

A view into another TensorLike. More...

#include <TensorView.hpp>

Inheritance diagram for sp::TensorView< TensorType, R >:
[legend]

Public Types

using ValueType = typename TensorType::ValueType
 

Public Member Functions

 TensorView (TensorType &target, sp::Vec< int, Rank > start, sp::Vec< int, Rank > size)
 Construct a TensorView. More...
 
- Public Member Functions inherited from sp::TensorLike< TensorView< TensorType, R >, R >
auto dims () const
 
bool boundsCheck (const Vec< int, Rank > &pos) const
 
auto vectorRead (const Vec< int, Rank > &pos) const
 
auto vectorOffsetRead (const Vec< int, Rank > &base, const Vec< int, Rank > &offset) const
 
auto maskedVectorRead (const Vec< int, Rank > &pos) const
 
void vectorWrite (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 
void maskedVectorWrite (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 
int sizeQuantisation () const
 
int totalSize () const
 Get the total memory occupied by the Tensor, in terms of elements. More...
 
auto getView (const sp::Vec< int, Rank > &start, const sp::Vec< int, Rank > &size)
 Get an object that represents (and aliases) a portion of this object. More...
 
int dim (int d) const
 Behaviour common to all TensorLikes ///. More...
 
auto read (const Vec< int, Rank > &pos) const
 Get the element at a given position. More...
 
void write (const Vec< int, Rank > &pos, const T &value)
 Set a single element. More...
 
int size () const
 
void boundsCheckAccess (Vec< int, Rank > pos) const
 Bounds-check an L-element vector read at pos. More...
 

Static Public Attributes

static constexpr int Rank = R
 
- Static Public Attributes inherited from sp::TensorLike< TensorView< TensorType, R >, R >
constexpr static int Rank
 

Protected Member Functions

sp::Vec< int, Rank > dimsImpl () const
 
template<int L, CacheMode Mode>
Vec< ValueType, L > vectorReadImpl (const Vec< int, Rank > &pos) const
 
template<int L, CacheMode Mode>
void vectorWriteImpl (const Vec< int, Rank > &pos, const Vec< ValueType, L > &values)
 
auto getViewImpl (const Vec< int, Rank > &subStart, const Vec< int, Rank > &subSize)
 
- Protected Member Functions inherited from sp::TensorLike< TensorView< TensorType, R >, R >
auto dimsImpl () const
 Get an sp::Vec<int, X> representing the dimensions of the object. More...
 
bool boundsCheckImpl (const sp::Vec< int, Rank > &) const
 Return true iff the given coordinates are inside the object (Default implementation below) More...
 
int sizeQuantisationImpl () const
 The last dimension is rounded up to the next multiple of this value for the purposes of bounds checks. More...
 
auto vectorReadImpl (const Vec< int, Rank > &) const
 Read L elements, adjacent in the last dimension, starting at the given position. More...
 
auto vectorOffsetReadImpl (const Vec< int, Rank > &base, const Vec< int, Rank > &offset) const
 Read L elements, adjacent in the last dimension, from position base + offset. More...
 
auto maskedVectorReadImpl (const Vec< int, Rank > &pos) const
 Do a vectorRead that copes with the possibility of part of the vector being out of bounds. More...
 
void maskedVectorWriteImpl (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 Do a vectorWrite that copes with the possibility of part of the vector being out of bounds. More...
 
void vectorWriteImpl (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 Write L elements, adjacent in the last dimension, starting at the given position. More...
 
auto getViewImpl (const sp::Vec< int, Rank > &start, const sp::Vec< int, Rank > &size)
 The default implementation just makes a TensorView. Not hugely fast, but always works. More...
 

Friends

class TensorLike< TensorView< TensorType, R >, R >
 

Detailed Description

template<typename TensorType, int R>
class sp::TensorView< TensorType, R >

A view into another TensorLike.

This object works by simply applying a coordinate transform to reads/writes into the underlying TensorLike, and doing its own bounds checking (in debug builds).

While very general, this is the least efficient possible way of creating a view. For this reason, it is preferable to obtain a view using the getView() function of the TensorLike you want a view into. That gives the underlying object the opportunity to return something more efficient that functions as a view.

For instance, a memory-backed Tensor will return another memory-backed Tensor from getView() (with the start pointer and coordinates suitably adjusted). This avoids the need to store an additional set of start/size values as this object has to do, and potentially saving some integer math.

Constructor & Destructor Documentation

◆ TensorView()

template<typename TensorType , int R>
sp::TensorView< TensorType, R >::TensorView ( TensorType &  target,
sp::Vec< int, Rank >  start,
sp::Vec< int, Rank >  size 
)

Construct a TensorView.

Parameters
targetThe underlying TensorLike
startThe coordinates (in target) of the first element in the view.
sizeThe size of the view.