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

A wrapper around a TensorLike that adds buffer ownership. More...

#include <TensorOwner.hpp>

Public Types

using ValueType = typename TensorType::ValueType
 
using Type = typename TensorType::Type
 

Public Member Functions

template<typename... Args>
 TensorOwner (sp::UniquePtr< Type > &&inBuffer, Args &&... args)
 Construct from a unique pointer, and take ownership of it. Behaviour is undefined if the buffer is too small. More...
 
 TensorOwner ()=default
 Creates an uninitialised TensorOwner. More...
 
 operator TensorType () const
 Implicitly convert to the underlying TensorLike. More...
 
auto get () const
 Explicitly convert to the underlying TensorLike. More...
 
template<typename std::enable_if<!std::is_same_v< TensorType, typename TensorType::ConstTensor >, int >::type = 0>
 operator typename TensorType::ConstTensor () const
 Implicitly convert to the underlying TensorLike. More...
 
auto data ()
 Allow access to the buffer (since a common use-case is initialisation). More...
 
auto data () const
 

Static Public Attributes

constexpr static int Rank = TensorType::Rank
 

Detailed Description

template<typename TensorType>
class sp::TensorOwner< TensorType >

A wrapper around a TensorLike that adds buffer ownership.

Typically, this is used indirectly via libSCALE's Device or Host objects. Something like:

auto gpu = sp::Device::get(0);
// Allocate a tensor on a specific GPU
auto myTensor = gpu.allocateTensorLike<sp::Tensor<__device float, 2>>({1, 2, 3});
// Works with any TensorLike...
auto myTriangular = gpu.allocateTensorLike<sp::TriangularMatrix<__device float>>(4);
static Device & get(int i)
Represents a Tensor- a multidimensional array that can represent a multilinear map.
Definition: Tensor.hpp:32

Objects allocated in this way will automatically be unallocated when they go out of scope, and will implicitly convert to the underlying TensorLike type. Usually, you'll create some TensorOwner<T>s to own the memory, and pass them (with an implicit conversion) to functions/kernels that accept T to do the actual processing.

Constructor & Destructor Documentation

◆ TensorOwner() [1/2]

template<typename TensorType >
template<typename... Args>
sp::TensorOwner< TensorType >::TensorOwner ( sp::UniquePtr< Type > &&  inBuffer,
Args &&...  args 
)

Construct from a unique pointer, and take ownership of it. Behaviour is undefined if the buffer is too small.

◆ TensorOwner() [2/2]

template<typename TensorType >
sp::TensorOwner< TensorType >::TensorOwner ( )
default

Creates an uninitialised TensorOwner.

Member Function Documentation

◆ data()

template<typename TensorType >
auto sp::TensorOwner< TensorType >::data ( )

Allow access to the buffer (since a common use-case is initialisation).

◆ get()

template<typename TensorType >
auto sp::TensorOwner< TensorType >::get ( ) const

Explicitly convert to the underlying TensorLike.

◆ operator TensorType()

template<typename TensorType >
sp::TensorOwner< TensorType >::operator TensorType ( ) const

Implicitly convert to the underlying TensorLike.

◆ operator typename TensorType::ConstTensor()

template<typename TensorType >
template<typename std::enable_if<!std::is_same_v< TensorType, typename TensorType::ConstTensor >, int >::type = 0>
sp::TensorOwner< TensorType >::operator typename TensorType::ConstTensor ( ) const

Implicitly convert to the underlying TensorLike.