355#include <type_traits>
370 template<jit::
float_scalar T,
bool SAFE_MATH=false>
371 class leaf_node :
public std::enable_shared_from_this<leaf_node<T, SAFE_MATH>> {
378 std::unordered_map<size_t, std::shared_ptr<leaf_node<T, SAFE_MATH>>>
df_cache;
415 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
reduce() {
425 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
427 return std::shared_ptr<leaf_node<T, SAFE_MATH>> ();
471 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
484 return this == x.get();
518 virtual void set(
const std::vector<T> &
d) {}
539 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
to_vizgraph(std::stringstream &stream,
566 return this->
evaluate().is_normal();
653 virtual void endline(std::ostringstream &stream,
656#ifndef SHOW_USE_COUNT
662 <<
" // used " <<
usage.at(
this)
677 std::unordered_map<size_t, std::shared_ptr<leaf_node<T, SAFE_MATH>>>
nodes;
679 std::unordered_map<size_t, backend::buffer<T>>
backends;
690 template<jit::
float_scalar T,
bool SAFE_MATH=false>
700 template<jit::
float_scalar T,
bool SAFE_MATH=false>
705 template<jit::
float_scalar T,
bool SAFE_MATH=false>
709 template<jit::
float_scalar T,
bool SAFE_MATH=false>
712 template<jit::
float_scalar T,
bool SAFE_MATH=false>
720 template<jit::
float_scalar T,
bool SAFE_MATH=false>
722 std::stringstream stream;
726 stream <<
"graph \"\" {" << std::endl;
727 stream <<
" node [fontname = \"Helvetica\", ordering = out]" << std::endl << std::endl;
728 node->to_vizgraph(stream, registers);
729 stream <<
"}" << std::endl;
731 std::cout << stream.str() << std::endl;
743 template<jit::
float_scalar T,
bool SAFE_MATH=false>
751 static std::string to_string() {
790 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
795 if (registers.find(
this) == registers.end()) {
799 stream <<
"int " << registers[
this] <<
" = index";
800 }
else if constexpr (jit::use_metal<T> ()) {
801 stream <<
"uint " << registers[
this] <<
" = index";
803 stream <<
"size_t " << registers[
this] <<
" = i";
827 if (registers.find(
this) == registers.end()) {
829 registers[
this] =
name;
830 stream <<
" " <<
name
831 <<
" [label = \"i\", shape = box, style = \"rounded,filled\", fillcolor = black, fontcolor = white];" << std::endl;
855 template<jit::
float_scalar T,
bool SAFE_MATH=false>
857 auto temp = std::make_shared<index_node<T, SAFE_MATH>> ();
868#if defined(__clang__) || defined(__GNUC__)
871 assert(
false &&
"Should never reach.");
876 template<jit::
float_scalar T,
bool SAFE_MATH=false>
888 template<jit::
float_scalar T,
bool SAFE_MATH=false>
890 return std::dynamic_pointer_cast<index_node<T, SAFE_MATH>> (x);
902 template<jit::
float_scalar T,
bool SAFE_MATH=false>
911 static std::string to_string(
const T
d) {
912 return jit::format_to_string<T> (
d);
927 assert(
d.is_normal() &&
"Denormal encountered");
929 assert(
d.size() == 1 &&
"Constants need to be scalar functions.");
965 if (registers.find(
this) == registers.end()) {
966#ifdef USE_CONSTANT_CACHE
969 jit::add_type<T> (stream);
972 stream <<
" " << registers[
this] <<
" = ";
974 jit::add_type<T> (stream);
980 registers[
this] = jit::get_type_string<T> () +
"("
984 registers[
this] =
"(" + jit::get_type_string<T> () +
")"
1000 if (
this == x.get()) {
1016 return data.size() == 1 && data.at(0) ==
d;
1024 return std::imag(
temp) == 0 &&
1032 std::cout << data.at(0);
1044 if (registers.find(
this) == registers.end()) {
1046 registers[
this] =
name;
1047 stream <<
" " <<
name
1048 <<
" [label = \"" << this->
evaluate().at(0)
1049 <<
"\", shape = box, style = \"rounded,filled\", fillcolor = black, fontcolor = white];" << std::endl;
1110 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1112 auto temp = std::make_shared<constant_node<T, SAFE_MATH>> (
d);
1123#if defined(__clang__) || defined(__GNUC__)
1126 assert(
false &&
"Should never reach.");
1139 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1153 template<jit::
float_scalar T,
bool SAFE_MATH>
1166 template<jit::
float_scalar T,
bool SAFE_MATH>
1179 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1185 template<jit::complex_scalar T>
1186 constexpr T
i = T(0.0, 1.0);
1189 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1201 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1203 return std::dynamic_pointer_cast<constant_node<T, SAFE_MATH>> (x);
1218 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1232 const std::string
s) :
1242 return arg->evaluate();
1265 if (!
visited.contains(
this)) {
1266 arg->compile_preamble(stream, registers,
1271#ifdef SHOW_USE_COUNT
1311 return arg->is_all_variables();
1336 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1355 const std::string
s) :
1371 const std::string
s,
1397 if (!
visited.contains(
this)) {
1398 left->compile_preamble(stream, registers,
1402 right->compile_preamble(stream, registers,
1407#ifdef SHOW_USE_COUNT
1439 return left->is_all_variables() &&
1440 right->is_all_variables();
1448 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
1466 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1484 const std::string
s) :
1514 if (!
visited.contains(
this)) {
1515 this->
left->compile_preamble(stream, registers,
1519 this->middle->compile_preamble(stream, registers,
1523 this->
right->compile_preamble(stream, registers,
1528#ifdef SHOW_USE_COUNT
1551 return this->
left->is_all_variables() &&
1552 middle->is_all_variables() &&
1553 this->
right->is_all_variables();
1570 template<
size_t N, jit::
float_scalar T,
bool SAFE_MATH=false>
1584 const bool test =
b->has_pseudo();
1614 const std::string
s) :
1639 if (!
visited.contains(
this)) {
1641 b->compile_preamble(stream, registers,
1648#ifdef SHOW_USE_COUNT
1673 const bool test =
b->is_all_variables();
1686 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
1697 template<
typename T>
1715 template<
typename S=
bool>
1716 std::shared_ptr<leaf_node<T, SAFE_MATH>>
1725 requires(std::is_base_of_v<leaf_node<T, SAFE_MATH>,
1737 const std::string
s)
1738 requires(std::is_base_of_v<straight_node<T, SAFE_MATH>,
1752 const std::string
s)
1753 requires(std::is_base_of_v<branch_node<T, SAFE_MATH>,
1769 const std::string
s)
1770 requires(std::is_base_of_v<triple_node<T, SAFE_MATH>,
1782 const std::string
s)
1783 requires(std::is_base_of_v<n_branch_node<N, T, SAFE_MATH>,
1800 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1806 const std::string symbol;
1826 const std::string &symbol) :
1828 buffer(
s), symbol(symbol) {}
1838 const std::string &symbol) :
1840 buffer(
s,
d), symbol(symbol) {
1851 const std::string &symbol) :
1853 buffer(
d), symbol(symbol) {
1864 const std::string &symbol) :
1866 buffer(
d), symbol(symbol) {
1914#ifdef SHOW_USE_COUNT
1962 virtual void set(
const std::vector<T> &
d) {
1998 if (registers.find(
this) == registers.end()) {
2000 registers[
this] =
name;
2001 stream <<
" " <<
name
2003 <<
"\", shape = box];" << std::endl;
2013 return buffer.size();
2022 return buffer.data();
2071 #ifndef SHOW_USE_COUNT
2075 stream << end <<
" // " << symbol
2076 #ifdef SHOW_USE_COUNT
2077 <<
" used " <<
usage.at(
this)
2092 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2094 const std::string &symbol) {
2095 return std::make_shared<variable_node<T, SAFE_MATH>> (
s, symbol);
2108 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2110 const std::string &symbol) {
2111 return std::make_shared<variable_node<T, SAFE_MATH>> (
s,
d, symbol);
2123 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2125 const std::string &symbol) {
2126 return std::make_shared<variable_node<T, SAFE_MATH>> (
d, symbol);
2138 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2140 const std::string &symbol) {
2141 return std::make_shared<variable_node<T, SAFE_MATH>> (
d, symbol);
2145 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2148 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2151 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2152 using map_nodes = std::vector<std::pair<shared_leaf<T, SAFE_MATH>,
2155 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2156 using copy_nodes = std::vector<std::pair<shared_variable<T, SAFE_MATH>,
2168 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2170 return std::dynamic_pointer_cast<variable_node<T, SAFE_MATH>> (x);
2186 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2222 std::cout <<
"\\left(";
2223 this->
arg->to_latex();
2224 std::cout <<
"\\right)";
2251 return this->
arg->get_power_base();
2260 return this->
arg->get_power_exponent();
2290 if (registers.find(
this) == registers.end()) {
2292 registers[
this] =
name;
2293 stream <<
" " <<
name
2294 <<
" [label = \"pseudo_variable\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
2296 auto a = this->
arg->to_vizgraph(stream, registers);
2297 stream <<
" " <<
name <<
" -- " << registers[
a.get()] <<
";" << std::endl;
2313 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2315 return std::make_shared<pseudo_variable_node<T, SAFE_MATH>> (x);
2319 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2331 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2333 return std::dynamic_pointer_cast<pseudo_variable_node<T, SAFE_MATH>> (x);
Class signature to implement compute backends.
Class representing a generic buffer.
Definition backend.hpp:29
bool is_normal() const
Check for normal values.
Definition backend.hpp:267
bool has_zero() const
Is any element zero.
Definition backend.hpp:141
void set(const T d)
Assign a constant value.
Definition backend.hpp:92
Class representing a branch node.
Definition node.hpp:1337
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1438
branch_node(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r, const std::string s, const size_t count, const bool pseudo)
Assigns the left and right branches.
Definition node.hpp:1369
shared_leaf< T, SAFE_MATH > get_left() const
Get the left branch.
Definition node.hpp:1420
shared_leaf< T, SAFE_MATH > get_right() const
Get the right branch.
Definition node.hpp:1429
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1449
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, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition node.hpp:1389
branch_node(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r, const std::string s)
Assigns the left and right branches.
Definition node.hpp:1353
shared_leaf< T, SAFE_MATH > right
Right branch of the tree.
Definition node.hpp:1342
shared_leaf< T, SAFE_MATH > left
Left branch of the tree.
Definition node.hpp:1340
Class representing data that cannot change.
Definition node.hpp:903
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1096
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:1031
virtual shared_leaf< T, SAFE_MATH > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)
Compile the node.
Definition node.hpp:961
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition node.hpp:1087
bool is(const T d)
Check if the constant is value.
Definition node.hpp:1015
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:937
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition node.hpp:999
constant_node(const backend::buffer< T > &d)
Construct a constant node from a vector.
Definition node.hpp:924
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:1042
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:947
virtual bool is_constant() const
Test if node is a constant.
Definition node.hpp:1060
virtual bool has_constant_zero() const
Test the constant node has a zero.
Definition node.hpp:1069
bool is_integer()
Check if the value is an integer.
Definition node.hpp:1022
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:1078
Index node.
Definition node.hpp:744
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:814
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:825
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:842
index_node()
Construct a constant node from a vector.
Definition node.hpp:759
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)
Compile the node.
Definition node.hpp:791
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:767
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:777
Class representing a node leaf.
Definition node.hpp:371
virtual ~leaf_node()
Destructor.
Definition node.hpp:399
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, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition node.hpp:445
virtual void set(const std::vector< T > &d)
Set the value of variable data.
Definition node.hpp:518
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:585
virtual bool is_match(std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
Query if the nodes match.
Definition node.hpp:483
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_exponent() const =0
Get the exponent of a power.
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)=0
Compile the node.
T base
Type def to retrieve the backend type.
Definition node.hpp:686
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:530
const bool contains_pseudo
Node contains pseudo variables.
Definition node.hpp:380
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > remove_pseudo()
Remove pseudo variable nodes.
Definition node.hpp:642
virtual void set(const backend::buffer< T > &d)
Set the value of variable data.
Definition node.hpp:525
static thread_local caches_t caches
A per thread instance of the cache structure.
Definition node.hpp:683
virtual bool is_all_variables() const
Test if all the sub-nodes terminate in variables.
Definition node.hpp:574
virtual void endline(std::ostringstream &stream, const jit::register_usage &usage, const char end=';') const
End a line in the kernel source.
Definition node.hpp:653
virtual bool is_constant() const
Test if node is a constant.
Definition node.hpp:547
virtual void set(const size_t index, const T d)
Set the value of variable data.
Definition node.hpp:510
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 std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_base()
Get the base of a power.
Definition node.hpp:596
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > reduce()
Reduction method.
Definition node.hpp:415
leaf_node(const std::string s, const size_t count, const bool pseudo)
Construct a basic node.
Definition node.hpp:390
virtual bool has_constant_zero() const
Test the constant node has a zero.
Definition node.hpp:556
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > df(std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
Transform node to derivative.
Definition node.hpp:426
virtual void set(const T d)
Set the value of variable data.
Definition node.hpp:502
const size_t complexity
Graph complexity.
Definition node.hpp:376
virtual backend::buffer< T > evaluate()=0
Evaluate method.
bool is_power_base_match(std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
Check if the base of the powers match.
Definition node.hpp:493
size_t get_complexity() const
Get the number of nodes in the subgraph.
Definition node.hpp:624
virtual bool has_pseudo() const
Query if the node contains pseudo variables.
Definition node.hpp:633
const size_t hash
Hash for node.
Definition node.hpp:374
std::unordered_map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > df_cache
Cache derivative terms.
Definition node.hpp:378
bool is_normal()
Test if the result is normal.
Definition node.hpp:565
size_t get_hash() const
Get the hash for the node.
Definition node.hpp:615
Class representing a N branch node.
Definition node.hpp:1571
size_t total_complexity(std::array< shared_leaf< T, SAFE_MATH >, N > &branches)
Check if any sub-node has a pseudo variable.
Definition node.hpp:1598
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1687
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1671
bool any_has_pseudo(std::array< shared_leaf< T, SAFE_MATH >, N > &branches)
Check if any sub-node has a pseudo variable.
Definition node.hpp:1582
n_branch_node(std::array< shared_leaf< T, SAFE_MATH >, N > branches, const std::string s)
Reduces and assigns the branches.
Definition node.hpp:1613
std::array< shared_leaf< T, SAFE_MATH >, N > branches
Branches of the tree.
Definition node.hpp:1574
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, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition node.hpp:1631
shared_leaf< T, SAFE_MATH > get_arg(const size_t index) const
Get the Nth arg.
Definition node.hpp:1662
Nodes without derivatives.
Definition node.hpp:1713
std::shared_ptr< leaf_node< T, SAFE_MATH > > df(std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
Transform node to derivative.
no_derivative(std::array< shared_leaf< T, SAFE_MATH >, N > b, const std::string s)
Constructor for base n branch nodes base classes.
Definition node.hpp:1781
no_derivative(const std::string s)
Constructor for base leaf nodes base classes.
Definition node.hpp:1724
no_derivative(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > m, shared_leaf< T, SAFE_MATH > r, const std::string s)
Constructor for base triple nodes base classes.
Definition node.hpp:1766
no_derivative(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r, const std::string s)
Constructor for base branch nodes base classes.
Definition node.hpp:1750
no_derivative(shared_leaf< T, SAFE_MATH > arg, const std::string s)
Constructor for straight node base classes.
Definition node.hpp:1736
Class representing a subexpression that acts like a variable.
Definition node.hpp:2187
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:2221
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:2214
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:2241
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:2288
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:2259
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:2232
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition node.hpp:2277
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition node.hpp:2250
virtual bool has_pseudo() const
Query if the node contains pseudo variables.
Definition node.hpp:2268
pseudo_variable_node(shared_leaf< T, SAFE_MATH > a)
Construct a pseudo variable node.
Definition node.hpp:2205
Class representing a straight node.
Definition node.hpp:1219
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1319
shared_leaf< T, SAFE_MATH > arg
Argument.
Definition node.hpp:1222
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:1241
shared_leaf< T, SAFE_MATH > get_arg() const
Get the argument.
Definition node.hpp:1301
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, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition node.hpp:1257
straight_node(shared_leaf< T, SAFE_MATH > a, const std::string s)
Construct a straight node.
Definition node.hpp:1231
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1310
virtual shared_leaf< T, SAFE_MATH > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)
Compile the node.
Definition node.hpp:1289
Class representing a triple branch node.
Definition node.hpp:1467
shared_leaf< T, SAFE_MATH > get_middle() const
Get the middle branch.
Definition node.hpp:1541
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1550
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, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition node.hpp:1506
triple_node(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > m, shared_leaf< T, SAFE_MATH > r, const std::string s)
Reduces and assigns the left and right branches.
Definition node.hpp:1481
shared_leaf< T, SAFE_MATH > middle
Middle branch of the tree.
Definition node.hpp:1470
Class representing data that can change.
Definition node.hpp:1801
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition node.hpp:2048
variable_node(const backend::buffer< T > &d, const std::string &symbol)
Construct a variable node from backend buffer.
Definition node.hpp:1863
virtual void endline(std::ostringstream &stream, const jit::register_usage &usage, const char end=';') const
End a line in the kernel source.
Definition node.hpp:2068
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, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition node.hpp:1904
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:2030
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:1885
variable_node(const size_t s, const T d, const std::string &symbol)
Construct a variable node from a scalar.
Definition node.hpp:1837
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:1985
size_t size()
Get the size of the variable buffer.
Definition node.hpp:2012
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:1996
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:1875
virtual shared_leaf< T, SAFE_MATH > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)
Compile the node.
Definition node.hpp:1931
T * data()
Get a pointer to raw buffer.
Definition node.hpp:2021
virtual void set(const T d)
Set the value of variable data.
Definition node.hpp:1943
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:2039
virtual void set(const backend::buffer< T > &d)
Set the value of variable data.
Definition node.hpp:1971
virtual void set(const size_t index, const T d)
Set the value of variable data.
Definition node.hpp:1953
variable_node(const size_t s, const std::string &symbol)
Construct a variable node with a size.
Definition node.hpp:1825
virtual void set(const std::vector< T > &d)
Set the value of variable data.
Definition node.hpp:1962
variable_node(const std::vector< T > &d, const std::string &symbol)
Construct a variable node from a vector.
Definition node.hpp:1850
std::string get_symbol() const
Get Symbol.
Definition node.hpp:1978
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:2057
Complex scalar concept.
Definition register.hpp:25
Float scalar concept.
Definition register.hpp:30
subroutine assert(test, message)
Assert check.
Definition f_binding_test.f90:38
Name space for graph nodes.
Definition arithmetic.hpp:13
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:1154
std::shared_ptr< variable_node< T, SAFE_MATH > > shared_variable
Convenience type alias for shared variable nodes.
Definition node.hpp:2146
shared_leaf< T, SAFE_MATH > index()
Construct an index.
Definition node.hpp:856
constexpr shared_leaf< T, SAFE_MATH > none()
Create a one constant.
Definition node.hpp:1180
void make_vizgraph(shared_leaf< T, SAFE_MATH > node)
Build the vizgraph input.
Definition node.hpp:721
constexpr shared_leaf< T, SAFE_MATH > one()
Forward declare for one.
Definition node.hpp:1167
std::vector< shared_variable< T, SAFE_MATH > > input_nodes
Convenience type alias for a vector of inputs.
Definition node.hpp:2149
shared_constant< T, SAFE_MATH > constant_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a constant node.
Definition node.hpp:1202
shared_variable< T, SAFE_MATH > variable_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a variable node.
Definition node.hpp:2169
shared_index< T, SAFE_MATH > index_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a index node.
Definition node.hpp:889
constexpr T i
Convenience type for imaginary constant.
Definition node.hpp:1186
shared_leaf< T, SAFE_MATH > constant(const backend::buffer< T > &d)
Construct a constant.
Definition node.hpp:1111
std::vector< std::pair< shared_variable< T, SAFE_MATH >, shared_variable< T, SAFE_MATH > > > copy_nodes
Convenience type alias for copying buffers.
Definition node.hpp:2157
shared_leaf< T, SAFE_MATH > variable(const size_t s, const std::string &symbol)
Construct a variable.
Definition node.hpp:2093
std::shared_ptr< pseudo_variable_node< T, SAFE_MATH > > shared_pseudo_variable
Convenience type alias for shared pseudo variable nodes.
Definition node.hpp:2320
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:691
std::shared_ptr< index_node< T, SAFE_MATH > > shared_index
Convenience type alias for shared index nodes.
Definition node.hpp:877
std::vector< std::pair< shared_leaf< T, SAFE_MATH >, shared_variable< T, SAFE_MATH > > > map_nodes
Convenience type alias for mapping end codes back to inputs.
Definition node.hpp:2153
constexpr shared_leaf< T, SAFE_MATH > null_leaf()
Create a null leaf.
Definition node.hpp:701
std::shared_ptr< constant_node< T, SAFE_MATH > > shared_constant
Convenience type alias for shared constant nodes.
Definition node.hpp:1190
std::vector< shared_leaf< T, SAFE_MATH > > output_nodes
Convenience type alias for a vector of output nodes.
Definition node.hpp:706
shared_leaf< T, SAFE_MATH > pseudo_variable(shared_leaf< T, SAFE_MATH > x)
Define pseudo variable convenience function.
Definition node.hpp:2314
shared_pseudo_variable< T, SAFE_MATH > pseudo_variable_cast(shared_leaf< T, SAFE_MATH > &x)
Cast to a pseudo variable node.
Definition node.hpp:2332
std::unordered_set< void * > visiter_map
Type alias for listing visited nodes.
Definition register.hpp:263
std::string format_to_string(const T value)
Convert a value to a string while avoiding locale.
Definition register.hpp:213
std::unordered_map< void *, size_t > register_usage
Type alias for counting register usage.
Definition register.hpp:261
std::unordered_set< std::string > preamble_map
Type alias for preamble defined functions.
Definition register.hpp:269
std::unordered_map< void *, std::string > register_map
Type alias for mapping node pointers to register names.
Definition register.hpp:259
constexpr bool use_cuda()
Test to use Cuda.
Definition register.hpp:68
std::unordered_map< void *, std::array< size_t, 2 > > texture2d_list
Type alias for indexing 2D textures.
Definition register.hpp:267
std::unordered_map< void *, size_t > texture1d_list
Type alias for indexing 1D textures.
Definition register.hpp:265
std::string to_string(const char prefix, const NODE *pointer)
Convert a graph::leaf_node pointer to a string.
Definition register.hpp:247
void test()
Test function.
Definition no_derivative_test.cpp:67
Type trait for not having a valid derivative.
Definition node.hpp:1698
Data structure to contain the two caches.
Definition node.hpp:675
std::unordered_map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > nodes
Cache of node.
Definition node.hpp:677
std::unordered_map< size_t, backend::buffer< T > > backends
Cache of backend buffers.
Definition node.hpp:679