Skip to content

[SYCL] vec abi unification and trivially copyable #9492

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 30 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6883d86
test and tidy
cperkinsintel May 16, 2023
dd2ef1b
min functionality. incomplete headers tho
cperkinsintel May 16, 2023
fc31559
CMakeList to suppress warning
cperkinsintel May 16, 2023
9d2e2ed
removing SYCL_USE_VECTOR_EXT and adding VectorDataType
cperkinsintel May 17, 2023
eb2c2e6
some clean up
cperkinsintel May 17, 2023
5b46ab1
remove comment
cperkinsintel May 17, 2023
d58891d
stray comment
cperkinsintel May 17, 2023
a1ca45e
unused var warn
cperkinsintel May 17, 2023
9b3a18b
more uninitialized vars? why not seeing these when building locally?
cperkinsintel May 17, 2023
a6a933f
std::byte not convertible to uchar. adding cast to avoid initializati…
cperkinsintel May 19, 2023
471dc58
adjust windows test
cperkinsintel May 22, 2023
bde71ef
Merge branch 'sycl' into cperkins-vec-abi-unification
cperkinsintel Jul 6, 2023
e538116
checkpoint. overlooked constexpr contstructor.
cperkinsintel Jul 7, 2023
a40d764
cleanup. still a test failing though.
cperkinsintel Jul 7, 2023
8d71c2c
update generic_type_traits.hpp
cperkinsintel Jul 12, 2023
a744971
update vector_t, no need for late cast. Still having a conversion iss…
cperkinsintel Jul 13, 2023
9c1ade0
clang-format destroying code. Added the missing conversion.
cperkinsintel Jul 13, 2023
7261467
clang-format demands tribute
cperkinsintel Jul 13, 2023
4af50f7
copy constructor s.b. constexpr
cperkinsintel Jul 13, 2023
a47dba8
min macro from windows.h thwarted
cperkinsintel Jul 13, 2023
d97e2b1
Merge branch 'sycl' into cperkins-vec-abi-unification
cperkinsintel Jul 24, 2023
3410dd1
found and working around strange internal compiler error coming from …
cperkinsintel Jul 25, 2023
c6e3652
Merge branch 'sycl' into cperkins-vec-abi-unification
cperkinsintel Jul 25, 2023
50d33a3
abi symbols linux
cperkinsintel Jul 25, 2023
99ee99f
reviewer feedback
cperkinsintel Jul 26, 2023
0dd4021
host only uses std::array
cperkinsintel Jul 27, 2023
c558894
now that host is never using ext_vector_type, the __NO_EXT_VECTOR_TYP…
cperkinsintel Jul 27, 2023
a8a0a26
Steffen's kludge > Chris' kludge
cperkinsintel Jul 28, 2023
c3f9677
remove unneeded HAS_EXT_VECTOR_TYPEs
cperkinsintel Jul 31, 2023
47a38e3
merge conflict resolved
cperkinsintel Aug 1, 2023
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
16 changes: 12 additions & 4 deletions sycl/include/sycl/detail/vector_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ inline namespace _V1 {
namespace detail {

// 4.10.2.6 Memory layout and alignment
template <typename T, int N>
// due to MSVC the maximum alignment for sycl::vec is 64 and this proposed
// change is being brought to the spec committee.
constexpr size_t MaxVecAlignment = 64;
template <typename T, size_t N>
struct vector_alignment_impl
: std::conditional_t<N == 3, std::integral_constant<int, sizeof(T) * 4>,
std::integral_constant<int, sizeof(T) * N>> {};
: std::conditional_t<
N == 3,
std::integral_constant<size_t,
(std::min)(sizeof(T) * 4, MaxVecAlignment)>,
std::integral_constant<size_t,
(std::min)(sizeof(T) * N, MaxVecAlignment)>> {
};

template <typename T, int N>
template <typename T, size_t N>
struct vector_alignment
: vector_alignment_impl<std::remove_cv_t<std::remove_reference_t<T>>, N> {};
} // namespace detail
Expand Down
26 changes: 5 additions & 21 deletions sycl/include/sycl/half_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,12 @@ using BIsRepresentationT = half;
// for vec because they are actually defined as an integer type under the
// hood. As a result half values will be converted to the integer and passed
// as a kernel argument which is expected to be floating point number.
template <int NumElements> struct half_vec {
alignas(
vector_alignment<StorageT, NumElements>::value) StorageT s[NumElements];

__SYCL_CONSTEXPR_HALF half_vec() : s{0.0f} { initialize_data(); }
template <typename... Ts,
typename = std::enable_if_t<(sizeof...(Ts) == NumElements) &&
(std::is_same_v<half, Ts> && ...)>>
__SYCL_CONSTEXPR_HALF half_vec(const Ts &...hs) : s{hs...} {}

constexpr void initialize_data() {
for (size_t i = 0; i < NumElements; ++i) {
s[i] = StorageT(0.0f);
}
}
};

using Vec2StorageT = half_vec<2>;
using Vec3StorageT = half_vec<3>;
using Vec4StorageT = half_vec<4>;
using Vec8StorageT = half_vec<8>;
using Vec16StorageT = half_vec<16>;
using Vec2StorageT = std::array<StorageT, 2>;
using Vec3StorageT = std::array<StorageT, 3>;
using Vec4StorageT = std::array<StorageT, 4>;
using Vec8StorageT = std::array<StorageT, 8>;
using Vec16StorageT = std::array<StorageT, 16>;
#endif

#ifndef __SYCL_DEVICE_ONLY__
Expand Down
253 changes: 148 additions & 105 deletions sycl/include/sycl/types.hpp

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
else()
target_compile_options(${LIB_OBJ_NAME} PUBLIC
-fvisibility=hidden -fvisibility-inlines-hidden)

# Sycl math built-in macros cause a GCC 4.6 'note' to be output repeatedly.
# => note: the ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
# Seems to be no way to suppress it except use -Wno-psabi
target_compile_options(${LIB_OBJ_NAME} PUBLIC -Wno-psabi)

if (UNIX AND NOT APPLE)
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
target_link_libraries(
Expand Down
6 changes: 6 additions & 0 deletions sycl/source/detail/builtins_relational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,15 @@ __SYCL_EXPORT rel_res_t sycl_host_SignBitSet(s::cl_float x) __NOEXC {
__SYCL_EXPORT rel_res_t sycl_host_SignBitSet(s::cl_double x) __NOEXC {
return std::signbit(x);
}
#ifndef __GNUC__
// GCC 11.3.0 (and friends) has an internal compiler error when this function is
// passed to the macro declaration below. ( MAKE_1V ... 4 ... ) Fortunately, we
// don't actually need it when compiling the SYCL library itself.
// TODO: switch to templates instead of these overload expansions.
__SYCL_EXPORT s::cl_int __vSignBitSet(s::cl_float x) __NOEXC {
return -static_cast<s::cl_int>(std::signbit(x));
}
#endif
__SYCL_EXPORT s::cl_long __vSignBitSet(s::cl_double x) __NOEXC {
return -static_cast<s::cl_long>(std::signbit(x));
}
Expand Down
1 change: 0 additions & 1 deletion sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ _ZN10__host_std11__vIsNormalEd
_ZN10__host_std11__vIsNormalEf
_ZN10__host_std13__vSignBitSetEN4sycl3_V16detail9half_impl4halfE
_ZN10__host_std13__vSignBitSetEd
_ZN10__host_std13__vSignBitSetEf
_ZN10__host_std13sycl_host_AllEN4sycl3_V13vecIaLi16EEE
_ZN10__host_std13sycl_host_AllEN4sycl3_V13vecIaLi1EEE
_ZN10__host_std13sycl_host_AllEN4sycl3_V13vecIaLi2EEE
Expand Down
17 changes: 10 additions & 7 deletions sycl/test/basic_tests/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ template <typename T, int N> inline void checkVectorSizeAndAlignment() {
using VectorT = s::vec<T, N>;
constexpr auto RealLength = (N != 3 ? N : 4);
static_assert(sizeof(VectorT) == (sizeof(T) * RealLength), "");
#if defined(_WIN32) && (_MSC_VER) && \
defined(__NO_EXT_VECTOR_TYPE_ON_HOST__) && !defined(__SYCL_DEVICE_ONLY__)
// See comments around __SYCL_ALIGNED_VAR macro definition in types.hpp
// We can't enforce proper alignment of "huge" vectors (>64 bytes) on Windows
// and the test exposes this limitation.
if constexpr (alignof(T) * RealLength < 64)
#endif

// SYCL 2020 spec says that alignment is supposed to be same as size,
// but MSVC won't allow an alignment of anything larger than 64 for
// a direct parameter. The math built-ins use direct param calls.
// It has been decided to change the spec to have a max alignment of
// 64.
if constexpr (alignof(T) * RealLength <= 64)
static_assert(alignof(VectorT) == (alignof(T) * RealLength), "");
else
static_assert(alignof(VectorT) == 64,
"huge vectors should have a maximum alignment of 64");
}

template <typename T> inline void checkVectorsWithN() {
Expand Down
5 changes: 3 additions & 2 deletions sycl/test/basic_tests/valid_kernel_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ template <typename T> void check() {
}

SYCL_EXTERNAL void foo() {
#ifdef __SYCL_DEVICE_ONLY__

check<int>();
check<sycl::vec<sycl::opencl::cl_uchar, 4>>();
check<SomeStructure>();
#endif
check<sycl::int4>();
check<sycl::long16>();
check<SomeMarrayStructure>();
}