27 template<
class T,
class voider=
void>
52 template<
class OutputData,
class Stream>
55 template<
class OutputData,
class Stream>
58 template<
class Stream>
61 template<
class Stream>
65 template<
class Op,
class Array>
68 template<
class Stream>
74 template<
class Stream>
80 template<
class op,
class lv,
class rv>
83 template<
class Stream>
88 return make_bin_expr<op>(left, right, branch.
get_operation());
91 template<
class Stream>
102 expression_traits<T>::is_array::value &&
103 !expression_traits<T>::is_temporary::value>>:
108 template<
class Array>
111 std::enable_if_t<expression_traits<Array>::is_temporary::value>>:
114 template<
class Stream>
118 tmp.
deallocate(stream.template get_allocator_rebound<value_type>());
132 template<
class OutputData,
class Stream>
133 static auto evaluate_impl(Xpr branch, OutputData tensor,
Stream stream,
134 std::true_type valid_injection)
136 branch.eval(tensor, stream);
137 return tensor.data();
140 template<
class OutputData,
class Stream>
141 static auto evaluate_impl(Xpr branch, OutputData tensor,
Stream stream,
142 std::false_type valid_injection)
149 template<
class OutputData,
class Stream>
151 return evaluate_impl(branch, tensor, stream,
152 truth_type<Xpr::tensor_dim == OutputData::tensor_dim>());
155 template<
class OutputData,
class Stream>
157 return evaluate_impl(branch, tensor, stream,
158 truth_type<Xpr::tensor_dim == OutputData::tensor_dim>());
161 template<
class Stream>
164 using value_type =
typename Xpr::value_type;
168 stream.template get_allocator_rebound<value_type>(),
171 branch.eval(make_output_data<1, 0>(temporary), stream);
177 template<
class op,
class lv,
class rv>
181 expression_traits<Bin_Op<op, lv, rv>>
182 ::requires_greedy_evaluation::value>>:
189 template<
class op,
class value>
193 expression_traits<Un_Op<op, value>>
194 ::requires_greedy_evaluation::value>>:
204 template<
class op,
class lv,
class rv>
207 std::enable_if_t<oper::operation_traits<op>::is_linear_operation>>:
213 lv::tensor_dim == rv::tensor_dim;
223 template<
class OutputData,
class Stream>
228 auto rv_eval = [&](
auto update_beta=std::true_type()) {
229 using update_beta_t = std::decay_t<decltype(update_beta)>;
232 update_alpha_beta_modifiers<op, update_beta_t::value>(tensor),
239 constexpr_if<entirely_blas_expr>(
241 rv_eval(std::true_type());
242 return tensor.data();
244 constexpr_else_if<optimizer<lv>::entirely_blas_expr>(
246 auto right = rv_eval(std::true_type());
247 return constexpr_ternary<std::is_same<op, oper::Sub>::value>(
249 return make_un_expr<oper::Negation>(right);
256 constexpr_else_if<optimizer<rv>::entirely_blas_expr>(
265 auto right = rv_eval(left_evaluated());
266 return make_bin_expr<op>(left, right);
271 template<
class OutputData,
class Stream>
static 274 auto lv_eval = [&]() {
278 auto rv_eval = [&](
auto update_beta=std::true_type()) {
279 using update_beta_t = std::decay_t<decltype(update_beta)>;
282 update_alpha_beta_modifiers<op, update_beta_t::value>(tensor),
286 auto basic_eval = [&]()
290 return make_bin_expr<op>(lv_eval(), rv_eval(left_evaluated()));
293 return constexpr_if<entirely_blas_expr>(
296 rv_eval(std::true_type());
297 return tensor.data();
303 constexpr_else_if<optimizer<lv>::requires_greedy_eval>(
306 return make_bin_expr<op>(left, branch.
right);
308 constexpr_else_if<optimizer<rv>::requires_greedy_eval>(
311 return make_bin_expr<op>(branch.
left, right);
321 template<
class op,
class lv,
class rv>
325 oper::operation_traits<op>::is_nonlinear_operation &&
326 !expression_traits<Bin_Op<op, lv, rv>>
327 ::requires_greedy_evaluation::value>>:
336 template<
class OutputData,
class Stream>
static 341 template<
class OutputData,
class Stream>
static 349 auto right = branch.
right;
350 return make_bin_expr<op>(left, right, branch.
get_operation());
352 auto left = branch.
left;
354 return make_bin_expr<op>(left, right, branch.
get_operation());
360 template<
class Op,
class Array>
363 std::enable_if_t<!expression_traits<Un_Op<Op, Array>>
364 ::requires_greedy_evaluation::value>>:
371 template<
class OutputData,
class Stream>
static 376 template<
class OutputData,
class Stream>
static Definition: tree_evaluator_optimizer.h:124
static auto injection(Bin_Op< op, lv, rv > branch, OutputData tensor, Stream stream)
Definition: tree_evaluator_optimizer.h:342
auto make_kernel_array(Shape< N > shape, Allocator allocator, Tags...)
Definition: array_kernel_array.h:134
static void deallocate_temporaries(Bin_Op< op, lv, rv > branch, Stream stream)
Definition: tree_evaluator_optimizer.h:92
auto constexpr_ternary(f1 true_path, f2 false_path)
C++ 11/14 version of constexpr if.
Definition: constexpr_if.h:36
static auto temporary_injection(Bin_Op< op, lv, rv > branch, Stream stream)
Definition: tree_evaluator_optimizer.h:84
static constexpr bool requires_greedy_eval
Definition: tree_evaluator_optimizer.h:50
BCHOT auto make_un_expr(Expression expression, Operation operation=Operation())
Definition: expression_unary.h:73
BCINLINE const Operation & get_operation() const
Definition: expression_unary.h:35
static auto linear_eval(Un_Op< Op, Array > branch, OutputData tensor, Stream)
Definition: tree_evaluator_optimizer.h:372
auto constexpr_else(Function function)
Definition: constexpr_if.h:61
static auto injection(Bin_Op< op, lv, rv > branch, OutputData tensor, Stream stream)
Definition: tree_evaluator_optimizer.h:272
Rv right
Definition: expression_binary.h:62
Operation get_operation() const
Definition: expression_binary.h:64
Definition: expression_template_traits.h:48
auto constexpr_else_if(Function function)
Definition: constexpr_if.h:51
void deallocate()
Definition: array.h:161
static auto linear_eval(Bin_Op< op, lv, rv > &branch, OutputData tensor, Stream stream)
Definition: tree_evaluator_optimizer.h:225
static constexpr bool partial_blas_expr
Definition: tree_evaluator_optimizer.h:49
Lv left
Definition: expression_binary.h:61
auto constexpr_if(Function function)
Definition: constexpr_if.h:41
Definition: tree_evaluator_optimizer.h:31
static auto injection(T branch, OutputData, Stream)
Definition: tree_evaluator_optimizer.h:56
ArrayType array
Definition: expression_unary.h:32
static auto linear_eval(Bin_Op< op, lv, rv > branch, OutputData tensor, Stream)
Definition: tree_evaluator_optimizer.h:337
Definition: tree_evaluator_optimizer.h:66
static void deallocate_temporaries(Array tmp, Stream stream)
Definition: tree_evaluator_optimizer.h:115
static auto temporary_injection(Un_Op< Op, Array > branch, Stream stream)
Definition: tree_evaluator_optimizer.h:69
static constexpr bool entirely_blas_expr
entirely_blas_expr if we may replace this branch entirely with a temporary/cache expression is +/- op...
Definition: tree_evaluator_optimizer.h:48
static auto linear_eval(Xpr branch, OutputData tensor, Stream stream)
Definition: tree_evaluator_optimizer.h:150
Definition: tree_evaluator_optimizer.h:28
static auto linear_eval(T branch, OutputData, Stream)
Definition: tree_evaluator_optimizer.h:53
conditional_t< Bool, true_type, false_type > truth_type
Definition: type_traits.h:49
static void deallocate_temporaries(Un_Op< Op, Array > branch, Stream stream)
Definition: tree_evaluator_optimizer.h:75
Scalar value_type
Definition: array.h:34
static auto temporary_injection(T branch, Stream)
Definition: tree_evaluator_optimizer.h:59
static auto injection(Un_Op< Op, Array > branch, OutputData tensor, Stream stream)
Definition: tree_evaluator_optimizer.h:377
Definition: tree_evaluator_optimizer.h:81
static auto injection(Xpr branch, OutputData tensor, Stream stream)
Definition: tree_evaluator_optimizer.h:156
static void deallocate_temporaries(T, Stream)
Definition: tree_evaluator_optimizer.h:62
static auto temporary_injection(Xpr branch, Stream stream)
Definition: tree_evaluator_optimizer.h:162
Definition: expression_template_traits.h:19
The Evaluator determines if an expression needs to be greedily optimized.
Definition: algorithms.h:22