Speclib  0.1.2
The library for writing better CUDA libraries
sp::VariableBinding< Child, Names, Ts > Class Template Referencefinal

Represents a variable user and values to bind to it. More...

#include <Var.hpp>

Inheritance diagram for sp::VariableBinding< Child, Names, Ts >:
[legend]

Public Types

template<typename... NewChildren>
using ReplaceChildren = VariableBinding< NewChildren..., Names, Ts... >
 
using ValueNames = Names
 The set of variable names corresponding to the values in this object. More...
 
- Public Types inherited from sp::VariableUser< VariableBinding< Child, Names, Ts... >, Child >
using Substitute = std::conditional_t< std::is_same_v< VariableBinding< Child, Names, Ts... >, Old >, New, typename DeferSubclass< Old >::template ReplaceChildren< typename Children::template Substitute< Old, New >... > >
 Recursively substitute the given old user with the given new user. More...
 
using Vars = typename sp::cat_integer_sequences< typename Children::Vars... >::template sort<>::template unique<>
 The set of unbound variable names. More...
 
using VarType = typename VarTypeHelper< typename Children::template VarType< Name >... >::type
 The type of a named variable. More...
 
using ChildType = typename sp::TypeList< Children... >::template get< I >
 The type of the Ith child. More...
 

Public Member Functions

template<typename... NewChildren>
constexpr auto replaceChildren (NewChildren &&... newChildren) const
 
constexpr auto getBindResult () const
 Get the result of binding this object's values to the variable user. More...
 
constexpr auto filterValues () const
 Return a VariableBinding with all values that aren't used by the variable user removed. More...
 
template<VariableName Name, typename U >
constexpr auto setValue (U &&value) const
 Set or substitute a value in the VariableBinding with a different value. More...
 
template<VariableName Name>
constexpr const auto & getValue () const
 Get the value with the given name. More...
 
template<VariableName Name>
constexpr auto & getValue ()
 Get the value with the given name. More...
 
- Public Member Functions inherited from sp::VariableUser< VariableBinding< Child, Names, Ts... >, Child >
constexpr decltype(auto) operator() (Ts &&... values) const
 Calls operator() on the result of binding this object to a set of variables. More...
 
constexpr auto & get ()
 Get the Ith child. More...
 
constexpr const auto & get () const
 Get the Ith child. More...
 
constexpr auto bind (Ts &&... values) const
 Bind a specified set of values to the corresponding variables in this expression. More...
 
constexpr auto bind (Ts &&... values) const
 Bind a set of values to the expression's variables. More...
 
constexpr auto substitute (const New &newValue) const
 Substitute all instances of the given type with the the given new value. More...
 
constexpr auto replaceChildren (NewChildren &&... newChildren) const
 Replace the children of this variable user with the given new children. More...
 

Friends

template<VariableName... Ns, typename... Us, typename C >
requires (sizeof...(Ns) > 0)
constexpr friend auto getVariableBinding (const C &child, Us &&... values)
 
template<typename... Us, typename C >
requires (sizeof...(Us) > 0 && sizeof...(Us) == C::Vars::Size)
constexpr friend auto getVariableBinding (const C &child, Us &&... values)
 
template<typename C >
constexpr friend auto getVariableBinding (const C &child)
 

Additional Inherited Members

- Static Public Member Functions inherited from sp::VariableUser< VariableBinding< Child, Names, Ts... >, Child >
static constexpr VariableName getUnusedVariableName (int i=0)
 Get an unused variable name. More...
 
- Static Public Attributes inherited from sp::VariableUser< VariableBinding< Child, Names, Ts... >, Child >
static constexpr bool IsFullyBound
 True if there are no unbound variables, and false if there are. More...
 
static constexpr bool IsFullyUnbound
 False if there are any bound variables, and true if there aren't. More...
 
static constexpr int ChildCount
 The number of children. More...
 
