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/pi.h> // for PI_SAMPLER_ADDRESSING_MODE_CLAMP
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 {
29 };
30 
31 enum class filtering_mode : unsigned int {
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 
102  template <typename propertyT> propertyT get_property() const;
103 
104  addressing_mode get_addressing_mode() const;
105 
106  filtering_mode get_filtering_mode() const;
107 
108  coordinate_normalization_mode get_coordinate_normalization_mode() const;
109 
110 private:
111 #ifdef __SYCL_DEVICE_ONLY__
112  detail::sampler_impl impl;
113  void __init(__ocl_sampler_t Sampler) { impl.m_Sampler = Sampler; }
114  char padding[sizeof(std::shared_ptr<detail::sampler_impl>) - sizeof(impl)];
115 
116 public:
117  sampler() = default;
118 
119 private:
120 #else
121  std::shared_ptr<detail::sampler_impl> impl;
122  template <class Obj>
123  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
124 #endif
125  template <typename DataT, int Dimensions, sycl::access::mode AccessMode,
126  sycl::access::target AccessTarget,
128  friend class detail::image_accessor;
129 };
130 
131 // SYCL 2020 image_sampler struct
136 };
137 
138 } // namespace _V1
139 } // namespace sycl
140 
141 namespace std {
142 template <> struct hash<sycl::sampler> {
143  size_t operator()(const sycl::sampler &s) const {
144 #ifdef __SYCL_DEVICE_ONLY__
145  (void)s;
146  return 0;
147 #else
148  return hash<std::shared_ptr<sycl::detail::sampler_impl>>()(
150 #endif
151  }
152 };
153 } // namespace std
#define __SYCL_SPECIAL_CLASS
Definition: defines.hpp:29
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor 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:31
coordinate_normalization_mode
Definition: sampler.hpp:36
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
Definition: accessor.hpp:3233
addressing_mode
Definition: sampler.hpp:23
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS IsPlaceholder
Definition: accessor.hpp:3234
PropertyListT int access::address_space multi_ptr & operator=(multi_ptr &&)=default
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
Definition: accessor.hpp:3233
Definition: access.hpp:18
@ PI_SAMPLER_FILTER_MODE_NEAREST
Definition: pi.h:694
@ PI_SAMPLER_FILTER_MODE_LINEAR
Definition: pi.h:695
@ PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT
Definition: pi.h:686
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP
Definition: pi.h:689
@ PI_SAMPLER_ADDRESSING_MODE_NONE
Definition: pi.h:690
@ PI_SAMPLER_ADDRESSING_MODE_REPEAT
Definition: pi.h:687
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE
Definition: pi.h:688
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:143
addressing_mode addressing
Definition: sampler.hpp:133
coordinate_normalization_mode coordinate
Definition: sampler.hpp:134
filtering_mode filtering
Definition: sampler.hpp:135