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 
13 #include <CL/sycl/detail/cl.h>
17 
19 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,
40  access::target AccessTarget, access::placeholder IsPlaceholder>
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 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;
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, cl::sycl::access::mode AccessMode,
123  cl::sycl::access::target AccessTarget, access::placeholder IsPlaceholder>
125 };
126 } // namespace sycl
127 } // __SYCL_INLINE_NAMESPACE(cl)
128 
129 namespace std {
130 template <> struct hash<cl::sycl::sampler> {
131  size_t operator()(const cl::sycl::sampler &s) const {
132 #ifdef __SYCL_DEVICE_ONLY__
133  (void)s;
134  return 0;
135 #else
136  return hash<std::shared_ptr<cl::sycl::detail::sampler_impl>>()(
138 #endif
139  }
140 };
141 } // namespace std
PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT
@ PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT
Definition: pi.h:473
property_list.hpp
std::hash< cl::sycl::sampler >::operator()
size_t operator()(const cl::sycl::sampler &s) const
Definition: sampler.hpp:131
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:633
PI_SAMPLER_ADDRESSING_MODE_REPEAT
@ PI_SAMPLER_ADDRESSING_MODE_REPEAT
Definition: pi.h:474
cl::sycl::sampler
Encapsulates a configuration for sampling an image accessor.
Definition: sampler.hpp:66
cl::sycl
Definition: access.hpp:14
sycl
Definition: invoke_simd.hpp:68
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:583
cl::sycl::coordinate_normalization_mode::unnormalized
@ unnormalized
PI_SAMPLER_FILTER_MODE_NEAREST
@ PI_SAMPLER_FILTER_MODE_NEAREST
Definition: pi.h:481
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.h
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
PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE
Definition: pi.h:475
PI_SAMPLER_ADDRESSING_MODE_NONE
@ PI_SAMPLER_ADDRESSING_MODE_NONE
Definition: pi.h:477
cl::sycl::coordinate_normalization_mode
coordinate_normalization_mode
Definition: sampler.hpp:33
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:204
cl::sycl::addressing_mode
addressing_mode
Definition: sampler.hpp:20
std
Definition: accessor.hpp:2617
cl::sycl::ext::oneapi::experimental::detail::get_property
static constexpr std::enable_if_t< HasProperty, typename FindCompileTimePropertyValueType< CTPropertyT, PropertiesT >::type > get_property()
Definition: properties.hpp:65
cl::sycl::detail::image_accessor
Definition: accessor.hpp:378
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:38
cl::sycl::filtering_mode
filtering_mode
Definition: sampler.hpp:28
common.hpp
cl::sycl::access::mode
mode
Definition: access.hpp:28
PI_SAMPLER_FILTER_MODE_LINEAR
@ PI_SAMPLER_FILTER_MODE_LINEAR
Definition: pi.h:482
cl::sycl::Dimensions
Dimensions
Definition: backend.hpp:142
cl::sycl::clamp
detail::enable_if_t< detail::is_genfloat< T >::value, T > clamp(T x, T minval, T maxval) __NOEXC
Definition: builtins.hpp:506
__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
PI_SAMPLER_ADDRESSING_MODE_CLAMP
@ PI_SAMPLER_ADDRESSING_MODE_CLAMP
Definition: pi.h:476