VisionCpp  0.0.1
fuse.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 fuse.hpp
21 /// \brief This file contains the specialisation of the FuseExpr for terminal and
22 /// non-terminal nodes.
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_FUSE_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_FUSE_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 /// \brief the FuseExpr when the expression type is not a terminal node
30 /// (leafNode).
31 template <size_t LCIn, size_t LRIn, size_t LCT, size_t LRT, typename Expr, typename DeviceT>
32 struct FuseExpr {
33  /// \brief the fuse function for executing the given expr.
34  /// \param expr : the expression passed to be executed on the device
35  /// \param dev : the selected device for executing the expression
36  /// return void
37  static void fuse(Expr &expr, const DeviceT &dev) {
38  /// LRT is the workgroup size row and is checked with LR. LR is based
39  /// on LRIn. LCT is the workgroup size column checked with LC. LC is based
40  /// on LCIn. The local memory size and the work group size is calculated at
41  /// compile time.
42  constexpr size_t LR =
43  tools::IfConst<(Expr::RThread > LRIn), LRIn, Expr::RThread>::Value;
44  constexpr size_t LC =
45  tools::IfConst<(Expr::CThread > LCIn), LCIn, Expr::CThread>::Value;
46 
47  constexpr int rLThread =
48  tools::IfConst<(Expr::RThread > LRT), LRT, Expr::RThread>::Value;
49 
50  constexpr int cLThread =
51  tools::IfConst<(Expr::CThread > LCT), LCT, Expr::CThread>::Value;
52 
53  constexpr size_t rGThreads =
54  (tools::IfConst<(Expr::RThread % LR == 0), (Expr::RThread / LR),
55  ((Expr::RThread / LR) + 1)>::Value) *
56  rLThread;
57 
58  constexpr size_t cGThreads =
59  (tools::IfConst<(Expr::CThread % LC == 0), (Expr::CThread / LC),
60  ((Expr::CThread / LC) + 1)>::Value) *
61  cLThread;
62  dev.template execute<LC, LR, cGThreads, rGThreads, cLThread, rLThread>(
63  expr);
64  }
65 };
66 /// \brief specialisation of Fuse struct when the Expr is a terminal node
67 /// (leafNode)
68 template <size_t LC, size_t LR, size_t LCT, size_t LRT, size_t LVL,
69  typename RHS, typename DeviceT>
70 struct FuseExpr<LC, LR, LCT, LRT, LeafNode<RHS, LVL>, DeviceT> {
71  /// when the node is a terminal node (leafNode) we do nothing as there is no
72  /// need to run any expression
73  static void fuse(LeafNode<RHS, LVL> &expr, const DeviceT &dev) {}
74 };
75 
76 /// function fuse
77 /// \brief fuse function to generate a device kernel and execute.
78 /// template parameters:
79 /// \tparam LC: suggested column size for the local memory
80 /// \tparam LR: suggested row size for the local memory
81 /// \tparam LRT: suggested workgroup row size
82 /// \tparam LCT: suggested workgroup column size
83 /// \tparam Expr: the expression type
84 /// function parameters:
85 /// \param expr: the input expression
86 /// \param dev : the selected device for executing the expression
87 template <size_t LC, size_t LR, size_t LCT, size_t LRT, typename Expr,
88  typename DeviceT>
89 inline void fuse(Expr expr, const DeviceT &dev) {
91 };
92 } // internal
93 } // visioncpp
94 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_FUSE_HPP_
void fuse(Expr expr, const DeviceT &dev)
function fuse
Definition: fuse.hpp:89
VisionCpp namespace.
Definition: sycl/device.hpp:24
static void fuse(LeafNode< RHS, LVL > &expr, const DeviceT &dev)
when the node is a terminal node (leafNode) we do nothing as there is no need to run any expression
Definition: fuse.hpp:73
the FuseExpr when the expression type is not a terminal node (leafNode).
Definition: fuse.hpp:32
static void fuse(Expr &expr, const DeviceT &dev)
the fuse function for executing the given expr.
Definition: fuse.hpp:37
the definition is in LeafNode.
Definition: leaf_node.hpp:38