Graph Framework
|
Class representing a node leaf. More...
#include <node.hpp>
Classes | |
struct | caches_t |
Data structure to contain the two caches. More... | |
Public Types | |
typedef T | base |
Type def to retrieve the backend type. | |
Public Member Functions | |
leaf_node (const std::string s, const size_t count, const bool pseudo) | |
Construct a basic node. | |
virtual | ~leaf_node () |
Destructor. | |
virtual backend::buffer< T > | evaluate ()=0 |
Evaluate method. | |
virtual std::shared_ptr< leaf_node > | reduce ()=0 |
Reduction method. | |
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > | df (std::shared_ptr< leaf_node< T, SAFE_MATH > > x)=0 |
Transform node to derivative. | |
virtual void | compile_preamble (std::ostringstream &stream, jit::register_map ®isters, jit::visiter_map &visited, jit::register_usage &usage, jit::texture1d_list &textures1d, jit::texture2d_list &textures2d, int &avail_const_mem) |
Compile preamble. | |
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > | compile (std::ostringstream &stream, jit::register_map ®isters, jit::register_map &indices, const jit::register_usage &usage)=0 |
Compile the node. | |
virtual bool | is_match (std::shared_ptr< leaf_node< T, SAFE_MATH > > x) |
Querey if the nodes match. | |
bool | is_power_base_match (std::shared_ptr< leaf_node< T, SAFE_MATH > > x) |
Check if the base of the powers match. | |
virtual void | set (const T d) |
Set the value of variable data. | |
virtual void | set (const size_t index, const T d) |
Set the value of variable data. | |
virtual void | set (const std::vector< T > &d) |
Set the value of variable data. | |
virtual void | set (const backend::buffer< T > &d) |
Set the value of variable data. | |
virtual void | to_latex () const =0 |
Convert the node to latex. | |
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > | to_vizgraph (std::stringstream &stream, jit::register_map ®isters)=0 |
Convert the node to vizgraph. | |
virtual bool | is_constant () const |
Test if node is a constant. | |
virtual bool | has_constant_zero () const |
Test the constant node has a zero. | |
bool | is_normal () |
Test if the result is normal. | |
virtual bool | is_all_variables () const =0 |
Test if all the subnodes terminate in variables. | |
virtual bool | is_power_like () const |
Test if the node acts like a power of variable. | |
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > | get_power_base () |
Get the base of a power. | |
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > | get_power_exponent () const =0 |
Get the exponent of a power. | |
size_t | get_hash () const |
Get the hash for the node. | |
size_t | get_complexity () const |
Get the number of nodes in the subgraph. | |
virtual bool | has_pseudo () const |
Query if the node contains pseudo variables. | |
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > | remove_pseudo () |
Remove pseudo variable nodes. | |
virtual void | endline (std::ostringstream &stream, const jit::register_usage &usage) const final |
End a line in the kernel source. | |
Static Public Attributes | |
static thread_local caches_t | caches |
A per thread instance of the cache structure. | |
Protected Attributes | |
const size_t | hash |
Hash for node. | |
const size_t | complexity |
Graph complexity. | |
std::map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > | df_cache |
Cache derivative terms. | |
const bool | contains_pseudo |
Node contains pseudo variables. | |
Class representing a node leaf.
T | Base type of the calculation. |
SAFE_MATH | Use Safe Math operations. |
|
inline |
Construct a basic node.
[in] | s | Node string to hash. |
[in] | count | Number of nodes in the subgraph. |
[in] | pseudo | Node contains pseudo variable. |
|
pure virtual |
Compile the node.
[in,out] | stream | String buffer stream. |
[in,out] | registers | List of defined registers. |
[in,out] | indices | List of defined indices. |
[in] | usage | List of register usage count. |
Implemented in graph::add_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, and graph::arctan_node< T, SAFE_MATH >.
|
inlinevirtual |
Compile preamble.
Some nodes require additions to the preamble however most don't so define a generic method that does nothing.
[in,out] | stream | String buffer stream. |
[in,out] | registers | List of defined registers. |
[in,out] | visited | List of visited nodes. |
[in,out] | usage | List of register usage count. |
[in,out] | textures1d | List of 1D textures. |
[in,out] | textures2d | List of 2D textures. |
[in,out] | avail_const_mem | Available constant memory. |
Reimplemented in graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::branch_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::triple_node< T, SAFE_MATH >, graph::triple_node< T, false >, graph::variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, and graph::random_node< T, SAFE_MATH >.
|
pure virtual |
Transform node to derivative.
[in] | x | The variable to take the derivative to. |
|
inlinefinalvirtual |
End a line in the kernel source.
[in,out] | stream | String buffer stream. |
[in] | usage | List of register usage count. |
|
pure virtual |
Evaluate method.
Implemented in graph::add_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, and graph::arctan_node< T, SAFE_MATH >.
|
inline |
Get the number of nodes in the subgraph.
|
inline |
Get the hash for the node.
|
inlinevirtual |
Get the base of a power.
Most node can be treated as x^1 so just return this node.
Reimplemented in graph::sqrt_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, and graph::piecewise_2D_node< T, SAFE_MATH >.
|
pure virtual |
Get the exponent of a power.
Most node can be treated as x^1 so just return one for those nodes but we need todo that manually in the derived classes.
Implemented in graph::sqrt_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::branch_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, and graph::random_node< T, SAFE_MATH >.
|
inlinevirtual |
Test the constant node has a zero.
Reimplemented in graph::constant_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, and graph::piecewise_2D_node< T, SAFE_MATH >.
|
inlinevirtual |
Query if the node contains pseudo variables.
Reimplemented in graph::pseudo_variable_node< T, SAFE_MATH >.
|
pure virtual |
Test if all the subnodes terminate in variables.
Implemented in graph::pow_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::branch_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::triple_node< T, SAFE_MATH >, graph::triple_node< T, false >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, and graph::random_node< T, SAFE_MATH >.
|
inlinevirtual |
Test if node is a constant.
Reimplemented in graph::constant_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, and graph::piecewise_2D_node< T, SAFE_MATH >.
|
inlinevirtual |
Querey if the nodes match.
[in] | x | Other graph to check if it is a match. |
|
inline |
Test if the result is normal.
|
inline |
Check if the base of the powers match.
[in] | x | Other graph to check if the bases match. |
|
inlinevirtual |
Test if the node acts like a power of variable.
Most nodes are not so default to false.
Reimplemented in graph::sqrt_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, and graph::piecewise_2D_node< T, SAFE_MATH >.
|
pure virtual |
Reduction method.
For basic nodes, there's nothing to reduce.
Implemented in graph::add_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, and graph::arctan_node< T, SAFE_MATH >.
|
inlinevirtual |
Remove pseudo variable nodes.
Reimplemented in graph::add_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, and graph::arctan_node< T, SAFE_MATH >.
|
inlinevirtual |
Set the value of variable data.
[in] | d | Backend buffer data to set. |
Reimplemented in graph::variable_node< T, SAFE_MATH >.
|
inlinevirtual |
Set the value of variable data.
[in] | index | Buffer index to set value. |
[in] | d | Scalar data to set. |
Reimplemented in graph::variable_node< T, SAFE_MATH >.
|
inlinevirtual |
Set the value of variable data.
[in] | d | Vector data to set. |
Reimplemented in graph::variable_node< T, SAFE_MATH >.
|
inlinevirtual |
Set the value of variable data.
[in] | d | Scalar data to set. |
Reimplemented in graph::variable_node< T, SAFE_MATH >.
|
pure virtual |
Convert the node to latex.
Implemented in graph::add_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, and graph::arctan_node< T, SAFE_MATH >.
|
pure virtual |
Convert the node to vizgraph.
[in,out] | stream | String buffer stream. |
[in,out] | registers | List of defined registers. |
Implemented in graph::add_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, and graph::arctan_node< T, SAFE_MATH >.