VisionCpp  0.0.1
mem_coordinate.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_coordinate.hpp
21 /// \brief This files contains the Coordinate struct which is used to specify
22 /// local/global offset for local/global access to the local/global memory for
23 /// each thread on the device.
24 
25 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEMORY_ACCESS_MEM_COORDINATE_HPP_
26 #define VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEMORY_ACCESS_MEM_COORDINATE_HPP_
27 
28 // these two must be switched for row-major
29 namespace visioncpp {
30 namespace internal {
31 /// \brief Color / Row-major option
32 namespace mem_dim {
33 /// \brief when the sycl change the dim this should be applied and work
34 /// ColDim=1 and RowDim==0;
35 static constexpr size_t ColDim = 0;
36 static constexpr size_t RowDim = 1;
37 };
38 /// \struct Coordinate
39 /// \brief Coordinate is used to specify
40 /// local/global offset for local/global access to the local/global memory for
41 /// each thread on the device.
42 /// template parameters:
43 /// \tparam LC The column size for local memory
44 /// \tparam LR The Row size for the local memory
45 /// \tparam ItemID provided by sycl
46 template <size_t LC, size_t LR, typename ItemID>
47 struct Coordinate {
49  : itemID(itemID),
50  cLRng(itemID.get_local_range()[mem_dim::ColDim]),
51  rLRng(itemID.get_local_range()[mem_dim::RowDim]),
52  pointOp_gc(0),
53  pointOp_gr(0),
54  g_c(itemID.get_local_id(mem_dim::ColDim) +
55  (itemID.get_group(mem_dim::ColDim) * ((LC / cLRng) * cLRng))),
56  g_r(itemID.get_local_id(mem_dim::RowDim) +
57  itemID.get_group(mem_dim::RowDim) * ((LR / rLRng) * rLRng)),
58  l_c(itemID.get_local_id(mem_dim::ColDim)),
59  l_r(itemID.get_local_id(mem_dim::RowDim)) {}
60 
61  /// function barrier is used to call sycl local barrier for local threads
62  /// \return void
63  inline void barrier() {
64  itemID.barrier(cl::sycl::access::fence_space::local_space);
65  }
66  // function global_barrier is used to call sycl local barrier for global
67  // threads
68  /// \return void
69  inline void global_barrier() {
70  itemID.barrier(cl::sycl::access::fence_space::global_space);
71  }
72 
73  ItemID itemID;
74  size_t cLRng;
75  size_t rLRng;
76  size_t pointOp_gc;
77  size_t pointOp_gr;
78  size_t g_c;
79  size_t g_r;
80  size_t l_c;
81  size_t l_r;
82 };
83 /// deduction function for Coordinate
84 template <size_t LC, size_t LR, typename ItemID>
86  return Coordinate<LC, LR, ItemID>(itemID);
87 }
88 } // internal
89 } // visioncpp
90 #endif // VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEMORY_ACCESS_MEM_COORDINATE_HPP_
static constexpr size_t RowDim
static constexpr size_t ColDim
when the sycl change the dim this should be applied and work ColDim=1 and RowDim==0;
Coordinate< LC, LR, ItemID > memLocation(ItemID itemID)
deduction function for Coordinate
VisionCpp namespace.
Definition: sycl/device.hpp:24
Coordinate is used to specify local/global offset for local/global access to the local/global memory ...
void barrier()
function barrier is used to call sycl local barrier for local threads