DPC++ Runtime
Runtime libraries for oneAPI DPC++
types_elementary.hpp
Go to the documentation of this file.
1 //==------------- types_elementary.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 // Definitions and declarations which are used in ESIMD type system, and which
9 // don't depend on other ESIMD types.
10 //===----------------------------------------------------------------------===//
11 
12 #pragma once
13 
14 // ESIMD HEADERS SHOULD NOT BE INCLUDED HERE
15 #include <cstdint>
16 #include <type_traits>
17 
18 namespace sycl {
19 inline namespace _V1 {
20 namespace ext::intel::esimd {
21 
23 
24 namespace detail {
25 
26 // Unsigned integer type of given byte size or 'void'.
27 template <int N>
28 using uint_type_t = std::conditional_t<
29  N == 1, uint8_t,
30  std::conditional_t<
31  N == 2, uint16_t,
32  std::conditional_t<N == 4, uint32_t,
33  std::conditional_t<N == 8, uint64_t, void>>>>;
34 
35 template <typename T>
36 using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
37 
39 template <typename U> constexpr bool is_type() { return false; }
40 
41 template <typename U, typename T, typename... Ts> constexpr bool is_type() {
42  using UU = typename std::remove_const_t<U>;
43  using TT = typename std::remove_const_t<T>;
44  return std::is_same_v<UU, TT> || is_type<UU, Ts...>();
45 }
46 
47 // Converts types to single 'void' type (used for SFINAE).
48 template <class...> struct make_esimd_void {
49  using type = void;
50 };
51 template <class... Tys>
52 using __esimd_void_t = typename make_esimd_void<Tys...>::type;
53 
54 // Checks if standard arithmetic operations can be applied to given type.
55 template <class Ty, class = void>
56 struct is_esimd_arithmetic_type : std::false_type {};
57 
58 template <class Ty>
59 struct is_esimd_arithmetic_type<
60  Ty, __esimd_void_t<std::enable_if_t<std::is_arithmetic_v<Ty>>,
61  decltype(std::declval<Ty>() + std::declval<Ty>()),
62  decltype(std::declval<Ty>() - std::declval<Ty>()),
63  decltype(std::declval<Ty>() * std::declval<Ty>()),
64  decltype(std::declval<Ty>() / std::declval<Ty>())>>
65  : std::true_type {};
66 
67 template <typename Ty>
68 static inline constexpr bool is_esimd_arithmetic_type_v =
69  is_esimd_arithmetic_type<Ty>::value;
70 
71 // Checks if given type can serve as clang vector element type.
72 template <typename Ty>
73 struct is_vectorizable : std::conditional_t<is_esimd_arithmetic_type_v<Ty>,
74  std::true_type, std::false_type> {};
75 
76 template <typename Ty>
77 static inline constexpr bool is_vectorizable_v = is_vectorizable<Ty>::value;
78 
79 // Raw vector type, using clang vector type extension.
80 template <typename Ty, int N> struct raw_vector_type {
81  static_assert(!std::is_const_v<Ty>, "const element type not supported");
82  static_assert(is_vectorizable_v<Ty>, "element type not supported");
83  static_assert(N > 0, "zero-element vector not supported");
84 
85  static constexpr int length = N;
86  using type = Ty __attribute__((ext_vector_type(N)));
87 };
88 
89 // Alias for clang vector type with given element type and number of elements.
90 template <typename Ty, int N>
91 using vector_type_t = typename raw_vector_type<Ty, N>::type;
92 
93 // Checks if given type T is a raw clang vector type, plus provides some info
94 // about it if it is.
95 
96 struct invalid_element_type;
97 
98 template <class T> struct is_clang_vector_type : std::false_type {
99  static constexpr int length = 0;
100  using element_type = invalid_element_type;
101 };
102 
103 template <class T, int N>
104 struct is_clang_vector_type<T __attribute__((ext_vector_type(N)))>
105  : std::true_type {
106  static constexpr int length = N;
107  using element_type = T;
108 };
109 template <class T>
110 static inline constexpr bool is_clang_vector_type_v =
111  is_clang_vector_type<T>::value;
112 
113 template <class T> struct vector_element_type;
114 
115 template <class T, int N> struct vector_element_type<vector_type_t<T, N>> {
116  using type = T;
117 };
118 
119 template <class T, int N>
120 struct vector_element_type<T __attribute__((ext_vector_type(N)))> {
121  using type = T;
122 };
123 
124 template <class T>
125 using vector_element_type_t = typename vector_element_type<T>::type;
126 
127 } // namespace detail
128 
130 
131 } // namespace ext::intel::esimd
132 } // namespace _V1
133 } // namespace sycl
__attribute__((always_inline)) auto invoke_simd(sycl
The invoke_simd free function invokes a SIMD function using all work-items in a sub_group.
Definition: access.hpp:18
ValueT length(const ValueT *a, const int len)
Calculate the square root of the input array.
Definition: math.hpp:161