Speclib  0.1.2
The library for writing better CUDA libraries
sp::EltwiseTensorOp< Functor, Children > Struct Template Reference

Extends TensorExpr, allowing the definition of an N-ary tensor operator from any N-ary functor. More...

#include <TensorExpr.hpp>

Inheritance diagram for sp::EltwiseTensorOp< Functor, Children >:
[legend]

Public Types

using This = EltwiseTensorOp< Functor, Children... >
 
using ValueType = typename std::invoke_result_t< Functor, typename Children::ValueType... >
 
using Traits = f::Traits< Functor >
 Inherit the Traits given by the underlying functor. More...
 
- Public Types inherited from sp::TensorTensorOp< EltwiseTensorOp< Functor, Children... >, sp::INHERIT_RANK, TransformEltwiseChildType< Children, Children... >... >
using ValueType = sp::value_type_or_common_t< EltwiseTensorOp< Functor, Children... >, typename Children::ValueType... >
 
using Opts = typename sp::MergeTensorOpts< typename Children::Opts... >::type
 
- Public Types inherited from sp::Operator< Subtype, Children... >
using Traits = f::Traits< void >
 

Public Member Functions

 EltwiseTensorOp (const Children &... children)
 
template<int L, typename... Args>
Vec< ValueType, L > vectorCalculate (const sp::Vec< Args, L > &... inputs) const
 
template<int L, CacheMode Mode, int... I>
Vec< ValueType, L > reallyVectorRead (sp::int_sequence< I... >, const Vec< int, This::Rank > &dims) const
 Target for pattern-matching the sp::int_sequence for the subexpressions. More...
 
template<int L, CacheMode Mode>
Vec< ValueType, L > vectorReadImpl (const Vec< int, This::Rank > &dims) const
 Read L elements, adjacent in the last dimension, from the virtual tensor described by this operator. More...
 
- Public Member Functions inherited from sp::TensorTensorOp< EltwiseTensorOp< Functor, Children... >, sp::INHERIT_RANK, TransformEltwiseChildType< Children, Children... >... >
 TensorTensorOp (Children... args)
 
auto dimsImpl () const
 Delegate dims() to the first subexpression. A helpful default. More...
 
int totalSizeImpl () const
 Delegate totalSize() to the first child. More...
 
- Public Member Functions inherited from sp::TensorOp< Subtype, ExprRank, Children >
constexpr TensorOp (Children... args)
 
- Public Member Functions inherited from sp::Operator< Subtype, Children... >
constexpr auto & child ()
 Access children. More...
 
constexpr const auto & child () const
 
constexpr auto & lhs ()
 Get the first subexpression if this is a binary operation. More...
 
constexpr const auto & lhs () const
 
constexpr auto & rhs ()
 Get the second subexpression if this is a binary operation. More...
 
constexpr const auto & rhs () const
 
constexpr void forEachChild (F &lambda)
 Run a lambda function on each child. More...
 
- Public Member Functions inherited from sp::TensorLike< Subtype, ExprRank==INHERIT_RANK ? sp::deduce_rank_v< __type_pack_element< 0, Children... > > :ExprRank >
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 Member Functions

template<typename T >
constexpr static auto getIdentityImpl ()
 
- 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 ()
 
constexpr static auto getIdentityImpl ()
 
constexpr static auto getIdentity ()
 

Additional Inherited Members

- Static Public Attributes inherited from sp::TensorTensorOp< EltwiseTensorOp< Functor, Children... >, sp::INHERIT_RANK, TransformEltwiseChildType< Children, Children... >... >
static constexpr int Arity
 
static constexpr int MaxVectorSize
 
- Static Public Attributes inherited from sp::Operator< Subtype, Children... >
static constexpr int Arity
 
- Static Public Attributes inherited from sp::TensorLike< Subtype, ExprRank==INHERIT_RANK ? sp::deduce_rank_v< __type_pack_element< 0, Children... > > :ExprRank >
constexpr static int Rank
 
- Protected Member Functions inherited from sp::Operator< Subtype, Children... >
constexpr Operator (Children... args)
 
constexpr void forEachChild (F &lambda, sp::int_sequence< I... > &)
 
- Protected Member Functions inherited from sp::TensorLike< Subtype, ExprRank==INHERIT_RANK ? sp::deduce_rank_v< __type_pack_element< 0, Children... > > :ExprRank >
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...
 
- Protected Attributes inherited from sp::Operator< Subtype, Children... >
std::tuple< Children... > children
 

Detailed Description

template<typename Functor, typename... Children>
struct sp::EltwiseTensorOp< Functor, Children >

Extends TensorExpr, allowing the definition of an N-ary tensor operator from any N-ary functor.

The functor may be stateful

In practice, this is very often the thing you want to extend when defining a new tensor operator.

Template Parameters
FunctorThe function type to define the operator with.
ChildrenThe types of the subexpressions.

Member Typedef Documentation

◆ Traits

template<typename Functor , typename... Children>
using sp::EltwiseTensorOp< Functor, Children >::Traits = f::Traits<Functor>

Inherit the Traits given by the underlying functor.

Member Function Documentation

◆ reallyVectorRead()

template<typename Functor , typename... Children>
template<int L, CacheMode Mode, int... I>
Vec< ValueType, L > sp::EltwiseTensorOp< Functor, Children >::reallyVectorRead ( sp::int_sequence< I... >  ,
const Vec< int, This::Rank > &  dims 
) const

Target for pattern-matching the sp::int_sequence for the subexpressions.

◆ vectorCalculate()

template<typename Functor , typename... Children>
template<int L, typename... Args>
Vec< ValueType, L > sp::EltwiseTensorOp< Functor, Children >::vectorCalculate ( const sp::Vec< Args, L > &...  inputs) const
Parameters
inputsAn amount of L-vectors equal to the arity of this operator.
Returns
The result of element-wise applying this operator's defining function to the elements in inputs. This yields an L-vector of results, and is the result of reading from the virtual tensor.

◆ vectorReadImpl()

template<typename Functor , typename... Children>
template<int L, CacheMode Mode>
Vec< ValueType, L > sp::EltwiseTensorOp< Functor, Children >::vectorReadImpl ( const Vec< int, This::Rank > &  dims) const

Read L elements, adjacent in the last dimension, from the virtual tensor described by this operator.