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/detail/pi.h> // for PI_SAMPLER_ADDRESSING_MODE_CLAMP
16 #include <sycl/property_list.hpp> // for property_list
17 
18 #include <cstddef> // for size_t
19 #include <memory> // for shared_ptr, hash
20 #include <variant> // for hash
21 
22 namespace sycl {
23 inline namespace _V1 {
24 enum class addressing_mode : unsigned int {
30 };
31 
32 enum class filtering_mode : unsigned int {
35 };
36 
37 enum class coordinate_normalization_mode : unsigned int {
38  normalized = 1,
39  unnormalized = 0
40 };
41 
42 namespace detail {
43 template <typename DataT, int Dimensions, access::mode AccessMode,
45 class image_accessor;
46 }
47 
48 namespace detail {
49 #ifdef __SYCL_DEVICE_ONLY__
50 class __SYCL_EXPORT sampler_impl {
51 public:
52  sampler_impl() = default;
53 
54  sampler_impl(__ocl_sampler_t Sampler) : m_Sampler(Sampler) {}
55 
56  ~sampler_impl() = default;
57 
58  __ocl_sampler_t m_Sampler;
59 };
60 #else
61 class sampler_impl;
62 #endif
63 } // namespace detail
64 
70 class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(sampler) sampler {
71 public:
72  sampler(coordinate_normalization_mode normalizationMode,
73  addressing_mode addressingMode, filtering_mode filteringMode,
74  const property_list &propList = {});
75 
76 #ifdef __SYCL_INTERNAL_API
77  sampler(cl_sampler clSampler, const context &syclContext);
78 #endif
79 
80  sampler(const sampler &rhs) = default;
81 
82  sampler(sampler &&rhs) = default;
83 
84  sampler &operator=(const sampler &rhs) = default;
85 
86  sampler &operator=(sampler &&rhs) = default;
87 
88  bool operator==(const sampler &rhs) const;
89 
90  bool operator!=(const sampler &rhs) const;
91 
95  template <typename propertyT> bool has_property() const noexcept;
96 
103  template <typename propertyT> propertyT get_property() const;
104 
105  addressing_mode get_addressing_mode() const;
106 
107  filtering_mode get_filtering_mode() const;
108 
109  coordinate_normalization_mode get_coordinate_normalization_mode() const;
110 
111 private:
112 #ifdef __SYCL_DEVICE_ONLY__
113  detail::sampler_impl impl;
114  void __init(__ocl_sampler_t Sampler) { impl.m_Sampler = Sampler; }
115  char padding[sizeof(std::shared_ptr<detail::sampler_impl>) - sizeof(impl)];
116 
117 public:
118  sampler() = default;
119 
120 private:
121 #else
122  std::shared_ptr<detail::sampler_impl> impl;
123  template <class Obj>
124  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
125 #endif
126  template <typename DataT, int Dimensions, sycl::access::mode AccessMode,
127  sycl::access::target AccessTarget,
129  friend class detail::image_accessor;
130 };
131 
132 // SYCL 2020 image_sampler struct
137 };
138 
139 } // namespace _V1
140 } // namespace sycl
141 
142 namespace std {
143 template <> struct hash<sycl::sampler> {
144  size_t operator()(const sycl::sampler &s) const {
145 #ifdef __SYCL_DEVICE_ONLY__
146  (void)s;
147  return 0;
148 #else
149  return hash<std::shared_ptr<sycl::detail::sampler_impl>>()(
151 #endif
152  }
153 };
154 } // 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) getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:30
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:32
coordinate_normalization_mode
Definition: sampler.hpp:37
class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
addressing_mode
Definition: sampler.hpp:24
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
@ PI_SAMPLER_FILTER_MODE_NEAREST
Definition: pi.h:734
@ PI_SAMPLER_FILTER_MODE_LINEAR
Definition: pi.h:735
@ PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT
Definition: pi.h:726
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP
Definition: pi.h:729
@ PI_SAMPLER_ADDRESSING_MODE_NONE
Definition: pi.h:730
@ PI_SAMPLER_ADDRESSING_MODE_REPEAT
Definition: pi.h:727
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE
Definition: pi.h:728
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:144
addressing_mode addressing
Definition: sampler.hpp:134
coordinate_normalization_mode coordinate
Definition: sampler.hpp:135
filtering_mode filtering
Definition: sampler.hpp:136