- Protected Member Functions inherited from sp::VariableUser< VariableBinding< Child, Names, Ts... >, Child >
constexpr VariableUser (Ts &&... children)
 Copy the arguments into the children tuple. More...
 

Detailed Description

template<typename Child, typename Names, typename... Ts>
class sp::VariableBinding< Child, Names, Ts >

Represents a variable user and values to bind to it.

Use getVariableBinding() to construct.

This is useful for reasoning about a variable user in context with what is intended to be bound to it. For examples:

  • Algebraic transformations can be made, and then the variables that optimized away can be removed from the binding.
  • Two variables to be bound can be compared for equality at run time, and a version with one of the variables substituted for the other can be created and then bound.

This class makes it possible for a variadic function (like the specialization engine) to accept arguments that may not all be intended to be bound to the variable user.

This class is also useful for passing around arguments, e.g to a CUDA kernel, so that the compiler can prove where two arguments in a resulting expression (e.g: a TensorExpr) are the same.

Template Parameters
NamesThe variable names of each value to bind. These names need to be specified explicitly so that the variable user and variables to bind can be operated on independently. It is not necessary to have an value (and name) to bind for each variable in the variable user. It is permitted to specify values (and names) to bind for variables that do not exist in the variable user. These will be ignored. There is a templade deduction guide so that if the names are not explicitly given, they are inferred to be the variable names of the child.
ChildThe variable user type. If bind() is called on a VariableBinding, it is applied to the child variable user, without paying any attention to whether or not there is also an value in the VariableBinding for the variables given to bind(). When this is done, any values in the VariableBinding corresponding to those bound with bind() become ignored as they are not variables in the result of the bind().
TsThe types of the values to bind.

Member Typedef Documentation

◆ ValueNames

template<typename Child , typename Names , typename... Ts>
using sp::VariableBinding< Child, Names, Ts >::ValueNames = Names

The set of variable names corresponding to the values in this object.

Member Function Documentation

◆ filterValues()

template<typename Child , typename Names , typename... Ts>
constexpr auto sp::VariableBinding< Child, Names, Ts >::filterValues ( ) const
constexpr

Return a VariableBinding with all values that aren't used by the variable user removed.

This is useful if the variable binding is to be passed across an ABI boundary, e.g: during a CUDA kernel call, as it avoids the need to copy arguments that would not actually be used.

Returns
A copy of this object with the unused values removed.

◆ getBindResult()

template<typename Child , typename Names , typename... Ts>
constexpr auto sp::VariableBinding< Child, Names, Ts >::getBindResult ( ) const
constexpr

Get the result of binding this object's values to the variable user.

◆ getValue() [1/2]

template<typename Child , typename Names , typename... Ts>
template<VariableName Name>
constexpr auto & sp::VariableBinding< Child, Names, Ts >::getValue ( )
constexpr

Get the value with the given name.

Template Parameters
NameThe name of the value to get. It is an error if the value does not exist.
Returns
A reference to the requested value.

◆ getValue() [2/2]

template<typename Child , typename Names , typename... Ts>
template<VariableName Name>
constexpr const auto & sp::VariableBinding< Child, Names, Ts >::getValue ( ) const
constexpr

Get the value with the given name.

Template Parameters
NameThe name of the value to get. It is an error if the value does not exist.
Returns
A const reference to the requested value.

◆ setValue()

template<typename Child , typename Names , typename... Ts>
template<VariableName Name, typename U >
constexpr auto sp::VariableBinding< Child, Names, Ts >::setValue ( U &&  value) const
constexpr

Set or substitute a value in the VariableBinding with a different value.

If the variable name is in the VariableBinding already, it will be replaced in the result. If it is not, it will be added in the result. It is permitted to change the type of a value with this operation.

Parameters
valueThe value to set or substitute.
Template Parameters
NameThe name corresponding to the value to be added or substituted.
Returns
A copy of this object with the changed values.