DPC++ Runtime
Runtime libraries for oneAPI DPC++
sycl_util.hpp
Go to the documentation of this file.
1 //==------------- sycl_util.hpp - DPC++ Explicit SIMD API -----------------==//
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 // Utility functions related to interaction with generic SYCL and used for
9 // implementing Explicit SIMD APIs.
10 //===----------------------------------------------------------------------===//
11 
12 #pragma once
13 
15 
16 #include <sycl/accessor.hpp>
17 
18 namespace sycl {
20 namespace ext::intel::esimd::detail {
21 
22 // Checks that given type is a SYCL accessor type. Sets its static field
23 // \c value accordingly. Also, if the check is succesful, sets \c mode and
24 // \c target static fields to the accessor type's access mode and access target
25 // respectively. Otherwise they are set to -1.
26 template <typename T> struct is_sycl_accessor : public std::false_type {
27  static constexpr sycl::access::mode mode =
28  static_cast<sycl::access::mode>(-1);
29  static constexpr sycl::access::target target =
30  static_cast<sycl::access::target>(-1);
31 };
32 
33 template <typename DataT, int Dimensions, sycl::access::mode AccessMode,
34  sycl::access::target AccessTarget,
35  sycl::access::placeholder IsPlaceholder, typename PropertyListT>
36 struct is_sycl_accessor<sycl::accessor<
37  DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder, PropertyListT>>
38  : public std::true_type {
39  static constexpr sycl::access::mode mode = AccessMode;
40  static constexpr sycl::access::target target = AccessTarget;
41 };
42 
43 using accessor_mode_cap_val_t = bool;
44 
45 // Denotes an accessor's capability - whether it can read or write.
46 struct accessor_mode_cap {
47  static inline constexpr accessor_mode_cap_val_t can_read = false;
48  static inline constexpr accessor_mode_cap_val_t can_write = true;
49 };
50 
51 template <sycl::access::mode Mode, accessor_mode_cap_val_t Cap>
52 constexpr bool accessor_mode_has_capability() {
53  static_assert(Cap == accessor_mode_cap::can_read ||
54  Cap == accessor_mode_cap::can_write,
55  "unsupported capability");
56 
57  if constexpr (Mode == sycl::access::mode::atomic ||
59  Mode == sycl::access::mode::discard_read_write)
60  return true; // atomic and *read_write accessors can read/write
61 
62  return (Cap == accessor_mode_cap::can_read) ==
63  (Mode == sycl::access::mode::read);
64 }
65 
66 // Checks that given type is a SYCL accessor type with given capability and
67 // target.
68 template <typename T, accessor_mode_cap_val_t Capability,
69  sycl::access::target AccessTarget>
70 struct is_sycl_accessor_with
71  : public std::conditional_t<
72  accessor_mode_has_capability<is_sycl_accessor<T>::mode,
73  Capability>() &&
74  (is_sycl_accessor<T>::target == AccessTarget),
75  std::true_type, std::false_type> {};
76 
77 template <typename T, accessor_mode_cap_val_t Capability,
78  sycl::access::target AccessTarget, typename RetT>
79 using EnableIfAccessor = std::enable_if_t<
80  detail::is_sycl_accessor_with<T, Capability, AccessTarget>::value, RetT>;
81 
82 } // namespace ext::intel::esimd::detail
83 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
84 } // namespace sycl
85 
sycl::_V1::IsPlaceholder
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS IsPlaceholder
Definition: accessor.hpp:3068
sycl::_V1::access::mode
mode
Definition: access.hpp:30
T
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::Dimensions
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
Definition: accessor.hpp:3067
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::accessor
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor accessor(buffer< DataT, Dimensions, AllocatorT >) -> accessor< DataT, Dimensions, access::mode::read_write, target::device, access::placeholder::true_t >
Buffer accessor.
sycl::_V1::access::placeholder
placeholder
Definition: access.hpp:45
sycl::_V1::access::target
target
Definition: access.hpp:18
sycl::_V1::read_write
constexpr mode_tag_t< access_mode::read_write > read_write
Definition: access.hpp:76
accessor.hpp
sycl::_V1::AccessMode
class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
Definition: accessor.hpp:3067