VisionCpp  0.0.1
resizable_unary.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 resizable_unary.hpp
21 /// \brief This file contains RUnOP (Unary Operation) struct which is used to
22 /// apply Unary Operation on the right hand side(RHS) node.
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_RESIZABLE_UNARY_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_RESIZABLE_UNARY_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 /// \struct RUnOP
30 /// \brief RUnOP is used to
31 /// apply a unary operation on the right hand side(RHS) operand.
32 /// template parameters:
33 /// \tparam RHS is the right hand side expression
34 /// \tparam Cols: determines the column size of the output
35 /// \tparam Rows: determines the row size of the output
36 /// \tparam LfType: determines the type of the leafNode {Buffer2D, Buffer1D,
37 /// Host, Image}
38 /// \tparam LVL: the level of the node in the expression tree
39 template <typename UN_OP, typename RHS, size_t Cols, size_t Rows, size_t LfType,
40  size_t LVL>
41 struct RUnOP {
42  public:
43  static constexpr bool has_out = false;
44  using OutType = typename UN_OP::OutType;
45  using OPType = UN_OP;
46  using RHSExpr = RHS;
48  static constexpr size_t Level = LVL;
49  static constexpr size_t RThread = Rows;
50  static constexpr size_t CThread = Cols;
51  static constexpr size_t ND_Category = internal::expr_category::Unary;
52  static constexpr size_t LeafType = Type::LeafType;
53  static constexpr bool Unary_Conds =
54  (RHS::LeafType != memory_type::Const &&
55  ((RThread != RHS::RThread) || (CThread != RHS::CThread)));
56  static constexpr bool SubExpressionEvaluationNeeded =
57  Unary_Conds || RHS::SubExpressionEvaluationNeeded;
58  static constexpr size_t Operation_type = RHS::Operation_type;
59 
60  template <typename TmpRHS>
62 
63  RHS rhs;
65  RUnOP(RHS rhsArg) : rhs(rhsArg), subexpr_execution_reseter(false) {}
66 
67  void reset(bool reset) {
68  rhs.reset(reset);
70  }
71 
72  /// sub_expression_evaluation
73  /// \brief This function is used to break the expression tree whenever
74  /// necessary. The decision for breaking the tree will be determined based on
75  /// the static parameter called SubExpressionEvaluationNeeded. When this is
76  /// set to true, the sub_expression_evaluation is called recursively from the
77  /// root of the tree. Each node based on their parent decision will decide to
78  /// launch a kernel for itself. Also, they decide for each of their children
79  /// whether or not to launch a kernel separately.
80  /// template parameters:
81  ///\tparam ForcedToExec : a boolean value representing the decision made by
82  /// the parent of this node for launching a kernel.
83  /// \tparam LC: is the column size of the local memory required by Filter2D and
84  /// DownSmplOP
85  /// \tparam LR: is the row size of the local memory required by Filter2D and
86  /// DownSmplOP
87  /// \tparam LCT: is the column size of workgroup
88  /// \tparam LRT: is the row size of workgroup
89  /// \tparam DeviceT: type representing the device
90  /// function parameters:
91  /// \param dev : the selected device for executing the expression
92  /// \return LeafNode
93  template <bool ForcedToExec, size_t LC, size_t LR, size_t LCT, size_t LRT,
94  typename DeviceT>
95  auto inline sub_expression_evaluation(const DeviceT &dev)
96  -> decltype(execute_expr<Unary_Conds, ForcedToExec, ExprExchange<RHS>, LC,
97  LR, LCT, LRT>(
98  rhs.template sub_expression_evaluation<Unary_Conds, LC, LR, LCT, LRT>(
99  dev),
100  dev)) {
101  return execute_expr<Unary_Conds, ForcedToExec, ExprExchange<RHS>, LC, LR,
102  LCT, LRT>(
103  rhs.template sub_expression_evaluation<Unary_Conds, LC, LR, LCT, LRT>(
104  dev),
105  dev);
106  }
107 };
108 } // internal
109 
110 /// \brief template deduction for RUnOP struct where user determines the Column,
111 /// Row, and memory_type of the output.
112 template <typename OP, size_t Cols, size_t Rows, size_t LeafType, typename RHS>
113 internal::RUnOP<internal::PixelUnaryOp<OP, typename RHS::OutType>, RHS, Cols,
114  Rows, LeafType, 1 + RHS::Level>
115 point_operation(RHS rhs) {
117  Cols, Rows, LeafType, 1 + RHS::Level>(rhs);
118 }
119 
120 /// \brief template deduction for RUnOP struct where the Column, Row,
121 /// and memory_type of the output has been automatically deduced from LHS and
122 /// RHS operands
123 template <typename OP, typename RHS>
124 auto point_operation(RHS rhs)
126  RHS::Type::Cols, RHS::Type::Rows, RHS::Type::LeafType,
127  1 + RHS::Level> {
129  RHS::Type::Cols, RHS::Type::Rows, RHS::Type::LeafType,
130  1 + RHS::Level>(rhs);
131 }
132 
133 /// \brief template deduction for RUnOP when it is used to broadcast one const
134 /// value to all the channels of its parent node.
135 template <typename OP, size_t Cols, size_t Rows, size_t LeafType, size_t Sc,
136  typename ElementTp, typename Scalar>
137 internal::RUnOP<internal::PixelUnaryOp<OP, ElementTp>,
138  internal::VisionMemory<true, Sc, LeafType, Scalar, 1, 1,
139  ElementTp, 1, scope::Global, 0>,
140  Cols, Rows, LeafType, 1>
142  true, Sc, LeafType, Scalar, 1, 1, ElementTp, 1, scope::Global, 0> rhs) {
143  return internal::RUnOP<
145  internal::VisionMemory<true, Sc, LeafType, Scalar, 1, 1, ElementTp, 1,
146  scope::Global, 0>,
147  Cols, Rows, LeafType, 1>(rhs);
148 }
149 } // visioncpp
150 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_RESIZABLE_UNARY_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
static constexpr size_t Const
static constexpr ScopeType Global
VisionCpp namespace.
Definition: sycl/device.hpp:24
internal::RUnOP< internal::PixelUnaryOp< OP, ElementTp >, internal::VisionMemory< true, Sc, LeafType, Scalar, 1, 1, ElementTp, 1, scope::Global, 0 >, Cols, Rows, LeafType, 1 > broadcast_value(internal::VisionMemory< true, Sc, LeafType, Scalar, 1, 1, ElementTp, 1, scope::Global, 0 > rhs)
template deduction for RUnOP when it is used to broadcast one const value to all the channels of its ...
auto point_operation(LHS lhs, RHS rhs) -> internal::RBiOP< internal::PixelBinaryOp< OP, typename LHS::OutType, typename RHS::OutType >, LHS, RHS, internal::InheritTypeBinary< LHS, RHS >::Type::Cols, internal::InheritTypeBinary< LHS, RHS >::Type::Rows, internal::InheritTypeBinary< LHS, RHS >::Type::LeafType, 1+internal::tools::StaticIf<(LHS::Level > RHS::Level), LHS, RHS >::Type::Level >
template deduction for RBiOP struct where the Column, Row, and memory_type of the output has been aut...
This class is used to encapsulate the unary point operation functor and the types of each operand in ...
Definition: expr_tree.hpp:86
The definition is in RUnOP file.
static constexpr size_t CThread
static constexpr bool Unary_Conds
auto sub_expression_evaluation(const DeviceT &dev) -> decltype(execute_expr< Unary_Conds, ForcedToExec, ExprExchange< RHS >, LC, LR, LCT, LRT >(rhs.template sub_expression_evaluation< Unary_Conds, LC, LR, LCT, LRT >(dev), dev))
sub_expression_evaluation
static constexpr size_t Level
typename OutputMemory< OutType, LfType, Cols, Rows, LVL >::Type Type
static constexpr size_t RThread
static constexpr size_t ND_Category
static constexpr size_t Operation_type
static constexpr size_t LeafType
static constexpr bool SubExpressionEvaluationNeeded
typename UN_OP::OutType OutType
static constexpr bool has_out
Definition of VisionMemory.
Definition: mem_vision.hpp:53