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 
12 #include <sycl/access/access.hpp>
13 #include <sycl/detail/cl.h>
14 #include <sycl/detail/common.hpp>
15 #include <sycl/detail/export.hpp>
16 #include <sycl/property_list.hpp>
17 
18 namespace sycl {
20 enum class addressing_mode : unsigned int {
26 };
27 
28 enum class filtering_mode : unsigned int {
31 };
32 
33 enum class coordinate_normalization_mode : unsigned int {
34  normalized = 1,
35  unnormalized = 0
36 };
37 
38 namespace detail {
39 template <typename DataT, int Dimensions, access::mode AccessMode,
41 class image_accessor;
42 }
43 
44 namespace detail {
45 #ifdef __SYCL_DEVICE_ONLY__
46 class __SYCL_EXPORT sampler_impl {
47 public:
48  sampler_impl() = default;
49 
50  sampler_impl(__ocl_sampler_t Sampler) : m_Sampler(Sampler) {}
51 
52  ~sampler_impl() = default;
53 
54  __ocl_sampler_t m_Sampler;
55 };
56 #else
57 class sampler_impl;
58 #endif
59 } // namespace detail
60 
66 class __SYCL_EXPORT __SYCL_SPECIAL_CLASS __SYCL_TYPE(sampler) sampler {
67 public:
68  sampler(coordinate_normalization_mode normalizationMode,
69  addressing_mode addressingMode, filtering_mode filteringMode,
70  const property_list &propList = {});
71 
72 #ifdef __SYCL_INTERNAL_API
73  sampler(cl_sampler clSampler, const context &syclContext);
74 #endif
75 
76  sampler(const sampler &rhs) = default;
77 
78  sampler(sampler &&rhs) = default;
79 
80  sampler &operator=(const sampler &rhs) = default;
81 
82  sampler &operator=(sampler &&rhs) = default;
83 
84  bool operator==(const sampler &rhs) const;
85 
86  bool operator!=(const sampler &rhs) const;
87 
91  template <typename propertyT> bool has_property() const noexcept;
92 
99  template <typename propertyT> propertyT get_property() const;
100 
101  addressing_mode get_addressing_mode() const;
102 
103  filtering_mode get_filtering_mode() const;
104 
105  coordinate_normalization_mode get_coordinate_normalization_mode() const;
106 
107 private:
108 #ifdef __SYCL_DEVICE_ONLY__
110  void __init(__ocl_sampler_t Sampler) { impl.m_Sampler = Sampler; }
111  char padding[sizeof(std::shared_ptr<detail::sampler_impl>) - sizeof(impl)];
112 
113 public:
114  sampler() = default;
115 
116 private:
117 #else
118  std::shared_ptr<detail::sampler_impl> impl;
119  template <class Obj>
120  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
121 #endif
122  template <typename DataT, int Dimensions, sycl::access::mode AccessMode,
123  sycl::access::target AccessTarget,
125  friend class detail::image_accessor;
126 };
127 
128 // SYCL 2020 image_sampler struct
133 };
134 
135 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
136 } // namespace sycl
137 
138 namespace std {
139 template <> struct hash<sycl::sampler> {
140  size_t operator()(const sycl::sampler &s) const {
141 #ifdef __SYCL_DEVICE_ONLY__
142  (void)s;
143  return 0;
144 #else
145  return hash<std::shared_ptr<sycl::detail::sampler_impl>>()(
147 #endif
148  }
149 };
150 } // namespace std
sycl::_V1::IsPlaceholder
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS IsPlaceholder
Definition: accessor.hpp:3060
sycl::_V1::filtering_mode::linear
@ linear
sycl::_V1::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:24
PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT
@ PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT
Definition: pi.h:560
property_list.hpp
sycl::_V1::detail::image_accessor
Definition: accessor.hpp:701
sycl::_V1::access::mode
mode
Definition: access.hpp:30
sycl::_V1::image_sampler
Definition: sampler.hpp:129
PI_SAMPLER_ADDRESSING_MODE_REPEAT
@ PI_SAMPLER_ADDRESSING_MODE_REPEAT
Definition: pi.h:561
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::addressing_mode::repeat
@ repeat
sycl::_V1::Dimensions
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
Definition: accessor.hpp:3059
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
__SYCL_SPECIAL_CLASS
#define __SYCL_SPECIAL_CLASS
Definition: defines.hpp:30
access.hpp
operator==
bool operator==(const Slab &Lhs, const Slab &Rhs)
Definition: usm_allocator.cpp:313
PI_SAMPLER_FILTER_MODE_NEAREST
@ PI_SAMPLER_FILTER_MODE_NEAREST
Definition: pi.h:568
sycl::_V1::coordinate_normalization_mode::unnormalized
@ unnormalized
export.hpp
sycl::_V1::access::placeholder
placeholder
Definition: access.hpp:45
sycl::_V1::ext::oneapi::experimental::has_property
static constexpr bool has_property()
Definition: annotated_arg.hpp:162
cl.h
sycl::_V1::ext::oneapi::experimental::operator=
annotated_arg & operator=(annotated_arg &)=default
sycl::_V1::image_sampler::filtering
filtering_mode filtering
Definition: sampler.hpp:132
sycl::_V1::addressing_mode
addressing_mode
Definition: sampler.hpp:20
common.hpp
sycl::_V1::addressing_mode::mirrored_repeat
@ mirrored_repeat
sycl::_V1::access::target
target
Definition: access.hpp:18
sycl::_V1::coordinate_normalization_mode::normalized
@ normalized
sycl::_V1::coordinate_normalization_mode
coordinate_normalization_mode
Definition: sampler.hpp:33
sycl::_V1::ext::oneapi::experimental::get_property
static constexpr auto get_property()
Definition: annotated_arg.hpp:166
sycl::_V1::filtering_mode
filtering_mode
Definition: sampler.hpp:28
clamp
simd< _Tp, _Abi > clamp(const simd< _Tp, _Abi > &, const simd< _Tp, _Abi > &, const simd< _Tp, _Abi > &)
sycl::_V1::image_sampler::addressing
addressing_mode addressing
Definition: sampler.hpp:130
PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE
Definition: pi.h:562
PI_SAMPLER_ADDRESSING_MODE_NONE
@ PI_SAMPLER_ADDRESSING_MODE_NONE
Definition: pi.h:564
sycl::_V1::addressing_mode::clamp_to_edge
@ clamp_to_edge
std
Definition: accessor.hpp:3914
sycl::_V1::image_sampler::coordinate
coordinate_normalization_mode coordinate
Definition: sampler.hpp:131
std::hash< sycl::sampler >::operator()
size_t operator()(const sycl::sampler &s) const
Definition: sampler.hpp:140
__SYCL_TYPE
#define __SYCL_TYPE(x)
Definition: defines.hpp:40
sycl::_V1::detail::sampler_impl
Definition: sampler_impl.hpp:26
sycl::_V1::filtering_mode::nearest
@ nearest
PI_SAMPLER_FILTER_MODE_LINEAR
@ PI_SAMPLER_FILTER_MODE_LINEAR
Definition: pi.h:569
sycl::_V1::ext::intel::experimental::operator!=
bool operator!=(const cache_config &lhs, const cache_config &rhs)
Definition: kernel_execution_properties.hpp:37
sycl::_V1::AccessMode
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
Definition: accessor.hpp:3059
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:302
__ocl_sampler_t
void * __ocl_sampler_t
Definition: spirv_types.hpp:204
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41
spirv_types.hpp
PI_SAMPLER_ADDRESSING_MODE_CLAMP
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP
Definition: pi.h:563