Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit a621ef9

Browse files
author
Pavel Samolysov
authored
[SYCL] Extend the SpecConstants/vector-convolution-demo.cpp test (#830)
The test is extended with a specialization constant built upon an aligned structure. The CFE generates a padding represented as '[size x i8] undef' for such structures and the sycl-post-link tool crashed during property set generation for the specialization constant. The bug has been fixed in intel/llvm#5538, this extension is the E2E test for the fix to ensure that the default values and offsets given to the runtime are correct. Signed-off-by: Pavel Samolysov <[email protected]>
1 parent a45c46d commit a621ef9

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed

SYCL/SpecConstants/2020/vector-convolution-demo.cpp

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,44 @@ struct coeff_struct_t {
2424
std::array<std::array<float, 3>, 3> c;
2525
};
2626

27-
coeff_t get_coefficients() {
28-
return {{{1.0, 2.0, 3.0}, {1.1, 2.1, 3.1}, {1.2, 2.2, 3.2}}};
29-
}
27+
struct alignas(64) coeff_struct_aligned_t {
28+
std::array<std::array<float, 3>, 3> c;
29+
};
30+
31+
struct alignas(64) coeff_struct_aligned2_t {
32+
std::array<std::array<float, 3>, 3> c;
33+
int number;
34+
};
3035

31-
coeff_struct_t get_coefficient_struct() {
36+
template <typename T> constexpr T get_coefficients() {
3237
return {{{{1.0, 2.0, 3.0}, {1.1, 2.1, 3.1}, {1.2, 2.2, 3.2}}}};
3338
}
3439

40+
template <> constexpr coeff_t get_coefficients<coeff_t>() {
41+
return {{{1.0, 2.0, 3.0}, {1.1, 2.1, 3.1}, {1.2, 2.2, 3.2}}};
42+
}
43+
3544
constexpr specialization_id<coeff_t> coeff_id;
3645

3746
constexpr specialization_id<coeff_struct_t> coeff_struct_id;
3847

48+
// Represented in the IR as
49+
// clang-format off
50+
// { %struct.coeff_struct_aligned_t { %"class.std::array.0" zeroinitializer, [28 x i8] undef } }
51+
// ~ padding ~
52+
// clang-format on
53+
constexpr specialization_id<coeff_struct_aligned_t> coeff_struct_aligned_id;
54+
55+
// An extra specialization constant to check whether the runtime correctly
56+
// calculates the sizes and offsets of the specialization constants with
57+
// padding.
58+
// Represented in the IR as
59+
// clang-format off
60+
// { %struct.coeff_struct_aligned2_t { %"class.std::array.0" zeroinitializer, i32 0, [24 x i8] undef } }
61+
// ~ padding ~
62+
// clang-format on
63+
constexpr specialization_id<coeff_struct_aligned2_t> coeff_struct_aligned_id2;
64+
3965
template <typename IN>
4066
float calc_conv(const coeff_t &coeff, const IN &in, item<2> item_id) {
4167
float acc = 0;
@@ -64,8 +90,13 @@ void do_conv(buffer<float, 2> in, buffer<float, 2> out, CP coeff_provider) {
6490

6591
// Set the coefficient of the convolution as constant.
6692
// This will build a specific kernel the coefficient available as literals.
67-
cgh.set_specialization_constant<coeff_id>(get_coefficients());
68-
cgh.set_specialization_constant<coeff_struct_id>(get_coefficient_struct());
93+
cgh.set_specialization_constant<coeff_id>(get_coefficients<coeff_t>());
94+
cgh.set_specialization_constant<coeff_struct_id>(
95+
get_coefficients<coeff_struct_t>());
96+
cgh.set_specialization_constant<coeff_struct_aligned_id>(
97+
get_coefficients<coeff_struct_aligned_t>());
98+
cgh.set_specialization_constant<coeff_struct_aligned_id2>(
99+
get_coefficients<coeff_struct_aligned2_t>());
69100
cgh.parallel_for<KernelName>(
70101
in.get_range(), [=](item<2> item_id, kernel_handler h) {
71102
auto coeff = coeff_provider(h);
@@ -126,6 +157,18 @@ int main() {
126157

127158
compare_result(host_accessor{output, read_only}, expected);
128159

160+
do_conv<class Convolution3>(input, output, [](kernel_handler &h) {
161+
return h.get_specialization_constant<coeff_struct_aligned_id>().c;
162+
});
163+
164+
compare_result(host_accessor{output, read_only}, expected);
165+
166+
do_conv<class Convolution4>(input, output, [](kernel_handler &h) {
167+
return h.get_specialization_constant<coeff_struct_aligned_id2>().c;
168+
});
169+
170+
compare_result(host_accessor{output, read_only}, expected);
171+
129172
std::cout << "Good computation!" << std::endl;
130173
return 0;
131174
}

0 commit comments

Comments
 (0)