Speclib  0.1.2
The library for writing better CUDA libraries
sp::Specialisable Struct Reference

Base class for targets of sp::runSpecialised() More...

#include <Specialisable.hpp>

Inheritance diagram for sp::Specialisable:
[legend]

Public Types

template<typename T , int Rank, typename Opts >
using UsefulTensorType = sp::Tensor< T, Rank, Opts >
 Given a tensor type produced by the specailiser, transform it to the type of tensor argument to actually use for this operator. More...
 
using ScalarsToSpecialise = sp::int_sequence<-1, 0, 1 >
 A list of special scalar values to generate optimised code paths for. More...
 

Static Public Member Functions

template<int... Ranks>
constexpr static bool validTensorRanks ()
 
template<typename... Types>
constexpr static bool validTensorTypes ()
 
template<typename T >
constexpr static bool shouldSpecialiseArgument (int)
 Should the specialiser attempt to specialise the argument at the given position in the argument list, which is of type T? More...
 
template<typename KnownTensorTypes , typename... ScalarTypes>
constexpr static bool validScalarTypes ()
 
static void onInvalidTensorRank ()
 Called when a branch for which validTensorRanks() returned false is actually executed. Must throw. More...
 
static void onInvalidTensorType ()
 Called when a branch for which validTensorTypes() returned false is actually executed. Must throw. More...
 
static void onInvalidScalarType ()
 Called when a branch for which validScalarTypes() returned false is actually executed. Must throw. More...
 

Static Public Attributes

constexpr static PackMode MaxPackMode = PackMode::FULL
 The maximum Tensor packing mode that's worth optimising for. More...
 
constexpr static bool DesiresPitchedness = true
 True if we should attempt to set the pitchedness flag of TensorLikes. More...
 

Detailed Description

Base class for targets of sp::runSpecialised()

The valid*() functions define predicated which are used to prune specialisation trees. When a valid*() function returns false, the corresponding branch of the expansion tree instead throws RejectedSpecialisationException.

Member Typedef Documentation

◆ ScalarsToSpecialise

A list of special scalar values to generate optimised code paths for.

◆ UsefulTensorType

template<typename T , int Rank, typename Opts >
using sp::Specialisable::UsefulTensorType = sp::Tensor<T, Rank, Opts>

Given a tensor type produced by the specailiser, transform it to the type of tensor argument to actually use for this operator.

This allows you to fuse together cases that don't make any useful difference.

In contrast to validTensorTypes() (which may be overridden to make certain specialisations not work at all), this version allows you to combine multiple branches of the tree together to point to the same kernel. Usually, this is useful for fusing lots of "slow" cases together.

The default is an identity transform.

Member Function Documentation

◆ onInvalidScalarType()

static void sp::Specialisable::onInvalidScalarType ( )
static

Called when a branch for which validScalarTypes() returned false is actually executed. Must throw.

◆ onInvalidTensorRank()

static void sp::Specialisable::onInvalidTensorRank ( )
static

Called when a branch for which validTensorRanks() returned false is actually executed. Must throw.

◆ onInvalidTensorType()

static void sp::Specialisable::onInvalidTensorType ( )
static

Called when a branch for which validTensorTypes() returned false is actually executed. Must throw.

◆ shouldSpecialiseArgument()

template<typename T >
constexpr static bool sp::Specialisable::shouldSpecialiseArgument ( int  )
staticconstexpr

Should the specialiser attempt to specialise the argument at the given position in the argument list, which is of type T?

The default implementation always returns true.

◆ validScalarTypes()

template<typename KnownTensorTypes , typename... ScalarTypes>
constexpr static bool sp::Specialisable::validScalarTypes ( )
staticconstexpr
Template Parameters
KnownTensorTypesAn sp::TypeList<...> where ... is a list of the currently-known Tensor types about to be passed to the operator. This tuple may be of length zero, but only if the operator function has a scalar argument that occurs before any Tensor arguments.
ScalarTypesAll of the scalar types about to be passed to the function, in order. Since scalar types are known immediately (unlike tensor types/ranks), this routine gets the whole lot at once, which should simplify implementations.
Returns
false if the expansion should be pruned, true otherwise.

◆ validTensorRanks()

template<int... Ranks>
constexpr static bool sp::Specialisable::validTensorRanks ( )
staticconstexpr
Template Parameters
RanksA prefix of the list of Tensor ranks about to be used as arguments to the operator, in arg-order. The function is never called with a zero-length argument pack.
Returns
false if the given list of ranks is not valid for this operator, true otherwise.

◆ validTensorTypes()

template<typename... Types>
constexpr static bool sp::Specialisable::validTensorTypes ( )
staticconstexpr
Template Parameters
TypesA prefix of the list of Tensor types about to be used as arguments to the operator, in arg-order. The function is never called with a zero-length argument pack.
Returns
false if the given list of types is not valid for this operator, true otherwise.

Member Data Documentation

◆ DesiresPitchedness

constexpr static bool sp::Specialisable::DesiresPitchedness = true
staticconstexpr

True if we should attempt to set the pitchedness flag of TensorLikes.

◆ MaxPackMode

constexpr static PackMode sp::Specialisable::MaxPackMode = PackMode::FULL
staticconstexpr

The maximum Tensor packing mode that's worth optimising for.

Note that, for 1D tensors, FULL and PARTIAL are equivalent.