Skip to content

Commit 4d15c28

Browse files
author
Alexander Batashev
authored
[SYCL][NFC] Check alignment for key SYCL types (#2788)
Alignment of the type is part of ABI. Changing type aligment is a breaking change. Cover this with tests.
1 parent dab9deb commit 4d15c28

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

sycl/test/abi/symbol_size.cpp

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clangxx -fsycl %s -o %t
22

3-
// Changing symbol size is a breaking change. If it happens, refer to the ABI
4-
// Policy Guide for further instructions on breaking ABI.
3+
// Changing symbol size or alignment is a breaking change. If it happens, refer
4+
// to the ABI Policy Guide for further instructions on breaking ABI.
55

66
#include <CL/sycl/accessor.hpp>
77
#include <CL/sycl/buffer.hpp>
@@ -21,58 +21,71 @@
2121
#include <CL/sycl/queue.hpp>
2222
#include <CL/sycl/sampler.hpp>
2323
#include <CL/sycl/stream.hpp>
24+
#include <CL/sycl/types.hpp>
2425

2526
using namespace cl::sycl;
2627

27-
template <int newSize, int oldSize>
28-
void check_size() {
28+
template <int newSize, int oldSize> void check_size() {
2929
static_assert(newSize == oldSize, "Symbol size has changed.");
3030
}
3131

32-
template <typename T, size_t oldSize>
33-
void check_size() {
32+
template <int newAlignment, int oldAlignment> void check_alignment() {
33+
static_assert(newAlignment == oldAlignment, "Alignment has changed");
34+
}
35+
36+
template <typename T, size_t oldSize, size_t oldAlignment> void check() {
3437
check_size<sizeof(T), oldSize>();
38+
check_alignment<alignof(T), oldAlignment>();
3539
}
3640

3741
int main() {
3842
using accessor_t = accessor<int, 1, access::mode::read,
3943
access::target::global_buffer,
4044
access::placeholder::true_t>;
41-
check_size<accessor_t, 32>();
42-
check_size<detail::AccessorImplDevice<1>, 24>();
43-
check_size<detail::LocalAccessorBaseDevice<1>, 24>();
44-
check_size<detail::AccessorImplHost, 128>();
45-
check_size<detail::AccessorBaseHost, 16>();
46-
check_size<detail::LocalAccessorImplHost, 56>();
47-
check_size<buffer<int>, 40>();
48-
check_size<context, 16>();
49-
check_size<cpu_selector, 8>();
50-
check_size<device, 16>();
51-
check_size<device_event, 8>();
52-
check_size<device_selector, 8>();
53-
check_size<event, 16>();
54-
check_size<gpu_selector, 8>();
45+
check<accessor_t, 32, 8>();
46+
check<detail::AccessorImplDevice<1>, 24, 8>();
47+
check<detail::LocalAccessorBaseDevice<1>, 24, 8>();
48+
check<detail::AccessorImplHost, 128, 8>();
49+
check<detail::AccessorBaseHost, 16, 8>();
50+
check<detail::LocalAccessorImplHost, 56, 8>();
51+
check<buffer<int>, 40, 8>();
52+
check<context, 16, 8>();
53+
check<cpu_selector, 8, 8>();
54+
check<device, 16, 8>();
55+
check<device_event, 8, 8>();
56+
check<device_selector, 8, 8>();
57+
check<event, 16, 8>();
58+
check<gpu_selector, 8, 8>();
5559
#ifdef _MSC_VER
56-
check_size<handler, 552>();
57-
check_size<detail::buffer_impl, 216>();
58-
check_size<detail::image_impl<1>, 272>();
60+
check<handler, 552, 8>();
61+
check<detail::buffer_impl, 216, 8>();
62+
check<detail::image_impl<1>, 272, 8>();
5963
#else
60-
check_size<handler, 560>();
61-
check_size<detail::buffer_impl, 184>();
62-
check_size<detail::image_impl<1>, 240>();
64+
check<handler, 560, 8>();
65+
check<detail::buffer_impl, 184, 8>();
66+
check<detail::image_impl<1>, 240, 8>();
6367
#endif
64-
check_size<image<1>, 16>();
65-
check_size<kernel, 16>();
66-
check_size<platform, 16>();
68+
check<image<1>, 16, 8>();
69+
check<kernel, 16, 8>();
70+
check<platform, 16, 8>();
6771
#ifdef __SYCL_DEVICE_ONLY__
68-
check_size<private_memory<int, 1>, 4>();
69-
check_size<detail::sampler_impl, 8>();
72+
check<private_memory<int, 1>, 4, 4>();
73+
check<detail::sampler_impl, 8, 8>();
7074
#endif
71-
check_size<program, 16>();
72-
check_size<range<1>, 8>();
73-
check_size<sampler, 16>();
74-
check_size<stream, 144>();
75-
check_size<queue, 16>();
75+
check<program, 16, 8>();
76+
check<range<1>, 8, 8>();
77+
check<sampler, 16, 8>();
78+
check<stream, 144, 8>();
79+
check<queue, 16, 8>();
80+
check<vec<float, 1>, 4, 4>();
81+
check<vec<float, 2>, 8, 8>();
82+
check<vec<float, 4>, 16, 16>();
83+
check<vec<float, 8>, 32, 32>();
84+
check<vec<float, 16>, 64, 64>();
85+
check<vec<double, 1>, 8, 8>();
86+
check<vec<double, 2>, 16, 16>();
87+
check<vec<double, 4>, 32, 32>();
88+
check<vec<double, 8>, 64, 64>();
7689

7790
return 0;
7891
}

0 commit comments

Comments
 (0)