VisionCpp  0.0.1
extract_accessors.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 extract_accessors.hpp
21 /// \brief This files is used to provide an access mechanism for terminal nodes
22 /// on the device.
23 
24 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_EXTRACT_ACCESSORS_HPP_
25 #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_EXTRACT_ACCESSORS_HPP_
26 
27 namespace visioncpp {
28 namespace internal {
29 ///
30 /// \brief The extract accessor struct is used to extract the accessor from the
31 /// leafnodes and pack them in a tuple by using the in-order traverse algorithm
32 /// on the expression tree. As a different non-terminal node has different
33 /// behaviour the specialisation of the accessor extraction struct is required
34 /// per node.
35 ///
36 template <size_t Category, typename Expr>
38 
39 /// \brief Specialisation of ExtractAccessor class where the expression node is
40 /// LeafNode.
41 template <typename RHS, size_t LVL>
42 struct ExtractAccessor<expr_category::Unary, LeafNode<RHS, LVL>> {
43  /// getting read access when the leaf node is accessed by traversing the right-
44  /// hand side of an Assign or ParallelCopy (partial Assign) expression
45  static tools::tuple::Tuple<
46  typename RHS::template Accessor<cl::sycl::access::mode::read>>
47  getTuple(cl::sycl::handler &cgh, LeafNode<RHS, LVL> &expr) {
48  return expr.vilibMemory
49  .template get_device_accessor<cl::sycl::access::mode::read>(cgh);
50  }
51  /// getting write access when the leaf node is accessed by traversing the left-
52  /// hand side of ParallelCopy(partial assign) expression
53  static tools::tuple::Tuple<
54  typename RHS::template Accessor<cl::sycl::access::mode::write>>
55  getWriteTuple(cl::sycl::handler &cgh, LeafNode<RHS, LVL> &expr) {
56  return expr.vilibMemory
57  .template get_device_accessor<cl::sycl::access::mode::write>(cgh);
58  }
59  /// getting discard_write access when the leaf node is accessed by traversing
60  /// the left-hand side of an Assign expression
61  static tools::tuple::Tuple<
62  typename RHS::template Accessor<cl::sycl::access::mode::discard_write>>
63  getDiscardWriteTuple(cl::sycl::handler &cgh, LeafNode<RHS, LVL> &expr) {
64  return expr.vilibMemory
65  .template get_device_accessor<cl::sycl::access::mode::discard_write>(
66  cgh);
67  }
68 };
69 
70 /// \brief Specialisation of ExtractAccessor class where the expression node
71 /// has one child
72 template <typename Expr>
73 struct ExtractAccessor<expr_category::Unary, Expr> {
74  static auto getTuple(cl::sycl::handler &cgh, Expr &expr)
75  -> decltype(ExtractAccessor<Expr::RHSExpr::ND_Category,
76  typename Expr::RHSExpr>::getTuple(cgh,
77  expr.rhs)) {
78  auto RHSTuple =
79  ExtractAccessor<Expr::RHSExpr::ND_Category,
80  typename Expr::RHSExpr>::getTuple(cgh, expr.rhs);
81  return RHSTuple;
82  }
83 };
84 
85 /// \brief Specialisation of ExtractAccessor class where the expression node
86 /// has two children
87 template <typename Expr>
88 struct ExtractAccessor<expr_category::Binary, Expr> {
89  static auto getTuple(cl::sycl::handler &cgh, Expr &expr)
90  -> decltype(tools::tuple::append(
91  ExtractAccessor<Expr::LHSExpr::ND_Category,
92  typename Expr::LHSExpr>::getTuple(cgh, expr.lhs),
93  ExtractAccessor<Expr::RHSExpr::ND_Category,
94  typename Expr::RHSExpr>::getTuple(cgh, expr.rhs))) {
95  auto LHSTuple =
96  ExtractAccessor<Expr::LHSExpr::ND_Category,
97  typename Expr::LHSExpr>::getTuple(cgh, expr.lhs);
98  auto RHSTuple =
99  ExtractAccessor<Expr::RHSExpr::ND_Category,
100  typename Expr::RHSExpr>::getTuple(cgh, expr.rhs);
101  return tools::tuple::append(LHSTuple, RHSTuple);
102  }
103 };
104 
105 /// \brief Specialisation of ExtractAccessor class where the expression node is
106 /// Assign
107 template <typename LHSExpr, typename RHSExpr, size_t Cols, size_t Rows,
108  size_t LeafType, size_t LVL>
109 struct ExtractAccessor<expr_category::Binary,
110  Assign<LHSExpr, RHSExpr, Cols, Rows, LeafType, LVL>> {
111  static auto getTuple(
112  cl::sycl::handler &cgh,
114  -> decltype(tools::tuple::append(
116  cgh, expr.lhs),
118  expr.rhs))) {
119  auto LHSTuple =
121  cgh, expr.lhs);
122  auto RHSTuple =
124  return tools::tuple::append(LHSTuple, RHSTuple);
125  }
126 };
127 
128 /// \brief Specialisation of ExtractAccessor class where the expression node is
129 /// is a ParallelCopy (partial assign)
130 template <typename LHSExpr, typename RHSExpr, size_t Cols, size_t Rows,
131  size_t OffsetColIn, size_t OffsetRowIn, size_t OffsetColOut,
132  size_t OffsetRowOut, size_t LeafType, size_t LVL>
134  expr_category::Binary,
135  ParallelCopy<LHSExpr, RHSExpr, Cols, Rows, OffsetColIn, OffsetRowIn,
136  OffsetColOut, OffsetRowOut, LeafType, LVL>> {
137  static auto getTuple(
138  cl::sycl::handler &cgh,
139  ParallelCopy<LHSExpr, RHSExpr, Cols, Rows, OffsetColIn, OffsetRowIn,
140  OffsetColOut, OffsetRowOut, LeafType, LVL> &expr)
141  -> decltype(tools::tuple::append(
143  cgh, expr.lhs),
145  expr.rhs))) {
146  auto LHSTuple =
148  expr.lhs);
149  auto RHSTuple =
151  return tools::tuple::append(LHSTuple, RHSTuple);
152  }
153 };
154 } // internal
155 
156 template <typename Expr>
157 auto extract_accessors(cl::sycl::handler &cgh, Expr e) -> decltype(
160 }
161 
162 } // visioncpp
163 #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_EXTRACT_ACCESSORS_HPP_
Tuple< Args..., T > append(Tuple< Args... > t, T a)
append
Definition: tuple.hpp:235
VisionCpp namespace.
Definition: sycl/device.hpp:24
auto extract_accessors(cl::sycl::handler &cgh, Expr e) -> decltype(internal::ExtractAccessor< Expr::ND_Category, Expr >::getTuple(cgh, e))
The definition is in Assign file.
Definition: assign.hpp:44
static auto getTuple(cl::sycl::handler &cgh, Assign< LHSExpr, RHSExpr, Cols, Rows, LeafType, LVL > &expr) -> decltype(tools::tuple::append(ExtractAccessor< LHSExpr::ND_Category, LHSExpr >::getDiscardWriteTuple(cgh, expr.lhs), ExtractAccessor< RHSExpr::ND_Category, RHSExpr >::getTuple(cgh, expr.rhs)))
static auto getTuple(cl::sycl::handler &cgh, Expr &expr) -> decltype(tools::tuple::append(ExtractAccessor< Expr::LHSExpr::ND_Category, typename Expr::LHSExpr >::getTuple(cgh, expr.lhs), ExtractAccessor< Expr::RHSExpr::ND_Category, typename Expr::RHSExpr >::getTuple(cgh, expr.rhs)))
static auto getTuple(cl::sycl::handler &cgh, ParallelCopy< LHSExpr, RHSExpr, Cols, Rows, OffsetColIn, OffsetRowIn, OffsetColOut, OffsetRowOut, LeafType, LVL > &expr) -> decltype(tools::tuple::append(ExtractAccessor< LHSExpr::ND_Category, LHSExpr >::getWriteTuple(cgh, expr.lhs), ExtractAccessor< RHSExpr::ND_Category, RHSExpr >::getTuple(cgh, expr.rhs)))
static auto getTuple(cl::sycl::handler &cgh, Expr &expr) -> decltype(ExtractAccessor< Expr::RHSExpr::ND_Category, typename Expr::RHSExpr >::getTuple(cgh, expr.rhs))
static tools::tuple::Tuple< typename RHS::template Accessor< cl::sycl::access::mode::discard_write > > getDiscardWriteTuple(cl::sycl::handler &cgh, LeafNode< RHS, LVL > &expr)
getting discard_write access when the leaf node is accessed by traversing the left-hand side of an As...
static tools::tuple::Tuple< typename RHS::template Accessor< cl::sycl::access::mode::write > > getWriteTuple(cl::sycl::handler &cgh, LeafNode< RHS, LVL > &expr)
getting write access when the leaf node is accessed by traversing the left- hand side of ParallelCopy...
static tools::tuple::Tuple< typename RHS::template Accessor< cl::sycl::access::mode::read > > getTuple(cl::sycl::handler &cgh, LeafNode< RHS, LVL > &expr)
getting read access when the leaf node is accessed by traversing the right- hand side of an Assign or...
The extract accessor struct is used to extract the accessor from the leafnodes and pack them in a tup...
the definition is in LeafNode.
Definition: leaf_node.hpp:38
The definition is in ParallelCopy file.
The tuple is a fixed-size collection of heterogeneous values.
Definition: tuple.hpp:48