VisionCpp  0.0.1
mem_virtual.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 mem_virtual.hpp
21 /// This file contains the VirtualMemory struct. VirtualMemory struct is nothing
22 /// but a future LeafNode representing the result of the subexpression passed to
23 /// it to be executed. It is used by user to schedule any arbitrary
24 /// subexpression to be executed in a separate kernel. This will allow a user to
25 /// manually break the expression tree at compile time.
26 
27 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_VIRTUAL_HPP_
28 #define VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_VIRTUAL_HPP_
29 
30 namespace visioncpp {
31 namespace internal {
32 /// \struct VirtualMemory
33 /// \brief VirtualMemory struct is nothing but a future LeafNode representing
34 /// the result of the subexpression passed to it to be executed. It is used by
35 /// the user to schedule any arbitrary subexpression to be executed in a separate
36 /// kernel. This will allow a user to manually break the expression tree at
37 /// compile time.
38 /// template parameters
39 /// \tparam PlcType: represent the policyType for executing the subexpression
40 /// \tparam Node: the subexpression tree needed to be executed
41 /// template parameters:
42 /// \tparam LC: is the column size of local memory
43 /// \tparam LR: is the row size of local memory
44 /// \tparam LCT: is the column size of workgroup
45 /// \tparam LRT: is the row size of workgroup
46 template <bool PlcType, typename Node, size_t LC, size_t LR, size_t LCT,
47  size_t LRT>
48 struct VirtualMemory {
49  static constexpr bool policyType = PlcType;
50  using Type = typename Node::Type;
51  using Scalar = typename Type::Scalar;
52  using ElementType = typename Type::ElementType;
53  template <cl::sycl::access::mode acMd>
54  using Accessor = typename Type::template Accessor<acMd>;
55  static constexpr size_t Rows = Type::Rows;
56  static constexpr size_t Cols = Type::Cols;
57  static constexpr size_t Channels = Type::Channels;
58  static constexpr size_t LeafType = Type::LeafType;
59  static constexpr bool SubExpressionEvaluationNeeded = true;
60  static constexpr size_t Level = Node::Level;
61  Node subTree;
62  using syclBuffer = Node;
63  VirtualMemory(Node nd) : subTree(nd){};
64  /// sub_expression_evaluation
65  /// \brief This function is used to break the expression tree whenever
66  /// necessary. The decision for breaking the tree will be determined based on
67  /// the static parameter called SubExpressionEvaluationNeeded. When this is
68  /// set to true, the sub_expression_evaluation is called recursively from the
69  /// root of the tree. Each node based on their parent decision will decide to
70  /// launch a kernel for itself. Also, they decide for each of their children
71  /// whether or not to launch a kernel separately.
72  /// template parameters:
73  ///\tparam ForcedToExec : a boolean value representing the decision made by
74  /// the parent of this node for launching a kernel.
75  /// \tparam LC: is the column size of local memory required by Filter2D and
76  /// DownSmplOP
77  /// \tparam LR: is the row size of local memory required by Filter2D and
78  /// DownSmplOP
79  /// \tparam LCT: is the column size of workgroup
80  /// \tparam LRT: is the row size of workgroup
81  /// function parameters:
82  /// \param dev : the selected device for executing the expression
83  /// \return LeafNode
84  template <bool ForcedToExec, size_t LC1, size_t LR1, size_t LRT1, size_t LCT1,
85  typename DeviceT>
87  const DeviceT &dev) {
88  // this is manually breaking so we have to break and we cannot use the
89  // condition used in the subtree for evalifneeded
91  auto rhs =
92  subTree.template sub_expression_evaluation<false, LC1, LR1, LRT1, LCT1>(
93  dev);
94  auto a =
95  internal::Assign<decltype(lhs), decltype(rhs),
96  decltype(lhs)::Type::Cols, decltype(lhs)::Type::Rows,
97  decltype(lhs)::Type::LeafType,
99  (decltype(lhs)::Level > decltype(rhs)::Level),
100  decltype(lhs), decltype(rhs)>::Type::Level>(
101  lhs, rhs);
102  execute<PlcType, LC, LR, LCT, LRT>(a, dev);
103  return lhs;
104  }
105 };
106 }
107 /// brief function schedule is a template deduction function for VirtualMemory
108 /// when the local memory and workgroup size is defined by a user.
109 template <size_t plcType, size_t LWV, size_t LHV, size_t LCTV, size_t LRTV,
110  typename Type>
111 auto schedule(Type dt) -> decltype(internal::LeafNode<
113  dt)) {
114  return internal::LeafNode<
116  Type::Level>(
118 }
119 /// brief function schedule is a template deduction function for VirtualMemory
120 /// when the local memory and workgroup size is default
121 template <size_t plcType, typename Type>
122 auto schedule(Type dt)
124  Type::Level>(dt)) {
126  Type::Level>(
128 }
129 } // visioncpp
130 #endif // VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_VIRTUAL_HPP_
VisionCpp namespace.
Definition: sycl/device.hpp:24
auto schedule(Type dt) -> decltype(internal::LeafNode< internal::VirtualMemory< plcType, Type, LWV, LHV, LCTV, LRTV >, Type::Level >(dt))
brief function schedule is a template deduction function for VirtualMemory when the local memory and ...
The definition is in Assign file.
Definition: assign.hpp:44
the definition is in LeafNode.
Definition: leaf_node.hpp:38
the definition is in VirtualMemory
Definition: mem_virtual.hpp:48
static constexpr bool SubExpressionEvaluationNeeded
Definition: mem_virtual.hpp:59
static constexpr size_t Cols
Definition: mem_virtual.hpp:56
typename Type::Scalar Scalar
Definition: mem_virtual.hpp:51
typename Type::ElementType ElementType
Definition: mem_virtual.hpp:52
static constexpr size_t Rows
Definition: mem_virtual.hpp:55
static constexpr size_t Level
Definition: mem_virtual.hpp:60
static constexpr size_t LeafType
Definition: mem_virtual.hpp:58
internal::LeafNode< Type, Level > sub_expression_evaluation(const DeviceT &dev)
sub_expression_evaluation
Definition: mem_virtual.hpp:86
typename Type::template Accessor< acMd > Accessor
Definition: mem_virtual.hpp:54
static constexpr size_t Channels
Definition: mem_virtual.hpp:57
static constexpr bool policyType
Definition: mem_virtual.hpp:49
It is used to select either of the input type based the Conds template parameters.
Definition: static_if.hpp:52