VisionCpp  0.0.1
eval_expr_r_binary.hpp
Go to the documentation of this file.
1 // This file is part of VisionCpp, a lightweight C++ template library
2 // for computer vision and image processing.
3 //
4 // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved.
5 //
6 // Contact: visioncpp@codeplay.com
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 
20 /// \file eval_expr_r_binary.hpp
21 /// \brief This file contains the specialisation of the EvalExpr
22 /// for RBiOP( pointwise Binary operation node).
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_BINARY_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_BINARY_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 /// \brief Partial specialisation of the EvalExpr when the expression is
30 /// an RBiOP(binary operation) expression.
31 template <typename BI_OP, typename LHS, typename RHS, size_t Cols, size_t Rows,
32  size_t LfType, size_t LVL, typename Loc, typename... Params>
33 struct EvalExpr<RBiOP<BI_OP, LHS, RHS, Cols, Rows, LfType, LVL>, Loc,
34  Params...> {
35  /// \brief evaluate function when the internal::ops_category is PointOP.
36  static typename BI_OP::OutType
37  eval_point(Loc &cOffset, const tools::tuple::Tuple<Params...> &t) {
38  auto lhs_acc = EvalExpr<LHS, Loc, Params...>::eval_point(cOffset, t);
39  auto rhs_acc = EvalExpr<RHS, Loc, Params...>::eval_point(cOffset, t);
40  return
41  typename BI_OP::OP()(tools::convert<typename BI_OP::InType1>(lhs_acc),
42  tools::convert<typename BI_OP::InType2>(rhs_acc));
43  }
44  /// \brief evaluate function when the internal::ops_category is NeighbourOP.
45  template <bool IsRoot, size_t Halo_Top, size_t Halo_Left, size_t Halo_Butt,
46  size_t Halo_Right, size_t Offset, size_t Index, size_t LC,
47  size_t LR>
48  static auto eval_neighbour(Loc &cOffset,
50  -> decltype(
52  t)) {
53  constexpr size_t OutOffset = OutputLocation<IsRoot, Offset + Index - 1>::ID;
54  constexpr bool isLocal =
55  Trait<typename tools::RemoveAll<decltype(
56  tools::tuple::get<OutOffset>(t))>::Type>::scope == scope::Local;
57  static constexpr size_t RHSCount =
59 
60  auto lhs_acc = EvalExpr<LHS, Loc, Params...>::template eval_neighbour<
61  false, Halo_Top, Halo_Left, Halo_Butt, Halo_Right,
62  Offset, Index - 1 - RHSCount, LC, LR>(cOffset, t)
63  .get_pointer();
64  auto rhs_acc = EvalExpr<RHS, Loc, Params...>::template eval_neighbour<
65  false, Halo_Top, Halo_Left, Halo_Butt, Halo_Right,
66  Offset, Index - 1, LC, LR>(cOffset, t)
67  .get_pointer();
68  // eval the RBiOP
69  for (int i = 0; i < LC; i += cOffset.cLRng) {
70  if (get_compare<isLocal, LC, Cols>(cOffset.l_c, i, cOffset.g_c)) {
71  for (int j = 0; j < LR; j += cOffset.rLRng) {
72  if (get_compare<isLocal, LR, Rows>(cOffset.l_r, j, cOffset.g_r)) {
73  size_t child_index =
74  calculate_index(cOffset.l_c + i, cOffset.l_r + j, LC, LR);
75  *(tools::tuple::get<OutOffset>(t).get_pointer() +
76  calculate_index(id_val<isLocal>(cOffset.l_c, cOffset.g_c) + i,
77  id_val<isLocal>(cOffset.l_r, cOffset.g_r) + j,
78  id_val<isLocal>(LC, Cols),
79  id_val<isLocal>(LR, Rows))) =
80  tools::convert<typename MemoryTrait<
81  LfType, decltype(tools::tuple::get<OutOffset>(t))>::Type>(
82  typename BI_OP::OP()(*(lhs_acc + child_index),
83  rhs_acc[child_index]));
84  }
85  }
86  }
87  }
88 
89  // here you need to put a local barrier
90  cOffset.barrier();
91  // return the valid neighbour area for your parent
92  return tools::tuple::get<OutOffset>(t);
93  }
94 };
95 } // namespace internal
96 } // namespace visioncpp
97 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_BINARY_HPP_
EnableIf< k==0, typename ElemTypeHolder< 0, Tuple< Ts... > >::type & >::type get(Tuple< Ts... > &t)
get
Definition: tuple.hpp:99
T1 convert(T2 x)
function convert
Definition: convert.hpp:558
static size_t calculate_index(size_t c, size_t r, size_t cols, size_t rows)
function calculate_index
static constexpr ScopeType Local
VisionCpp namespace.
Definition: sycl/device.hpp:24
static BI_OP::OutType eval_point(Loc &cOffset, const tools::tuple::Tuple< Params... > &t)
evaluate function when the internal::ops_category is PointOP.
static auto eval_neighbour(Loc &cOffset, const tools::tuple::Tuple< Params... > &t) -> decltype(tools::tuple::get< OutputLocation< IsRoot, Offset+Index - 1 >::ID >(t))
evaluate function when the internal::ops_category is NeighbourOP.
eval_global_neighbour function:
Definition: evaluator.hpp:195
is used to count the total number of local memory for the subxpression.
This class is used to determine the ElementType of accessor template parameters.
This is used to find whether a node should use a global memory output or a local memory output is cre...
Definition: evaluator.hpp:265
The definition is in RBiOP file.
This struct is used to trait the value type inside the accessor.
Definition: evaluator.hpp:89
These methods are used to remove all the & const and * from a type.
The tuple is a fixed-size collection of heterogeneous values.
Definition: tuple.hpp:48