Skip to content

[SYCL] Recovery align aliases with SYCL specification patch. #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions sycl/include/CL/sycl/aliases.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//==----------- aliases.hpp --- SYCL type aliases --------------------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/detail/common.hpp>

#include <cstddef>
#include <cstdint>

namespace cl {
namespace sycl {
template <typename T, int N> class vec;
namespace detail {
namespace half_impl {
class half;
} // namespace half_impl
} // namespace detail
} // namespace sycl
} // namespace cl

#ifdef __SYCL_DEVICE_ONLY__
using half = _Float16;
#else
using half = cl::sycl::detail::half_impl::half;
#endif

#define MAKE_VECTOR_ALIAS(ALIAS, TYPE, N) \
using ALIAS##N = cl::sycl::vec<TYPE, N>;

#define MAKE_VECTOR_ALIASES_FOR_ARITHMETIC_TYPES(N) \
MAKE_VECTOR_ALIAS(char, char, N) \
MAKE_VECTOR_ALIAS(short, short, N) \
MAKE_VECTOR_ALIAS(int, int, N) \
MAKE_VECTOR_ALIAS(long, long, N) \
MAKE_VECTOR_ALIAS(float, float, N) \
MAKE_VECTOR_ALIAS(double, double, N) \
MAKE_VECTOR_ALIAS(half, half, N)

#define MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
MAKE_VECTOR_ALIAS(cl_char, cl::sycl::cl_char, N) \
MAKE_VECTOR_ALIAS(cl_uchar, cl::sycl::cl_uchar, N) \
MAKE_VECTOR_ALIAS(cl_short, cl::sycl::cl_short, N) \
MAKE_VECTOR_ALIAS(cl_ushort, cl::sycl::cl_ushort, N) \
MAKE_VECTOR_ALIAS(cl_int, cl::sycl::cl_int, N) \
MAKE_VECTOR_ALIAS(cl_uint, cl::sycl::cl_uint, N) \
MAKE_VECTOR_ALIAS(cl_long, cl::sycl::cl_long, N) \
MAKE_VECTOR_ALIAS(cl_ulong, cl::sycl::cl_ulong, N) \
MAKE_VECTOR_ALIAS(cl_float, cl::sycl::cl_float, N) \
MAKE_VECTOR_ALIAS(cl_double, cl::sycl::cl_double, N) \
MAKE_VECTOR_ALIAS(cl_half, cl::sycl::cl_half, N)

#define MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES(N) \
MAKE_VECTOR_ALIAS(schar, signed char, N) \
MAKE_VECTOR_ALIAS(uchar, unsigned char, N) \
MAKE_VECTOR_ALIAS(ushort, unsigned short, N) \
MAKE_VECTOR_ALIAS(uint, unsigned int, N) \
MAKE_VECTOR_ALIAS(ulong, unsigned long, N) \
MAKE_VECTOR_ALIAS(longlong, long long, N) \
MAKE_VECTOR_ALIAS(ulonglong, unsigned long long, N)

#define MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(N) \
MAKE_VECTOR_ALIASES_FOR_ARITHMETIC_TYPES(N) \
MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES(N)

namespace cl {
namespace sycl {
using byte = std::uint8_t;
using schar = signed char;
using uchar = unsigned char;
using ushort = unsigned short;
using uint = unsigned int;
using ulong = unsigned long;
using longlong = long long;
using ulonglong = unsigned long long;
// TODO cl::sycl::half is not in SYCL specification, but is used by Khronos CTS.
using half = half;
using cl_bool = bool;
using cl_char = std::int8_t;
using cl_uchar = std::uint8_t;
using cl_short = std::int16_t;
using cl_ushort = std::uint16_t;
using cl_int = std::int32_t;
using cl_uint = std::uint32_t;
using cl_long = std::int64_t;
using cl_ulong = std::uint64_t;
using cl_half = half;
using cl_float = float;
using cl_double = double;

MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(2)
MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(3)
MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(4)
MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(8)
MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(16)
} // namespace sycl
} // namespace cl

#undef MAKE_VECTOR_ALIAS
#undef MAKE_VECTOR_ALIASES_FOR_ARITHMETIC_TYPES
#undef MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES
#undef MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES
#undef MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH
8 changes: 4 additions & 4 deletions sycl/include/CL/sycl/detail/generic_type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ using is_charn = typename is_contained<
// scharn: schar2, schar3, schar4, schar8, schar16
template <typename T>
using is_scharn = typename is_contained<
T, type_list<cl_schar2, cl_schar3, cl_schar4, cl_schar8, cl_schar16>>::type;
T, type_list<schar2, schar3, schar4, schar8, schar16>>::type;

// ucharn: uchar2, uchar3, uchar4, uchar8, uchar16
template <typename T>
Expand All @@ -170,7 +170,7 @@ using is_ucharn = typename is_contained<
// igenchar: signed char, scharn
template <typename T>
using is_igenchar =
std::integral_constant<bool, is_contained<T, type_list<cl_schar>>::value ||
std::integral_constant<bool, is_contained<T, type_list<schar>>::value ||
is_scharn<T>::value>;

// ugenchar: unsigned char, ucharn
Expand Down Expand Up @@ -313,7 +313,7 @@ using is_ugeninteger = std::integral_constant<
// int
template <typename T>
using is_sgeninteger = typename is_contained<
T, type_list<cl_char, cl_schar, cl_uchar, cl_short, cl_ushort, cl_int,
T, type_list<cl_char, schar, cl_uchar, cl_short, cl_ushort, cl_int,
cl_uint, cl_long, cl_ulong, longlong, ulonglong>>::type;

// vgeninteger: charn, scharn, ucharn, shortn, ushortn, intn, uintn, longn,
Expand All @@ -329,7 +329,7 @@ using is_vgeninteger = std::integral_constant<
// sigeninteger: char, signed char, short, int, long int, , long long int
template <typename T>
using is_sigeninteger = typename is_contained<
T, type_list<cl_char, cl_schar, cl_short, cl_int, cl_long, longlong>>::type;
T, type_list<cl_char, schar, cl_short, cl_int, cl_long, longlong>>::type;

// sugeninteger: unsigned char, unsigned short, unsigned int, unsigned long
// int, unsigned long long int
Expand Down
Loading