VisionCpp  0.0.1
assign.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 assign.hpp
21 /// \brief This file contains the Assign struct which is used to allocate the result
22 /// of the right hand side expression (RHS) to the left hand side expression
23 /// LHS. LHS is always a leaf node.
24 
25 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_ASSIGN_HPP_
26 #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_ASSIGN_HPP_
27 
28 namespace visioncpp {
29 namespace internal {
30 /// \struct Assign
31 /// \brief Assign is used to allocate the result of the right hand side
32 /// expression (RHS) to the left hand side expression LHS. LHS is always a
33 /// leaf node. It can be used for PointOP, NeighbourOP, and GlobalNeighbourOP.
34 /// template parameters:
35 /// \tparam LHS is the output leafNode
36 /// \tparam RHS is the right hand side expression
37 /// \tparam Cols: determines the column size of the output
38 /// \tparam Rows: determines the row size of the output
39 /// \tparam LfType: determines the type of the leafNode {Buffer2D, Buffer1D,
40 /// Host, Image}
41 /// \tparam LVL: the level of the node in the expression tree
42 template <typename LHS, typename RHS, size_t Cols, size_t Rows, size_t LfType,
43  size_t LVL>
44 struct Assign {
45  static constexpr bool has_out = true;
46  using OutType = typename LHS::OutType;
47  using Type = typename LHS::Type;
48  using LHSExpr = LHS;
49  using RHSExpr = RHS;
50  static constexpr size_t Level = LVL;
51  static constexpr size_t LeafType = Type::LeafType;
52  static constexpr size_t RThread = RHS::RThread;
53  static constexpr size_t CThread = RHS::CThread;
54  static constexpr size_t ND_Category = expr_category::Binary;
55  static constexpr bool SubExpressionEvaluationNeeded =
56  LHS::SubExpressionEvaluationNeeded || RHS::SubExpressionEvaluationNeeded;
57  // may be this can be passed based on the shape of the cope . If
58  // source is equal to dest that can be passed as false
59  static constexpr size_t Operation_type = RHS::Operation_type;
60  template <typename TmpLHS, typename TmpRHS>
62 
63  LHS lhs;
64  RHS rhs;
66  Assign(LHS lhsArg, RHS rhsArg)
67  : lhs(lhsArg), rhs(rhsArg), subexpr_execution_reseter(false) {}
68  void reset(bool reset) {
69  lhs.reset(reset);
70  rhs.reset(reset);
72  }
73  /// sub_expression_evaluation
74  /// \brief This function is used to break the expression tree whenever
75  /// necessary. The decision for breaking the tree will be determined based on
76  /// the static parameter called SubExpressionEvaluationNeeded. When this is
77  /// set to true, the sub_expression_evaluation is called recursively from the
78  /// root of the tree. Each node based on their parent decision will decide to
79  /// launch a kernel for itself. Also, they decide for each of their children
80  /// whether or not to launch a kernel separately.
81  /// template parameters:
82  ///\tparam ForcedToExec : a boolean value representing the decision made by
83  /// the parent of this node for launching a kernel.
84  /// \tparam LC: is the column size of local memory required by Filter2D and
85  /// DownSmplOP
86  /// \tparam LR: is the row size of local memory required by Filter2D and
87  /// DownSmplOP
88  /// \tparam LCT: is the column size of workgroup
89  /// \tparam LRT: is the row size of workgroup
90  /// \tparam DeviceT: type representing the device
91  /// function parameters:
92  /// \param dev : the selected device for executing the expression
93  /// \return LeafNode
94  template <bool ForcedToExec, size_t LC, size_t LR, size_t LCT, size_t LRT,
95  typename DeviceT>
96  auto inline sub_expression_evaluation(const DeviceT &dev) -> decltype(
97  execute_expr<false, false, ExprExchange<LHS, RHS>, LC, LR, LCT, LRT>(
98  lhs.template sub_expression_evaluation<false, LC, LR, LCT, LRT>(dev),
99  rhs.template sub_expression_evaluation<false, LC, LR, LCT, LRT>(dev),
100  dev)) {
101  return execute_expr<false, false, ExprExchange<LHS, RHS>, LC, LR, LCT, LRT>(
102  lhs.template sub_expression_evaluation<false, LC, LR, LCT, LRT>(dev),
103  rhs.template sub_expression_evaluation<false, LC, LR, LCT, LRT>(dev),
104  dev);
105  }
106 };
107 } // internal
108 
109 /// assign function
110 /// \brief This function is used to deduce the Assign struct.
111 template <typename LHS, typename RHS>
112 auto assign(LHS lhs, RHS rhs)
113  -> internal::Assign<LHS, RHS, LHS::Type::Cols, LHS::Type::Rows,
114  LHS::Type::LeafType,
115  1 + internal::tools::StaticIf<(LHS::Level > RHS::Level),
116  LHS, RHS>::Type::Level> {
117  return internal::Assign<
118  LHS, RHS, LHS::Type::Cols, LHS::Type::Rows, LHS::Type::LeafType,
119  1 + internal::tools::StaticIf<(LHS::Level > RHS::Level), LHS,
120  RHS>::Type::Level>(lhs, rhs);
121 }
122 } // visioncpp
123 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_ASSIGN_HPP_
auto execute_expr(NestedExpr nestedExpr, const DeviceT &dev) -> decltype(internal::IfExprExecNeeded< Conds, ParentConds, internal::expr_category::Unary, Expr, DeviceT >::template execute_expr< LC, LR, LCT, LRT >(nestedExpr, dev))
template deduction for IfExprExecNeeded when the expression category is unary
VisionCpp namespace.
Definition: sycl/device.hpp:24
auto assign(LHS lhs, RHS rhs) -> internal::Assign< LHS, RHS, LHS::Type::Cols, LHS::Type::Rows, LHS::Type::LeafType, 1+internal::tools::StaticIf<(LHS::Level > RHS::Level), LHS, RHS >::Type::Level >
assign function
Definition: assign.hpp:112
The definition is in Assign file.
Definition: assign.hpp:44
static constexpr bool has_out
Definition: assign.hpp:45
static constexpr size_t Operation_type
Definition: assign.hpp:59
static constexpr size_t Level
Definition: assign.hpp:50
typename LHS::Type Type
Definition: assign.hpp:47
static constexpr size_t RThread
Definition: assign.hpp:52
static constexpr size_t ND_Category
Definition: assign.hpp:54
Assign(LHS lhsArg, RHS rhsArg)
Definition: assign.hpp:66
static constexpr bool SubExpressionEvaluationNeeded
Definition: assign.hpp:55
static constexpr size_t CThread
Definition: assign.hpp:53
auto sub_expression_evaluation(const DeviceT &dev) -> decltype(execute_expr< false, false, ExprExchange< LHS, RHS >, LC, LR, LCT, LRT >(lhs.template sub_expression_evaluation< false, LC, LR, LCT, LRT >(dev), rhs.template sub_expression_evaluation< false, LC, LR, LCT, LRT >(dev), dev))
sub_expression_evaluation
Definition: assign.hpp:96
void reset(bool reset)
Definition: assign.hpp:68
static constexpr size_t LeafType
Definition: assign.hpp:51
typename LHS::OutType OutType
Definition: assign.hpp:46
It is used to select either of the input type based the Conds template parameters.
Definition: static_if.hpp:52