VisionCpp  0.0.1
leaf_node.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 leaf_node.hpp
21 /// \brief This file contains the LeafNode struct which is a general representation
22 /// of our terminal node in the expression tree.
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_LEAF_NODE_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_LEAF_NODE_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 /// \struct LeafNode
30 /// \brief This file contains LeafNode struct which is a general representation
31 /// of our terminal node in the expression tree.
32 /// template parameters:
33 /// \tparam RHS is the visionMemory allocated to our terminal node. It can be
34 /// Sycl memory(Sycl memory with map allocator and device only sycl memory );
35 /// Host Memory or VirtualMemory.
36 /// \tparam LVL: the level of the node in the expression tree
37 template <typename RHS, size_t LVL>
38 struct LeafNode {
39  static constexpr bool has_out = false;
40  using Type =
41  typename internal::OutputMemory<typename RHS::ElementType, RHS::LeafType,
42  RHS::Cols, RHS::Rows, RHS::Level>::Type;
43  static constexpr size_t Level = LVL;
44  using RHSExpr = RHS;
45  using Scalar = typename Type::Scalar;
46  static constexpr size_t LeafType = RHS::LeafType;
47  static constexpr size_t RThread = RHS::Rows;
48  static constexpr size_t CThread = RHS::Cols;
49  using OutType = typename RHS::ElementType;
50  static constexpr size_t ND_Category = internal::expr_category::Unary;
52  static constexpr bool SubExpressionEvaluationNeeded =
53  RHS::SubExpressionEvaluationNeeded;
56  LeafNode() : LeafNode(Type()) {} // at this point RHS =Type must hold
57  /// buffer copy is lightweight no need to pass by ref
59  LeafNode(typename RHS::syclBuffer dt) : LeafNode(RHS(dt)) {}
60 
62 
63  /// sub_expression_evaluation
64  /// \brief This function is used to break the expression tree whenever
65  /// necessary. The decision for breaking the tree will be determined based on
66  /// the static parameter called SubExpressionEvaluationNeeded. When this is
67  /// set to true, the sub_expression_evaluation is called recursively from the
68  /// root of the tree. Each node based on their parent decision will decide to
69  /// launch a kernel for itself. Also, they decide for each of their children
70  /// whether or not to launch a kernel separately.
71  /// template parameters:
72  ///\tparam ForcedToExec : a boolean value representing the decision made by
73  /// the parent of this node for launching a kernel.
74  /// \tparam LC: is the column size of local memory required by Filter2D and
75  /// DownSmplOP
76  /// \tparam LR: is the row size of local memory required by Filter2D and
77  /// DownSmplOP
78  /// \tparam LCT: is the column size of workgroup
79  /// \tparam LRT: is the row size of workgroup
80  /// \tparam DeviceT: type representing the device
81  /// function parameters:
82  /// \param dev : the selected device for executing the expression
83  /// \return LeafNode
84  template <bool ForcedToExec, size_t LC, size_t LR, size_t LCT, size_t LRT,
85  typename DeviceT>
87  const DeviceT &dev) {
88  return vilibMemory
89  .template sub_expression_evaluation<false, LC, LR, LCT, LRT>(dev);
90  }
91  /// \brief set_output function is used to destroy the sycl buffer and manually
92  /// allocate the data to the provided pointer. This is used when we needed to
93  /// return the value of the device only buffer.
94  /// \param ptr: the pointer for manually allocating the data
95  /// \return void
96  inline void set_output(std::shared_ptr<Scalar> &ptr) {
97  (vilibMemory.set_output(ptr));
98  }
99 
100  /// \brief reset_input is used to manually reset the input value of an input
101  /// sycl buffer. This can be used when we are dealing with video streaming and
102  /// we want to pass different input stream to the expression.
103  /// \return void
104  inline void reset_input(Scalar *dt) { vilibMemory.reset_input(dt); }
105 
106  /// \brief lock function is used to access the sycl buffer on the host using
107  /// a host pointer. Because the host accessor is blocking. We are creating it
108  /// dynamically so by calling the lock function. It is the responsibility of
109  /// a user to call the unlock function in order to destroy the accessor once its
110  /// work is finished. This is useful when we are dealing with video and we
111  /// want to display each frame of the video at the end of each iteration.
112  /// \return void
113  inline void lock() { vilibMemory.lock(); }
114  /// \brief The unlock function for destroying the host accessor. It must be
115  /// called by user if the lock has been called in order to destroy the host
116  /// accessor and release the execution.
117  /// \return void
118  inline void unlock() { vilibMemory.unlock(); }
119 };
120 } // internal
121 
122 /// \brief template deduction of LeafNode for buffer/image/host 2d where the
123 /// element_category is Struct
124 template <typename ElemTp, size_t Cols, size_t Rows, size_t MemoryType,
125  size_t Sc = scope::Global>
130  MemoryType,
133  0>,
134  0> {
135  return internal::LeafNode<
144 }
145 
146 /// \brief creation of the device only memory when the type is struct
147 // device only memory
148 template <typename ElemTp, size_t Cols, size_t Rows, size_t MemoryType,
149  size_t Sc = scope::Global>
155  0> {
156  return internal::LeafNode<
161  Sc, 0>,
166 }
167 
168 /// \brief template deduction of LeafNode where the memory_type is a constant
169 /// variable and element_category is Struct
170 template <typename ElemTp, size_t LeafType>
177  scope::Global, 0>,
178  0> {
179  return internal::LeafNode<
184  scope::Global, 0>,
189 }
190 } // visioncpp
191 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_LEAF_NODE_HPP_
static constexpr ScopeType Global
VisionCpp namespace.
Definition: sycl/device.hpp:24
auto terminal(typename internal::MemoryProperties< ElemTp >::ChannelType *dt) -> internal::LeafNode< internal::VisionMemory< true, internal::MemoryProperties< ElemTp >::ElementCategory, MemoryType, typename internal::MemoryProperties< ElemTp >::ChannelType, Cols, Rows, ElemTp, internal::MemoryProperties< ElemTp >::ChannelSize, Sc, 0 >, 0 >
template deduction of LeafNode for buffer/image/host 2d where the element_category is Struct
Definition: leaf_node.hpp:126
the definition is in LeafNode.
Definition: leaf_node.hpp:38
void unlock()
The unlock function for destroying the host accessor.
Definition: leaf_node.hpp:118
typename Type::Scalar Scalar
Definition: leaf_node.hpp:45
void set_output(std::shared_ptr< Scalar > &ptr)
set_output function is used to destroy the sycl buffer and manually allocate the data to the provided...
Definition: leaf_node.hpp:96
static constexpr size_t Operation_type
Definition: leaf_node.hpp:54
LeafNode(typename RHS::syclBuffer dt)
Definition: leaf_node.hpp:59
static constexpr size_t Level
Definition: leaf_node.hpp:43
static constexpr bool SubExpressionEvaluationNeeded
Definition: leaf_node.hpp:52
LeafNode< typename RHS::Type, Level > sub_expression_evaluation(const DeviceT &dev)
sub_expression_evaluation
Definition: leaf_node.hpp:86
typename internal::OutputMemory< typename RHS::ElementType, RHS::LeafType, RHS::Cols, RHS::Rows, RHS::Level >::Type Type
Definition: leaf_node.hpp:42
static constexpr size_t ND_Category
Definition: leaf_node.hpp:50
void reset_input(Scalar *dt)
reset_input is used to manually reset the input value of an input sycl buffer.
Definition: leaf_node.hpp:104
void lock()
lock function is used to access the sycl buffer on the host using a host pointer.
Definition: leaf_node.hpp:113
static constexpr bool has_out
Definition: leaf_node.hpp:39
static constexpr size_t CThread
Definition: leaf_node.hpp:48
typename RHS::ElementType OutType
Definition: leaf_node.hpp:49
static constexpr size_t LeafType
Definition: leaf_node.hpp:46
static constexpr size_t RThread
Definition: leaf_node.hpp:47
bool subexpr_execution_reseter
buffer copy is lightweight no need to pass by ref
Definition: leaf_node.hpp:58
This file is used to detect the ChannelType ElementCategory {basic or struct}, and the channel size o...
Definition: mem_prop.hpp:32
typename ElementTp::data_type ChannelType
Definition: mem_prop.hpp:34
OutputMemory is used to deduce the output type of each node in the expression tree by using certain p...
Definition: memory.hpp:53
Definition of VisionMemory.
Definition: mem_vision.hpp:53