DPC++ Runtime
Runtime libraries for oneAPI DPC++
sampler.hpp
Go to the documentation of this file.
1 //==----------------- sampler.hpp - SYCL standard header file --------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/access/access.hpp> // for mode, placeholder, target
12 #include <sycl/detail/defines.hpp> // for __SYCL_SPECIAL_CLASS, __SYCL_TYPE
13 #include <sycl/detail/export.hpp> // for __SYCL_EXPORT
14 #include <sycl/detail/impl_utils.hpp> // for getSyclObjImpl
15 #include <sycl/property_list.hpp> // for property_list
16 
17 #include <cstddef> // for size_t
18 #include <memory> // for shared_ptr, hash
19 #include <variant> // for hash
20 
21 namespace sycl {
22 inline namespace _V1 {
23 enum class addressing_mode : unsigned int {
24  mirrored_repeat = 0x1134, // Value of CL_ADDRESS_MIRRORED_REPEAT
25  repeat = 0x1133, // Value of CL_ADDRESS_REPEAT
26  clamp_to_edge = 0x1131, // Value of CL_ADDRESS_CLAMP_TO_EDGE
27  clamp = 0x1132, // Value of CL_ADDRESS_CLAMP
28  none = 0x1130 // Value of CL_ADDRESS_NONE
29 };
30 
31 enum class filtering_mode : unsigned int {
32  nearest = 0x1140, // Value of CL_FILTER_NEAREST
33  linear = 0x1141 // Value of CL_FILTER_LINEAR
34 };
35 
36 enum class coordinate_normalization_mode : unsigned int {
37  normalized = 1,
38  unnormalized = 0
39 };
40 
41 namespace detail {
42 template <typename DataT, int Dimensions, access::mode AccessMode,
44 class image_accessor;
45 }
46 
47 namespace detail {
48 #ifdef __SYCL_DEVICE_ONLY__
49 class __SYCL_EXPORT sampler_impl {
50 public:
51  sampler_impl() = default;
52 
53  sampler_impl(__ocl_sampler_t Sampler) : m_Sampler(Sampler) {}
54 
55  ~sampler_impl() = default;
56 
57  __ocl_sampler_t m_Sampler;
58 };
59 #else
60 class sampler_impl;
61 #endif
62 } // namespace detail
63 
69 class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(sampler) sampler {
70 public:
71  sampler(coordinate_normalization_mode normalizationMode,
72  addressing_mode addressingMode, filtering_mode filteringMode,
73  const property_list &propList = {});
74 
75 #ifdef __SYCL_INTERNAL_API
76  sampler(cl_sampler clSampler, const context &syclContext);
77 #endif
78 
79  sampler(const sampler &rhs) = default;
80 
81  sampler(sampler &&rhs) = default;
82 
83  sampler &operator=(const sampler &rhs) = default;
84 
85  sampler &operator=(sampler &&rhs) = default;
86 
87  bool operator==(const sampler &rhs) const;
88 
89  bool operator!=(const sampler &rhs) const;
90 
94  template <typename propertyT> bool has_property() const noexcept {
95  return getPropList().template has_property<propertyT>();
96  }
97 
104  template <typename propertyT> propertyT get_property() const {
105  return getPropList().template get_property<propertyT>();
106  }
107 
108  addressing_mode get_addressing_mode() const;
109 
110  filtering_mode get_filtering_mode() const;
111 
112  coordinate_normalization_mode get_coordinate_normalization_mode() const;
113 
114 private:
115 #ifdef __SYCL_DEVICE_ONLY__
116  detail::sampler_impl impl;
117  void __init(__ocl_sampler_t Sampler) { impl.m_Sampler = Sampler; }
118  char padding[sizeof(std::shared_ptr<detail::sampler_impl>) - sizeof(impl)];
119 
120 public:
121  sampler() = default;
122 
123 private:
124 #else
125  std::shared_ptr<detail::sampler_impl> impl;
126  template <class Obj>
127  friend const decltype(Obj::impl) &
128  detail::getSyclObjImpl(const Obj &SyclObject);
129 #endif
130  template <typename DataT, int Dimensions, sycl::access::mode AccessMode,
131  sycl::access::target AccessTarget,
133  friend class detail::image_accessor;
134 
135  const property_list &getPropList() const;
136 };
137 
138 // SYCL 2020 image_sampler struct
143 };
144 
145 } // namespace _V1
146 } // namespace sycl
147 
148 namespace std {
149 template <> struct hash<sycl::sampler> {
150  size_t operator()(const sycl::sampler &s) const {
151 #ifdef __SYCL_DEVICE_ONLY__
152  (void)s;
153  return 0;
154 #else
155  return hash<std::shared_ptr<sycl::detail::sampler_impl>>()(
157 #endif
158  }
159 };
160 } // namespace std
#define __SYCL_SPECIAL_CLASS
Definition: defines.hpp:29
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor< DataT
Image accessors.
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:31
bool operator==(const cache_config &lhs, const cache_config &rhs)
bool operator!=(const cache_config &lhs, const cache_config &rhs)
static constexpr bool has_property()
static constexpr auto get_property()
filtering_mode
Definition: sampler.hpp:31
coordinate_normalization_mode
Definition: sampler.hpp:36
class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
addressing_mode
Definition: sampler.hpp:23
class __SYCL_EBO __SYCL_SPECIAL_CLASS IsPlaceholder
PropertyListT int access::address_space multi_ptr & operator=(multi_ptr &&)=default
class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
Definition: access.hpp:18
void * __ocl_sampler_t
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324
size_t operator()(const sycl::sampler &s) const
Definition: sampler.hpp:150
addressing_mode addressing
Definition: sampler.hpp:140
coordinate_normalization_mode coordinate
Definition: sampler.hpp:141
filtering_mode filtering
Definition: sampler.hpp:142