25 template<jit::
float_scalar T>
27 const std::string ®ister_name,
35 stream <<
"<" << type <<
">";
40 stream <<
"<" << type <<
">";
46 stream <<
"(" << register_name <<
" - ";
48 stream << jit::get_type_string<T> ();
50 stream << offset <<
")/";
52 stream << jit::get_type_string<T> ();
61 stream <<
"(" << type <<
")";
66 stream <<
"(" << type <<
")";
68 stream << length - 1 <<
")";
83 template<jit::
float_scalar T>
85 const std::string &x_register_name,
86 const std::string &y_register_name,
87 const size_t num_columns) {
88 stream << x_register_name <<
"*" << 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) {}
185 return this->shared_from_this();
204 if (registers.find(
this) == registers.end()) {
205 auto a = this->
arg->compile(stream, registers,
208#ifdef USE_INDEX_CACHE
212 << registers[
this] <<
" = ";
217 std::ostringstream source_buffer;
219 length, scale, offset);
220 registers[
this] = source_buffer.str();
224 return this->shared_from_this();
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;
291 return this->shared_from_this();
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,
316 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
325#if defined(__clang__) || defined(__GNUC__)
326 __builtin_unreachable();
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));
426 for (
size_t i = h; i < std::numeric_limits<size_t>::max();
i++) {
435#if defined(__clang__) || defined(__GNUC__)
436 __builtin_unreachable();
438 assert(
false &&
"Should never reach.");
443 const size_t data_hash;
480 const size_t i = std::real(this->
arg->evaluate().at(0));
487 return this->shared_from_this();
519 int &avail_const_mem) {
520 if (!visited.contains(
this)) {
521 this->
arg->compile_preamble(stream, registers,
523 textures1d, textures2d,
524 pre_funcs, avail_const_mem);
533#ifdef USE_CUDA_TEXTURES
540 const int buffer_size = length*
sizeof(T);
541 if (avail_const_mem - buffer_size > 0) {
542 avail_const_mem -= buffer_size;
543 stream <<
"__constant__ ";
552 stream << leaf_node<T, SAFE_MATH>::caches.backends[data_hash][0];
553 for (
size_t i = 1;
i < length;
i++) {
558 stream << leaf_node<T, SAFE_MATH>::caches.backends[data_hash][
i];
560 stream <<
"};" << std::endl;
569#ifdef USE_CUDA_TEXTURES
576 visited.insert(
this);
611 if (registers.find(
this) == registers.end()) {
612 auto a = this->
arg->compile(stream, registers,
618 stream <<
" " << registers[
this] <<
" = ";
619#ifdef USE_CUDA_TEXTURES
622 if constexpr (complex_scalar<T>) {
623 stream <<
"to_cmp_float(tex1D<float2> (";
625 stream <<
"tex1D<float> (";
628 if constexpr (complex_scalar<T>) {
629 stream <<
"to_cmp_double(tex1D<uint4> (";
631 stream <<
"to_double(tex1D<uint2> (";
636 stream << registers[leaf_node<T, SAFE_MATH>::caches.backends[data_hash].data()];
639 << registers[a.get()]
641#ifdef USE_CUDA_TEXTURES
644 << registers[a.get()]
652 << registers[a.get()]
658 return this->shared_from_this();
673 return x_cast.get() &&
674 this->data_hash == x_cast->data_hash &&
675 this->
arg->is_match(x_cast->get_arg());
690 return x_cast.get() &&
691 this->
arg->is_match(x_cast->get_arg());
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;
721 return this->shared_from_this();
770 return this->shared_from_this();
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();
798 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
807#if defined(__clang__) || defined(__GNUC__)
808 __builtin_unreachable();
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));
939 for (
size_t i = h; i < std::numeric_limits<size_t>::max();
i++) {
948#if defined(__clang__) || defined(__GNUC__)
949 __builtin_unreachable();
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));
1042 return this->shared_from_this();
1074 int &avail_const_mem) {
1075 if (!visited.contains(
this)) {
1076 this->
left->compile_preamble(stream, registers,
1078 textures1d, textures2d,
1079 pre_funcs, avail_const_mem);
1080 this->
right->compile_preamble(stream, registers,
1082 textures1d, textures2d,
1083 pre_funcs, avail_const_mem);
1091 std::array<size_t, 2> ({
1095#ifdef USE_CUDA_TEXTURES
1098 std::array<size_t, 2> ({
1104 const int buffer_size = length*
sizeof(T);
1105 if (avail_const_mem - buffer_size > 0) {
1106 avail_const_mem -= buffer_size;
1107 stream <<
"__constant__ ";
1116 stream << leaf_node<T, SAFE_MATH>::caches.backends[data_hash][0];
1117 for (
size_t i = 1;
i < length;
i++) {
1122 stream << leaf_node<T, SAFE_MATH>::caches.backends[data_hash][
i];
1124 stream <<
"};" << std::endl;
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,
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 ";
1227 stream <<
" " << registers[
this] <<
" = ";
1228#ifdef USE_CUDA_TEXTURES
1231 if constexpr (complex_scalar<T>) {
1232 stream <<
"to_cmp_float(tex1D<float2> (";
1234 stream <<
"tex1D<float> (";
1237 if constexpr (complex_scalar<T>) {
1238 stream <<
"to_cmp_double(tex1D<uint4> (";
1240 stream <<
"to_double(tex1D<uint2> (";
1245 stream << registers[leaf_node<T, SAFE_MATH>::caches.backends[data_hash].data()];
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()] <<
"]";
1274 return this->shared_from_this();
1288 return x_cast.get() &&
1289 this->data_hash == x_cast->data_hash &&
1290 this->num_columns == x_cast->get_num_columns() &&
1291 this->
left->is_match(x_cast->get_left()) &&
1292 this->
right->is_match(x_cast->get_right());
1306 return x_cast.get() &&
1307 this->num_columns == x_cast->get_num_columns() &&
1308 this->
left->is_match(x_cast->get_left()) &&
1309 this->
right->is_match(x_cast->get_right());
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;
1343 return this->shared_from_this();
1392 return this->shared_from_this();
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();
1448 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
1457#if defined(__clang__) || defined(__GNUC__)
1458 __builtin_unreachable();
1460 assert(
false &&
"Should never reach.");
1480 template<jit::
float_scalar T,
bool SAFE_MATH=false>
1490 argument(x, x_scale, x_offset, d.size()/n),
1491 argument(y, y_scale, y_offset, n))->reduce();
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 ";
1606 stream <<
" " << registers[
this] <<
" = ";
1607 if (thread_mem.contains(var.get())) {
1608 stream << thread_mem.at(var.get());
1612 stream <<
"[" << registers[a.get()] <<
"]";
1617 return this->shared_from_this();
1631 return x_cast.get() &&
1632 this->
left->is_match(x_cast->get_left()) &&
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;
1668 return this->shared_from_this();
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();
1718 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
1727#if defined(__clang__) || defined(__GNUC__)
1728 __builtin_unreachable();
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 ";
1924 stream <<
" " << registers[
this] <<
" = ";
1925 if (thread_mem.contains(var.get())) {
1926 stream << thread_mem.at(var.get());
1930 stream <<
"[" << registers[temp.get()] <<
"]";
1935 return this->shared_from_this();
1949 return x_cast.get() &&
1950 this->
left->is_match(x_cast->get_left()) &&
1951 this->
middle->is_match(x_cast->get_middle()) &&
1952 this->
right->is_match(x_cast->get_right()) &&
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;
1992 return this->shared_from_this();
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();
2050 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
2059#if defined(__clang__) || defined(__GNUC__)
2060 __builtin_unreachable();
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.");
2097 y_offset, n))->reduce();
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";
2246 stream <<
"_fetch_add_explicit(";
2248 stream <<
"_ref(*(";
2250 stream << registers[
this];
2255 stream <<
")).fetch_add(";
2257 stream << registers[r.get()];
2261 stream <<
", memory_order_relaxed)";
2266 return this->shared_from_this();
2280 return x_cast.get() &&
2281 this->
left->is_match(x_cast->get_left()) &&
2283 this->
right->is_match(x_cast->get_right());
2298 return x_cast.get() &&
2299 this->
middle->is_match(x_cast->get_middle());
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;
2337 return this->shared_from_this();
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();
2369 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
2378#if defined(__clang__) || defined(__GNUC__)
2379 __builtin_unreachable();
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
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
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
branch_node(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r, const std::string s)
Definition node.hpp:1352
shared_leaf< T, SAFE_MATH > right
Definition node.hpp:1341
shared_leaf< T, SAFE_MATH > left
Definition node.hpp:1339
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
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
virtual void endline(std::ostringstream &stream, const jit::register_usage &usage, const char end=';') const
Definition node.hpp:652
static caches_t caches
A per thread instance of the cache structure.
Definition node.hpp:682
no_derivative(const std::string s)
Definition node.hpp:1723
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
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:1218
shared_leaf< T, SAFE_MATH > arg
Definition node.hpp:1221
straight_node(shared_leaf< T, SAFE_MATH > a, const std::string s)
Definition node.hpp:1230
triple_node(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > m, shared_leaf< T, SAFE_MATH > r, const std::string s)
Definition node.hpp:1480
shared_leaf< T, SAFE_MATH > middle
Definition node.hpp:1469
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
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:855
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
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
constexpr shared_leaf< T, SAFE_MATH > one()
Forward declare for one.
Definition node.hpp:1166
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:2412
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:690
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:1201
shared_variable< T, SAFE_MATH > variable_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a variable node.
Definition node.hpp:2171
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:1185
std::shared_ptr< index_1D_node< T, SAFE_MATH > > shared_index_1D
Convenience type alias for shared index 1D nodes.
Definition piecewise.hpp:1758
shared_leaf< T, SAFE_MATH > constant(const backend::buffer< T > &d)
Construct a constant.
Definition node.hpp:1110
shared_argument< T, SAFE_MATH > argument_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a argument node.
Definition piecewise.hpp:346
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
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< index_2D_node< T, SAFE_MATH > > shared_index_2D
Convenience type alias for shared index 2D nodes.
Definition piecewise.hpp:2102
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
constexpr bool use_metal()
Test to use metal.
Definition register.hpp:82
std::string type_to_string()
Convert a base type to a string.
Definition register.hpp:57
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::string smallest_uint_type(const size_t max_size)
Get smallest integer type.
Definition register.hpp:109
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