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 detail::plugin &Plugin = getSyclObjImpl(syclContext)->getPlugin();
29  Plugin.call<PiApiKind::piSamplerRetain>(Sampler);
32  &MCoordNormMode, nullptr);
35  sizeof(pi_sampler_addressing_mode), &MAddrMode, nullptr);
37  sizeof(pi_sampler_filter_mode),
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 detail::plugin &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 detail::plugin &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
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
void checkPiResult(RT::PiResult pi_result) const
Checks return value from PI calls.
Definition: plugin.hpp:116
RT::PiResult call_nocheck(ArgsT... Args) const
Calls the PiApi, traces the call, and returns the result.
Definition: plugin.hpp:170
RT::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.
#define __SYCL_INLINE_VER_NAMESPACE(X)
::pi_sampler PiSampler
Definition: pi.hpp:122
::pi_result PiResult
Definition: pi.hpp:108
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240
filtering_mode
Definition: sampler.hpp:28
coordinate_normalization_mode
Definition: sampler.hpp:33
addressing_mode
Definition: sampler.hpp:20
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
pi_uint32 pi_bool
Definition: pi.h:105
pi_result piSamplerRetain(pi_sampler sampler)
_pi_sampler_filter_mode pi_sampler_filter_mode
Definition: pi.h:605
pi_bitfield pi_sampler_properties
Definition: pi.h:511
pi_result piSamplerCreate(pi_context context, const pi_sampler_properties *sampler_properties, pi_sampler *result_sampler)
_pi_sampler_addressing_mode pi_sampler_addressing_mode
Definition: pi.h:604
@ PI_SAMPLER_INFO_NORMALIZED_COORDS
Definition: pi.h:482
@ PI_SAMPLER_INFO_FILTER_MODE
Definition: pi.h:484
@ PI_SAMPLER_INFO_ADDRESSING_MODE
Definition: pi.h:483
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)
pi_result piSamplerRelease(pi_sampler sampler)