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/context_impl.hpp>
11 #include <detail/sampler_impl.hpp>
12 
14 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 } // namespace sycl
96 } // __SYCL_INLINE_NAMESPACE(cl)
property_list.hpp
pi_bool
pi_uint32 pi_bool
Definition: pi.h:96
context_impl.hpp
cl::sycl::detail::sampler_impl::get_filtering_mode
filtering_mode get_filtering_mode() const
Definition: sampler_impl.cpp:87
_pi_result
_pi_result
Definition: pi.h:105
PI_SAMPLER_INFO_FILTER_MODE
@ PI_SAMPLER_INFO_FILTER_MODE
Definition: pi.h:466
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:1467
cl::sycl::errc::feature_not_supported
@ feature_not_supported
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
piSamplerCreate
pi_result piSamplerCreate(pi_context context, const pi_sampler_properties *sampler_properties, pi_sampler *result_sampler)
Definition: pi_esimd_emulator.cpp:1462
cl::sycl::detail::plugin::call_nocheck
RT::PiResult call_nocheck(ArgsT... Args) const
Calls the PiApi, traces the call, and returns the result.
Definition: plugin.hpp:170
cl::sycl::detail::plugin::call
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
piSamplerRetain
pi_result piSamplerRetain(pi_sampler sampler)
Definition: pi_esimd_emulator.cpp:1472
cl::sycl::detail::sampler_impl::getOrCreateSampler
RT::PiSampler getOrCreateSampler(const context &Context)
Definition: sampler_impl.cpp:50
_pi_sampler
Implementation of samplers for CUDA.
Definition: pi_cuda.hpp:944
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
cl::sycl::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
pi_sampler_properties
pi_bitfield pi_sampler_properties
Definition: pi.h:493
cl::sycl::detail::sampler_impl::get_coordinate_normalization_mode
coordinate_normalization_mode get_coordinate_normalization_mode() const
Definition: sampler_impl.cpp:90
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::detail::plugin::checkPiResult
void checkPiResult(RT::PiResult pi_result) const
Checks return value from PI calls.
Definition: plugin.hpp:116
cl::sycl::addressing_mode
addressing_mode
Definition: sampler.hpp:20
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:38
pi_sampler_addressing_mode
_pi_sampler_addressing_mode pi_sampler_addressing_mode
Definition: pi.h:585
cl::sycl::filtering_mode
filtering_mode
Definition: sampler.hpp:28
pi_sampler_filter_mode
_pi_sampler_filter_mode pi_sampler_filter_mode
Definition: pi.h:586
cl::sycl::detail::sampler_impl::~sampler_impl
~sampler_impl()
Definition: sampler_impl.cpp:41
piSamplerRelease
pi_result piSamplerRelease(pi_sampler sampler)
Definition: pi_esimd_emulator.cpp:1474
PI_SAMPLER_INFO_NORMALIZED_COORDS
@ PI_SAMPLER_INFO_NORMALIZED_COORDS
Definition: pi.h:464
cl::sycl::detail::sampler_impl::get_addressing_mode
addressing_mode get_addressing_mode() const
Definition: sampler_impl.cpp:85
sampler_impl.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12
PI_SAMPLER_INFO_ADDRESSING_MODE
@ PI_SAMPLER_INFO_ADDRESSING_MODE
Definition: pi.h:465