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() {
416 return this->shared_from_this();
425 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
427 return std::shared_ptr<leaf_node<T, SAFE_MATH>> ();
452 int &avail_const_mem) {
454 if (usage.find(
this) == usage.end()) {
471 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
472 compile(std::ostringstream &stream,
484 return this == x.get();
502 virtual void set(
const T d) {}
510 virtual void set(
const size_t index,
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();
596 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
get_power_base() {
597 return this->shared_from_this();
642 virtual std::shared_ptr<leaf_node<T, SAFE_MATH>>
remove_pseudo() {
643 return this->shared_from_this();
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>
691 using shared_leaf = std::shared_ptr<leaf_node<T, SAFE_MATH>>;
700 template<jit::
float_scalar T,
bool SAFE_MATH=false>
705 template<jit::
float_scalar T,
bool SAFE_MATH=false>
706 using output_nodes = std::vector<shared_leaf<T, SAFE_MATH>>;
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;
724 stream << std::setprecision(jit::max_digits10<T> ());
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>>
791 compile(std::ostringstream &stream,
795 if (registers.find(
this) == registers.end()) {
799 stream <<
"int " << registers[
this] <<
" = index";
801 stream <<
"uint " << registers[
this] <<
" = index";
803 stream <<
"size_t " << registers[
this] <<
" = i";
808 return this->shared_from_this();
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;
834 return this->shared_from_this();
855 template<jit::
float_scalar T,
bool SAFE_MATH=false>
857 auto temp = std::make_shared<index_node<T, SAFE_MATH>> ();
859 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
868#if defined(__clang__) || defined(__GNUC__)
869 __builtin_unreachable();
871 assert(
false &&
"Should never reach.");
876 template<jit::
float_scalar T,
bool SAFE_MATH=false>
877 using shared_index = std::shared_ptr<index_node<T, SAFE_MATH>>;
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) {
926 if constexpr (SAFE_MATH) {
929 assert(d.size() == 1 &&
"Constants need to be scalar functions.");
961 compile(std::ostringstream &stream,
965 if (registers.find(
this) == registers.end()) {
966#ifdef USE_CONSTANT_CACHE
970 const T temp = this->
evaluate().at(0);
972 stream <<
" " << registers[
this] <<
" = ";
990 return this->shared_from_this();
1000 if (
this == x.get()) {
1006 return this->
evaluate() == x_cast->evaluate();
1015 bool is(
const T d) {
1016 return data.size() == 1 && data.at(0) == d;
1023 const auto temp = this->
evaluate().at(0);
1024 return std::imag(temp) == 0 &&
1025 fmod(std::real(temp), 1.0) == 0.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;
1052 return this->shared_from_this();
1070 return data.has_zero();
1088 return this->shared_from_this();
1110 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1112 auto temp = std::make_shared<constant_node<T, SAFE_MATH>> (d);
1114 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
1123#if defined(__clang__) || defined(__GNUC__)
1124 __builtin_unreachable();
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();
1264 int &avail_const_mem) {
1265 if (!visited.contains(
this)) {
1266 arg->compile_preamble(stream, registers,
1268 textures1d, textures2d,
1269 pre_funcs, avail_const_mem);
1270 visited.insert(
this);
1271#ifdef SHOW_USE_COUNT
1289 compile(std::ostringstream &stream,
1293 return arg->compile(stream, registers, thread_mem, usage);
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,
1373 const bool pseudo) :
1374 leaf_node<T, SAFE_MATH> (s, count, pseudo),
1396 int &avail_const_mem) {
1397 if (!visited.contains(
this)) {
1398 left->compile_preamble(stream, registers,
1400 textures1d, textures2d,
1401 pre_funcs, avail_const_mem);
1402 right->compile_preamble(stream, registers,
1404 textures1d, textures2d,
1405 pre_funcs, avail_const_mem);
1406 visited.insert(
this);
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) :
1513 int &avail_const_mem) {
1514 if (!visited.contains(
this)) {
1515 this->
left->compile_preamble(stream, registers,
1517 textures1d, textures2d,
1518 pre_funcs, avail_const_mem);
1519 this->middle->compile_preamble(stream, registers,
1521 textures1d, textures2d,
1522 pre_funcs, avail_const_mem);
1523 this->
right->compile_preamble(stream, registers,
1525 textures1d, textures2d,
1526 pre_funcs, avail_const_mem);
1527 visited.insert(
this);
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>
1574 std::array<shared_leaf<T, SAFE_MATH>, N>
branches;
1584 const bool test = b->has_pseudo();
1614 const std::string s) :
1638 int &avail_const_mem) {
1639 if (!visited.contains(
this)) {
1641 b->compile_preamble(stream, registers,
1643 textures1d, textures2d,
1644 pre_funcs, avail_const_mem);
1647 visited.insert(
this);
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<
bool HAS_DF=false>
1716 std::shared_ptr<leaf_node<T, SAFE_MATH>>
1725 requires(std::is_base_of_v<leaf_node<T, SAFE_MATH>,
1728 leaf_node<T, SAFE_MATH> (s, 0, false) {}
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) {
1841 assert(buffer.is_normal() &&
"NaN or Inf value.");
1851 const std::string &symbol) :
1853 buffer(d), symbol(symbol) {
1854 assert(buffer.is_normal() &&
"NaN or Inf value.");
1864 const std::string &symbol) :
1866 buffer(d), symbol(symbol) {
1867 assert(buffer.is_normal() &&
"NaN or Inf value.");
1911 int &avail_const_mem) {
1912 if (usage.find(
this) == usage.end()) {
1914#ifdef SHOW_USE_COUNT
1931 compile(std::ostringstream &stream,
1935 return this->shared_from_this();
1943 virtual void set(
const T d) {
1953 virtual void set(
const size_t index,
const T d) {
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;
2006 return this->shared_from_this();
2013 return buffer.size();
2022 return buffer.data();
2049 return this->shared_from_this();
2068 virtual void endline(std::ostringstream &stream,
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>
2149 using input_nodes = std::vector<shared_variable<T, SAFE_MATH>>;
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>,
2159 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2171 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2173 return std::dynamic_pointer_cast<variable_node<T, SAFE_MATH>> (x);
2189 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2225 std::cout <<
"\\left(";
2226 this->
arg->to_latex();
2227 std::cout <<
"\\right)";
2254 return this->
arg->get_power_base();
2263 return this->
arg->get_power_exponent();
2293 if (registers.find(
this) == registers.end()) {
2295 registers[
this] = name;
2296 stream <<
" " << name
2297 <<
" [label = \"pseudo_variable\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
2299 auto a = this->
arg->to_vizgraph(stream, registers);
2300 stream <<
" " << name <<
" -- " << registers[a.get()] <<
";" << std::endl;
2303 return this->shared_from_this();
2316 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2318 return std::make_shared<pseudo_variable_node<T, SAFE_MATH>> (x);
2322 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2334 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2336 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
Class representing a branch node.
Definition node.hpp:1336
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1437
shared_leaf< T, SAFE_MATH > get_left() const
Get the left branch.
Definition node.hpp:1419
shared_leaf< T, SAFE_MATH > get_right() const
Get the right branch.
Definition node.hpp:1428
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1448
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:1388
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:1352
shared_leaf< T, SAFE_MATH > right
Right branch of the tree.
Definition node.hpp:1341
shared_leaf< T, SAFE_MATH > left
Left branch of the tree.
Definition node.hpp:1339
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1095
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:1030
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:960
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition node.hpp:1086
bool is(const T d)
Check if the constant is value.
Definition node.hpp:1014
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:936
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition node.hpp:998
constant_node(const backend::buffer< T > &d)
Construct a constant node from a vector.
Definition node.hpp:923
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:1041
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:946
virtual bool is_constant() const
Test if node is a constant.
Definition node.hpp:1059
virtual bool has_constant_zero() const
Test the constant node has a zero.
Definition node.hpp:1068
bool is_integer()
Check if the value is an integer.
Definition node.hpp:1021
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:1077
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:813
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:824
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:841
index_node()
Construct a constant node from a vector.
Definition node.hpp:758
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:790
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:766
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:776
Class representing a node leaf.
Definition node.hpp:370
virtual ~leaf_node()
Destructor.
Definition node.hpp:398
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:444
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:584
virtual bool is_match(std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
Query if the nodes match.
Definition node.hpp:482
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:685
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:529
const bool contains_pseudo
Node contains pseudo variables.
Definition node.hpp:379
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > remove_pseudo()
Remove pseudo variable nodes.
Definition node.hpp:641
virtual bool is_all_variables() const
Test if all the sub-nodes terminate in variables.
Definition node.hpp:573
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:652
virtual bool is_constant() const
Test if node is a constant.
Definition node.hpp:546
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:595
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > reduce()
Reduction method.
Definition node.hpp:414
leaf_node(const std::string s, const size_t count, const bool pseudo)
Construct a basic node.
Definition node.hpp:389
virtual bool has_constant_zero() const
Test the constant node has a zero.
Definition node.hpp:555
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:425
virtual void set(const T d)
Set the value of variable data.
Definition node.hpp:501
const size_t complexity
Graph complexity.
Definition node.hpp:375
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:492
static caches_t caches
A per thread instance of the cache structure.
Definition node.hpp:682
size_t get_complexity() const
Get the number of nodes in the subgraph.
Definition node.hpp:623
virtual bool has_pseudo() const
Query if the node contains pseudo variables.
Definition node.hpp:632
const size_t hash
Hash for node.
Definition node.hpp:373
std::unordered_map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > df_cache
Cache derivative terms.
Definition node.hpp:377
bool is_normal()
Test if the result is normal.
Definition node.hpp:564
size_t get_hash() const
Get the hash for the node.
Definition node.hpp:614
Class representing a N branch node.
Definition node.hpp:1570
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:1597
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1686
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1670
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:1581
n_branch_node(std::array< shared_leaf< T, SAFE_MATH >, N > branches, const std::string s)
Reduces and assigns the branches.
Definition node.hpp:1612
std::array< shared_leaf< T, SAFE_MATH >, N > branches
Branches of the tree.
Definition node.hpp:1573
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:1630
shared_leaf< T, SAFE_MATH > get_arg(const size_t index) const
Get the Nth arg.
Definition node.hpp:1661
std::shared_ptr< leaf_node< T, SAFE_MATH > > df(std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
Transform node to derivative.
no_derivative(const std::string s)
Constructor for base leaf nodes base classes.
Definition node.hpp:1723
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:2223
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:2216
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:2243
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:2290
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:2261
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:2234
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition node.hpp:2279
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition node.hpp:2252
virtual bool has_pseudo() const
Query if the node contains pseudo variables.
Definition node.hpp:2270
pseudo_variable_node(shared_leaf< T, SAFE_MATH > a)
Construct a pseudo variable node.
Definition node.hpp:2207
Class representing a straight node.
Definition node.hpp:1218
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:1318
shared_leaf< T, SAFE_MATH > arg
Argument.
Definition node.hpp:1221
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:1240
shared_leaf< T, SAFE_MATH > get_arg() const
Get the argument.
Definition node.hpp:1300
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:1256
straight_node(shared_leaf< T, SAFE_MATH > a, const std::string s)
Construct a straight node.
Definition node.hpp:1230
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1309
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:1288
Class representing a triple branch node.
Definition node.hpp:1466
shared_leaf< T, SAFE_MATH > get_middle() const
Get the middle branch.
Definition node.hpp:1540
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:1549
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:1505
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:1480
shared_leaf< T, SAFE_MATH > middle
Middle branch of the tree.
Definition node.hpp:1469
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition node.hpp:2047
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:2067
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:1903
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition node.hpp:2029
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition node.hpp:1884
virtual void to_latex() const
Convert the node to latex.
Definition node.hpp:1984
size_t size()
Get the size of the variable buffer.
Definition node.hpp:2011
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition node.hpp:1995
virtual backend::buffer< T > evaluate()
Evaluate method.
Definition node.hpp:1874
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:1930
T * data()
Get a pointer to raw buffer.
Definition node.hpp:2020
virtual void set(const T d)
Set the value of variable data.
Definition node.hpp:1942
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition node.hpp:2038
variable_node(const size_t s, const std::string &symbol)
Construct a variable node with a size.
Definition node.hpp:1824
std::string get_symbol() const
Get Symbol.
Definition node.hpp:1977
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition node.hpp:2056
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
std::vector< shared_leaf< T, SAFE_MATH > > output_nodes
Convenience type alias for a vector of output nodes.
Definition node.hpp:705
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:1153
std::shared_ptr< index_node< T, SAFE_MATH > > shared_index
Convenience type alias for shared index nodes.
Definition node.hpp:876
std::shared_ptr< pseudo_variable_node< T, SAFE_MATH > > shared_pseudo_variable
Convenience type alias for shared pseudo variable nodes.
Definition node.hpp:2322
std::shared_ptr< constant_node< T, SAFE_MATH > > shared_constant
Convenience type alias for shared constant nodes.
Definition node.hpp:1189
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:2151
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:2155
shared_leaf< T, SAFE_MATH > index()
Construct an index.
Definition node.hpp:855
constexpr shared_leaf< T, SAFE_MATH > none()
Create a one constant.
Definition node.hpp:1179
void make_vizgraph(shared_leaf< T, SAFE_MATH > node)
Build the vizgraph input.
Definition node.hpp:720
constexpr shared_leaf< T, SAFE_MATH > one()
Forward declare for one.
Definition node.hpp:1166
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:690
shared_constant< T, SAFE_MATH > constant_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a constant node.
Definition node.hpp:1201
input_nodes< T, SAFE_MATH > atomic_nodes
Convenience type alias for atomic inputd.
Definition node.hpp:2159
shared_variable< T, SAFE_MATH > variable_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a variable node.
Definition node.hpp:2171
shared_index< T, SAFE_MATH > index_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a index node.
Definition node.hpp:888
constexpr T i
Convenience type for imaginary constant.
Definition node.hpp:1185
shared_leaf< T, SAFE_MATH > constant(const backend::buffer< T > &d)
Construct a constant.
Definition node.hpp:1110
shared_leaf< T, SAFE_MATH > variable(const size_t s, const std::string &symbol)
Construct a variable.
Definition node.hpp:2092
std::shared_ptr< variable_node< T, SAFE_MATH > > shared_variable
Convenience type alias for shared variable nodes.
Definition node.hpp:2145
constexpr shared_leaf< T, SAFE_MATH > null_leaf()
Create a null leaf.
Definition node.hpp:700
shared_leaf< T, SAFE_MATH > pseudo_variable(shared_leaf< T, SAFE_MATH > x)
Define pseudo variable convenience function.
Definition node.hpp:2316
shared_pseudo_variable< T, SAFE_MATH > pseudo_variable_cast(shared_leaf< T, SAFE_MATH > &x)
Cast to a pseudo variable node.
Definition node.hpp:2334
std::vector< shared_variable< T, SAFE_MATH > > input_nodes
Convenience type alias for a vector of inputs.
Definition node.hpp:2148
std::unordered_set< void * > visiter_map
Type alias for listing visited nodes.
Definition register.hpp:263
constexpr bool use_metal()
Test to use metal.
Definition register.hpp:82
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
void add_type(std::basic_ostream< char > &stream)
Write out the node base type to a general stream.
Definition register.hpp:165
std::unordered_map< void *, std::string > register_map
Type alias for mapping node pointers to register names.
Definition register.hpp:259
std::string get_type_string()
Get the type string.
Definition register.hpp:145
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:1697
Data structure to contain the two caches.
Definition node.hpp:674
std::unordered_map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > nodes
Cache of node.
Definition node.hpp:676
std::unordered_map< size_t, backend::buffer< T > > backends
Cache of backend buffers.
Definition node.hpp:678