VisionCpp  0.0.1
mem_const.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_const.hpp
21 /// \brief specialisations of SyclMem type when we are passing constant variable
22 /// to the device. In this case we are not using syclbuffer which can be stored
23 /// on device memory. we have created struct supporting c++ standard layout.
24 /// Therefore, the constant variable can be detectable by sycl compiler on the
25 /// device side and each thread can have a copy of it on the private memory.
26 
27 #ifndef VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_CONST_HPP_
28 #define VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_CONST_HPP_
29 
30 namespace visioncpp {
31 namespace internal {
32 /// \struct ConstMemory
33 /// \brief represents a c++ standard layout for detecting constant variable on
34 /// the device.
35 /// template parameters:
36 /// \tparam T: the type of the constant variable
37 template <typename T>
38 struct ConstMemory {
39  ConstMemory(T r) : r(r) {}
40  template <typename T2>
41  ConstMemory(T r, T2 &x)
42  : ConstMemory(r) {}
43  using value_type = T;
44  const T r;
45  const value_type &operator[](cl::sycl::nd_item<2> itemID) const { return r; }
46  const value_type &operator[](cl::sycl::nd_item<1> itemID) const { return r; }
47  const value_type &operator[](cl::sycl::id<2> itemID) const { return r; }
48  const value_type &operator[](int itemID) const { return r; }
49  const value_type &operator[](size_t itemID) const { return r; }
50  /// this function is used to mimic the getpointer function used by evaluator
51  /// expression, in order to access a ConstMemory Node.
52  /// \return ConstMemory
53  const ConstMemory<T> &get_pointer() const { return *this; }
54 };
55 } // internal
56 } // visioncpp
57 #endif // VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_CONST_HPP_
VisionCpp namespace.
Definition: sycl/device.hpp:24
The definition can be found in ConstMemory.
Definition: mem_const.hpp:38
const ConstMemory< T > & get_pointer() const
this function is used to mimic the getpointer function used by evaluator expression,...
Definition: mem_const.hpp:53
const value_type & operator[](int itemID) const
Definition: mem_const.hpp:48
const value_type & operator[](size_t itemID) const
Definition: mem_const.hpp:49
const value_type & operator[](cl::sycl::nd_item< 2 > itemID) const
Definition: mem_const.hpp:45
const value_type & operator[](cl::sycl::nd_item< 1 > itemID) const
Definition: mem_const.hpp:46
const value_type & operator[](cl::sycl::id< 2 > itemID) const
Definition: mem_const.hpp:47