Speclib  0.1.2
The library for writing better CUDA libraries
sp::Scalar< T > Struct Template Reference

A scalar (as a rank-zero tensor). More...

#include <Scalar.hpp>

Inheritance diagram for sp::Scalar< T >:
[legend]

Public Types

using Opts = sp::MostAggressiveTensorOptions
 
using StorageType = sp::remove_cvref_t< T >
 
using ValueType = sp::value_type_or_identity_t< StorageType >
 
- Public Types inherited from sp::Operator< Subtype, Children >
using Traits = f::Traits< void >
 

Public Member Functions

constexpr Scalar (const T v)
 
template<int L, CacheMode Mode>
constexpr Vec< ValueType, L > vectorReadImpl (const Vec< int, 0 > &) const
 Get L copies of a :D. More...
 
constexpr operator ValueType () const
 Allow implicit conversion to the underlying scalar type. More...
 
- Public Member Functions inherited from sp::TensorOp< Scalar< T >, 0, T >
constexpr TensorOp (Children... args)
 
- Public Member Functions inherited from sp::Operator< Subtype, Children >
template<int N = 0>
constexpr auto & child ()
 Access children. More...
 
constexpr auto & lhs ()
 Get the first subexpression if this is a binary operation. More...
 
constexpr auto & rhs ()
 Get the second subexpression if this is a binary operation. More...
 
template<int N = 0>
constexpr const auto & child () const
 
constexpr const auto & lhs () const
 
constexpr const auto & rhs () const
 
template<typename F >
constexpr void forEachChild (F &lambda)
 Run a lambda function on each child. More...
 
- Public Member Functions inherited from sp::TensorLike< Subclass, TensorRank >
auto dims () const
 
bool boundsCheck (const Vec< int, Rank > &pos) const
 
template<int L, CacheMode Mode = CacheMode::DEFAULT>
auto vectorRead (const Vec< int, Rank > &pos) const
 
template<int L, CacheMode Mode = CacheMode::DEFAULT>
auto vectorOffsetRead (const Vec< int, Rank > &base, const Vec< int, Rank > &offset) const
 
template<int L, CacheMode Mode = CacheMode::DEFAULT>
auto maskedVectorRead (const Vec< int, Rank > &pos) const
 
template<int L, CacheMode Mode = CacheMode::DEFAULT, typename T >
void vectorWrite (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 
template<int L, CacheMode Mode = CacheMode::DEFAULT, typename T >
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...
 
template<CacheMode Mode = CacheMode::DEFAULT>
auto read (const Vec< int, Rank > &pos) const
 Get the element at a given position. More...
 
template<CacheMode Mode = CacheMode::DEFAULT, typename T >
void write (const Vec< int, Rank > &pos, const T &value)
 Set a single element. More...
 
template<int Dummy = 0>
int size () const
 
template<int L>
void boundsCheckAccess (Vec< int, Rank > pos) const
 Bounds-check an L-element vector read at pos. More...
 

Static Public Member Functions

constexpr static bool known ()
 Is the value known at compile-time? More...
 
template<typename Q >
constexpr static bool is (Q x)
 Is the value known at compile-time to be the given value? More...
 
template<typename Q >
constexpr static bool isLt (Q x)
 Is the value known at compile time to be less than the given value? More...
 
template<typename Q >
constexpr static bool isLe (Q x)
 Is the value known at compile time to be less than or equal to the given value? More...
 
template<typename Q >
constexpr static bool isGt (Q x)
 Is the value known at compile time to be greater than the given value? More...
 
template<typename Q >
constexpr static bool isGe (Q x)
 Is the value known at compile time to greater than or equal to the given value? More...
 
- Static Public Member Functions inherited from sp::Operator< Subtype, Children >
constexpr static bool commutative ()
 
constexpr static bool associative ()
 
constexpr static bool total ()
 
constexpr static bool hasIdentity ()
 
constexpr static bool invertible ()
 
template<typename T >
constexpr static auto getIdentityImpl ()
 
template<typename T >
constexpr static auto getIdentity ()
 

Static Public Attributes

static constexpr int MaxVectorSize = getMaxGMemVectorSize<ValueType>()
 
- Static Public Attributes inherited from sp::Operator< Subtype, Children >
static constexpr int Arity = sizeof...(Children)
 
- Static Public Attributes inherited from sp::TensorLike< Subclass, TensorRank >
constexpr static int Rank = TensorRank
 

Additional Inherited Members

- Protected Member Functions inherited from sp::Operator< Subtype, Children >
constexpr Operator (Children... args)
 
template<typename F , int... I>
constexpr void forEachChild (F &lambda, sp::int_sequence< I... > &)
 
- Protected Member Functions inherited from sp::TensorLike< Subclass, TensorRank >
template<typename Dummy = void*>
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...
 
template<int L, CacheMode Mode = CacheMode::DEFAULT>
auto vectorReadImpl (const Vec< int, Rank > &) const
 Read L elements, adjacent in the last dimension, starting at the given position. More...
 
template<int L, CacheMode Mode = CacheMode::DEFAULT>
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...
 
template<int L, CacheMode Mode = CacheMode::DEFAULT>
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...
 
template<int L, CacheMode Mode = CacheMode::DEFAULT, typename T >
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...
 
template<int L, CacheMode Mode, typename T >
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...
 
- Protected Attributes inherited from sp::Operator< Subtype, Children >
std::tuple< Children... > children
 

Detailed Description

template<typename T>
struct sp::Scalar< T >

A scalar (as a rank-zero tensor).

Typically, users do not have to use (or care about) this node at all. Just pass the actual underlying scalar value you want: implicit conversions will take care of the rest.

This operator can be thought of as the "promote scalar value to rank-zero tensor" operator. T may be any numeric type, or any type that defines a member typedef ValueType and can be implicitly converted to that type.

The resulting Scalar node will behave as if it were the result of that conversion.

Member Function Documentation

◆ is()

template<typename T >
template<typename Q >
constexpr static bool sp::Scalar< T >::is ( x)
staticconstexpr

Is the value known at compile-time to be the given value?

Note that if this returns false it does not mean that the runtime value of the scalar can never be the requested value. This is intended for carrying out compile-time checks of the value (usually with if constexpr).

This will always return false if known() returns false.

◆ isGe()

template<typename T >
template<typename Q >
constexpr static bool sp::Scalar< T >::isGe ( x)
staticconstexpr

Is the value known at compile time to greater than or equal to the given value?

◆ isGt()

template<typename T >
template<typename Q >
constexpr static bool sp::Scalar< T >::isGt ( x)
staticconstexpr

Is the value known at compile time to be greater than the given value?

◆ isLe()

template<typename T >
template<typename Q >
constexpr static bool sp::Scalar< T >::isLe ( x)
staticconstexpr

Is the value known at compile time to be less than or equal to the given value?

◆ isLt()

template<typename T >
template<typename Q >
constexpr static bool sp::Scalar< T >::isLt ( x)
staticconstexpr

Is the value known at compile time to be less than the given value?

◆ known()

template<typename T >
constexpr static bool sp::Scalar< T >::known ( )
staticconstexpr

Is the value known at compile-time?

◆ operator ValueType()

template<typename T >
constexpr sp::Scalar< T >::operator ValueType ( ) const
constexpr

Allow implicit conversion to the underlying scalar type.

◆ vectorReadImpl()

template<typename T >
template<int L, CacheMode Mode>
constexpr Vec< ValueType, L > sp::Scalar< T >::vectorReadImpl ( const Vec< int, 0 > &  ) const
constexpr

Get L copies of a :D.