VisionCpp  0.0.1
nofuse.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 nofuse.hpp
21 /// \brief This file contains the specialisation of the NoFuseExpr for
22 /// different nodes.
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_NOFUSE_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_NOFUSE_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 /// \brief The specialisation of the NoFuseExpr for LeafNode.
30 template <size_t LC, size_t LR, size_t LCT, size_t LRT, typename RHS,
31  size_t LVL, typename DeviceT>
32 struct NoFuseExpr<LC, LR, LCT, LRT, internal::expr_category::Unary,
33  LeafNode<RHS, LVL>, DeviceT> {
35  /// \brief the no_fuse function to execute a leafNode. It does nothing but to
36  /// return the node.
37  /// \param rhs : the leafNode passed to be executed on the device
38  /// \param dev : the selected device for executing the expression
39  /// \return the leafNode passed to the function
40  static ALHS no_fuse(LeafNode<RHS, LVL> rhs, const DeviceT &dev) {
41  return rhs;
42  }
43 };
44 /// \brief The specialisation of the NoFuseExpr for Expression node with one
45 /// operand.
46 template <size_t LC, size_t LR, size_t LCT, size_t LRT, typename Expr,typename DeviceT>
47 struct NoFuseExpr<LC, LR, LCT, LRT, internal::expr_category::Unary, Expr, DeviceT> {
49  /// \brief the no_fuse function to execute an expression node with one
50  /// operand. It recursively calls the no_fuse function for its RHS; collects
51  /// the result; launch a device kernel for the current expr with the new
52  /// collected result; and returns a leafNode representing the output result of
53  /// the expression.
54  /// \param expr : the expression passed to be executed on the device
55  /// \param dev : the selected device for executing the expression
56  /// \return the leafNode representing the result of the expression
57  /// execution.
58  static ALHS no_fuse(Expr expr, const DeviceT &dev) {
59  auto iOutput = NoFuseExpr<LC, LR, LCT, LRT, decltype(expr.rhs)::ND_Category,
60  decltype(expr.rhs), DeviceT>::no_fuse(expr.rhs, dev);
61  using IOutput = decltype(iOutput);
62  auto lhs = ALHS();
63  using ARHS = typename Expr::template ExprExchange<IOutput>;
64  fuse<LC, LR, LCT, LRT>(
65  Assign<ALHS, ARHS, ALHS::Type::Cols, ALHS::Type::Rows,
66  ALHS::Type::LeafType,
67  1 + tools::StaticIf<(ALHS::Level > ARHS::Level), ALHS,
68  ARHS>::Type::Level>(lhs, ARHS(iOutput)),
69  dev);
70  return lhs;
71  }
72 };
73 /// \brief The specialisation of the NoFuseExpr for Expression node with two
74 /// operands.
75 template <size_t LC, size_t LR, size_t LCT, size_t LRT, typename Expr, typename DeviceT>
76 struct NoFuseExpr<LC, LR, LCT, LRT, internal::expr_category::Binary, Expr, DeviceT> {
78  /// \brief the no_fuse function to execute an expression node with two
79  /// operands. It recursively calls the no_fuse function for its LHS and RHS;
80  /// collects the results; launch a device kernel for the current expr with the
81  /// expression with new collected results; and returns a leafNode
82  /// representing the output result of the expression.
83  /// \param expr : the expression passed to be executed on the device
84  /// \param dev : the selected device for executing the expression
85  /// \return the leafNode representing the result of the expression
86  /// execution.
87  static ALHS no_fuse(Expr expr, const DeviceT &dev) {
88  auto i_lhs_output =
89  NoFuseExpr<LC, LR, LCT, LRT, decltype(expr.lhs)::ND_Category,
90  decltype(expr.lhs), DeviceT>::no_fuse(expr.lhs, dev);
91 
92  auto i_rhs_output =
93  NoFuseExpr<LC, LR, LCT, LRT, decltype(expr.rhs)::ND_Category,
94  decltype(expr.rhs), DeviceT>::no_fuse(expr.rhs, dev);
95 
96  using ARHS = typename Expr::template ExprExchange<decltype(i_lhs_output),
97  decltype(i_rhs_output)>;
98  auto lhs = ALHS();
99  fuse<LC, LR, LCT, LRT>(
100  Assign<ALHS, ARHS, ALHS::Type::Cols, ALHS::Type::Rows,
101  ALHS::Type::LeafType,
102  1 + tools::StaticIf<(ALHS::Level > ARHS::Level), ALHS,
103  ARHS>::Type::Level>(
104  lhs, ARHS(i_lhs_output, i_rhs_output)),
105  dev);
106  return lhs;
107  }
108 };
109 
110 /// \brief The specialisation of the NoFuseExpr for Assign where it is a root
111 /// node and has its own lhs leaf node
112 template <size_t LC, size_t LR, size_t LCT, size_t LRT, typename LHS,
113  typename RHS, size_t Cols, size_t Rows, size_t LeafType, size_t LVL, typename DeviceT>
114 struct NoFuseExpr<LC, LR, LCT, LRT, internal::expr_category::Binary,
115  Assign<LHS, RHS, Cols, Rows, LeafType, LVL>, DeviceT> {
116  using out_Type = LHS;
118  /// \brief the no_fuse function to execute an Assign expression. It
119  /// recursively
120  /// calls the no_fuse function for its RHS; collects the result; launch a
121  /// device kernel for the current expr with the new collected result; and
122  /// returns a leafNode representing the output result of the expression.
123  /// \param expr : the expression passed to be executed on the device
124  /// \param dev : the selected device for executing the expression
125  /// \return the leafNode representing the result of the expression
126  /// execution.
128  const DeviceT &dev) {
129  auto i_rhs_output =
131 
132  using ARHS =
133  typename Expr::template ExprExchange<LHS, decltype(i_rhs_output)>;
134  fuse<LC, LR, LCT, LRT>(ARHS(expr.lhs, i_rhs_output), dev);
135  return expr.lhs;
136  }
137 };
138 
139 /// \brief template deduction function for no_fuse expression
140 template <size_t LC, size_t LR, size_t LCT, size_t LRT, typename Expr,
141  typename DeviceT>
142 void no_fuse(Expr expr, const DeviceT &dev) {
144 }
145 } // internal
146 } // visioncpp
147 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_NOFUSE_HPP_
void no_fuse(Expr expr, const DeviceT &dev)
template deduction function for no_fuse expression
Definition: nofuse.hpp:142
VisionCpp namespace.
Definition: sycl/device.hpp:24
The definition is in Assign file.
Definition: assign.hpp:44
the definition is in LeafNode.
Definition: leaf_node.hpp:38
static ALHS no_fuse(Expr expr, const DeviceT &dev)
the no_fuse function to execute an expression node with one operand.
Definition: nofuse.hpp:58
static ALHS no_fuse(Expr expr, const DeviceT &dev)
the no_fuse function to execute an expression node with two operands.
Definition: nofuse.hpp:87
static ALHS no_fuse(LeafNode< RHS, LVL > rhs, const DeviceT &dev)
the no_fuse function to execute a leafNode.
Definition: nofuse.hpp:40
static LHS no_fuse(Assign< LHS, RHS, Cols, Rows, LeafType, LVL > expr, const DeviceT &dev)
the no_fuse function to execute an Assign expression.
Definition: nofuse.hpp:127
The NoFuseExpr struct is used to generate one device kernel per each non-terminal node in the express...
Definition: executor.hpp:57
It is used to select either of the input type based the Conds template parameters.
Definition: static_if.hpp:52