Skip to content

[SYCL] Implement SYCL 2020 vec aliases #7889

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
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
30 changes: 30 additions & 0 deletions sycl/include/sycl/aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sycl/detail/cl.h>
#include <sycl/detail/common.hpp>
#include <sycl/detail/defines_elementary.hpp>

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -62,6 +63,22 @@ class half;
__SYCL_MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
__SYCL_MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES(N)

// FIXME: OpenCL vector aliases are not defined by SYCL 2020 spec and should be
// removed from here. See intel/llvm#7888
#define __SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(N) \
__SYCL_MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
__SYCL_MAKE_VECTOR_ALIAS(char, std::int8_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(uchar, std::uint8_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(short, std::int16_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(ushort, std::uint16_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(int, std::int32_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(uint, std::uint32_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(long, std::int64_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(ulong, std::uint64_t, N) \
__SYCL_MAKE_VECTOR_ALIAS(float, float, N) \
__SYCL_MAKE_VECTOR_ALIAS(double, double, N) \
__SYCL_MAKE_VECTOR_ALIAS(half, half, N)

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
using byte __SYCL2020_DEPRECATED("use std::byte instead") = std::uint8_t;
Expand All @@ -73,6 +90,9 @@ using ulong = unsigned long;
using longlong = long long;
using ulonglong = unsigned long long;
using half = sycl::detail::half_impl::half;

// FIXME: SYCL 2020 spec says that cl_* aliases should reside in sycl::opencl
// namespace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is blocking us from applying these FIXME comments right away?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, we still use some of these aliases: #7888. I don't know exactly about cl_* scalar aliases, but we for sure use cl_* vector aliases.

I would prefer an incremental approach and get this merged first as a fix for vector aliases and then submit a separate patch for scalar aliases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took another look at this: vector cl_* aliases depend on scalar cl_* aliases and those in turn are still used (#7888)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, we still use some of these aliases: #7888. I don't know exactly about cl_* scalar aliases, but we for sure use cl_* vector aliases.

I would prefer an incremental approach and get this merged first as a fix for vector aliases and then submit a separate patch for scalar aliases

I also prefer incremental approach, which should be remove cl_* alias usages from DPC++ code base first and remove alias definitions after that. This way there will be no technical debt.

using cl_bool = bool;
using cl_char = std::int8_t;
using cl_uchar = std::uint8_t;
Expand All @@ -86,11 +106,20 @@ using cl_half = half;
using cl_float = float;
using cl_double = double;

// Vector aliases are different between SYCL 1.2.1 and SYCL 2020
#if SYCL_LANGUAGE_VERSION >= 202001
__SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(2)
__SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(3)
__SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(4)
__SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(8)
__SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(16)
#else
__SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(2)
__SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(3)
__SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(4)
__SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(8)
__SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(16)
#endif
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl

Expand All @@ -99,3 +128,4 @@ __SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH(16)
#undef __SYCL_MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES
#undef __SYCL_MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES
#undef __SYCL_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH
#undef __SYCL_2020_MAKE_VECTOR_ALIASES_FOR_VECTOR_LENGTH
2 changes: 1 addition & 1 deletion sycl/test/basic_tests/aliases.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %clangxx -fsycl -sycl-std=1.2.1 -fsycl-targets=%sycl_triple -fsyntax-only %s
//==------------ aliases.cpp - SYCL type aliases test ----------------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Expand Down
34 changes: 34 additions & 0 deletions sycl/test/basic_tests/vectors/aliases.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %clangxx -fsycl -fsyntax-only -fsycl-device-only %s

#include <sycl/sycl.hpp>

#include <cstdint>
#include <type_traits>

#define CHECK_ALIAS(type, storage_type, elems) \
static_assert( \
std::is_same_v<sycl::type##elems, sycl::vec<storage_type, elems>>);

#define CHECK_ALIASES_FOR_VEC_LENGTH(N) \
CHECK_ALIAS(char, std::int8_t, N) \
CHECK_ALIAS(uchar, std::uint8_t, N) \
CHECK_ALIAS(short, std::int16_t, N) \
CHECK_ALIAS(ushort, std::uint16_t, N) \
CHECK_ALIAS(int, std::int32_t, N) \
CHECK_ALIAS(uint, std::uint32_t, N) \
CHECK_ALIAS(long, std::int64_t, N) \
CHECK_ALIAS(ulong, std::uint64_t, N) \
CHECK_ALIAS(half, sycl::half, N) \
CHECK_ALIAS(float, float, N) \
CHECK_ALIAS(double, double, N)

int main() {

CHECK_ALIASES_FOR_VEC_LENGTH(2)
CHECK_ALIASES_FOR_VEC_LENGTH(3)
CHECK_ALIASES_FOR_VEC_LENGTH(4)
CHECK_ALIASES_FOR_VEC_LENGTH(8)
CHECK_ALIASES_FOR_VEC_LENGTH(16)

return 0;
}
1 change: 0 additions & 1 deletion sycl/test/type_traits/type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ int main() {
test_nan_types<s::ushort2, s::ushort2>();
test_nan_types<s::uint2, s::uint2>();
test_nan_types<s::ulong2, s::ulong2>();
test_nan_types<s::ulonglong2, s::ulonglong2>();

test_make_signed_t<int, int>();
test_make_signed_t<const int, const int>();
Expand Down