VisionCpp  0.0.1
square_pattern.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 square_pattern.hpp
21 /// \brief this file contains the partial specialisation of the Fill for
22 /// LeafNode
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_LOAD_PATTERN_SQUARE_PATTERN_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_LOAD_PATTERN_SQUARE_PATTERN_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 /// \brief Partial specialisation of the Fill when the LeafNode contains the
30 /// const variable. In this case we load nothing in to the shared memory as
31 /// there is no shared memory for const variable and the const variable directly
32 /// copied to the device and accessed by each thread.
33 template <size_t N, size_t Rows, size_t Cols, size_t Sc, size_t LVL,
34  typename Loc, typename... Params>
35 struct Fill<LeafNode<PlaceHolder<memory_type::Const, N, Cols, Rows, Sc>, LVL>,
36  Loc, Params...> {
37  template <size_t Halo_Top, size_t Halo_Left, size_t Halo_Butt,
38  size_t Halo_Right, size_t Offset, size_t LC, size_t LR>
39  static void fill_neighbour(Loc &cOffset,
41  // no need to do anything the memory is read only
42  }
43 };
44 /// \brief Partial specialisation of the Fill when the LeafNode contains a sycl
45 /// buffer created on constant memory. In this case we load nothing in to the
46 /// shared memory as there is no shared memory created for a buffer on a device
47 /// constant memory. Such a buffer is directly accessed on the device by each
48 /// thread.
49 template <size_t Memory_Type, size_t N, size_t Rows, size_t Cols, size_t LVL,
50  typename Loc, typename... Params>
51 struct Fill<
52  LeafNode<PlaceHolder<Memory_Type, N, Cols, Rows, scope::Constant>, LVL>,
53  Loc, Params...> {
54  template <size_t Halo_Top, size_t Halo_Left, size_t Halo_Butt,
55  size_t Halo_Right, size_t Offset, size_t LC, size_t LR>
56  static void fill_neighbour(Loc &cOffset,
58 };
59 /// \brief Partial specialisation of the Fill when the LeafNode contains the
60 /// sycl buffer on the global memory. In this case each work group loads a
61 /// rectangle block of (LR,LC) in to their dedicated local memory.
62 template <size_t Memory_Type, size_t N, size_t Rows, size_t Cols, size_t LVL,
63  size_t Sc, typename Loc, typename... Params>
64 struct Fill<LeafNode<PlaceHolder<Memory_Type, N, Cols, Rows, Sc>, LVL>, Loc,
65  Params...> {
66  template <size_t Halo_Top, size_t Halo_Left, size_t Halo_Butt,
67  size_t Halo_Right, size_t Index, size_t LC, size_t LR>
68  static void fill_neighbour(Loc &cOffset,
70  static_assert(Cols > 0 && LC > 0, "Cols must be greater than 0");
71  static_assert(Rows > 0 && LR > 0, "Rows must be greater than 0");
72  // calculation begins from here for unary op
73  for (int i = 0; i < LC; i += cOffset.cLRng) {
74  if ((cOffset.l_c + i < LC)) {
75  size_t val_c = get_global_range<Halo_Left, Cols>(cOffset.g_c + i);
76  for (size_t j = 0; j < LR; j += cOffset.rLRng) {
77  size_t val_r = get_global_range<Halo_Top, Rows>(cOffset.g_r + j);
78  if ((cOffset.l_r + j < LR)) {
79  tools::tuple::get<Index>(t)
80  .get_pointer()[(cOffset.l_c + i) + (LC * (cOffset.l_r + j))] =
81  tools::convert<typename MemoryTrait<
82  Memory_Type, decltype(tools::tuple::get<Index>(t))>::Type>(
83  *(tools::tuple::get<N>(t).get_pointer() +
84  calculate_index(val_c, val_r, Cols, Rows)));
85  /// FIXME: image cannot be accessed by pointer
86  }
87  }
88  }
89  }
90  // here you need to put local barrier
91  cOffset.barrier();
92  }
93 };
94 
95 // template deduction for Fill struct.
96 template <size_t Halo_Top, size_t Halo_Left, size_t Halo_Butt,
97  size_t Halo_Right, size_t Offset, size_t LC, size_t LR, typename Expr,
98  typename Loc, typename... Params>
99 static void fill_local_neighbour(Loc &cOffset,
101  Fill<Expr, Loc, Params...>::template fill_neighbour<
102  Halo_Top, Halo_Left, Halo_Butt, Halo_Right, Offset, LC, LR>(cOffset, t);
103 }
104 } // namespace internal
105 } // namespace visioncpp
106 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_LOAD_PATTERN_SQUARE_PATTERN_HPP_
T1 convert(T2 x)
function convert
Definition: convert.hpp:558
static size_t calculate_index(size_t c, size_t r, size_t cols, size_t rows)
function calculate_index
static void fill_local_neighbour(Loc &cOffset, const internal::tools::tuple::Tuple< Params... > &t)
template deduction for Fill struct.
static constexpr size_t Const
static constexpr ScopeType Constant
VisionCpp namespace.
Definition: sycl/device.hpp:24
The Fill is used to load a rectangle neighbour area from global memory to local memory.
Definition: evaluator.hpp:89
the definition is in LeafNode.
Definition: leaf_node.hpp:38
This class is used to determine the ElementType of accessor template parameters.
PlaceHolder is used to replace the Vision Memory in the LeafNode containing sycl buffer.
The tuple is a fixed-size collection of heterogeneous values.
Definition: tuple.hpp:48