VisionCpp  0.0.1
stencil_no_filter.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 stencil_no_filter.hpp
21 /// \brief This file contains StnNoFilt struct which is used to construct a
22 /// convolutional operation when the value of the filter is fixed and there is
23 /// no
24 /// need to pass it as a parameter.
25 
26 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_NEIGHBOUR_OPS_STENCIL_NO_FILTER_HPP_
27 #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_NEIGHBOUR_OPS_STENCIL_NO_FILTER_HPP_
28 
29 namespace visioncpp {
30 namespace internal {
31 /// \struct StnNoFilt
32 /// \brief stencil without filter is used to construct a convolutional
33 /// operation when the value of the filter is fixed and there is no need to pass
34 /// it as a parameter. It can be used for NeighbourOP
35 /// \tparam FilterOP: convolution functor with no filter parameter
36 /// \tparam Halo_T: The top side size of Halo
37 /// \tparam Halo_L: The left side size of Halo
38 /// \tparam Halo_B: The bottom side size of Halo
39 /// \tparam Halo_R: The right side size of Halo
40 /// \tparam RHS is the input
41 /// \tparam Cols: determines the column size of the output
42 /// \tparam Rows: determines the row size of the output
43 /// \tparam LfType: determines the type of the leafNode {Buffer2D, Buffer1D,
44 /// Host, Image}
45 /// \tparam LVL: the level of the node in the expression tree
46 
47 template <typename FilterOP, size_t Halo_T, size_t Halo_L, size_t Halo_B,
48  size_t Halo_R, typename RHS, size_t Cols, size_t Rows, size_t LfType,
49  size_t LVL>
50 struct StnNoFilt {
51  public:
52  static constexpr bool has_out = false;
53  using OutType = typename FilterOP::OutType;
54  using OPType = FilterOP;
55  using RHSExpr = RHS;
56  using Type = typename visioncpp::internal::OutputMemory<OutType, LfType, Cols,
57  Rows, LVL>::Type;
58  static constexpr size_t Level = LVL;
59  static constexpr size_t LeafType = Type::LeafType;
60  static constexpr size_t Operation_type = FilterOP::Operation_type;
61  static constexpr size_t Halo_Top = Halo_T;
62  static constexpr size_t Halo_Butt = Halo_B;
63  static constexpr size_t Halo_Left = Halo_L;
64  static constexpr size_t Halo_Right = Halo_R;
65  static constexpr size_t RThread = Rows;
66  static constexpr size_t CThread = Cols;
67  static constexpr size_t ND_Category = internal::expr_category::Unary;
68  static constexpr bool Stencil_Conds =
69  ((RThread != RHS::RThread) || (CThread != RHS::CThread));
70  static constexpr bool SubExpressionEvaluationNeeded =
71  Stencil_Conds || RHS::SubExpressionEvaluationNeeded;
72  template <typename TmpRHS>
73  using ExprExchange =
74  internal::StnNoFilt<FilterOP, Halo_T, Halo_L, Halo_B, Halo_R, TmpRHS,
75  Cols, Rows, LfType, LVL>;
76  RHS rhs;
78  StnNoFilt(RHS rhsArg) : rhs(rhsArg), subexpr_execution_reseter(false) {}
79 
80  void reset(bool reset) {
81  rhs.reset(reset);
83  }
84  /// sub_expression_evaluation
85  /// \brief This function is used to break the expression tree whenever
86  /// necessary. The decision for breaking the tree will be determined based on
87  /// the static parameter called SubExpressionEvaluationNeeded. When this is
88  /// set to true, the sub_expression_evaluation is called recursively from the
89  /// root of the tree. Each node based on their parent decision will decide to
90  /// launch a kernel for itself. Also, they decide for each of their children
91  /// whether or not to launch a kernel separately.
92  /// template parameters:
93  ///\tparam ForcedToExec : a boolean value representing the decision made by
94  /// the parent of this node for launching a kernel.
95  /// \tparam LC: is the column size of local memory required by Filter2D and
96  /// DownSmplOP
97  /// \tparam LR: is the row size of local memory required by Filter2D and
98  /// DownSmplOP
99  /// \tparam LCT: is the column size of workgroup
100  /// \tparam LRT: is the row size of workgroup
101  /// \tparam DeviceT: type representing the device
102  /// function parameters:
103  /// \param dev : the selected device for executing the expression
104  /// \return LeafNode
105  template <bool ForcedToExec, size_t LC, size_t LR, size_t LCT, size_t LRT,
106  typename DeviceT>
107  auto inline sub_expression_evaluation(const DeviceT &dev)
108  -> decltype(execute_expr<Stencil_Conds, ForcedToExec, ExprExchange<RHS>,
109  LC, LR, LCT, LRT>(
110  rhs.template sub_expression_evaluation<Stencil_Conds, LC, LR, LRT,
111  LCT>(dev),
112  dev)) {
113  return execute_expr<Stencil_Conds, ForcedToExec, ExprExchange<RHS>, LC, LR,
114  LCT, LRT>(
115  rhs.template sub_expression_evaluation<Stencil_Conds, LC, LR, LCT, LRT>(
116  dev),
117  dev);
118  }
119 };
120 
121 /// \brief template deduction for StnNoFilt class when the memory type of the
122 /// output and column and row are defined by a user.
123 template <typename OP, size_t Halo_T, size_t Halo_L, size_t Halo_B,
124  size_t Halo_R, size_t Cols, size_t Rows, size_t LeafType,
125  typename RHS>
126 auto neighbour_operation(RHS rhs)
128  Halo_T, Halo_L, Halo_B, Halo_R, RHS, Cols, Rows,
129  LeafType, 1 + RHS::Level> {
131  Halo_T, Halo_L, Halo_B, Halo_R, RHS, Cols, Rows,
132  LeafType, 1 + RHS::Level>(rhs);
133 }
134 } // namespace
135 
136 /// \brief template deduction for StnNoFilt class when the memory type of the
137 /// output and column and row are automatically deduced from the input.
138 template <typename OP, size_t Halo_T, size_t Halo_L, size_t Halo_B,
139  size_t Halo_R, typename RHS>
140 auto neighbour_operation(RHS rhs)
142  Halo_T, Halo_L, Halo_B, Halo_R, RHS, RHS::Type::Cols,
143  RHS::Type::Rows, RHS::Type::LeafType,
144  1 + RHS::Level> {
146  Halo_T, Halo_L, Halo_B, Halo_R, RHS,
147  RHS::Type::Cols, RHS::Type::Rows,
148  RHS::Type::LeafType, 1 + RHS::Level>(rhs);
149 }
150 } // visioncpp
151 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_NEIGHBOUR_OPS_STENCIL_NO_FILTER_HPP_
auto neighbour_operation(RHS rhs) -> internal::StnNoFilt< internal::LocalUnaryOp< OP, typename RHS::OutType >, Halo_T, Halo_L, Halo_B, Halo_R, RHS, Cols, Rows, LeafType, 1+RHS::Level >
template deduction for StnNoFilt class when the memory type of the output and column and row are defi...
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 neighbour_operation(RHS rhs) -> internal::RDCN< internal::LocalUnaryOp< OP, typename RHS::OutType >, RHS, Cols, Rows, LeafType, 1+RHS::Level >
template deduction function for RDCN when it is used for NeighbourOP.
Definition: reduction.hpp:133
OutputMemory is used to deduce the output type of each node in the expression tree by using certain p...
Definition: memory.hpp:53
The definition is in StnNoFilt file.
static constexpr size_t CThread
static constexpr size_t RThread
static constexpr size_t LeafType
static constexpr size_t ND_Category
static constexpr size_t Halo_Right
static constexpr size_t Operation_type
static constexpr size_t Level
typename FilterOP::OutType OutType
static constexpr bool SubExpressionEvaluationNeeded
static constexpr size_t Halo_Left
static constexpr size_t Halo_Butt
static constexpr bool Stencil_Conds
typename visioncpp::internal::OutputMemory< OutType, LfType, Cols, Rows, LVL >::Type Type
static constexpr size_t Halo_Top
auto sub_expression_evaluation(const DeviceT &dev) -> decltype(execute_expr< Stencil_Conds, ForcedToExec, ExprExchange< RHS >, LC, LR, LCT, LRT >(rhs.template sub_expression_evaluation< Stencil_Conds, LC, LR, LRT, LCT >(dev), dev))
sub_expression_evaluation