DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 
16 
18 namespace sycl {
19 enum class addressing_mode : unsigned int {
20  mirrored_repeat = CL_ADDRESS_MIRRORED_REPEAT,
21  repeat = CL_ADDRESS_REPEAT,
22  clamp_to_edge = CL_ADDRESS_CLAMP_TO_EDGE,
23  clamp = CL_ADDRESS_CLAMP,
24  none = CL_ADDRESS_NONE
25 };
26 
27 enum class filtering_mode : unsigned int {
28  nearest = CL_FILTER_NEAREST,
29  linear = CL_FILTER_LINEAR
30 };
31 
32 enum class coordinate_normalization_mode : unsigned int {
33  normalized = 1,
34  unnormalized = 0
35 };
36 
37 namespace detail {
38 template <typename DataT, int Dimensions, access::mode AccessMode,
39  access::target AccessTarget, access::placeholder IsPlaceholder>
40 class image_accessor;
41 }
42 
43 namespace detail {
44 #ifdef __SYCL_DEVICE_ONLY__
45 class __SYCL_EXPORT sampler_impl {
46 public:
47  sampler_impl() = default;
48 
49  sampler_impl(__ocl_sampler_t Sampler) : m_Sampler(Sampler) {}
50 
51  ~sampler_impl() = default;
52 
53  __ocl_sampler_t m_Sampler;
54 };
55 #else
56 class sampler_impl;
57 #endif
58 } // namespace detail
59 
65 class __SYCL_EXPORT __SYCL_SPECIAL_CLASS sampler {
66 public:
67  sampler(coordinate_normalization_mode normalizationMode,
68  addressing_mode addressingMode, filtering_mode filteringMode,
69  const property_list &propList = {});
70 
71 #ifdef __SYCL_INTERNAL_API
72  sampler(cl_sampler clSampler, const context &syclContext);
73 #endif
74 
75  sampler(const sampler &rhs) = default;
76 
77  sampler(sampler &&rhs) = default;
78 
79  sampler &operator=(const sampler &rhs) = default;
80 
81  sampler &operator=(sampler &&rhs) = default;
82 
83  bool operator==(const sampler &rhs) const;
84 
85  bool operator!=(const sampler &rhs) const;
86 
90  template <typename propertyT> bool has_property() const;
91 
98  template <typename propertyT> propertyT get_property() const;
99 
100  addressing_mode get_addressing_mode() const;
101 
102  filtering_mode get_filtering_mode() const;
103 
104  coordinate_normalization_mode get_coordinate_normalization_mode() const;
105 
106 private:
107 #ifdef __SYCL_DEVICE_ONLY__
109  void __init(__ocl_sampler_t Sampler) { impl.m_Sampler = Sampler; }
110  char padding[sizeof(std::shared_ptr<detail::sampler_impl>) - sizeof(impl)];
111 
112 public:
113  sampler() = default;
114 
115 private:
116 #else
117  std::shared_ptr<detail::sampler_impl> impl;
118  template <class Obj>
119  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
120 #endif
121  template <typename DataT, int Dimensions, cl::sycl::access::mode AccessMode,
122  cl::sycl::access::target AccessTarget, access::placeholder IsPlaceholder>
124 };
125 } // namespace sycl
126 } // __SYCL_INLINE_NAMESPACE(cl)
127 
128 namespace std {
129 template <> struct hash<cl::sycl::sampler> {
130  size_t operator()(const cl::sycl::sampler &s) const {
131 #ifdef __SYCL_DEVICE_ONLY__
132  (void)s;
133  return 0;
134 #else
135  return hash<std::shared_ptr<cl::sycl::detail::sampler_impl>>()(
137 #endif
138  }
139 };
140 } // namespace std
property_list.hpp
std::hash< cl::sycl::sampler >::operator()
size_t operator()(const cl::sycl::sampler &s) const
Definition: sampler.hpp:130
cl::sycl::filtering_mode::linear
@ linear
cl::sycl::access::placeholder
placeholder
Definition: access.hpp:43
cl::sycl::operator!=
bool operator!=(const multi_ptr< ElementType, Space > &lhs, const multi_ptr< ElementType, Space > &rhs)
Definition: multi_ptr.hpp:626
cl::sycl::sampler
Encapsulates a configuration for sampling an image accessor.
Definition: sampler.hpp:65
cl::sycl
Definition: access.hpp:14
detail
Definition: pi_opencl.cpp:86
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
cl::sycl::addressing_mode::clamp_to_edge
@ clamp_to_edge
__SYCL_SPECIAL_CLASS
#define __SYCL_SPECIAL_CLASS
Definition: defines.hpp:27
access.hpp
operator==
bool operator==(const Slab &Lhs, const Slab &Rhs)
Definition: usm_allocator.cpp:546
cl::sycl::coordinate_normalization_mode::unnormalized
@ unnormalized
cl::sycl::coordinate_normalization_mode::normalized
@ normalized
export.hpp
cl::sycl::detail::sampler_impl
Definition: sampler_impl.hpp:26
cl::sycl::addressing_mode::repeat
@ repeat
cl::sycl::addressing_mode::mirrored_repeat
@ mirrored_repeat
cl::sycl::access::target
target
Definition: access.hpp:17
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::coordinate_normalization_mode
coordinate_normalization_mode
Definition: sampler.hpp:32
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
cl::sycl::addressing_mode
addressing_mode
Definition: sampler.hpp:19
std
Definition: accessor.hpp:2532
cl::sycl::detail::image_accessor
Definition: accessor.hpp:379
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
cl::sycl::filtering_mode
filtering_mode
Definition: sampler.hpp:27
common.hpp
cl::sycl::access::mode
mode
Definition: access.hpp:28
cl::sycl::clamp
detail::enable_if_t< detail::is_genfloat< T >::value, T > clamp(T x, T minval, T maxval) __NOEXC
Definition: builtins.hpp:499
__ocl_sampler_t
void * __ocl_sampler_t
Definition: spirv_types.hpp:175
spirv_types.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12
cl::sycl::filtering_mode::nearest
@ nearest