DPC++ Runtime
Runtime libraries for oneAPI DPC++
aliases.hpp
Go to the documentation of this file.
1 //==----------- aliases.hpp --- SYCL type aliases --------------------------==//
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 
9 #pragma once
10 
11 #include <sycl/detail/cl.h>
12 #include <sycl/detail/common.hpp>
14 
15 #include <cstddef>
16 #include <cstdint>
17 
18 namespace sycl {
20 template <typename T, int N> class vec;
21 namespace detail::half_impl {
22 class half;
23 } // namespace detail::half_impl
24 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
25 } // namespace sycl
26 
27 #define __SYCL_MAKE_VECTOR_ALIAS(ALIAS, TYPE, N) \
28  using ALIAS##N = sycl::vec<TYPE, N>;
29 
30 #define __SYCL_MAKE_VECTOR_ALIASES_FOR_ARITHMETIC_TYPES(N) \
31  __SYCL_MAKE_VECTOR_ALIAS(char, char, N) \
32  __SYCL_MAKE_VECTOR_ALIAS(short, short, N) \
33  __SYCL_MAKE_VECTOR_ALIAS(int, int, N) \
34  __SYCL_MAKE_VECTOR_ALIAS(long, long, N) \
35  __SYCL_MAKE_VECTOR_ALIAS(float, float, N) \
36  __SYCL_MAKE_VECTOR_ALIAS(double, double, N) \
37  __SYCL_MAKE_VECTOR_ALIAS(half, half, N)
38 
39 #define __SYCL_MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
40  __SYCL_MAKE_VECTOR_ALIAS(cl_char, sycl::cl_char, N) \
41  __SYCL_MAKE_VECTOR_ALIAS(cl_uchar, sycl::cl_uchar, N) \
42  __SYCL_MAKE_VECTOR_ALIAS(cl_short, sycl::cl_short, N) \
43  __SYCL_MAKE_VECTOR_ALIAS(cl_ushort, sycl::cl_ushort, N) \
44  __SYCL_MAKE_VECTOR_ALIAS(cl_int, sycl::cl_int, N) \
45  __SYCL_MAKE_VECTOR_ALIAS(cl_uint, sycl::cl_uint, N) \
46  __SYCL_MAKE_VECTOR_ALIAS(cl_long, sycl::cl_long, N) \
47  __SYCL_MAKE_VECTOR_ALIAS(cl_ulong, sycl::cl_ulong, N) \
48  __SYCL_MAKE_VECTOR_ALIAS(cl_float, sycl::cl_float, N) \
49  __SYCL_MAKE_VECTOR_ALIAS(cl_double, sycl::cl_double, N) \
50  __SYCL_MAKE_VECTOR_ALIAS(cl_half, sycl::cl_half, N)
51 
52 #define __SYCL_MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES(N) \
53  __SYCL_MAKE_VECTOR_ALIAS(schar, signed char, N) \
54  __SYCL_MAKE_VECTOR_ALIAS(uchar, unsigned char, N) \
55  __SYCL_MAKE_VECTOR_ALIAS(ushort, unsigned short, N) \
56  __SYCL_MAKE_VECTOR_ALIAS(uint, unsigned int, N) \
57  __SYCL_MAKE_VECTOR_ALIAS(ulong, unsigned long, N) \
58  __SYCL_MAKE_VECTOR_ALIAS(longlong, long long, N) \
59  __SYCL_MAKE_VECTOR_ALIAS(ulonglong, unsigned long long, N)
60 
61 #define __SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(N) \
62  __SYCL_MAKE_VECTOR_ALIASES_FOR_ARITHMETIC_TYPES(N) \
63  __SYCL_MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
64  __SYCL_MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES(N)
65 
66 // FIXME: OpenCL vector aliases are not defined by SYCL 2020 spec and should be
67 // removed from here. See intel/llvm#7888
68 // FIXME: schar, longlong and ulonglong aliases are not defined by SYCL 2020
69 // spec, but they are preserved in SYCL 2020 mode, because SYCL-CTS is
70 // still using them.
71 // See KhronosGroup/SYCL-CTS#446 and KhronosGroup/SYCL-Docs#335
72 #define __SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(N) \
73  __SYCL_MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
74  __SYCL_MAKE_VECTOR_ALIAS(schar, std::int8_t, N) \
75  __SYCL_MAKE_VECTOR_ALIAS(longlong, std::int64_t, N) \
76  __SYCL_MAKE_VECTOR_ALIAS(ulonglong, std::uint64_t, N) \
77  __SYCL_MAKE_VECTOR_ALIAS(char, std::int8_t, N) \
78  __SYCL_MAKE_VECTOR_ALIAS(uchar, std::uint8_t, N) \
79  __SYCL_MAKE_VECTOR_ALIAS(short, std::int16_t, N) \
80  __SYCL_MAKE_VECTOR_ALIAS(ushort, std::uint16_t, N) \
81  __SYCL_MAKE_VECTOR_ALIAS(int, std::int32_t, N) \
82  __SYCL_MAKE_VECTOR_ALIAS(uint, std::uint32_t, N) \
83  __SYCL_MAKE_VECTOR_ALIAS(long, std::int64_t, N) \
84  __SYCL_MAKE_VECTOR_ALIAS(ulong, std::uint64_t, N) \
85  __SYCL_MAKE_VECTOR_ALIAS(float, float, N) \
86  __SYCL_MAKE_VECTOR_ALIAS(double, double, N) \
87  __SYCL_MAKE_VECTOR_ALIAS(half, half, N)
88 
89 namespace sycl {
91 using byte __SYCL2020_DEPRECATED("use std::byte instead") = std::uint8_t;
92 using schar = signed char;
93 using uchar = unsigned char;
94 using ushort = unsigned short;
95 using uint = unsigned int;
96 using ulong = unsigned long;
97 using longlong = long long;
98 using ulonglong = unsigned long long;
100 
101 // FIXME: SYCL 2020 spec says that cl_* aliases should reside in sycl::opencl
102 // namespace.
103 using cl_bool = bool;
104 using cl_char = std::int8_t;
105 using cl_uchar = std::uint8_t;
106 using cl_short = std::int16_t;
107 using cl_ushort = std::uint16_t;
108 using cl_int = std::int32_t;
109 using cl_uint = std::uint32_t;
111 using cl_ulong = std::uint64_t;
112 using cl_half = half;
113 using cl_float = float;
114 using cl_double = double;
115 
116 namespace opencl {
117 // Strictly speaking, cl_* aliases should not be defined in opencl namespace in
118 // SYCL 1.2.1 mode, but we do so to simplify our implementation
119 using cl_bool = bool;
120 using cl_char = std::int8_t;
121 using cl_uchar = std::uint8_t;
122 using cl_short = std::int16_t;
123 using cl_ushort = std::uint16_t;
124 using cl_int = std::int32_t;
125 using cl_uint = std::uint32_t;
127 using cl_ulong = std::uint64_t;
128 using cl_half = half;
129 using cl_float = float;
130 using cl_double = double;
131 } // namespace opencl
132 
133 // Vector aliases are different between SYCL 1.2.1 and SYCL 2020
134 #if SYCL_LANGUAGE_VERSION >= 202001
140 #else
146 #endif
147 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
148 } // namespace sycl
149 
150 #undef __SYCL_MAKE_VECTOR_ALIAS
151 #undef __SYCL_MAKE_VECTOR_ALIASES_FOR_ARITHMETIC_TYPES
152 #undef __SYCL_MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES
153 #undef __SYCL_MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES
154 #undef __SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH
155 #undef __SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH
#define __SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(N)
Definition: aliases.hpp:72
#define __SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(N)
Definition: aliases.hpp:61
#define __SYCL_INLINE_VER_NAMESPACE(X)
#define __SYCL2020_DEPRECATED(message)
conditional< sizeof(long)==8, long, long long >::type int64_t
Definition: kernel_desc.hpp:34
std::uint64_t cl_ulong
Definition: aliases.hpp:127
std::int32_t cl_int
Definition: aliases.hpp:124
std::int8_t cl_char
Definition: aliases.hpp:120
std::uint8_t cl_uchar
Definition: aliases.hpp:121
std::uint16_t cl_ushort
Definition: aliases.hpp:123
std::int16_t cl_short
Definition: aliases.hpp:122
std::uint32_t cl_uint
Definition: aliases.hpp:125
std::int64_t cl_long
Definition: aliases.hpp:126
std::int8_t cl_char
Definition: aliases.hpp:104
half cl_half
Definition: aliases.hpp:112
long long longlong
Definition: aliases.hpp:97
std::int16_t cl_short
Definition: aliases.hpp:106
std::uint8_t cl_uchar
Definition: aliases.hpp:105
unsigned int uint
Definition: aliases.hpp:95
unsigned char uchar
Definition: aliases.hpp:93
std::int64_t cl_long
Definition: aliases.hpp:110
bool cl_bool
Definition: aliases.hpp:103
std::uint16_t cl_ushort
Definition: aliases.hpp:107
double cl_double
Definition: aliases.hpp:114
unsigned short ushort
Definition: aliases.hpp:94
std::int32_t cl_int
Definition: aliases.hpp:108
std::uint32_t cl_uint
Definition: aliases.hpp:109
unsigned long long ulonglong
Definition: aliases.hpp:98
float cl_float
Definition: aliases.hpp:113
sycl::detail::half_impl::half half
Definition: aliases.hpp:99
unsigned long ulong
Definition: aliases.hpp:96
signed char schar
Definition: aliases.hpp:92
std::uint64_t cl_ulong
Definition: aliases.hpp:111
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14