From 816ae07efd139fb99ba1166d79e198f181e12f67 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Fri, 11 Feb 2022 09:57:49 +0300 Subject: [PATCH 1/4] [SYCL] Extend the SpecConstants/vector-convolution-demo.cpp test 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 --- .../2020/vector-convolution-demo.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp index 5284391f00..812102be03 100644 --- a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp +++ b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp @@ -24,6 +24,10 @@ struct coeff_struct_t { std::array, 3> c; }; +struct alignas(64) coeff_struct_aligned_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}}}; } @@ -32,10 +36,21 @@ coeff_struct_t get_coefficient_struct() { return {{{{1.0, 2.0, 3.0}, {1.1, 2.1, 3.1}, {1.2, 2.2, 3.2}}}}; } +// 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 +coeff_struct_aligned_t get_coefficient_struct_aligned() { + 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; +constexpr specialization_id coeff_struct_aligned_id; + template float calc_conv(const coeff_t &coeff, const IN &in, item<2> item_id) { float acc = 0; @@ -66,6 +81,8 @@ void do_conv(buffer in, buffer out, CP coeff_provider) { // 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_coefficient_aligned_struct()); cgh.parallel_for( in.get_range(), [=](item<2> item_id, kernel_handler h) { auto coeff = coeff_provider(h); @@ -126,6 +143,12 @@ 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); + std::cout << "Good computation!" << std::endl; return 0; } From 0b6c2137ec24f2580b4b9e1bde7d83aa394ddbe4 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Fri, 11 Feb 2022 13:09:50 +0300 Subject: [PATCH 2/4] [SYCL] Fix compilation error in vector-convolution-demo.cpp --- SYCL/SpecConstants/2020/vector-convolution-demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp index 812102be03..00f5e0fd6a 100644 --- a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp +++ b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp @@ -82,7 +82,7 @@ void do_conv(buffer in, buffer out, CP coeff_provider) { cgh.set_specialization_constant(get_coefficients()); cgh.set_specialization_constant(get_coefficient_struct()); cgh.set_specialization_constant( - get_coefficient_aligned_struct()); + get_coefficient_struct_aligned()); cgh.parallel_for( in.get_range(), [=](item<2> item_id, kernel_handler h) { auto coeff = coeff_provider(h); From 737b320a2544d53911bc77e7e0b128c36bbf2594 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Tue, 15 Feb 2022 14:17:55 +0300 Subject: [PATCH 3/4] Add a second spec. constant with padding An extra specialization constant is required to check whether the runtime correctly calculates the sizes and offsets of the specialization constants with padding. Signed-off-by: Pavel Samolysov --- .../2020/vector-convolution-demo.cpp | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp index 00f5e0fd6a..f6a0fe6967 100644 --- a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp +++ b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp @@ -28,29 +28,42 @@ struct alignas(64) coeff_struct_aligned_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_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}}}}; } -// 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 -coeff_struct_aligned_t get_coefficient_struct_aligned() { - 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; @@ -79,10 +92,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_coefficient_struct_aligned()); + 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); @@ -149,6 +165,12 @@ 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); + std::cout << "Good computation!" << std::endl; return 0; } From 3a4b86a3f7b8b14219b2924b8c2a24dccfdce0e4 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Tue, 15 Feb 2022 14:44:38 +0300 Subject: [PATCH 4/4] [NFC] Fix formatting issues Signed-off-by: Pavel Samolysov --- SYCL/SpecConstants/2020/vector-convolution-demo.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp index f6a0fe6967..4a04f6956a 100644 --- a/SYCL/SpecConstants/2020/vector-convolution-demo.cpp +++ b/SYCL/SpecConstants/2020/vector-convolution-demo.cpp @@ -33,13 +33,11 @@ struct alignas(64) coeff_struct_aligned2_t { int number; }; -template -constexpr T get_coefficients() { +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() { +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}}}; }