25 template<jit::
float_scalar T>
31 const std::string type = jit::type_to_string<T> ();
32 stream <<
"(" << jit::smallest_uint_type<T> (length) <<
")min";
33 if constexpr (!jit::use_metal<T> () &&
35 stream <<
"<" << type <<
">";
38 if constexpr (!jit::use_metal<T> () &&
40 stream <<
"<" << type <<
">";
50 stream << offset <<
")/";
59 if constexpr (jit::use_metal<T> () ||
61 stream <<
"(" << type <<
")";
64 if constexpr (jit::use_metal<T> () ||
66 stream <<
"(" << type <<
")";
68 stream << length - 1 <<
")";
83 template<jit::
float_scalar T>
87 const size_t num_columns) {
101 template<jit::
float_scalar T,
bool SAFE_MATH=false>
123 const size_t length) {
142 const size_t length) :
147 scale(scale), offset(offset), length(length) {}
204 if (registers.find(
this) == registers.end()) {
205 auto a = this->arg->compile(stream, registers,
208#ifdef USE_INDEX_CACHE
211 << jit::smallest_uint_type<T> (length) <<
" "
212 << registers[
this] <<
" = ";
217 std::ostringstream source_buffer;
219 length, scale, offset);
220 registers[
this] = source_buffer.str();
239 this->arg->is_match(
temp->get_arg()) &&
240 (
temp->get_size() == this->length) &&
241 (
temp->get_scale() == this->scale) &&
242 (
temp->get_offset() == this->offset);
281 if (registers.find(
this) == registers.end()) {
283 registers[
this] =
name;
284 stream <<
" " <<
name
285 <<
" [label = \"arg\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
287 auto a = this->arg->to_vizgraph(stream, registers);
288 stream <<
" " <<
name <<
" -- " << registers[
a.get()] <<
";" << std::endl;
307 template<jit::
float_scalar T,
bool SAFE_MATH=false>
311 const size_t length) {
312 auto temp = std::make_shared<argument_node<T, SAFE_MATH>> (x, scale,
325#if defined(__clang__) || defined(__GNUC__)
328 assert(
false &&
"Should never reach.");
333 template<jit::
float_scalar T,
bool SAFE_MATH=false>
345 template<jit::
float_scalar T,
bool SAFE_MATH=false>
347 return std::dynamic_pointer_cast<argument_node<T, SAFE_MATH>> (x);
387 template<jit::
float_scalar T,
bool SAFE_MATH=false>
398 for (
size_t i = 0,
ie =
d.size();
i <
ie;
i++) {
414 return piecewise_1D_node::to_string(
d) +
425 const size_t h = std::hash<std::string>{} (piecewise_1D_node::to_string(
d));
435#if defined(__clang__) || defined(__GNUC__)
438 assert(
false &&
"Should never reach.");
443 const size_t data_hash;
480 const size_t i = std::real(this->
arg->evaluate().at(0));
521 this->
arg->compile_preamble(stream, registers,
530 if constexpr (jit::use_metal<T> ()) {
533#ifdef USE_CUDA_TEXTURES
543 stream <<
"__constant__ ";
547 jit::add_type<T> (stream);
550 jit::add_type<T> (stream);
553 for (
size_t i = 1;
i < length;
i++) {
556 jit::add_type<T> (stream);
560 stream <<
"};" << std::endl;
566 if constexpr (jit::use_metal<T> ()) {
569#ifdef USE_CUDA_TEXTURES
611 if (registers.find(
this) == registers.end()) {
612 auto a = this->
arg->compile(stream, registers,
617 jit::add_type<T> (stream);
618 stream <<
" " << registers[
this] <<
" = ";
619#ifdef USE_CUDA_TEXTURES
623 stream <<
"to_cmp_float(tex1D<float2> (";
625 stream <<
"tex1D<float> (";
629 stream <<
"to_cmp_double(tex1D<uint4> (";
631 stream <<
"to_double(tex1D<uint2> (";
637 if constexpr (jit::use_metal<T> ()) {
639 << registers[
a.get()]
641#ifdef USE_CUDA_TEXTURES
644 << registers[
a.get()]
652 << registers[
a.get()]
674 this->data_hash ==
x_cast->data_hash &&
698 std::cout <<
"r\\_" <<
reinterpret_cast<size_t> (
this) <<
"_{i}";
710 if (registers.find(
this) == registers.end()) {
712 registers[
this] =
name;
713 stream <<
" " <<
name
714 <<
" [label = \"r_" <<
reinterpret_cast<size_t> (
this)
715 <<
"_{i}\", shape = hexagon, style = filled, fillcolor = black, fontcolor = white];" << std::endl;
717 auto a = this->
arg->to_vizgraph(stream, registers);
718 stream <<
" " <<
name <<
" -- " << registers[
a.get()] <<
";" << std::endl;
793 template<jit::
float_scalar T,
bool SAFE_MATH=false>
796 auto temp = std::make_shared<piecewise_1D_node<T, SAFE_MATH>> (
d, x)->reduce();
807#if defined(__clang__) || defined(__GNUC__)
810 assert(
false &&
"Should never reach.");
826 template<jit::
float_scalar T,
bool SAFE_MATH=false>
836 template<jit::
float_scalar T,
bool SAFE_MATH=false>
848 template<jit::
float_scalar T,
bool SAFE_MATH=false>
850 return std::dynamic_pointer_cast<piecewise_1D_node<T, SAFE_MATH>> (x);
897 template<jit::
float_scalar T,
bool SAFE_MATH=false>
908 for (
size_t i = 0,
ie =
d.size();
i <
ie;
i++) {
926 return piecewise_2D_node::to_string(
d) +
938 const size_t h = std::hash<std::string>{} (piecewise_2D_node::to_string(
d));
948#if defined(__clang__) || defined(__GNUC__)
951 assert(
false &&
"Should never reach.");
956 const size_t data_hash;
958 const size_t num_columns;
977 "Expected the data buffer to be a multiple of the number of columns.");
1022 const size_t i = std::real(this->
left->evaluate().at(0));
1023 const size_t j = std::real(this->
right->evaluate().at(0));
1027 const size_t i = std::real(this->
left->evaluate().at(0));
1032 const size_t j = std::real(this->
right->evaluate().at(0));
1075 if (!
visited.contains(
this)) {
1076 this->
left->compile_preamble(stream, registers,
1080 this->
right->compile_preamble(stream, registers,
1089 if constexpr (jit::use_metal<T> ()) {
1091 std::array<size_t, 2> ({
1095#ifdef USE_CUDA_TEXTURES
1098 std::array<size_t, 2> ({
1107 stream <<
"__constant__ ";
1111 jit::add_type<T> (stream);
1114 jit::add_type<T> (stream);
1117 for (
size_t i = 1;
i < length;
i++) {
1120 jit::add_type<T> (stream);
1124 stream <<
"};" << std::endl;
1130 if constexpr (jit::use_metal<T> ()) {
1132 std::array<size_t, 2> ({
1136#ifdef USE_CUDA_TEXTURES
1139 std::array<size_t, 2> ({
1146 visited.insert(
this);
1147#ifdef SHOW_USE_COUNT
1194 if (registers.find(
this) == registers.end()) {
1195 auto x = this->
left->compile(stream, registers,
1197 auto y = this->
right->compile(stream, registers,
1201 if constexpr (!jit::use_metal<T> ()) {
1202 if (registers.find(
temp.get()) == registers.end()) {
1203#ifndef USE_CUDA_TEXTURES
1204#ifdef USE_INDEX_CACHE
1208 <<
" " << registers[
temp.get()] <<
" = ";
1210 this->get_num_columns());
1213 std::ostringstream source_buffer;
1214 temp->compile(source_buffer,
1218 registers[
temp.get()] = source_buffer.str();
1225 stream <<
" const ";
1226 jit::add_type<T> (stream);
1227 stream <<
" " << registers[
this] <<
" = ";
1228#ifdef USE_CUDA_TEXTURES
1232 stream <<
"to_cmp_float(tex1D<float2> (";
1234 stream <<
"tex1D<float> (";
1238 stream <<
"to_cmp_double(tex1D<uint4> (";
1240 stream <<
"to_double(tex1D<uint2> (";
1247 if constexpr (jit::use_metal<T> ()) {
1249 << jit::smallest_uint_type<T> (std::max(this->
get_num_rows(),
1252 << registers[y.get()]
1254 << registers[x.get()]
1256#ifdef USE_CUDA_TEXTURES
1259 << registers[y.get()]
1261 << registers[x.get()];
1268 stream <<
"[" << registers[
temp.get()] <<
"]";
1289 this->data_hash ==
x_cast->data_hash &&
1290 this->num_columns ==
x_cast->get_num_columns() &&
1307 this->num_columns ==
x_cast->get_num_columns() &&
1318 std::cout <<
"r\\_" <<
reinterpret_cast<size_t> (
this) <<
"_{ij}";
1330 if (registers.find(
this) == registers.end()) {
1332 registers[
this] =
name;
1333 stream <<
" " <<
name
1334 <<
" [label = \"r_" <<
reinterpret_cast<size_t> (
this)
1335 <<
"_{ij}\", shape = hexagon, style = filled, fillcolor = black, fontcolor = white];" << std::endl;
1337 auto l = this->
left->to_vizgraph(stream, registers);
1338 stream <<
" " <<
name <<
" -- " << registers[l.get()] <<
";" << std::endl;
1339 auto r = this->
right->to_vizgraph(stream, registers);
1340 stream <<
" " <<
name <<
" -- " << registers[
r.get()] <<
";" << std::endl;
1412 return temp.get() && this->
left->is_match(
temp->get_arg());
1425 return temp.get() && this->
right->is_match(
temp->get_arg());
1441 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1446 auto temp = std::make_shared<piecewise_2D_node<T, SAFE_MATH>> (
d,
n, x, y)->reduce();
1457#if defined(__clang__) || defined(__GNUC__)
1460 assert(
false &&
"Should never reach.");
1480 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1495 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1507 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1509 return std::dynamic_pointer_cast<piecewise_2D_node<T, SAFE_MATH>> (x);
1527 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1565 return this->
left->evaluate();
1597 if (registers.find(
this) == registers.end()) {
1598 auto a = this->
right->compile(stream, registers,
1600 auto var = this->
left->compile(stream, registers,
1604 stream <<
" const ";
1605 jit::add_type<T> (stream);
1606 stream <<
" " << registers[
this] <<
" = ";
1612 stream <<
"[" << registers[
a.get()] <<
"]";
1640 std::cout <<
"v\\_" <<
reinterpret_cast<size_t> (this->
left.get())
1642 <<
reinterpret_cast<size_t> (this->
right.get())
1655 if (registers.find(
this) == registers.end()) {
1657 registers[
this] =
name;
1658 stream <<
" " <<
name
1659 <<
" [label = \"r_" <<
reinterpret_cast<size_t> (this->
left.get())
1660 <<
"\", shape = hexagon, style = filled, fillcolor = black, fontcolor = white];" << std::endl;
1662 auto l = this->
left->to_vizgraph(stream, registers);
1663 stream <<
" " <<
name <<
" -- " << registers[l.get()] <<
";" << std::endl;
1664 auto r = this->
right->to_vizgraph(stream, registers);
1665 stream <<
" " <<
name <<
" -- " << registers[
r.get()] <<
";" << std::endl;
1697 return temp.get() && this->
right->is_match(
temp->get_right());
1711 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1715 "index_1D requires a argument node for second arg.");
1716 auto temp = std::make_shared<index_1D_node<T, SAFE_MATH>> (v, x)->reduce();
1727#if defined(__clang__) || defined(__GNUC__)
1730 assert(
false &&
"Should never reach.");
1746 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1752 "index_1D requires a variable node for first arg.");
1757 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1769 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1771 return std::dynamic_pointer_cast<index_1D_node<T, SAFE_MATH>> (x);
1790 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1810 const size_t num_columns;
1857 return this->
left->evaluate();
1890 if (registers.find(
this) == registers.end()) {
1891 auto x = this->
middle->compile(stream, registers,
1893 auto y = this->
right->compile(stream, registers,
1899 if (registers.find(
temp.get()) == registers.end()) {
1900#ifdef USE_INDEX_CACHE
1904 <<
" " << registers[
temp.get()] <<
" = ";
1906 this->get_num_columns());
1910 std::ostringstream source_buffer;
1912 this->get_num_columns());
1913 registers[
temp.get()] = source_buffer.str();
1917 auto var = this->
left->compile(stream, registers,
1922 stream <<
" const ";
1923 jit::add_type<T> (stream);
1924 stream <<
" " << registers[
this] <<
" = ";
1930 stream <<
"[" << registers[
temp.get()] <<
"]";
1953 this->num_columns ==
x_cast->get_num_columns();
1960 std::cout <<
"r\\_" <<
reinterpret_cast<size_t> (this->
left.get())
1962 <<
reinterpret_cast<size_t> (this->
middle.get())
1964 <<
reinterpret_cast<size_t> (this->
right.get())
1977 if (registers.find(
this) == registers.end()) {
1979 registers[
this] =
name;
1980 stream <<
" " <<
name
1981 <<
" [label = \"r_" <<
reinterpret_cast<size_t> (this->
left.get())
1982 <<
"\", shape = hexagon, style = filled, fillcolor = black, fontcolor = white];" << std::endl;
1984 auto l = this->
left->to_vizgraph(stream, registers);
1985 stream <<
" " <<
name <<
" -- " << registers[l.get()] <<
";" << std::endl;
1986 auto m = this->
middle->to_vizgraph(stream, registers);
1987 stream <<
" " <<
name <<
" -- " << registers[m.get()] <<
";" << std::endl;
1988 auto r = this->
right->to_vizgraph(stream, registers);
1989 stream <<
" " <<
name <<
" -- " << registers[
r.get()] <<
";" << std::endl;
2021 return temp.get() &&
2022 this->
middle->is_match(
temp->get_middle()) &&
2023 this->
right->is_match(
temp->get_right());
2039 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2045 "index_2D requires a argument node for second arg.");
2047 "index_2D requires a argument node for third arg.");
2048 auto temp = std::make_shared<index_2D_node<T, SAFE_MATH>> (v,
n, x, y)->reduce();
2059#if defined(__clang__) || defined(__GNUC__)
2062 assert(
false &&
"Should never reach.");
2082 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2092 "index_2D requires a variable node for first arg.");
2101 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2113 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2115 return std::dynamic_pointer_cast<index_2D_node<T, SAFE_MATH>> (x);
2134 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2177 return this->
left->evaluate();
2231 if (registers.find(
this) == registers.end()) {
2232 auto a = this->
left->compile(stream, registers,
2234 auto index = this->
middle->compile(stream, registers,
2236 auto r = this->
right->compile(stream, registers,
2241 + registers[
index.get()];
2242 stream <<
" atomic";
2245 }
else if constexpr (jit::use_metal<T> ()){
2246 stream <<
"_fetch_add_explicit(";
2248 stream <<
"_ref(*(";
2250 stream << registers[
this];
2252 jit::use_metal<T> ()) {
2255 stream <<
")).fetch_add(";
2257 stream << registers[
r.get()];
2261 stream <<
", memory_order_relaxed)";
2306 std::cout <<
"v\\_" <<
reinterpret_cast<size_t> (this->
left.get())
2308 <<
reinterpret_cast<size_t> (this->
middle.get())
2310 this->
right->to_latex();
2322 if (registers.find(
this) == registers.end()) {
2324 registers[
this] =
name;
2325 stream <<
" " <<
name
2326 <<
" [label = \"r_" <<
reinterpret_cast<size_t> (this->
left.get())
2327 <<
"\", shape = hexagon, style = filled, fillcolor = black, fontcolor = white];" << std::endl;
2329 auto l = this->
left->to_vizgraph(stream, registers);
2330 stream <<
" " <<
name <<
" -- " << registers[l.get()] <<
";" << std::endl;
2331 auto m = this->
middle->to_vizgraph(stream, registers);
2332 stream <<
" " <<
name <<
" -- " << registers[m.get()] <<
";" << std::endl;
2333 auto r = this->
right->to_vizgraph(stream, registers);
2334 stream <<
" " <<
name <<
" -- " << registers[
r.get()] <<
";" << std::endl;
2361 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2366 "atomic_accumulate_1D requires a argument node for second arg.");
2367 auto temp = std::make_shared<atomic_accumulate_1D_node<T, SAFE_MATH>> (v,
i, x)->reduce();
2378#if defined(__clang__) || defined(__GNUC__)
2381 assert(
false &&
"Should never reach.");
2398 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2405 "atomic_accumulate_1D requires a variable node for first arg.");
2411 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2413 std::shared_ptr<atomic_accumulate_1D_node<T, SAFE_MATH>>;
2424 template<jit::
float_scalar T,
bool SAFE_MATH=false>
2427 return std::dynamic_pointer_cast<atomic_accumulate_1D_node<T, SAFE_MATH>> (x);
Class representing a generic buffer.
Definition backend.hpp:29
void real()
Take cos.
Definition backend.hpp:244
Node class to contain the index argument.
Definition piecewise.hpp:102
T get_scale() const
Get argument scale.
Definition piecewise.hpp:250
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduction method.
Definition piecewise.hpp:180
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition piecewise.hpp:236
size_t get_size() const
Get the size of the array.
Definition piecewise.hpp:268
T get_offset() const
Get argument offset.
Definition piecewise.hpp:259
argument_node(shared_leaf< T, SAFE_MATH > x, const T scale, const T offset, const size_t length)
Construct an Argument node.
Definition piecewise.hpp:139
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition piecewise.hpp:279
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 piecewise.hpp:200
virtual backend::buffer< T > evaluate()
Evaluate the argument.
Definition piecewise.hpp:158
Class representing a 1D accumulated array.
Definition piecewise.hpp:2135
virtual backend::buffer< T > evaluate()
Evaluate the results of accumulate.
Definition piecewise.hpp:2176
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition piecewise.hpp:2277
virtual void to_latex() const
Convert the node to latex.
Definition piecewise.hpp:2305
virtual bool is_arg_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes arguments match.
Definition piecewise.hpp:2295
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 piecewise.hpp:2227
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition piecewise.hpp:2320
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition piecewise.hpp:2194
atomic_accumulate_1D_node(shared_leaf< T, SAFE_MATH > var, shared_leaf< T, SAFE_MATH > index, shared_leaf< T, SAFE_MATH > x)
Construct a 1D index.
Definition piecewise.hpp:2161
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition piecewise.hpp:2345
Class representing a branch node.
Definition node.hpp:1337
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 a 1D index.
Definition piecewise.hpp:1528
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition piecewise.hpp:1685
virtual backend::buffer< T > evaluate()
Evaluate the results of the 1D index.
Definition piecewise.hpp:1564
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition piecewise.hpp:1676
bool is_arg_match(shared_leaf< T, SAFE_MATH > x)
Check if the args match.
Definition piecewise.hpp:1695
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 piecewise.hpp:1593
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition piecewise.hpp:1628
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition piecewise.hpp:1653
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition piecewise.hpp:1574
virtual void to_latex() const
Convert the node to latex.
Definition piecewise.hpp:1639
index_1D_node(shared_leaf< T, SAFE_MATH > var, shared_leaf< T, SAFE_MATH > x)
Construct a 1D index.
Definition piecewise.hpp:1550
Class representing a 2D index.
Definition piecewise.hpp:1791
size_t get_num_columns() const
Get the number of columns.
Definition piecewise.hpp:1834
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition piecewise.hpp:1866
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition piecewise.hpp:2000
virtual backend::buffer< T > evaluate()
Evaluate the results of the piecewise constant.
Definition piecewise.hpp:1856
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition piecewise.hpp:1946
virtual void to_latex() const
Convert the node to latex.
Definition piecewise.hpp:1959
index_2D_node(shared_leaf< T, SAFE_MATH > var, const size_t n, shared_leaf< T, SAFE_MATH > x, shared_leaf< T, SAFE_MATH > y)
Construct a 2D index.
Definition piecewise.hpp:1821
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition piecewise.hpp:2009
bool is_arg_match(shared_leaf< T, SAFE_MATH > x)
Check if the args match.
Definition piecewise.hpp:2019
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)
the node.
Definition piecewise.hpp:1886
size_t get_num_rows() const
Get the number of columns.
Definition piecewise.hpp:1843
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition piecewise.hpp:1975
Class representing a node leaf.
Definition node.hpp:371
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
Nodes without derivatives.
Definition node.hpp:1713
Class representing a 1D piecewise constant.
Definition piecewise.hpp:388
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition piecewise.hpp:760
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 piecewise.hpp:512
virtual bool is_constant() const
Test if node is a constant.
Definition piecewise.hpp:729
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition piecewise.hpp:670
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition piecewise.hpp:778
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduction method.
Definition piecewise.hpp:478
virtual backend::buffer< T > evaluate()
Evaluate the results of the piecewise constant.
Definition piecewise.hpp:466
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition piecewise.hpp:496
virtual void to_latex() const
Convert the node to latex.
Definition piecewise.hpp:697
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition piecewise.hpp:769
virtual bool has_constant_zero() const
Test the constant node has a zero.
Definition piecewise.hpp:751
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition piecewise.hpp:708
virtual bool is_arg_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes arguments match.
Definition piecewise.hpp:687
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition piecewise.hpp:742
piecewise_1D_node(const backend::buffer< T > &d, shared_leaf< T, SAFE_MATH > x)
Construct 1D a piecewise constant node.
Definition piecewise.hpp:452
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 piecewise.hpp:607
Class representing a 2D piecewise constant.
Definition piecewise.hpp:898
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 piecewise.hpp:1067
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 piecewise.hpp:1190
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition piecewise.hpp:1051
virtual bool is_power_like() const
Test if the node acts like a power of variable.
Definition piecewise.hpp:1382
piecewise_2D_node(const backend::buffer< T > &d, const size_t n, shared_leaf< T, SAFE_MATH > x, shared_leaf< T, SAFE_MATH > y)
Construct 2D a piecewise constant node.
Definition piecewise.hpp:969
size_t get_num_columns() const
Get the number of columns.
Definition piecewise.hpp:985
virtual shared_leaf< T, SAFE_MATH > get_power_base()
Get the base of a power.
Definition piecewise.hpp:1391
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition piecewise.hpp:1285
virtual bool is_all_variables() const
Test if node acts like a variable.
Definition piecewise.hpp:1364
virtual bool is_constant() const
Test if node is a constant.
Definition piecewise.hpp:1351
size_t get_num_rows() const
Get the number of columns.
Definition piecewise.hpp:994
bool is_col_match(shared_leaf< T, SAFE_MATH > x)
Do the columns match.
Definition piecewise.hpp:1423
virtual void to_latex() const
Convert the node to latex.
Definition piecewise.hpp:1317
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition piecewise.hpp:1328
bool is_row_match(shared_leaf< T, SAFE_MATH > x)
Do the rows match.
Definition piecewise.hpp:1410
virtual bool is_arg_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition piecewise.hpp:1303
virtual shared_leaf< T, SAFE_MATH > get_power_exponent() const
Get the exponent of a power.
Definition piecewise.hpp:1400
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduction method.
Definition piecewise.hpp:1019
virtual backend::buffer< T > evaluate()
Evaluate the results of the piecewise constant.
Definition piecewise.hpp:1007
virtual bool has_constant_zero() const
Test the constant node has a zero.
Definition piecewise.hpp:1373
Class representing a straight node.
Definition node.hpp:1219
shared_leaf< T, SAFE_MATH > arg
Argument.
Definition node.hpp:1222
Class representing a triple branch node.
Definition node.hpp:1467
shared_leaf< T, SAFE_MATH > middle
Middle branch of the tree.
Definition node.hpp:1470
Complex scalar concept.
Definition register.hpp:25
Double base concept.
Definition register.hpp:43
float base concept.
Definition register.hpp:38
subroutine assert(test, message)
Assert check.
Definition f_binding_test.f90:38
buffer< T > min(buffer< T > &a, buffer< T > &b)
Min operation.
Definition backend.hpp:1052
buffer< T > max(buffer< T > &a, buffer< T > &b)
Max operation.
Definition backend.hpp:1038
Name space for graph nodes.
Definition arithmetic.hpp:13
shared_piecewise_2D< T, SAFE_MATH > piecewise_2D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a piecewise 2D node.
Definition piecewise.hpp:1508
std::shared_ptr< argument_node< T, SAFE_MATH > > shared_argument
Convenience type alias for shared argument nodes.
Definition piecewise.hpp:334
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:1154
shared_index_2D< T, SAFE_MATH > index_2D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a index 2D node.
Definition piecewise.hpp:2114
void compile_2D_index(std::ostringstream &stream, const std::string &x_register_name, const std::string &y_register_name, const size_t num_columns)
Compile an 2D index.
Definition piecewise.hpp:84
shared_leaf< T, SAFE_MATH > index()
Construct an index.
Definition node.hpp:856
shared_atomic_accumulate_1D< T, SAFE_MATH > atomic_accumulate_1D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a atomic accumulate 1D node.
Definition piecewise.hpp:2426
std::shared_ptr< index_2D_node< T, SAFE_MATH > > shared_index_2D
Convenience type alias for shared index 2D nodes.
Definition piecewise.hpp:2102
shared_leaf< T, SAFE_MATH > atomic_accumulate_1D(shared_leaf< T, SAFE_MATH > v, shared_leaf< T, SAFE_MATH > i, shared_leaf< T, SAFE_MATH > x)
Define atomic_accumulate_1D convenience function.
Definition piecewise.hpp:2362
shared_piecewise_1D< T, SAFE_MATH > piecewise_1D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a piecewise 1D node.
Definition piecewise.hpp:849
std::shared_ptr< piecewise_2D_node< T, SAFE_MATH > > shared_piecewise_2D
Convenience type alias for shared piecewise 2D nodes.
Definition piecewise.hpp:1496
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
std::shared_ptr< piecewise_1D_node< T, SAFE_MATH > > shared_piecewise_1D
Convenience type alias for shared piecewise 1D nodes.
Definition piecewise.hpp:837
constexpr T i
Convenience type for imaginary constant.
Definition node.hpp:1186
shared_argument< T, SAFE_MATH > argument_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a argument node.
Definition piecewise.hpp:346
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:691
shared_leaf< T, SAFE_MATH > argument(shared_leaf< T, SAFE_MATH > x, const T scale, const T offset, const size_t length)
Define argument convenience function.
Definition piecewise.hpp:308
std::shared_ptr< index_1D_node< T, SAFE_MATH > > shared_index_1D
Convenience type alias for shared index 1D nodes.
Definition piecewise.hpp:1758
void compile_index(std::ostringstream &stream, const std::string ®ister_name, const size_t length, const T scale, const T offset)
Compile an index.
Definition piecewise.hpp:26
std::shared_ptr< atomic_accumulate_1D_node< T, SAFE_MATH > > shared_atomic_accumulate_1D
Convenience type alias for shared atomic accumulate 1D nodes.
Definition piecewise.hpp:2413
shared_index_1D< T, SAFE_MATH > index_1D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a index 1D node.
Definition piecewise.hpp:1770
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
Base nodes of graph computation framework.
void index_2D()
Tests for 2D index nodes.
Definition piecewise_test.cpp:870
void piecewise_1D()
Tests for 1D piecewise nodes.
Definition piecewise_test.cpp:82
void index_1D()
Tests for 1D index nodes.
Definition piecewise_test.cpp:836
void piecewise_2D()
Tests for 2D piecewise nodes.
Definition piecewise_test.cpp:321