DPC++ Runtime
Runtime libraries for oneAPI DPC++
sampler_impl.cpp
Go to the documentation of this file.
1 //==----------------- sampler_impl.cpp - SYCL sampler ----------------------==//
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 
10 #include <detail/sampler_impl.hpp>
11 #include <sycl/property_list.hpp>
12 
13 namespace sycl {
15 namespace detail {
16 
17 sampler_impl::sampler_impl(coordinate_normalization_mode normalizationMode,
18  addressing_mode addressingMode,
19  filtering_mode filteringMode,
20  const property_list &propList)
21  : MCoordNormMode(normalizationMode), MAddrMode(addressingMode),
22  MFiltMode(filteringMode), MPropList(propList) {}
23 
24 sampler_impl::sampler_impl(cl_sampler clSampler, const context &syclContext) {
25 
26  RT::PiSampler Sampler = pi::cast<RT::PiSampler>(clSampler);
27  MContextToSampler[syclContext] = Sampler;
28  const PluginPtr &Plugin = getSyclObjImpl(syclContext)->getPlugin();
29  Plugin->call<PiApiKind::piSamplerRetain>(Sampler);
30  Plugin->call<PiApiKind::piSamplerGetInfo>(
32  &MCoordNormMode, nullptr);
33  Plugin->call<PiApiKind::piSamplerGetInfo>(
35  sizeof(pi_sampler_addressing_mode), &MAddrMode, nullptr);
36  Plugin->call<PiApiKind::piSamplerGetInfo>(
38  &MFiltMode, nullptr);
39 }
40 
42  std::lock_guard<std::mutex> Lock(MMutex);
43  for (auto &Iter : MContextToSampler) {
44  // TODO catch an exception and add it to the list of asynchronous exceptions
45  const PluginPtr &Plugin = getSyclObjImpl(Iter.first)->getPlugin();
46  Plugin->call<PiApiKind::piSamplerRelease>(Iter.second);
47  }
48 }
49 
51  {
52  std::lock_guard<std::mutex> Lock(MMutex);
53  auto It = MContextToSampler.find(Context);
54  if (It != MContextToSampler.end())
55  return It->second;
56  }
57 
58  const pi_sampler_properties sprops[] = {
60  static_cast<pi_sampler_properties>(MCoordNormMode),
62  static_cast<pi_sampler_properties>(MAddrMode),
64  static_cast<pi_sampler_properties>(MFiltMode),
65  0};
66 
67  RT::PiResult errcode_ret = PI_SUCCESS;
68  RT::PiSampler resultSampler = nullptr;
69  const PluginPtr &Plugin = getSyclObjImpl(Context)->getPlugin();
70 
71  errcode_ret = Plugin->call_nocheck<PiApiKind::piSamplerCreate>(
72  getSyclObjImpl(Context)->getHandleRef(), sprops, &resultSampler);
73 
74  if (errcode_ret == PI_ERROR_INVALID_OPERATION)
75  throw feature_not_supported("Images are not supported by this device.",
76  errcode_ret);
77 
78  Plugin->checkPiResult(errcode_ret);
79  std::lock_guard<std::mutex> Lock(MMutex);
80  MContextToSampler[Context] = resultSampler;
81 
82  return resultSampler;
83 }
84 
86 
87 filtering_mode sampler_impl::get_filtering_mode() const { return MFiltMode; }
88 
91  return MCoordNormMode;
92 }
93 
94 } // namespace detail
95 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
96 } // namespace sycl
sycl::_V1::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:24
property_list.hpp
pi_bool
pi_uint32 pi_bool
Definition: pi.h:144
context_impl.hpp
sycl::_V1::errc::feature_not_supported
@ feature_not_supported
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
PI_SAMPLER_INFO_FILTER_MODE
@ PI_SAMPLER_INFO_FILTER_MODE
Definition: pi.h:553
piSamplerGetInfo
pi_result piSamplerGetInfo(pi_sampler sampler, pi_sampler_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: pi_esimd_emulator.cpp:1560
sycl::_V1::detail::sampler_impl::~sampler_impl
~sampler_impl()
Definition: sampler_impl.cpp:41
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::detail::pi::PiSampler
::pi_sampler PiSampler
Definition: pi.hpp:139
piSamplerCreate
pi_result piSamplerCreate(pi_context context, const pi_sampler_properties *sampler_properties, pi_sampler *result_sampler)
Definition: pi_esimd_emulator.cpp:1555
sycl::_V1::detail::sampler_impl::get_coordinate_normalization_mode
coordinate_normalization_mode get_coordinate_normalization_mode() const
Definition: sampler_impl.cpp:90
sycl::_V1::detail::pi::PiResult
::pi_result PiResult
Definition: pi.hpp:123
sycl::_V1::addressing_mode
addressing_mode
Definition: sampler.hpp:20
piSamplerRetain
pi_result piSamplerRetain(pi_sampler sampler)
Definition: pi_esimd_emulator.cpp:1565
sycl::_V1::coordinate_normalization_mode
coordinate_normalization_mode
Definition: sampler.hpp:33
pi_sampler_properties
pi_bitfield pi_sampler_properties
Definition: pi.h:580
sycl::_V1::filtering_mode
filtering_mode
Definition: sampler.hpp:28
sycl::_V1::detail::sampler_impl::sampler_impl
sampler_impl(coordinate_normalization_mode normalizationMode, addressing_mode addressingMode, filtering_mode filteringMode, const property_list &propList)
Definition: sampler_impl.cpp:17
sycl::_V1::detail::sampler_impl::getOrCreateSampler
RT::PiSampler getOrCreateSampler(const context &Context)
Definition: sampler_impl.cpp:50
pi_sampler_addressing_mode
_pi_sampler_addressing_mode pi_sampler_addressing_mode
Definition: pi.h:689
pi_sampler_filter_mode
_pi_sampler_filter_mode pi_sampler_filter_mode
Definition: pi.h:690
sycl::_V1::detail::sampler_impl::get_filtering_mode
filtering_mode get_filtering_mode() const
Definition: sampler_impl.cpp:87
piSamplerRelease
pi_result piSamplerRelease(pi_sampler sampler)
Definition: pi_esimd_emulator.cpp:1567
PI_SAMPLER_INFO_NORMALIZED_COORDS
@ PI_SAMPLER_INFO_NORMALIZED_COORDS
Definition: pi.h:551
sycl::_V1::detail::sampler_impl::get_addressing_mode
addressing_mode get_addressing_mode() const
Definition: sampler_impl.cpp:85
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:302
sampler_impl.hpp
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41
sycl::_V1::detail::PluginPtr
std::shared_ptr< plugin > PluginPtr
Definition: pi.hpp:47
PI_SAMPLER_INFO_ADDRESSING_MODE
@ PI_SAMPLER_INFO_ADDRESSING_MODE
Definition: pi.h:552