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 {
14 inline namespace _V1 {
15 namespace detail {
16 
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 
27  pi::cast<sycl::detail::pi::PiSampler>(clSampler);
28  MContextToSampler[syclContext] = Sampler;
29  const PluginPtr &Plugin = getSyclObjImpl(syclContext)->getPlugin();
30  Plugin->call<PiApiKind::piSamplerRetain>(Sampler);
31  Plugin->call<PiApiKind::piSamplerGetInfo>(
33  &MCoordNormMode, nullptr);
34  Plugin->call<PiApiKind::piSamplerGetInfo>(
36  sizeof(pi_sampler_addressing_mode), &MAddrMode, nullptr);
37  Plugin->call<PiApiKind::piSamplerGetInfo>(
39  &MFiltMode, nullptr);
40 }
41 
43  std::lock_guard<std::mutex> Lock(MMutex);
44  for (auto &Iter : MContextToSampler) {
45  // TODO catch an exception and add it to the list of asynchronous exceptions
46  const PluginPtr &Plugin = getSyclObjImpl(Iter.first)->getPlugin();
47  Plugin->call<PiApiKind::piSamplerRelease>(Iter.second);
48  }
49 }
50 
53  {
54  std::lock_guard<std::mutex> Lock(MMutex);
55  auto It = MContextToSampler.find(Context);
56  if (It != MContextToSampler.end())
57  return It->second;
58  }
59 
60  const pi_sampler_properties sprops[] = {
62  static_cast<pi_sampler_properties>(MCoordNormMode),
64  static_cast<pi_sampler_properties>(MAddrMode),
66  static_cast<pi_sampler_properties>(MFiltMode),
67  0};
68 
69  sycl::detail::pi::PiResult errcode_ret = PI_SUCCESS;
70  sycl::detail::pi::PiSampler resultSampler = nullptr;
71  const PluginPtr &Plugin = getSyclObjImpl(Context)->getPlugin();
72 
73  errcode_ret = Plugin->call_nocheck<PiApiKind::piSamplerCreate>(
74  getSyclObjImpl(Context)->getHandleRef(), sprops, &resultSampler);
75 
76  if (errcode_ret == PI_ERROR_UNSUPPORTED_FEATURE)
77  throw sycl::exception(sycl::errc::feature_not_supported,
78  "Images are not supported by this device.");
79 
80  Plugin->checkPiResult(errcode_ret);
81  std::lock_guard<std::mutex> Lock(MMutex);
82  MContextToSampler[Context] = resultSampler;
83 
84  return resultSampler;
85 }
86 
88 
89 filtering_mode sampler_impl::get_filtering_mode() const { return MFiltMode; }
90 
93  return MCoordNormMode;
94 }
95 
96 } // namespace detail
97 } // namespace _V1
98 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:51
sycl::detail::pi::PiSampler getOrCreateSampler(const context &Context)
filtering_mode get_filtering_mode() const
addressing_mode get_addressing_mode() const
coordinate_normalization_mode get_coordinate_normalization_mode() const
sampler_impl(coordinate_normalization_mode normalizationMode, addressing_mode addressingMode, filtering_mode filteringMode, const property_list &propList)
Objects of the property_list class are containers for the SYCL properties.
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:30
std::shared_ptr< plugin > PluginPtr
Definition: pi.hpp:48
filtering_mode
Definition: sampler.hpp:31
coordinate_normalization_mode
Definition: sampler.hpp:36
addressing_mode
Definition: sampler.hpp:23
Definition: access.hpp:18
_pi_result
Definition: pi.h:224
pi_uint32 pi_bool
Definition: pi.h:215
pi_result piSamplerRetain(pi_sampler sampler)
Definition: pi_cuda.cpp:649
_pi_sampler_filter_mode pi_sampler_filter_mode
Definition: pi.h:839
pi_bitfield pi_sampler_properties
Definition: pi.h:724
pi_result piSamplerCreate(pi_context context, const pi_sampler_properties *sampler_properties, pi_sampler *result_sampler)
Definition: pi_cuda.cpp:635
_pi_sampler_addressing_mode pi_sampler_addressing_mode
Definition: pi.h:838
@ PI_SAMPLER_INFO_NORMALIZED_COORDS
Definition: pi.h:690
@ PI_SAMPLER_INFO_FILTER_MODE
Definition: pi.h:692
@ PI_SAMPLER_INFO_ADDRESSING_MODE
Definition: pi.h:691
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_cuda.cpp:641
pi_result piSamplerRelease(pi_sampler sampler)
Definition: pi_cuda.cpp:653