diff --git a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp index 5284391f00..4a04f6956a 100644 --- a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp +++ b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp @@ -24,18 +24,44 @@ struct coeff_struct_t { std::array, 3> c; }; -coeff_t get_coefficients() { - return {{{1.0, 2.0, 3.0}, {1.1, 2.1, 3.1}, {1.2, 2.2, 3.2}}}; -} +struct alignas(64) coeff_struct_aligned_t { + std::array, 3> c; +}; + +struct alignas(64) coeff_struct_aligned2_t { + std::array, 3> c; + int number; +}; -coeff_struct_t get_coefficient_struct() { +template constexpr T get_coefficients() { return {{{{1.0, 2.0, 3.0}, {1.1, 2.1, 3.1}, {1.2, 2.2, 3.2}}}}; } +template <> constexpr coeff_t get_coefficients() { + return {{{1.0, 2.0, 3.0}, {1.1, 2.1, 3.1}, {1.2, 2.2, 3.2}}}; +} + constexpr specialization_id coeff_id; constexpr specialization_id coeff_struct_id; +// Represented in the IR as +// clang-format off +// { %struct.coeff_struct_aligned_t { %"class.std::array.0" zeroinitializer, [28 x i8] undef } } +// ~ padding ~ +// clang-format on +constexpr specialization_id coeff_struct_aligned_id; + +// An extra specialization constant to check whether the runtime correctly +// calculates the sizes and offsets of the specialization constants with +// padding. +// Represented in the IR as +// clang-format off +// { %struct.coeff_struct_aligned2_t { %"class.std::array.0" zeroinitializer, i32 0, [24 x i8] undef } } +// ~ padding ~ +// clang-format on +constexpr specialization_id coeff_struct_aligned_id2; + template float calc_conv(const coeff_t &coeff, const IN &in, item<2> item_id) { float acc = 0; @@ -64,8 +90,13 @@ void do_conv(buffer in, buffer out, CP coeff_provider) { // Set the coefficient of the convolution as constant. // This will build a specific kernel the coefficient available as literals. - cgh.set_specialization_constant(get_coefficients()); - cgh.set_specialization_constant(get_coefficient_struct()); + cgh.set_specialization_constant(get_coefficients()); + cgh.set_specialization_constant( + get_coefficients()); + cgh.set_specialization_constant( + get_coefficients()); + cgh.set_specialization_constant( + get_coefficients()); cgh.parallel_for( in.get_range(), [=](item<2> item_id, kernel_handler h) { auto coeff = coeff_provider(h); @@ -126,6 +157,18 @@ int main() { compare_result(host_accessor{output, read_only}, expected); + do_conv(input, output, [](kernel_handler &h) { + return h.get_specialization_constant().c; + }); + + compare_result(host_accessor{output, read_only}, expected); + + do_conv(input, output, [](kernel_handler &h) { + return h.get_specialization_constant().c; + }); + + compare_result(host_accessor{output, read_only}, expected); + std::cout << "Good computation!" << std::endl; return 0; }