11 #ifndef PANZER_EXPR_EVAL_IMPL_HPP
12 #define PANZER_EXPR_EVAL_IMPL_HPP
26 static KOKKOS_FORCEINLINE_FUNCTION
27 T
apply(
bool cond, T
const& left, T
const& right) {
28 return cond ? left : right;
33 static KOKKOS_FORCEINLINE_FUNCTION
34 bool apply(
bool left,
bool right) {
40 static KOKKOS_FORCEINLINE_FUNCTION
41 bool apply(
bool left,
bool right) {
48 static KOKKOS_FORCEINLINE_FUNCTION
49 bool apply(T
const& left, T
const& right) {
56 static KOKKOS_FORCEINLINE_FUNCTION
57 bool apply(T
const& left, T
const& right) {
64 static KOKKOS_FORCEINLINE_FUNCTION
65 bool apply(T
const& left, T
const& right) {
72 static KOKKOS_FORCEINLINE_FUNCTION
73 bool apply(T
const& left, T
const& right) {
80 static KOKKOS_FORCEINLINE_FUNCTION
81 bool apply(T
const& left, T
const& right) {
88 static KOKKOS_FORCEINLINE_FUNCTION
89 T
apply(T
const& left, T
const& right) {
96 static KOKKOS_FORCEINLINE_FUNCTION
97 T
apply(T
const& left, T
const& right) {
103 template <
typename T>
104 static KOKKOS_FORCEINLINE_FUNCTION
105 T
apply(T
const& left, T
const& right) {
111 template <
typename T>
112 static KOKKOS_FORCEINLINE_FUNCTION
113 T
apply(T
const& left, T
const& right) {
119 template <
typename T>
120 static KOKKOS_FORCEINLINE_FUNCTION
121 T
apply(T
const& left, T
const& right) {
123 return pow(left, right);
128 template <
typename T>
129 static KOKKOS_FORCEINLINE_FUNCTION
136 template <
typename Indexed,
size_t IterationRank,
size_t IndexedRank = Indexed::rank>
139 template <
typename ViewType>
141 template <
typename Integral>
142 static KOKKOS_FORCEINLINE_FUNCTION
143 typename ViewType::reference_type
index(ViewType
const& x, Integral) {
return x(); }
146 template <
typename ViewType>
148 template <
typename Integral>
149 static KOKKOS_FORCEINLINE_FUNCTION
150 typename ViewType::reference_type
index(ViewType
const& x, Integral i) {
return x(i); }
153 template <
typename ViewType>
155 template <
typename Integral>
156 static KOKKOS_FORCEINLINE_FUNCTION
157 typename ViewType::reference_type
index(ViewType
const& x, Integral, Integral) {
return x(); }
160 template <
typename ViewType>
162 template <
typename Integral>
163 static KOKKOS_FORCEINLINE_FUNCTION
164 typename ViewType::reference_type
index(ViewType
const& x, Integral i, Integral) {
return x(i); }
167 template <
typename ViewType>
169 template <
typename Integral>
170 static KOKKOS_FORCEINLINE_FUNCTION
171 typename ViewType::reference_type
index(ViewType
const& x, Integral i, Integral j) {
return x(i, j); }
175 template <
typename T,
typename ... TS>
178 template <
typename T>
180 static constexpr
size_t value = T::rank;
183 template <
typename T,
typename ... TS>
190 template <
typename A,
typename B>
192 static constexpr
size_t a_rank = A::rank;
193 static constexpr
size_t b_rank = B::rank;
199 template <
typename C,
typename A,
typename B>
201 static constexpr
size_t a_rank = A::rank;
202 static constexpr
size_t b_rank = B::rank;
203 static constexpr
size_t c_rank = C::rank;
210 template <
typename Op,
typename Result,
typename Left,
typename Right,
size_t Rank = Result::rank>
213 template <
typename Op,
typename Result,
typename Left,
typename Right>
220 KOKKOS_INLINE_FUNCTION
222 result_() = Op::apply(left_(), right_());
225 left_ = Teuchos::any_cast<Left>(left);
226 right_ = Teuchos::any_cast<Right>(right);
227 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name));
228 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, 1), *
this);
229 result = Result(result_);
233 template <
typename Op,
typename Result,
typename Left,
typename Right>
240 KOKKOS_INLINE_FUNCTION
241 void operator()(
typename execution_space::size_type i)
const {
248 left_ = Teuchos::any_cast<Left>(left);
249 right_ = Teuchos::any_cast<Right>(right);
250 auto extent_0 = std::max(left_.extent(0), right_.extent(0));
251 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0);
252 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, extent_0), *
this);
253 result = Result{result_};
257 template <
typename Op,
typename Result,
typename Left,
typename Right>
264 KOKKOS_INLINE_FUNCTION
265 void operator()(
typename execution_space::size_type i,
typename execution_space::size_type j)
const {
272 left_ = Teuchos::any_cast<Left>(left);
273 right_ = Teuchos::any_cast<Right>(right);
274 auto extent_0 = std::max(left_.extent(0), right_.extent(0));
275 auto extent_1 = std::max(left_.extent(1), right_.extent(1));
276 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0, extent_1);
277 using policy_type = Kokkos::MDRangePolicy<execution_space, Kokkos::Rank<2>>;
278 Kokkos::parallel_for(name, policy_type({0, 0}, {extent_0, extent_1}), *
this);
279 result = Result{result_};
283 template <typename Cond, typename Left, typename Right, size_t Rank = MaxRank<Cond, Left, Right>::value>
286 template <
typename Cond,
typename Left,
typename Right>
295 KOKKOS_INLINE_FUNCTION
296 void operator()(
typename execution_space::size_type i)
const {
303 cond_ = Teuchos::any_cast<Cond>(cond);
304 left_ = Teuchos::any_cast<Left>(left);
305 right_ = Teuchos::any_cast<Right>(right);
307 std::max(cond_.extent(0),
308 std::max(left_.extent(0), right_.extent(0)));
309 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0);
310 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, extent_0), *
this);
315 template <
typename Cond,
typename Left,
typename Right>
324 KOKKOS_INLINE_FUNCTION
325 void operator()(
typename execution_space::size_type i,
typename execution_space::size_type j)
const {
332 cond_ = Teuchos::any_cast<Cond>(cond);
333 left_ = Teuchos::any_cast<Left>(left);
334 right_ = Teuchos::any_cast<Right>(right);
336 std::max(cond_.extent(0),
337 std::max(left_.extent(0), right_.extent(0)));
339 std::max(cond_.extent(1),
340 std::max(left_.extent(1), right_.extent(1)));
341 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0, extent_1);
342 using policy_type = Kokkos::MDRangePolicy<execution_space, Kokkos::Rank<2>>;
343 Kokkos::parallel_for(name, policy_type({0, 0}, {extent_0, extent_1}), *
this);
348 template <
typename DT,
typename ... VP>
354 template <
typename DT,
typename ... VP>
357 auto host_view = Kokkos::create_mirror_view(view);
359 Kokkos::deep_copy(view, host_view);
363 template <
typename DT,
typename ... VP>
366 auto host_view = Kokkos::create_mirror_view(view);
368 Kokkos::deep_copy(view, host_view);
371 this->inspect_arg(symbol_map[name], a, b);
374 template <
typename DT,
typename ... VP>
376 symbol_map[name] = value;
379 template <
typename DT,
typename ... VP>
382 auto host_view = Kokkos::create_mirror_view(view);
384 Kokkos::deep_copy(view, host_view);
387 this->inspect_arg(result, a, b);
390 template <
typename DT,
typename ... VP>
406 "value is of illegal type " << arg.
typeName() <<
", view type is "
411 template <
typename DT,
typename ... VP>
418 template <
typename DT,
typename ... VP>
426 template <
typename DT,
typename ... VP>
434 template <
typename DT,
typename ... VP>
441 template <
typename DT,
typename ... VP>
461 template <
typename DT,
typename ... VP>
483 template <
typename DT,
typename ... VP>
505 template <
typename DT,
typename ... VP>
525 template <
typename Op,
typename Result,
size_t Rank = Result::rank>
528 template <
typename Op,
typename Result>
534 KOKKOS_INLINE_FUNCTION
535 void operator()(
typename execution_space::size_type i)
const {
536 result_() = Op::apply(right_());
539 right_ = Teuchos::any_cast<Result>(right);
540 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name));
541 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, 1), *
this);
542 result = Result(result_);
546 template <
typename Op,
typename Result>
552 KOKKOS_INLINE_FUNCTION
553 void operator()(
typename execution_space::size_type i)
const {
554 result_(i) = Op::apply(right_(i));
557 right_ = Teuchos::any_cast<Result>(right);
558 auto extent_0 = right_.extent(0);
559 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0);
560 Kokkos::parallel_for(name, Kokkos::RangePolicy<execution_space>(0, extent_0), *
this);
561 result = Result(result_);
565 template <
typename Op,
typename Result>
571 KOKKOS_INLINE_FUNCTION
572 void operator()(
typename execution_space::size_type i,
typename execution_space::size_type j)
const {
573 result_(i, j) = Op::apply(right_(i, j));
576 right_ = Teuchos::any_cast<Result>(right);
577 auto extent_0 = right_.extent(0);
578 auto extent_1 = right_.extent(1);
579 result_ =
NonConstResult(Kokkos::ViewAllocateWithoutInitializing(name), extent_0, extent_1);
580 using policy_type = Kokkos::MDRangePolicy<execution_space, Kokkos::Rank<2>>;
581 Kokkos::parallel_for(name, policy_type({0, 0}, {extent_0, extent_1}), *
this);
582 result = Result(result_);
586 template <
typename DT,
typename ... VP>
591 template <
typename DT,
typename ... VP>
597 template <
typename T>
598 static KOKKOS_FORCEINLINE_FUNCTION
606 template <
typename T>
607 static KOKKOS_FORCEINLINE_FUNCTION
615 template <
typename T>
616 static KOKKOS_FORCEINLINE_FUNCTION
624 template <
typename T>
625 static KOKKOS_FORCEINLINE_FUNCTION
633 template <
typename T>
634 static KOKKOS_FORCEINLINE_FUNCTION
642 template <
typename T>
643 static KOKKOS_FORCEINLINE_FUNCTION
651 template <
typename T>
652 static KOKKOS_FORCEINLINE_FUNCTION
659 template <
typename Op,
typename EvalType>
662 auto& right = rhs.at(0);
663 using single_type =
typename EvalType::const_single_view_type;
664 using many_type =
typename EvalType::const_view_type;
665 if (right.type() ==
typeid(single_type)) {
667 }
else if (right.type() ==
typeid(many_type)) {
671 "Unexpected type " << right.typeName() <<
" passed to UnaryFunction \"" << name <<
"\"\n");
676 template <
typename DT,
typename ... VP>
678 using eval_type =
Eval<DT, VP ...>;
691 #endif // PANZER_EXPR_EVAL_IMPL_HPP
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
void many_many_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
Base class for panzer::Expr::Eval, does everything that is independent of the Kokkos::View template p...
void make_constant(Teuchos::any &result, double const &value) override
void set(std::string const &name, bool value)
Assign a boolean value to a variable symbol.
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
typename RebindViewType< biggest_type, typename biggest_type::const_value_type >::type const_type
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
BinaryOpCode
Denotes the native binary operators in the Teuchos::MathExpr language.
UnaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &right)
typename Result::execution_space execution_space
void single_many_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
BinaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)
std::function< void(std::string const &name, Teuchos::any &, std::vector< Teuchos::any > &rhs)> Function
The type of user-defined functions which are callable in the math language.
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral, Integral)
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i, typename execution_space::size_type j) const
typename std::conditional<(b_rank > a_rank), Right, Left >::type biggest_ab_type
static constexpr size_t c_rank
typename TernaryResultType< Cond, Left, Right >::non_const_type NonConstResult
void single_neg_op(Teuchos::any &result, Teuchos::any &right) override
UnaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &right)
typename Result::execution_space execution_space
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
TernaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static constexpr size_t b_rank
void set(std::string const &name, Function const &value)
Registers an EvalBase::Function, binding it to a name and making it callable.
Declares the panzer::Expr::Eval templated class.
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral i, Integral)
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(bool cond, T const &left, T const &right)
typename Result::execution_space execution_space
static constexpr size_t left_value
typename Result::execution_space execution_space
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
typename std::conditional<(c_rank > biggest_ab_type::rank), Cond, biggest_ab_type >::type biggest_type
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral i, Integral j)
typename Result::execution_space execution_space
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
void single_many_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
void operator()(std::string const &name, Teuchos::any &result, std::vector< Teuchos::any > &rhs) const
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
void inspect_arg(Teuchos::any const &arg, bool &is_many, bool &is_bool) override
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
typename RebindViewType< Result, typename Result::non_const_value_type >::type NonConstResult
typename original_view_type::non_const_value_type scalar_type
The scalar type.
void many_many_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
static constexpr size_t a_rank
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
typename TernaryResultType< Cond, Left, Right >::type Result
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &right)
typename Result::execution_space execution_space
typename Result::execution_space execution_space
BinaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral)
Builds on RebindDataType, but acts directly on a Kokkos::View type.
typename RebindViewType< biggest_type, typename biggest_type::non_const_value_type >::type type
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type) const
UnaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &right)
Interprets mathematical expressions in a string and evaluates them using Kokkos::View objects as valu...
void many_neg_op(Teuchos::any &result, Teuchos::any &right) override
static KOKKOS_FORCEINLINE_FUNCTION bool apply(bool left, bool right)
typename RebindViewType< biggest_type, typename Left::non_const_value_type >::type non_const_type
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i, typename execution_space::size_type j) const
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i) const
static constexpr size_t right_value
void many_single_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
static KOKKOS_FORCEINLINE_FUNCTION ViewType::reference_type index(ViewType const &x, Integral i)
TernaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right)
static constexpr size_t value
static KOKKOS_FORCEINLINE_FUNCTION bool apply(T const &left, T const &right)
std::string typeName() const
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
static constexpr size_t a_rank
void single_single_ternary_op(Teuchos::any &result, Teuchos::any &cond, Teuchos::any &left, Teuchos::any &right) override
typename RebindViewType< biggest_type, typename Left::const_value_type >::type type
const std::type_info & type() const
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)
typename std::conditional<(b_rank > a_rank), B, A >::type biggest_type
typename Result::execution_space execution_space
void single_single_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
void set_cmath_functions(Eval< DT, VP...> &eval)
Add support for functions such as sqrt(), sin(), and cos()
typename TernaryResultType< Cond, Left, Right >::non_const_type NonConstResult
BinaryFunctor(std::string const &name, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right)
static constexpr size_t b_rank
KOKKOS_INLINE_FUNCTION void operator()(typename execution_space::size_type i, typename execution_space::size_type j) const
void many_single_binary_op(BinaryOpCode code, Teuchos::any &result, Teuchos::any &left, Teuchos::any &right) override
typename TernaryResultType< Cond, Left, Right >::type Result
static KOKKOS_FORCEINLINE_FUNCTION bool apply(bool left, bool right)
static KOKKOS_FORCEINLINE_FUNCTION T apply(T const &left, T const &right)