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 <CL/sycl/accessor.hpp>
17 
19 namespace sycl {
20 namespace ext {
21 namespace intel {
22 namespace esimd {
23 namespace detail {
24 
25 // Checks that given type is a SYCL accessor type. Sets its static field
26 // \c value accordingly. Also, if the check is succesful, sets \c mode and
27 // \c target static fields to the accessor type's access mode and access target
28 // respectively. Otherwise they are set to -1.
29 template <typename T> struct is_sycl_accessor : public std::false_type {
30  static constexpr sycl::access::mode mode =
31  static_cast<sycl::access::mode>(-1);
32  static constexpr sycl::access::target target =
33  static_cast<sycl::access::target>(-1);
34 };
35 
36 template <typename DataT, int Dimensions, sycl::access::mode AccessMode,
37  sycl::access::target AccessTarget,
38  sycl::access::placeholder IsPlaceholder, typename PropertyListT>
39 struct is_sycl_accessor<sycl::accessor<
40  DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder, PropertyListT>>
41  : public std::true_type {
42  static constexpr sycl::access::mode mode = AccessMode;
43  static constexpr sycl::access::target target = AccessTarget;
44 };
45 
46 using accessor_mode_cap_val_t = bool;
47 
48 // Denotes an accessor's capability - whether it can read or write.
49 struct accessor_mode_cap {
50  static inline constexpr accessor_mode_cap_val_t can_read = false;
51  static inline constexpr accessor_mode_cap_val_t can_write = true;
52 };
53 
54 template <sycl::access::mode Mode, accessor_mode_cap_val_t Cap>
55 constexpr bool accessor_mode_has_capability() {
56  static_assert(Cap == accessor_mode_cap::can_read ||
57  Cap == accessor_mode_cap::can_write,
58  "unsupported capability");
59 
60  if constexpr (Mode == sycl::access::mode::atomic ||
61  Mode == sycl::access::mode::read_write ||
62  Mode == sycl::access::mode::discard_read_write)
63  return true; // atomic and *read_write accessors can read/write
64 
65  return (Cap == accessor_mode_cap::can_read) ==
66  (Mode == sycl::access::mode::read);
67 }
68 
69 // Checks that given type is a SYCL accessor type with given capability and
70 // target.
71 template <typename T, accessor_mode_cap_val_t Capability,
72  sycl::access::target AccessTarget>
73 struct is_sycl_accessor_with
74  : public std::conditional_t<
75  accessor_mode_has_capability<is_sycl_accessor<T>::mode,
76  Capability>() &&
77  (is_sycl_accessor<T>::target == AccessTarget),
78  std::true_type, std::false_type> {};
79 
80 template <typename T, accessor_mode_cap_val_t Capability,
81  sycl::access::target AccessTarget, typename RetT>
82 using EnableIfAccessor = sycl::detail::enable_if_t<
83  detail::is_sycl_accessor_with<T, Capability, AccessTarget>::value, RetT>;
84 
85 } // namespace detail
86 } // namespace esimd
87 } // namespace intel
88 } // namespace ext
89 } // namespace sycl
90 } // __SYCL_INLINE_NAMESPACE(cl)
91 
T
cl::sycl::access::placeholder
placeholder
Definition: access.hpp:43
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::conditional_t
typename std::conditional< B, T, F >::type conditional_t
Definition: stl_type_traits.hpp:27
cl::sycl::access::target
target
Definition: access.hpp:17
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
accessor.hpp
cl::sycl::access::mode
mode
Definition: access.hpp:28
cl::sycl::detail::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: stl_type_traits.hpp:24
cl::sycl::Dimensions
Dimensions
Definition: backend.hpp:142
cl::sycl::errc::accessor
@ accessor
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12