VisionCpp  0.0.1
pyramid_mem.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 pyramid_mem.hpp
21 /// \brief This file is used to create a pyramid output memory when the auto
22 /// generate output memory is selected. Here a tuple of output memory will be
23 /// constructed. The size of the tuple is a template variable determined based
24 /// on the depth of the pyramid.
25 
26 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_COMPLEX_OPS_TREE_PYRAMID_MEM_HPP_
27 #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_COMPLEX_OPS_TREE_PYRAMID_MEM_HPP_
28 
29 namespace visioncpp {
30 namespace internal {
31 
32 /// \brief CreatePyramidTupleType: This file is used to create each output
33 /// element type for each downsampling output of the pyramid memory. It is used
34 /// when we need the pyramid node auto generate the output node.
35 /// template parameters:
36 /// \tparam SatisfyingConds: a boolean variable is used to determine the end of
37 /// the recursive creation of the pyramid output tuple.
38 /// \tparam Cols: determines the column size of the input pyramid
39 /// \tparam Rows: determines the row size of the input pyramid
40 /// \tparam LeafType: determines the type of the leafNode {Buffer2D, Buffer1D,
41 /// Host, Image}
42 /// \tparam Depth: represents the depth of down sampling
43 /// \tparam CurrentDepth: represents the number of outputs created so far in the
44 /// recursion
45 /// \tparam LHS is the final output of the pyramid combining all the node
46 /// together
47 /// \tparam ChildType... : is the total number of output types generated so far
48 template <bool SatisfyingConds, size_t Cols, size_t Rows, size_t LeafType,
49  size_t Depth, size_t CurrentDepth, typename LHS,
50  typename... ChildType>
53  VisionMemory<false, LHS::Type::MemoryCategory, LHS::Type::LeafType,
54  typename LHS::Type::Scalar, Cols, Rows,
55  typename LHS::Type::ElementType, LHS::Type::Channels,
56  LHS::Type::scope, CurrentDepth + 100>,
57  CurrentDepth + 100>;
58  using Type = typename CreatePyramidTupleType<
59  (Depth == CurrentDepth + 1), Cols / 2, Rows / 2, LeafType, Depth,
60  CurrentDepth + 1, LHS, ChildType..., SubBuffer>::Type;
61 };
62 
63 /// \brief specialisation of the CreatePyramidTupleType when the
64 /// SatisfyingConds is true. It does nothing but representing the end of
65 /// recursive constructing output types in the Tuple
66 template <size_t Cols, size_t Rows, size_t LeafType, size_t Depth,
67  size_t CurrentDepth, typename LHS, typename... ChildType>
68 struct CreatePyramidTupleType<true, Cols, Rows, LeafType, Depth, CurrentDepth,
69  LHS, ChildType...> {
70  using Type = tools::tuple::Tuple<ChildType...>;
71 };
72 
73 /// \brief CreatePyramidTuple. Once the type of each output element for the
74 /// output element of the pyramid has been created, The CreatePyramidTuple is
75 /// used to instantiate the output elements of the Tuple.
76 /// \tparam SatisfyingConds: a boolean variable is used to determine the end of
77 /// the recursive creation of the pyramid output tuple.
78 /// \tparam Cols: determines the column size of the input pyramid
79 /// \tparam Rows: determines the row size of the input pyramid
80 /// \tparam LeafType: determines the type of the leafNode {Buffer2D, Buffer1D,
81 /// Host, Image}
82 /// \tparam Depth: represents the depth of down sampling
83 /// \tparam CurrentDepth: represents the number of output created so far in the
84 /// recursion
85 /// \tparam LHS is the final output of the pyramid combining all the nodes
86 /// together
87 template <bool SatisfyingConds, size_t Cols, size_t Rows, size_t LeafType,
88  size_t Depth, size_t CurrentDepth, typename LHS>
91  VisionMemory<false, LHS::Type::MemoryCategory, LHS::Type::LeafType,
92  typename LHS::Type::Scalar, Cols, Rows,
93  typename LHS::Type::ElementType, LHS::Type::Channels,
94  LHS::Type::scope, CurrentDepth + 100>,
95  CurrentDepth + 100>;
96 
97  using SubBuffer = typename SyclMem<false, LHS::Type::LeafType, LHS::Type::Dim,
98  typename LHS::Type::ElementType>::Type;
99 
100  /// create_tuple function:
101  /// \brief This function is used to instantiate the output tuple.
102  /// \return Tuple
103  static auto create_tuple() -> decltype(tools::tuple::append(
105  SubBufferNode(SubBuffer(get_range<LHS::Type::Dim>(Rows, Cols)))),
106  CreatePyramidTuple<(Depth == (CurrentDepth + 1)), Cols / 2, Rows / 2,
107  LeafType, Depth, CurrentDepth + 1,
108  LHS>::create_tuple())) {
109  auto subBufferExpr = tools::tuple::make_tuple(
110  SubBufferNode(SubBuffer(get_range<LHS::Type::Dim>(Rows, Cols))));
111 
112  auto nestedExpr = CreatePyramidTuple<(Depth == (CurrentDepth + 1)),
113  Cols / 2, Rows / 2, LeafType, Depth,
114  CurrentDepth + 1, LHS>::create_tuple();
115 
116  return tools::tuple::append(subBufferExpr, nestedExpr);
117  }
118 };
119 
120 /// \brief specialisation of the CreatePyramidTuple when the
121 /// SatisfyingConds is true. It does nothing but representing the end of
122 /// recursive instantiating the output types in the Tuple
123 template <size_t Cols, size_t Rows, size_t LeafType, size_t Depth,
124  size_t CurrentDepth, typename LHS>
125 struct CreatePyramidTuple<true, Cols, Rows, LeafType, Depth, CurrentDepth,
126  LHS> {
128  VisionMemory<false, LHS::Type::MemoryCategory, LHS::Type::LeafType,
129  typename LHS::Type::Scalar, Cols, Rows,
130  typename LHS::Type::ElementType, LHS::Type::Channels,
131  LHS::Type::scope, CurrentDepth + 100>,
132  CurrentDepth + 100>;
133 
134  using SubBuffer = typename SyclMem<false, LHS::Type::LeafType, LHS::Type::Dim,
135  typename LHS::Type::ElementType>::Type;
136 
137  /// create_tuple function:
138  /// \brief This function is used to instantiate the output tuple.
139  /// \return Tuple
140  static decltype(tools::tuple::make_tuple()) inline create_tuple() {
141  return tools::tuple::make_tuple();
142  }
143 };
144 
145 // template deduction for pyramid tuple
146 template <size_t Cols, size_t Rows, size_t Depth, size_t CurrentDepth,
147  typename LHS>
148 typename CreatePyramidTupleType<false, Cols, Rows, LHS::Type::LeafType, Depth,
149  0, LHS>::Type inline create_pyramid_memory() {
150  return CreatePyramidTuple<(Depth == 0), Cols, Rows, LHS::Type::LeafType,
151  Depth, 0, LHS>::create_tuple();
152 }
153 } // internal
154 } // visioncpp
155 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_COMPLEX_OPS_TREE_PYRAMID_MEM_HPP_
Tuple< Args..., T > append(Tuple< Args... > t, T a)
append
Definition: tuple.hpp:235
Tuple< Args... > make_tuple(Args... args)
make_tuple
Definition: tuple.hpp:153
CreatePyramidTupleType< false, Cols, Rows, LHS::Type::LeafType, Depth, 0, LHS >::Type create_pyramid_memory()
create_pyramid_memory template deduction function for CreatePyramidTuple struct.
VisionCpp namespace.
Definition: sycl/device.hpp:24
CreatePyramidTupleType: This file is used to create each output element type for each downsampling ou...
Definition: pyramid_mem.hpp:51
typename CreatePyramidTupleType<(Depth==CurrentDepth+1), Cols/2, Rows/2, LeafType, Depth, CurrentDepth+1, LHS, ChildType..., SubBuffer >::Type Type
Definition: pyramid_mem.hpp:60
typename SyclMem< false, LHS::Type::LeafType, LHS::Type::Dim, typename LHS::Type::ElementType >::Type SubBuffer
typename SyclMem< false, LHS::Type::LeafType, LHS::Type::Dim, typename LHS::Type::ElementType >::Type SubBuffer
Definition: pyramid_mem.hpp:98
LeafNode< VisionMemory< false, LHS::Type::MemoryCategory, LHS::Type::LeafType, typename LHS::Type::Scalar, Cols, Rows, typename LHS::Type::ElementType, LHS::Type::Channels, LHS::Type::scope, CurrentDepth+100 >, CurrentDepth+100 > SubBufferNode
Definition: pyramid_mem.hpp:95
static auto create_tuple() -> decltype(tools::tuple::append(tools::tuple::make_tuple(SubBufferNode(SubBuffer(get_range< LHS::Type::Dim >(Rows, Cols)))), CreatePyramidTuple<(Depth==(CurrentDepth+1)), Cols/2, Rows/2, LeafType, Depth, CurrentDepth+1, LHS >::create_tuple()))
create_tuple function:
the definition is in LeafNode.
Definition: leaf_node.hpp:38
SyclMem is used to create VisionMemory data storage.
Definition: memory.hpp:254
Definition of VisionMemory.
Definition: mem_vision.hpp:53
The tuple is a fixed-size collection of heterogeneous values.
Definition: tuple.hpp:48