From 152821a0ce1ab3848b271b4bcfd1ac19d1f07aa1 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Wed, 17 Jan 2024 05:52:36 -0800 Subject: [PATCH 1/6] Fix `-Wc++11-narrowing` warnings Newer versions of `clang` make it error by default, which affect clang-based implementations (like DPCPP). --- tests/common/type_list.h | 56 +++++++++++++------ tests/spec_constants/spec_constants_common.h | 4 +- .../spec_constants_defined_various_ways.h | 4 +- ...ec_constants_defined_various_ways_helper.h | 18 +++--- ...pec_constants_exceptions_throwing_common.h | 4 +- .../spec_constants/spec_constants_external.h | 10 ++-- .../spec_constants/spec_constants_multiple.h | 14 ++--- ...spec_constants_same_command_group_common.h | 14 ++--- .../spec_constants_same_name_inter_link.h | 8 +-- ...ec_constants_same_name_inter_link_helper.h | 2 +- .../spec_constants_same_name_stress_helper.h | 20 +++---- .../spec_constants_separate_unit.cpp | 2 +- .../spec_constants_via_handler_common.h | 30 +++++----- .../spec_constants_via_kernel_bundle.h | 8 +-- 14 files changed, 110 insertions(+), 84 deletions(-) diff --git a/tests/common/type_list.h b/tests/common/type_list.h index 64ad0f270..c6476c117 100644 --- a/tests/common/type_list.h +++ b/tests/common/type_list.h @@ -164,31 +164,55 @@ struct arrow_operator_overloaded { // Returns instance of type T template -inline constexpr auto get_init_value_helper(int x) { - return x; -} +struct init_value_helper { + static constexpr auto get(int x) { + return static_cast(x); + } +}; + +// Returns instance of type T +template +struct init_value_helper> { + static constexpr auto get(int x) { + return sycl::vec{static_cast(x)}; + } +}; + +// Returns instance of type T +template +struct init_value_helper> { + static constexpr auto get(int x) { + return sycl::marray{static_cast(x)}; + } +}; // Returns instance of type bool template <> -inline constexpr auto get_init_value_helper(int x) { - return (x % 2 != 0); -} +struct init_value_helper { + static constexpr bool get(int x) { + return x % 2 != 0; + } +}; // Returns instance of user defined struct with no constructor template <> -inline constexpr auto get_init_value_helper(int x) { - no_cnstr instance{}; - instance = x; - return instance; -} +struct init_value_helper { + static constexpr auto get(int x) { + no_cnstr instance{}; + instance = x; + return instance; + } +}; // Returns instance of user defined struct default constructor template <> -inline constexpr auto get_init_value_helper(int x) { - def_cnstr instance; - instance = x; - return instance; -} +struct init_value_helper { + static constexpr auto get(int x) { + def_cnstr instance; + instance = x; + return instance; + } +}; } // namespace user_def_types diff --git a/tests/spec_constants/spec_constants_common.h b/tests/spec_constants/spec_constants_common.h index ab4d8a1d3..68d7fd723 100644 --- a/tests/spec_constants/spec_constants_common.h +++ b/tests/spec_constants/spec_constants_common.h @@ -48,11 +48,11 @@ constexpr int default_val = 20; template constexpr sycl::specialization_id spec_const( - user_def_types::get_init_value_helper(default_val)); + user_def_types::init_value_helper::get(default_val)); template void fill_init_values(T &result, int val) { - result = user_def_types::get_init_value_helper(val); + result = user_def_types::init_value_helper::get(val); } template diff --git a/tests/spec_constants/spec_constants_defined_various_ways.h b/tests/spec_constants/spec_constants_defined_various_ways.h index 0f52b6f43..c45ac2d52 100644 --- a/tests/spec_constants/spec_constants_defined_various_ways.h +++ b/tests/spec_constants/spec_constants_defined_various_ways.h @@ -35,8 +35,8 @@ void perform_test(util::logger &log, const std::string &type_name, } } sycl::range<1> range(1); - T result { user_def_types::get_init_value_helper(0) }; - T ref { user_def_types::get_init_value_helper(0) }; + T result { user_def_types::init_value_helper::get(0) }; + T ref { user_def_types::init_value_helper::get(0) }; { fill_init_values(ref, case_num); sycl::buffer result_buffer(&result, range); diff --git a/tests/spec_constants/spec_constants_defined_various_ways_helper.h b/tests/spec_constants/spec_constants_defined_various_ways_helper.h index 7482205ce..036881309 100644 --- a/tests/spec_constants/spec_constants_defined_various_ways_helper.h +++ b/tests/spec_constants/spec_constants_defined_various_ways_helper.h @@ -56,14 +56,14 @@ static std::string get_hint(sc_vw_id test_id) { // Defined in a non-global named namespace template constexpr sycl::specialization_id sc_nonglob( - user_def_types::get_init_value_helper(case_num)); + user_def_types::init_value_helper::get(case_num)); // A static member variable of a struct in a non-global namespace struct struct_nonglob { constexpr struct_nonglob() {} template static constexpr sycl::specialization_id sc{ - user_def_types::get_init_value_helper(case_num)}; + user_def_types::init_value_helper::get(case_num)}; }; } // namespace spec_const_help @@ -71,33 +71,33 @@ namespace { // Defined in an unnamed namespace template constexpr sycl::specialization_id sc_unnamed( - user_def_types::get_init_value_helper(case_num)); + user_def_types::init_value_helper::get(case_num)); // A static member variable of a struct in an unnamed namespace struct struct_unnamed { constexpr struct_unnamed() {} template static constexpr sycl::specialization_id sc{ - user_def_types::get_init_value_helper(case_num)}; + user_def_types::init_value_helper::get(case_num)}; }; } // unnamed namespace // Defined in the global namespace as inline constexpr template inline constexpr sycl::specialization_id sc_glob_inl( - user_def_types::get_init_value_helper(case_num)); + user_def_types::init_value_helper::get(case_num)); // Defined in the global namespace as static constexpr template static constexpr sycl::specialization_id sc_glob_static( - user_def_types::get_init_value_helper(case_num)); + user_def_types::init_value_helper::get(case_num)); // A static member variable of a struct in the global namespace struct struct_glob { constexpr struct_glob() {} template static constexpr sycl::specialization_id sc{ - user_def_types::get_init_value_helper(case_num)}; + user_def_types::init_value_helper::get(case_num)}; }; // A static member variable declared inline constexpr of a struct in the global @@ -106,7 +106,7 @@ struct struct_glob_inl { constexpr struct_glob_inl() {} template static inline constexpr sycl::specialization_id sc{ - user_def_types::get_init_value_helper(case_num)}; + user_def_types::init_value_helper::get(case_num)}; }; // A static member variable of a templated struct in the global namespace @@ -115,7 +115,7 @@ struct struct_glob_tmpl { constexpr struct_glob_tmpl() {} template static constexpr sycl::specialization_id sc{ - user_def_types::get_init_value_helper(case_num)}; + user_def_types::init_value_helper::get(case_num)}; }; #endif // __SYCLCTS_TESTS_SPEC_CONST_DEFINED_VARIOUS_WAYS_HELPER_H diff --git a/tests/spec_constants/spec_constants_exceptions_throwing_common.h b/tests/spec_constants/spec_constants_exceptions_throwing_common.h index 63f13cbfa..2d0eb9601 100644 --- a/tests/spec_constants/spec_constants_exceptions_throwing_common.h +++ b/tests/spec_constants/spec_constants_exceptions_throwing_common.h @@ -51,7 +51,7 @@ class check_spec_constant_exception_throw_for_type { // kernel_bundle { bool exception_was_thrown = false; - T res{user_def_types::get_init_value_helper(0)}; + T res{user_def_types::init_value_helper::get(0)}; const int case_num = 1; auto queue = sycl_cts::util::get_cts_object::queue(); @@ -85,7 +85,7 @@ class check_spec_constant_exception_throw_for_type { // kernel_bundle { bool exception_was_thrown = false; - T sc_val{user_def_types::get_init_value_helper(0)}; + T sc_val{user_def_types::init_value_helper::get(0)}; const int case_num = 2; auto queue = sycl_cts::util::get_cts_object::queue(); diff --git a/tests/spec_constants/spec_constants_external.h b/tests/spec_constants/spec_constants_external.h index 472af54e7..b297de2ce 100644 --- a/tests/spec_constants/spec_constants_external.h +++ b/tests/spec_constants/spec_constants_external.h @@ -17,7 +17,7 @@ using namespace get_spec_const; template inline constexpr sycl::specialization_id spec_const_external( - user_def_types::get_init_value_helper(default_val)); + user_def_types::init_value_helper::get(default_val)); #define FUNC_DECLARE(TYPE) \ SYCL_EXTERNAL bool check_kernel_handler_by_reference_external_handler( \ @@ -74,7 +74,7 @@ class check_specialization_constants_external { // handler bool passed = false; { - T ref { user_def_types::get_init_value_helper(5) }; + T ref { user_def_types::init_value_helper::get(5) }; const int case_num = static_cast(test_cases_external::by_reference_via_handler); sycl::buffer result_buffer(&passed, range); @@ -99,7 +99,7 @@ class check_specialization_constants_external { // handler passed = false; { - T ref { user_def_types::get_init_value_helper(10) }; + T ref { user_def_types::init_value_helper::get(10) }; const int case_num = static_cast(test_cases_external::by_value_via_handler); sycl::buffer result_buffer(&passed, range); @@ -128,7 +128,7 @@ class check_specialization_constants_external { // via kernel_bundle passed = false; { - T ref { user_def_types::get_init_value_helper(15) }; + T ref { user_def_types::init_value_helper::get(15) }; const int case_num = static_cast(test_cases_external::by_reference_via_bundle); sycl::buffer result_buffer(&passed, range); @@ -170,7 +170,7 @@ class check_specialization_constants_external { // kernel_bundle passed = false; { - T ref { user_def_types::get_init_value_helper(20) }; + T ref { user_def_types::init_value_helper::get(20) }; const int case_num = static_cast(test_cases_external::by_value_via_bundle); sycl::buffer result_buffer(&passed, range); diff --git a/tests/spec_constants/spec_constants_multiple.h b/tests/spec_constants/spec_constants_multiple.h index 71b8d8168..48c206fbe 100644 --- a/tests/spec_constants/spec_constants_multiple.h +++ b/tests/spec_constants/spec_constants_multiple.h @@ -16,7 +16,7 @@ template constexpr sycl::specialization_id sc_multiple( - user_def_types::get_init_value_helper(def_val)); + user_def_types::init_value_helper::get(def_val)); namespace specialization_constants_multiple { using namespace sycl_cts; @@ -57,9 +57,9 @@ class check_specialization_constants_multiple_for_type { int val_A = 5; int val_B = 10; int val_C = 30; - T ref1{user_def_types::get_init_value_helper(0)}; - T ref2{user_def_types::get_init_value_helper(0)}; - T ref3{user_def_types::get_init_value_helper(0)}; + T ref1{user_def_types::init_value_helper::get(0)}; + T ref2{user_def_types::init_value_helper::get(0)}; + T ref3{user_def_types::init_value_helper::get(0)}; fill_init_values(ref1, val_A); fill_init_values(ref2, val_B); fill_init_values(ref3, val_C); @@ -115,13 +115,13 @@ class check_specialization_constants_multiple_for_type { !check_equal_values(ref2, result_vec[1].value) || !check_equal_values(ref3, result_vec[2].value) || !check_equal_values( - T(user_def_types::get_init_value_helper(def_values[3])), + T(user_def_types::init_value_helper::get(def_values[3])), result_vec[3].value) || !check_equal_values( - T(user_def_types::get_init_value_helper(def_values[4])), + T(user_def_types::init_value_helper::get(def_values[4])), result_vec[4].value) || !check_equal_values( - T(user_def_types::get_init_value_helper(def_values[5])), + T(user_def_types::init_value_helper::get(def_values[5])), result_vec[5].value)) FAIL(log, "multiple spec const for " + type_name_string::get(type_name)); diff --git a/tests/spec_constants/spec_constants_same_command_group_common.h b/tests/spec_constants/spec_constants_same_command_group_common.h index 3cdfc3cff..6a2ae2c66 100644 --- a/tests/spec_constants/spec_constants_same_command_group_common.h +++ b/tests/spec_constants/spec_constants_same_command_group_common.h @@ -46,13 +46,13 @@ template class check_specialization_constants_same_command_group { public: void operator()(util::logger &log, const std::string &type_name) { - T ref_A{user_def_types::get_init_value_helper(5)}; - T ref_B{user_def_types::get_init_value_helper(10)}; + T ref_A{user_def_types::init_value_helper::get(5)}; + T ref_B{user_def_types::init_value_helper::get(10)}; auto queue = util::get_cts_object::queue(); sycl::range<1> range(1); { - T result1{user_def_types::get_init_value_helper(0)}; - T result2{user_def_types::get_init_value_helper(0)}; + T result1{user_def_types::init_value_helper::get(0)}; + T result2{user_def_types::init_value_helper::get(0)}; { command_group_object cmo; sycl::buffer result_buffer1(&result1, range); @@ -73,8 +73,8 @@ class check_specialization_constants_same_command_group { } { - T result1{user_def_types::get_init_value_helper(0)}; - T result2{user_def_types::get_init_value_helper(0)}; + T result1{user_def_types::init_value_helper::get(0)}; + T result2{user_def_types::init_value_helper::get(0)}; { command_group_object cmo; sycl::buffer result_buffer1(&result1, range); @@ -91,7 +91,7 @@ class check_specialization_constants_same_command_group { if (!check_equal_values(ref_A, result1)) FAIL(log, "case 2 failed for value A for " + type_name); if (!check_equal_values( - T(user_def_types::get_init_value_helper(default_val)), + T(user_def_types::init_value_helper::get(default_val)), result2)) FAIL(log, "case 2 failed for default value for " + type_name); } diff --git a/tests/spec_constants/spec_constants_same_name_inter_link.h b/tests/spec_constants/spec_constants_same_name_inter_link.h index d341294e3..3587d5822 100644 --- a/tests/spec_constants/spec_constants_same_name_inter_link.h +++ b/tests/spec_constants/spec_constants_same_name_inter_link.h @@ -48,10 +48,10 @@ class check_specialization_constants_same_name_inter_link_for_type { } } sycl::range<1> range(1); - T def_value{user_def_types::get_init_value_helper(0)}; - T ref_def_value{user_def_types::get_init_value_helper(0)}; - T result{user_def_types::get_init_value_helper(0)}; - T ref{user_def_types::get_init_value_helper(0)}; + T def_value{user_def_types::init_value_helper::get(0)}; + T ref_def_value{user_def_types::init_value_helper::get(0)}; + T result{user_def_types::init_value_helper::get(0)}; + T ref{user_def_types::init_value_helper::get(0)}; { // Setting ref values according to TU number fill_init_values(ref_def_value, TestConfig::tu); diff --git a/tests/spec_constants/spec_constants_same_name_inter_link_helper.h b/tests/spec_constants/spec_constants_same_name_inter_link_helper.h index a47863335..7c5f7ebcf 100644 --- a/tests/spec_constants/spec_constants_same_name_inter_link_helper.h +++ b/tests/spec_constants/spec_constants_same_name_inter_link_helper.h @@ -30,7 +30,7 @@ namespace { // SC_SN_IL_TU_NUM is defined in every TU template constexpr sycl::specialization_id sc_same_name_inter_link( - user_def_types::get_init_value_helper(SC_SN_IL_TU_NUM)); + user_def_types::init_value_helper::get(SC_SN_IL_TU_NUM)); } // namespace diff --git a/tests/spec_constants/spec_constants_same_name_stress_helper.h b/tests/spec_constants/spec_constants_same_name_stress_helper.h index db75b3d3d..779c5fea4 100644 --- a/tests/spec_constants/spec_constants_same_name_stress_helper.h +++ b/tests/spec_constants/spec_constants_same_name_stress_helper.h @@ -56,21 +56,21 @@ static std::string get_hint(int test_id) { // Specialization constant defined in global namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::glob))); namespace g_outer { // Specialization constant defined in outer namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::outer))); namespace g_inner { // Specialization constant defined in outer::inner namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::outer_inner))); } // namespace g_inner @@ -78,7 +78,7 @@ namespace { // Specialization constant defined in outer::unnamed namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::outer_unnamed))); template @@ -88,7 +88,7 @@ namespace g_u_inner { // Specialization constant defined in outer::unnamed::inner namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::outer_unnamed_inner))); template @@ -99,7 +99,7 @@ namespace { // namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::outer_unnamed_inner_unnamed))); template @@ -113,7 +113,7 @@ namespace { // Specialization constant defined in unnamed namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::unnamed))); template @@ -123,7 +123,7 @@ namespace u_outer { // Specialization constant defined in unnamed::outer namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::unnamed_outer))); template @@ -133,7 +133,7 @@ namespace { // Specialization constant defined in unnamed::outer::unnamed namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::unnamed_outer_unnamed))); template @@ -144,7 +144,7 @@ namespace u_inner { // namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( to_integral(spec_const_help::sc_st_id::unnamed_outer_unnamed_inner))); template diff --git a/tests/spec_constants/spec_constants_separate_unit.cpp b/tests/spec_constants/spec_constants_separate_unit.cpp index a801371d8..a52113f81 100644 --- a/tests/spec_constants/spec_constants_separate_unit.cpp +++ b/tests/spec_constants/spec_constants_separate_unit.cpp @@ -14,7 +14,7 @@ using namespace get_spec_const; template inline constexpr sycl::specialization_id spec_const_external( - user_def_types::get_init_value_helper(default_val)); + user_def_types::init_value_helper::get(default_val)); template bool check_kernel_handler_by_reference_external(sycl::kernel_handler &h, diff --git a/tests/spec_constants/spec_constants_via_handler_common.h b/tests/spec_constants/spec_constants_via_handler_common.h index 410cade48..c545ecf50 100644 --- a/tests/spec_constants/spec_constants_via_handler_common.h +++ b/tests/spec_constants/spec_constants_via_handler_common.h @@ -22,14 +22,14 @@ inline constexpr int val_A = 5; template constexpr sycl::specialization_id sc_multiple( - user_def_types::get_init_value_helper(case_num)); + user_def_types::init_value_helper::get(case_num)); template class kernel; template bool check_kernel_handler_by_reference(sycl::kernel_handler &h) { - T ref{user_def_types::get_init_value_helper(0)}; + T ref{user_def_types::init_value_helper::get(0)}; fill_init_values(ref, val_A); return check_equal_values( ref, h.get_specialization_constant>()); @@ -37,7 +37,7 @@ bool check_kernel_handler_by_reference(sycl::kernel_handler &h) { template bool check_kernel_handler_by_value(sycl::kernel_handler h) { - T ref{user_def_types::get_init_value_helper(0)}; + T ref{user_def_types::init_value_helper::get(0)}; fill_init_values(ref, val_A); return check_equal_values( ref, h.get_specialization_constant>()); @@ -49,9 +49,9 @@ class check_spec_constant_with_handler_for_type { void operator()(util::logger &log, const std::string &type_name) { auto queue = util::get_cts_object::queue(); sycl::range<1> range(1); - T result{user_def_types::get_init_value_helper(0)}; - T ref{user_def_types::get_init_value_helper(0)}; - T ref_other{user_def_types::get_init_value_helper(0)}; + T result{user_def_types::init_value_helper::get(0)}; + T ref{user_def_types::init_value_helper::get(0)}; + T ref_other{user_def_types::init_value_helper::get(0)}; int val_B = 10; fill_init_values(ref, val_A); fill_init_values(ref_other, val_B); @@ -59,7 +59,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 1; { - result = user_def_types::get_init_value_helper(0); + result = user_def_types::init_value_helper::get(0); queue.submit([&](sycl::handler &cgh) { cgh.set_specialization_constant>(ref); result = cgh.get_specialization_constant>(); @@ -74,7 +74,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 2; { - result = user_def_types::get_init_value_helper(0); + result = user_def_types::init_value_helper::get(0); queue.submit([&](sycl::handler &cgh) { cgh.set_specialization_constant>(ref); cgh.set_specialization_constant>(ref_other); @@ -91,7 +91,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 3; { - result = user_def_types::get_init_value_helper(0); + result = user_def_types::init_value_helper::get(0); sycl::buffer result_buffer(&result, range); queue.submit([&](sycl::handler &cgh) { auto res_acc = @@ -113,7 +113,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 4; { - result = user_def_types::get_init_value_helper(0); + result = user_def_types::init_value_helper::get(0); sycl::buffer result_buffer(&result, range); queue.submit([&](sycl::handler &cgh) { auto res_acc = @@ -164,13 +164,14 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 6; { - result = user_def_types::get_init_value_helper(0); + result = user_def_types::init_value_helper::get(0); queue.submit([&](sycl::handler &cgh) { result = cgh.get_specialization_constant>(); }); } if (!check_equal_values( - T(user_def_types::get_init_value_helper(default_val)), result)) + T(user_def_types::init_value_helper::get(default_val)), + result)) FAIL(log, "case " + std::to_string(case_num) + " for " + type_name_string::get(type_name)); } @@ -180,7 +181,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 7; { - result = user_def_types::get_init_value_helper(0); + result = user_def_types::init_value_helper::get(0); sycl::buffer result_buffer(&result, range); queue.submit([&](sycl::handler &cgh) { auto res_acc = @@ -192,7 +193,8 @@ class check_spec_constant_with_handler_for_type { }); } if (!check_equal_values( - T(user_def_types::get_init_value_helper(default_val)), result)) + T(user_def_types::init_value_helper::get(default_val)), + result)) FAIL(log, "case " + std::to_string(case_num) + " for " + type_name_string::get(type_name)); } diff --git a/tests/spec_constants/spec_constants_via_kernel_bundle.h b/tests/spec_constants/spec_constants_via_kernel_bundle.h index caf2704a2..2c515d5e2 100644 --- a/tests/spec_constants/spec_constants_via_kernel_bundle.h +++ b/tests/spec_constants/spec_constants_via_kernel_bundle.h @@ -136,7 +136,7 @@ struct values> : values {}; */ template constexpr sycl::specialization_id spec_const_by_kernel_bundle( - user_def_types::get_init_value_helper( + user_def_types::init_value_helper::get( specialization_constants_via_kernel_bundle::values::initial)); namespace specialization_constants_via_kernel_bundle { @@ -300,7 +300,7 @@ void set_value(sycl::kernel_bundle& bundle) { " set_specialization_constant"); for (int i = 0; i < id::n_set; ++i) { // Prepare value to store - T value { user_def_types::get_init_value_helper(0) }; + T value { user_def_types::init_value_helper::get(0) }; fill_init_values(value, values::reference(i)); bundle.template set_specialization_constant< @@ -323,11 +323,11 @@ bool check_value(specStorageT&& storage) { using namespace get_spec_const; // Prepare to read value - T value { user_def_types::get_init_value_helper(0) }; + T value { user_def_types::init_value_helper::get(0) }; fill_init_values(value, values::empty); // Prepare to compare values - T expected { user_def_types::get_init_value_helper(0) }; + T expected { user_def_types::init_value_helper::get(0) }; if constexpr (id::n_set == 0) { fill_init_values(expected, values::initial); } else { From a627bcd9d8f37f96a36c23bb03642eee55ced9a8 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Wed, 17 Jan 2024 06:02:33 -0800 Subject: [PATCH 2/6] Apply clang-format --- tests/common/type_list.h | 8 ++------ .../spec_constants/spec_constants_defined_various_ways.h | 4 ++-- tests/spec_constants/spec_constants_external.h | 8 ++++---- tests/spec_constants/spec_constants_via_kernel_bundle.h | 6 +++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tests/common/type_list.h b/tests/common/type_list.h index c6476c117..abded3432 100644 --- a/tests/common/type_list.h +++ b/tests/common/type_list.h @@ -165,9 +165,7 @@ struct arrow_operator_overloaded { // Returns instance of type T template struct init_value_helper { - static constexpr auto get(int x) { - return static_cast(x); - } + static constexpr auto get(int x) { return static_cast(x); } }; // Returns instance of type T @@ -189,9 +187,7 @@ struct init_value_helper> { // Returns instance of type bool template <> struct init_value_helper { - static constexpr bool get(int x) { - return x % 2 != 0; - } + static constexpr bool get(int x) { return x % 2 != 0; } }; // Returns instance of user defined struct with no constructor diff --git a/tests/spec_constants/spec_constants_defined_various_ways.h b/tests/spec_constants/spec_constants_defined_various_ways.h index c45ac2d52..cee2676a3 100644 --- a/tests/spec_constants/spec_constants_defined_various_ways.h +++ b/tests/spec_constants/spec_constants_defined_various_ways.h @@ -35,8 +35,8 @@ void perform_test(util::logger &log, const std::string &type_name, } } sycl::range<1> range(1); - T result { user_def_types::init_value_helper::get(0) }; - T ref { user_def_types::init_value_helper::get(0) }; + T result{user_def_types::init_value_helper::get(0)}; + T ref{user_def_types::init_value_helper::get(0)}; { fill_init_values(ref, case_num); sycl::buffer result_buffer(&result, range); diff --git a/tests/spec_constants/spec_constants_external.h b/tests/spec_constants/spec_constants_external.h index b297de2ce..b0ab03dd9 100644 --- a/tests/spec_constants/spec_constants_external.h +++ b/tests/spec_constants/spec_constants_external.h @@ -74,7 +74,7 @@ class check_specialization_constants_external { // handler bool passed = false; { - T ref { user_def_types::init_value_helper::get(5) }; + T ref{user_def_types::init_value_helper::get(5)}; const int case_num = static_cast(test_cases_external::by_reference_via_handler); sycl::buffer result_buffer(&passed, range); @@ -99,7 +99,7 @@ class check_specialization_constants_external { // handler passed = false; { - T ref { user_def_types::init_value_helper::get(10) }; + T ref{user_def_types::init_value_helper::get(10)}; const int case_num = static_cast(test_cases_external::by_value_via_handler); sycl::buffer result_buffer(&passed, range); @@ -128,7 +128,7 @@ class check_specialization_constants_external { // via kernel_bundle passed = false; { - T ref { user_def_types::init_value_helper::get(15) }; + T ref{user_def_types::init_value_helper::get(15)}; const int case_num = static_cast(test_cases_external::by_reference_via_bundle); sycl::buffer result_buffer(&passed, range); @@ -170,7 +170,7 @@ class check_specialization_constants_external { // kernel_bundle passed = false; { - T ref { user_def_types::init_value_helper::get(20) }; + T ref{user_def_types::init_value_helper::get(20)}; const int case_num = static_cast(test_cases_external::by_value_via_bundle); sycl::buffer result_buffer(&passed, range); diff --git a/tests/spec_constants/spec_constants_via_kernel_bundle.h b/tests/spec_constants/spec_constants_via_kernel_bundle.h index 2c515d5e2..04b92c5e5 100644 --- a/tests/spec_constants/spec_constants_via_kernel_bundle.h +++ b/tests/spec_constants/spec_constants_via_kernel_bundle.h @@ -300,7 +300,7 @@ void set_value(sycl::kernel_bundle& bundle) { " set_specialization_constant"); for (int i = 0; i < id::n_set; ++i) { // Prepare value to store - T value { user_def_types::init_value_helper::get(0) }; + T value{user_def_types::init_value_helper::get(0)}; fill_init_values(value, values::reference(i)); bundle.template set_specialization_constant< @@ -323,11 +323,11 @@ bool check_value(specStorageT&& storage) { using namespace get_spec_const; // Prepare to read value - T value { user_def_types::init_value_helper::get(0) }; + T value{user_def_types::init_value_helper::get(0)}; fill_init_values(value, values::empty); // Prepare to compare values - T expected { user_def_types::init_value_helper::get(0) }; + T expected{user_def_types::init_value_helper::get(0)}; if constexpr (id::n_set == 0) { fill_init_values(expected, values::initial); } else { From 6211bfc04faed9ce593f601af3b1e925e6ea7d33 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Fri, 19 Jan 2024 03:40:43 -0800 Subject: [PATCH 3/6] Rework according to the comments --- tests/buffer/buffer_deduction_guides.cpp | 12 ++-- tests/common/type_list.h | 65 +++++++++---------- tests/multi_ptr/multi_ptr_access_members.h | 16 ++--- .../multi_ptr_accessor_constructor.h | 3 +- .../multi_ptr_common_assignment_ops.h | 4 +- .../multi_ptr/multi_ptr_common_constructors.h | 2 +- tests/multi_ptr/multi_ptr_comparison_op.h | 4 +- .../multi_ptr_convert_assignment_ops.h | 6 +- .../multi_ptr/multi_ptr_deduction_guides.cpp | 2 +- .../multi_ptr_explicit_conversions.h | 4 +- .../multi_ptr_implicit_conversions.h | 4 +- tests/multi_ptr/multi_ptr_prefetch_member.h | 2 +- tests/spec_constants/spec_constants_common.h | 4 +- .../spec_constants_defined_various_ways.h | 4 +- ...ec_constants_defined_various_ways_helper.h | 18 ++--- ...pec_constants_exceptions_throwing_common.h | 4 +- .../spec_constants/spec_constants_external.h | 10 +-- .../spec_constants/spec_constants_multiple.h | 14 ++-- ...spec_constants_same_command_group_common.h | 14 ++-- .../spec_constants_same_name_inter_link.h | 8 +-- ...ec_constants_same_name_inter_link_helper.h | 2 +- .../spec_constants_same_name_stress_helper.h | 20 +++--- .../spec_constants_separate_unit.cpp | 2 +- .../spec_constants_via_handler_common.h | 28 ++++---- .../spec_constants_via_kernel_bundle.h | 8 +-- 25 files changed, 127 insertions(+), 133 deletions(-) diff --git a/tests/buffer/buffer_deduction_guides.cpp b/tests/buffer/buffer_deduction_guides.cpp index 7b1a5e4a9..84eea53ae 100644 --- a/tests/buffer/buffer_deduction_guides.cpp +++ b/tests/buffer/buffer_deduction_guides.cpp @@ -41,9 +41,9 @@ class check_buffer_deduction { void operator()(const std::string& type) { // create container // using this API because of no_cnstr and no_def_cnstr types - std::array arr = {user_def_types::get_init_value_helper(0), - user_def_types::get_init_value_helper(0), - user_def_types::get_init_value_helper(0)}; + std::array arr = {user_def_types::get_init_value(0), + user_def_types::get_init_value(0), + user_def_types::get_init_value(0)}; type_name = type; test_inputiterator(arr); @@ -123,9 +123,9 @@ class check_buffer_deduction { const int arr_size = r.size(); std::unique_ptr data( - new T[size]{user_def_types::get_init_value_helper(0), - user_def_types::get_init_value_helper(0), - user_def_types::get_init_value_helper(0)}); + new T[size]{user_def_types::get_init_value(0), + user_def_types::get_init_value(0), + user_def_types::get_init_value(0)}); INFO("buffer_ctors_deduction::test_type() " + type_name); // buffer with no alloccator and no property list diff --git a/tests/common/type_list.h b/tests/common/type_list.h index abded3432..6ecf8d4c9 100644 --- a/tests/common/type_list.h +++ b/tests/common/type_list.h @@ -162,53 +162,52 @@ struct arrow_operator_overloaded { } }; -// Returns instance of type T +// Helper structure to extract element type of vec/marray +// Fallback for scalars, which returns unmodified T template -struct init_value_helper { - static constexpr auto get(int x) { return static_cast(x); } +struct vec_marray_element_type { + using type = T; }; -// Returns instance of type T +// vec and marray specializations template -struct init_value_helper> { - static constexpr auto get(int x) { - return sycl::vec{static_cast(x)}; - } +struct vec_marray_element_type> { + using type = T; }; -// Returns instance of type T template -struct init_value_helper> { - static constexpr auto get(int x) { - return sycl::marray{static_cast(x)}; - } +struct vec_marray_element_type> { + using type = T; }; -// Returns instance of type bool +// Returns instance of type T +template +inline constexpr auto get_init_value(int x) { + // Explicit cast is required to silence a warning about narrowing conversion + // in case when T is smaller than int. + return T{static_cast::type>(x)}; +} + +// Special case for bool template <> -struct init_value_helper { - static constexpr bool get(int x) { return x % 2 != 0; } -}; +inline constexpr auto get_init_value(int x) { + return x % 2 != 0; +} -// Returns instance of user defined struct with no constructor +// Specializations for user-defined types template <> -struct init_value_helper { - static constexpr auto get(int x) { - no_cnstr instance{}; - instance = x; - return instance; - } -}; +inline constexpr auto get_init_value(int x) { + no_cnstr instance{}; + instance = x; + return instance; +} -// Returns instance of user defined struct default constructor template <> -struct init_value_helper { - static constexpr auto get(int x) { - def_cnstr instance; - instance = x; - return instance; - } -}; +inline constexpr auto get_init_value(int x) { + def_cnstr instance; + instance = x; + return instance; +} } // namespace user_def_types diff --git a/tests/multi_ptr/multi_ptr_access_members.h b/tests/multi_ptr/multi_ptr_access_members.h index 83f3e15fc..014eb047a 100644 --- a/tests/multi_ptr/multi_ptr_access_members.h +++ b/tests/multi_ptr/multi_ptr_access_members.h @@ -51,14 +51,10 @@ struct test_result { int value_to_init = 49; // Variables that will be used to check that access members returns correct // value - T dereference_ret_value = - user_def_types::get_init_value_helper(value_to_init); - T dereference_op_ret_value = - user_def_types::get_init_value_helper(value_to_init); - T get_member_ret_value = - user_def_types::get_init_value_helper(value_to_init); - T get_raw_member_ret_value = - user_def_types::get_init_value_helper(value_to_init); + T dereference_ret_value = user_def_types::get_init_value(value_to_init); + T dereference_op_ret_value = user_def_types::get_init_value(value_to_init); + T get_member_ret_value = user_def_types::get_init_value(value_to_init); + T get_raw_member_ret_value = user_def_types::get_init_value(value_to_init); }; } // namespace detail @@ -92,7 +88,7 @@ class run_access_members_tests { const std::string &is_decorated_name) { auto queue = once_per_unit::get_queue(); constexpr int val_to_init = 42; - T value = user_def_types::get_init_value_helper(val_to_init); + T value = user_def_types::get_init_value(val_to_init); // Variable that contains all variables that will be used to verify test // result @@ -170,7 +166,7 @@ class run_access_members_tests { } }); } - T expected_value = user_def_types::get_init_value_helper(val_to_init); + T expected_value = user_def_types::get_init_value(val_to_init); // Dereference and multi_ptr::operator->() available only when: // !std::is_void::value if constexpr (!std::is_void_v) { diff --git a/tests/multi_ptr/multi_ptr_accessor_constructor.h b/tests/multi_ptr/multi_ptr_accessor_constructor.h index 606211151..90092fb50 100644 --- a/tests/multi_ptr/multi_ptr_accessor_constructor.h +++ b/tests/multi_ptr/multi_ptr_accessor_constructor.h @@ -63,8 +63,7 @@ void run_tests(sycl_cts::util::logger& log, const std::string& type_name) { bool same_value = false; // default value - T init_value = - user_def_types::get_init_value_helper>(10); + T init_value = user_def_types::get_init_value>(10); auto queue = once_per_unit::get_queue(); diff --git a/tests/multi_ptr/multi_ptr_common_assignment_ops.h b/tests/multi_ptr/multi_ptr_common_assignment_ops.h index 42228569b..b7ea13b83 100644 --- a/tests/multi_ptr/multi_ptr_common_assignment_ops.h +++ b/tests/multi_ptr/multi_ptr_common_assignment_ops.h @@ -60,7 +60,7 @@ class run_common_assign_tests { const std::string &address_space_name, const std::string &is_decorated_name) { auto queue = once_per_unit::get_queue(); - T value = user_def_types::get_init_value_helper(expected_val); + T value = user_def_types::get_init_value(expected_val); sycl::range r(1); std::array res; res.fill(false); @@ -96,7 +96,7 @@ class run_common_assign_tests { check(const_mptr_in, mptr_in, ref, res_acc); } else { T private_val = - user_def_types::get_init_value_helper(expected_val); + user_def_types::get_init_value(expected_val); multi_ptr_t mptr_in = sycl::address_space_cast( diff --git a/tests/multi_ptr/multi_ptr_common_constructors.h b/tests/multi_ptr/multi_ptr_common_constructors.h index 9b41f9778..861eeddd3 100644 --- a/tests/multi_ptr/multi_ptr_common_constructors.h +++ b/tests/multi_ptr/multi_ptr_common_constructors.h @@ -79,7 +79,7 @@ void run_tests(sycl_cts::util::logger &log, const std::string &type_name) { // Arrays for result values bool same_type[types_size]{}; bool same_value[values_size]{}; - T ref_value{user_def_types::get_init_value_helper(0)}; + T ref_value{user_def_types::get_init_value(0)}; auto queue = once_per_unit::get_queue(); using GlobalAccType = sycl::accessor; diff --git a/tests/multi_ptr/multi_ptr_comparison_op.h b/tests/multi_ptr/multi_ptr_comparison_op.h index 9902f25ed..6994d9d9b 100644 --- a/tests/multi_ptr/multi_ptr_comparison_op.h +++ b/tests/multi_ptr/multi_ptr_comparison_op.h @@ -142,8 +142,8 @@ class run_multi_ptr_comparison_op_test { using multi_ptr_t = sycl::multi_ptr; - const T m_small_value = user_def_types::get_init_value_helper(1); - const T m_great_value = user_def_types::get_init_value_helper(2); + const T m_small_value = user_def_types::get_init_value(1); + const T m_great_value = user_def_types::get_init_value(2); // Use an array to be sure that we have two elements that has consecutive // memory addresses const T m_values_arr[2] = {m_small_value, m_great_value}; diff --git a/tests/multi_ptr/multi_ptr_convert_assignment_ops.h b/tests/multi_ptr/multi_ptr_convert_assignment_ops.h index d1acf7d9f..46766c130 100644 --- a/tests/multi_ptr/multi_ptr_convert_assignment_ops.h +++ b/tests/multi_ptr/multi_ptr_convert_assignment_ops.h @@ -59,7 +59,7 @@ class run_convert_assignment_operators_tests { const std::string &src_is_decorated_name, const std::string &dst_is_decorated_name) { auto queue = once_per_unit::get_queue(); - T value = user_def_types::get_init_value_helper(expected_val); + T value = user_def_types::get_init_value(expected_val); auto r = sycl::range(1); SECTION( sycl_cts::section_name( @@ -113,7 +113,7 @@ class run_convert_assignment_operators_tests { res_acc[0] = *(mptr_out.get_raw()) == ref; } else { T private_val = - user_def_types::get_init_value_helper(expected_val); + user_def_types::get_init_value(expected_val); const src_multi_ptr_t mptr_in( sycl::address_space_cast< @@ -184,7 +184,7 @@ class run_convert_assignment_operators_tests { res_acc[0] = *(mptr_out.get_raw()) == ref; } else { T private_val = - user_def_types::get_init_value_helper(expected_val); + user_def_types::get_init_value(expected_val); const src_multi_ptr_t mptr_in( sycl::address_space_cast< diff --git a/tests/multi_ptr/multi_ptr_deduction_guides.cpp b/tests/multi_ptr/multi_ptr_deduction_guides.cpp index 77bb17d35..9565e85c0 100644 --- a/tests/multi_ptr/multi_ptr_deduction_guides.cpp +++ b/tests/multi_ptr/multi_ptr_deduction_guides.cpp @@ -70,7 +70,7 @@ class check_multi_ptr_deduction { accessor, local_accessor>; bool res = false; - T data{user_def_types::get_init_value_helper(0)}; + T data{user_def_types::get_init_value(0)}; auto r = sycl_cts::util::get_cts_object::range::get(1, 1, 1); { sycl::buffer buf_res(&res, {1}); diff --git a/tests/multi_ptr/multi_ptr_explicit_conversions.h b/tests/multi_ptr/multi_ptr_explicit_conversions.h index 33d663129..a2853bd48 100644 --- a/tests/multi_ptr/multi_ptr_explicit_conversions.h +++ b/tests/multi_ptr/multi_ptr_explicit_conversions.h @@ -66,7 +66,7 @@ class run_explicit_convert_tests { template void run_test(sycl::queue &queue, sycl::range<1> &r) { bool res = false; - T value = user_def_types::get_init_value_helper(expected_val); + T value = user_def_types::get_init_value(expected_val); { sycl::buffer res_buf(&res, sycl::range<1>(1)); sycl::buffer val_buffer(&value, sycl::range<1>(1)); @@ -103,7 +103,7 @@ class run_explicit_convert_tests { res_acc[0] = (*(mptr_out.get()) == ref); } else { T private_val = - user_def_types::get_init_value_helper(expected_val); + user_def_types::get_init_value(expected_val); input_multi_ptr_t mptr_in = sycl::address_space_cast< sycl::access::address_space::generic_space, decorated, T>( diff --git a/tests/multi_ptr/multi_ptr_implicit_conversions.h b/tests/multi_ptr/multi_ptr_implicit_conversions.h index 0839abbda..91adf3693 100644 --- a/tests/multi_ptr/multi_ptr_implicit_conversions.h +++ b/tests/multi_ptr/multi_ptr_implicit_conversions.h @@ -76,7 +76,7 @@ class run_implicit_convert_tests { template void preform_implicit_conversion_test() { auto queue = once_per_unit::get_queue(); - T value = user_def_types::get_init_value_helper(expected_val); + T value = user_def_types::get_init_value(expected_val); bool res = false; constexpr sycl::access::decorated src_multi_ptr_decorated = @@ -128,7 +128,7 @@ class run_implicit_convert_tests { const T value_dest = *(reinterpret_cast(mptr_dest.get())); res_acc[0] = (value_dest == - user_def_types::get_init_value_helper(expected_val)); + user_def_types::get_init_value(expected_val)); }; using kname = diff --git a/tests/multi_ptr/multi_ptr_prefetch_member.h b/tests/multi_ptr/multi_ptr_prefetch_member.h index 820ff34ea..17f9a081d 100644 --- a/tests/multi_ptr/multi_ptr_prefetch_member.h +++ b/tests/multi_ptr/multi_ptr_prefetch_member.h @@ -60,7 +60,7 @@ class run_prefetch_test { "Data type shouldn't be is same to void type"); auto queue = once_per_unit::get_queue(); - T value = user_def_types::get_init_value_helper(expected_val); + T value = user_def_types::get_init_value(expected_val); SECTION(sycl_cts::section_name("Check multi_ptr::prefetch()") .with("T", type_name) .with("address_space", "access::address_space::global_space") diff --git a/tests/spec_constants/spec_constants_common.h b/tests/spec_constants/spec_constants_common.h index 68d7fd723..9b53817e3 100644 --- a/tests/spec_constants/spec_constants_common.h +++ b/tests/spec_constants/spec_constants_common.h @@ -48,11 +48,11 @@ constexpr int default_val = 20; template constexpr sycl::specialization_id spec_const( - user_def_types::init_value_helper::get(default_val)); + user_def_types::get_init_value(default_val)); template void fill_init_values(T &result, int val) { - result = user_def_types::init_value_helper::get(val); + result = user_def_types::get_init_value(val); } template diff --git a/tests/spec_constants/spec_constants_defined_various_ways.h b/tests/spec_constants/spec_constants_defined_various_ways.h index cee2676a3..50a314b08 100644 --- a/tests/spec_constants/spec_constants_defined_various_ways.h +++ b/tests/spec_constants/spec_constants_defined_various_ways.h @@ -35,8 +35,8 @@ void perform_test(util::logger &log, const std::string &type_name, } } sycl::range<1> range(1); - T result{user_def_types::init_value_helper::get(0)}; - T ref{user_def_types::init_value_helper::get(0)}; + T result{user_def_types::get_init_value(0)}; + T ref{user_def_types::get_init_value(0)}; { fill_init_values(ref, case_num); sycl::buffer result_buffer(&result, range); diff --git a/tests/spec_constants/spec_constants_defined_various_ways_helper.h b/tests/spec_constants/spec_constants_defined_various_ways_helper.h index 036881309..16158a577 100644 --- a/tests/spec_constants/spec_constants_defined_various_ways_helper.h +++ b/tests/spec_constants/spec_constants_defined_various_ways_helper.h @@ -56,14 +56,14 @@ static std::string get_hint(sc_vw_id test_id) { // Defined in a non-global named namespace template constexpr sycl::specialization_id sc_nonglob( - user_def_types::init_value_helper::get(case_num)); + user_def_types::get_init_value(case_num)); // A static member variable of a struct in a non-global namespace struct struct_nonglob { constexpr struct_nonglob() {} template static constexpr sycl::specialization_id sc{ - user_def_types::init_value_helper::get(case_num)}; + user_def_types::get_init_value(case_num)}; }; } // namespace spec_const_help @@ -71,33 +71,33 @@ namespace { // Defined in an unnamed namespace template constexpr sycl::specialization_id sc_unnamed( - user_def_types::init_value_helper::get(case_num)); + user_def_types::get_init_value(case_num)); // A static member variable of a struct in an unnamed namespace struct struct_unnamed { constexpr struct_unnamed() {} template static constexpr sycl::specialization_id sc{ - user_def_types::init_value_helper::get(case_num)}; + user_def_types::get_init_value(case_num)}; }; } // unnamed namespace // Defined in the global namespace as inline constexpr template inline constexpr sycl::specialization_id sc_glob_inl( - user_def_types::init_value_helper::get(case_num)); + user_def_types::get_init_value(case_num)); // Defined in the global namespace as static constexpr template static constexpr sycl::specialization_id sc_glob_static( - user_def_types::init_value_helper::get(case_num)); + user_def_types::get_init_value(case_num)); // A static member variable of a struct in the global namespace struct struct_glob { constexpr struct_glob() {} template static constexpr sycl::specialization_id sc{ - user_def_types::init_value_helper::get(case_num)}; + user_def_types::get_init_value(case_num)}; }; // A static member variable declared inline constexpr of a struct in the global @@ -106,7 +106,7 @@ struct struct_glob_inl { constexpr struct_glob_inl() {} template static inline constexpr sycl::specialization_id sc{ - user_def_types::init_value_helper::get(case_num)}; + user_def_types::get_init_value(case_num)}; }; // A static member variable of a templated struct in the global namespace @@ -115,7 +115,7 @@ struct struct_glob_tmpl { constexpr struct_glob_tmpl() {} template static constexpr sycl::specialization_id sc{ - user_def_types::init_value_helper::get(case_num)}; + user_def_types::get_init_value(case_num)}; }; #endif // __SYCLCTS_TESTS_SPEC_CONST_DEFINED_VARIOUS_WAYS_HELPER_H diff --git a/tests/spec_constants/spec_constants_exceptions_throwing_common.h b/tests/spec_constants/spec_constants_exceptions_throwing_common.h index 2d0eb9601..8e92954f1 100644 --- a/tests/spec_constants/spec_constants_exceptions_throwing_common.h +++ b/tests/spec_constants/spec_constants_exceptions_throwing_common.h @@ -51,7 +51,7 @@ class check_spec_constant_exception_throw_for_type { // kernel_bundle { bool exception_was_thrown = false; - T res{user_def_types::init_value_helper::get(0)}; + T res{user_def_types::get_init_value(0)}; const int case_num = 1; auto queue = sycl_cts::util::get_cts_object::queue(); @@ -85,7 +85,7 @@ class check_spec_constant_exception_throw_for_type { // kernel_bundle { bool exception_was_thrown = false; - T sc_val{user_def_types::init_value_helper::get(0)}; + T sc_val{user_def_types::get_init_value(0)}; const int case_num = 2; auto queue = sycl_cts::util::get_cts_object::queue(); diff --git a/tests/spec_constants/spec_constants_external.h b/tests/spec_constants/spec_constants_external.h index b0ab03dd9..129e7f380 100644 --- a/tests/spec_constants/spec_constants_external.h +++ b/tests/spec_constants/spec_constants_external.h @@ -17,7 +17,7 @@ using namespace get_spec_const; template inline constexpr sycl::specialization_id spec_const_external( - user_def_types::init_value_helper::get(default_val)); + user_def_types::get_init_value(default_val)); #define FUNC_DECLARE(TYPE) \ SYCL_EXTERNAL bool check_kernel_handler_by_reference_external_handler( \ @@ -74,7 +74,7 @@ class check_specialization_constants_external { // handler bool passed = false; { - T ref{user_def_types::init_value_helper::get(5)}; + T ref{user_def_types::get_init_value(5)}; const int case_num = static_cast(test_cases_external::by_reference_via_handler); sycl::buffer result_buffer(&passed, range); @@ -99,7 +99,7 @@ class check_specialization_constants_external { // handler passed = false; { - T ref{user_def_types::init_value_helper::get(10)}; + T ref{user_def_types::get_init_value(10)}; const int case_num = static_cast(test_cases_external::by_value_via_handler); sycl::buffer result_buffer(&passed, range); @@ -128,7 +128,7 @@ class check_specialization_constants_external { // via kernel_bundle passed = false; { - T ref{user_def_types::init_value_helper::get(15)}; + T ref{user_def_types::get_init_value(15)}; const int case_num = static_cast(test_cases_external::by_reference_via_bundle); sycl::buffer result_buffer(&passed, range); @@ -170,7 +170,7 @@ class check_specialization_constants_external { // kernel_bundle passed = false; { - T ref{user_def_types::init_value_helper::get(20)}; + T ref{user_def_types::get_init_value(20)}; const int case_num = static_cast(test_cases_external::by_value_via_bundle); sycl::buffer result_buffer(&passed, range); diff --git a/tests/spec_constants/spec_constants_multiple.h b/tests/spec_constants/spec_constants_multiple.h index 48c206fbe..5f8ea7556 100644 --- a/tests/spec_constants/spec_constants_multiple.h +++ b/tests/spec_constants/spec_constants_multiple.h @@ -16,7 +16,7 @@ template constexpr sycl::specialization_id sc_multiple( - user_def_types::init_value_helper::get(def_val)); + user_def_types::get_init_value(def_val)); namespace specialization_constants_multiple { using namespace sycl_cts; @@ -57,9 +57,9 @@ class check_specialization_constants_multiple_for_type { int val_A = 5; int val_B = 10; int val_C = 30; - T ref1{user_def_types::init_value_helper::get(0)}; - T ref2{user_def_types::init_value_helper::get(0)}; - T ref3{user_def_types::init_value_helper::get(0)}; + T ref1{user_def_types::get_init_value(0)}; + T ref2{user_def_types::get_init_value(0)}; + T ref3{user_def_types::get_init_value(0)}; fill_init_values(ref1, val_A); fill_init_values(ref2, val_B); fill_init_values(ref3, val_C); @@ -115,13 +115,13 @@ class check_specialization_constants_multiple_for_type { !check_equal_values(ref2, result_vec[1].value) || !check_equal_values(ref3, result_vec[2].value) || !check_equal_values( - T(user_def_types::init_value_helper::get(def_values[3])), + T(user_def_types::get_init_value(def_values[3])), result_vec[3].value) || !check_equal_values( - T(user_def_types::init_value_helper::get(def_values[4])), + T(user_def_types::get_init_value(def_values[4])), result_vec[4].value) || !check_equal_values( - T(user_def_types::init_value_helper::get(def_values[5])), + T(user_def_types::get_init_value(def_values[5])), result_vec[5].value)) FAIL(log, "multiple spec const for " + type_name_string::get(type_name)); diff --git a/tests/spec_constants/spec_constants_same_command_group_common.h b/tests/spec_constants/spec_constants_same_command_group_common.h index 6a2ae2c66..e4a4b8592 100644 --- a/tests/spec_constants/spec_constants_same_command_group_common.h +++ b/tests/spec_constants/spec_constants_same_command_group_common.h @@ -46,13 +46,13 @@ template class check_specialization_constants_same_command_group { public: void operator()(util::logger &log, const std::string &type_name) { - T ref_A{user_def_types::init_value_helper::get(5)}; - T ref_B{user_def_types::init_value_helper::get(10)}; + T ref_A{user_def_types::get_init_value(5)}; + T ref_B{user_def_types::get_init_value(10)}; auto queue = util::get_cts_object::queue(); sycl::range<1> range(1); { - T result1{user_def_types::init_value_helper::get(0)}; - T result2{user_def_types::init_value_helper::get(0)}; + T result1{user_def_types::get_init_value(0)}; + T result2{user_def_types::get_init_value(0)}; { command_group_object cmo; sycl::buffer result_buffer1(&result1, range); @@ -73,8 +73,8 @@ class check_specialization_constants_same_command_group { } { - T result1{user_def_types::init_value_helper::get(0)}; - T result2{user_def_types::init_value_helper::get(0)}; + T result1{user_def_types::get_init_value(0)}; + T result2{user_def_types::get_init_value(0)}; { command_group_object cmo; sycl::buffer result_buffer1(&result1, range); @@ -91,7 +91,7 @@ class check_specialization_constants_same_command_group { if (!check_equal_values(ref_A, result1)) FAIL(log, "case 2 failed for value A for " + type_name); if (!check_equal_values( - T(user_def_types::init_value_helper::get(default_val)), + T(user_def_types::get_init_value(default_val)), result2)) FAIL(log, "case 2 failed for default value for " + type_name); } diff --git a/tests/spec_constants/spec_constants_same_name_inter_link.h b/tests/spec_constants/spec_constants_same_name_inter_link.h index 3587d5822..0f6b70376 100644 --- a/tests/spec_constants/spec_constants_same_name_inter_link.h +++ b/tests/spec_constants/spec_constants_same_name_inter_link.h @@ -48,10 +48,10 @@ class check_specialization_constants_same_name_inter_link_for_type { } } sycl::range<1> range(1); - T def_value{user_def_types::init_value_helper::get(0)}; - T ref_def_value{user_def_types::init_value_helper::get(0)}; - T result{user_def_types::init_value_helper::get(0)}; - T ref{user_def_types::init_value_helper::get(0)}; + T def_value{user_def_types::get_init_value(0)}; + T ref_def_value{user_def_types::get_init_value(0)}; + T result{user_def_types::get_init_value(0)}; + T ref{user_def_types::get_init_value(0)}; { // Setting ref values according to TU number fill_init_values(ref_def_value, TestConfig::tu); diff --git a/tests/spec_constants/spec_constants_same_name_inter_link_helper.h b/tests/spec_constants/spec_constants_same_name_inter_link_helper.h index 7c5f7ebcf..6f56c0a51 100644 --- a/tests/spec_constants/spec_constants_same_name_inter_link_helper.h +++ b/tests/spec_constants/spec_constants_same_name_inter_link_helper.h @@ -30,7 +30,7 @@ namespace { // SC_SN_IL_TU_NUM is defined in every TU template constexpr sycl::specialization_id sc_same_name_inter_link( - user_def_types::init_value_helper::get(SC_SN_IL_TU_NUM)); + user_def_types::get_init_value(SC_SN_IL_TU_NUM)); } // namespace diff --git a/tests/spec_constants/spec_constants_same_name_stress_helper.h b/tests/spec_constants/spec_constants_same_name_stress_helper.h index 779c5fea4..4e3fb9c4c 100644 --- a/tests/spec_constants/spec_constants_same_name_stress_helper.h +++ b/tests/spec_constants/spec_constants_same_name_stress_helper.h @@ -56,21 +56,21 @@ static std::string get_hint(int test_id) { // Specialization constant defined in global namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::glob))); namespace g_outer { // Specialization constant defined in outer namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::outer))); namespace g_inner { // Specialization constant defined in outer::inner namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::outer_inner))); } // namespace g_inner @@ -78,7 +78,7 @@ namespace { // Specialization constant defined in outer::unnamed namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::outer_unnamed))); template @@ -88,7 +88,7 @@ namespace g_u_inner { // Specialization constant defined in outer::unnamed::inner namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::outer_unnamed_inner))); template @@ -99,7 +99,7 @@ namespace { // namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::outer_unnamed_inner_unnamed))); template @@ -113,7 +113,7 @@ namespace { // Specialization constant defined in unnamed namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::unnamed))); template @@ -123,7 +123,7 @@ namespace u_outer { // Specialization constant defined in unnamed::outer namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::unnamed_outer))); template @@ -133,7 +133,7 @@ namespace { // Specialization constant defined in unnamed::outer::unnamed namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::unnamed_outer_unnamed))); template @@ -144,7 +144,7 @@ namespace u_inner { // namespace template constexpr sycl::specialization_id sc_same_name( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( to_integral(spec_const_help::sc_st_id::unnamed_outer_unnamed_inner))); template diff --git a/tests/spec_constants/spec_constants_separate_unit.cpp b/tests/spec_constants/spec_constants_separate_unit.cpp index a52113f81..2d84f6e46 100644 --- a/tests/spec_constants/spec_constants_separate_unit.cpp +++ b/tests/spec_constants/spec_constants_separate_unit.cpp @@ -14,7 +14,7 @@ using namespace get_spec_const; template inline constexpr sycl::specialization_id spec_const_external( - user_def_types::init_value_helper::get(default_val)); + user_def_types::get_init_value(default_val)); template bool check_kernel_handler_by_reference_external(sycl::kernel_handler &h, diff --git a/tests/spec_constants/spec_constants_via_handler_common.h b/tests/spec_constants/spec_constants_via_handler_common.h index c545ecf50..3e9837adc 100644 --- a/tests/spec_constants/spec_constants_via_handler_common.h +++ b/tests/spec_constants/spec_constants_via_handler_common.h @@ -22,14 +22,14 @@ inline constexpr int val_A = 5; template constexpr sycl::specialization_id sc_multiple( - user_def_types::init_value_helper::get(case_num)); + user_def_types::get_init_value(case_num)); template class kernel; template bool check_kernel_handler_by_reference(sycl::kernel_handler &h) { - T ref{user_def_types::init_value_helper::get(0)}; + T ref{user_def_types::get_init_value(0)}; fill_init_values(ref, val_A); return check_equal_values( ref, h.get_specialization_constant>()); @@ -37,7 +37,7 @@ bool check_kernel_handler_by_reference(sycl::kernel_handler &h) { template bool check_kernel_handler_by_value(sycl::kernel_handler h) { - T ref{user_def_types::init_value_helper::get(0)}; + T ref{user_def_types::get_init_value(0)}; fill_init_values(ref, val_A); return check_equal_values( ref, h.get_specialization_constant>()); @@ -49,9 +49,9 @@ class check_spec_constant_with_handler_for_type { void operator()(util::logger &log, const std::string &type_name) { auto queue = util::get_cts_object::queue(); sycl::range<1> range(1); - T result{user_def_types::init_value_helper::get(0)}; - T ref{user_def_types::init_value_helper::get(0)}; - T ref_other{user_def_types::init_value_helper::get(0)}; + T result{user_def_types::get_init_value(0)}; + T ref{user_def_types::get_init_value(0)}; + T ref_other{user_def_types::get_init_value(0)}; int val_B = 10; fill_init_values(ref, val_A); fill_init_values(ref_other, val_B); @@ -59,7 +59,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 1; { - result = user_def_types::init_value_helper::get(0); + result = user_def_types::get_init_value(0); queue.submit([&](sycl::handler &cgh) { cgh.set_specialization_constant>(ref); result = cgh.get_specialization_constant>(); @@ -74,7 +74,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 2; { - result = user_def_types::init_value_helper::get(0); + result = user_def_types::get_init_value(0); queue.submit([&](sycl::handler &cgh) { cgh.set_specialization_constant>(ref); cgh.set_specialization_constant>(ref_other); @@ -91,7 +91,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 3; { - result = user_def_types::init_value_helper::get(0); + result = user_def_types::get_init_value(0); sycl::buffer result_buffer(&result, range); queue.submit([&](sycl::handler &cgh) { auto res_acc = @@ -113,7 +113,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 4; { - result = user_def_types::init_value_helper::get(0); + result = user_def_types::get_init_value(0); sycl::buffer result_buffer(&result, range); queue.submit([&](sycl::handler &cgh) { auto res_acc = @@ -164,13 +164,13 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 6; { - result = user_def_types::init_value_helper::get(0); + result = user_def_types::get_init_value(0); queue.submit([&](sycl::handler &cgh) { result = cgh.get_specialization_constant>(); }); } if (!check_equal_values( - T(user_def_types::init_value_helper::get(default_val)), + T(user_def_types::get_init_value(default_val)), result)) FAIL(log, "case " + std::to_string(case_num) + " for " + type_name_string::get(type_name)); @@ -181,7 +181,7 @@ class check_spec_constant_with_handler_for_type { { const int case_num = 7; { - result = user_def_types::init_value_helper::get(0); + result = user_def_types::get_init_value(0); sycl::buffer result_buffer(&result, range); queue.submit([&](sycl::handler &cgh) { auto res_acc = @@ -193,7 +193,7 @@ class check_spec_constant_with_handler_for_type { }); } if (!check_equal_values( - T(user_def_types::init_value_helper::get(default_val)), + T(user_def_types::get_init_value(default_val)), result)) FAIL(log, "case " + std::to_string(case_num) + " for " + type_name_string::get(type_name)); diff --git a/tests/spec_constants/spec_constants_via_kernel_bundle.h b/tests/spec_constants/spec_constants_via_kernel_bundle.h index 04b92c5e5..5f299a804 100644 --- a/tests/spec_constants/spec_constants_via_kernel_bundle.h +++ b/tests/spec_constants/spec_constants_via_kernel_bundle.h @@ -136,7 +136,7 @@ struct values> : values {}; */ template constexpr sycl::specialization_id spec_const_by_kernel_bundle( - user_def_types::init_value_helper::get( + user_def_types::get_init_value( specialization_constants_via_kernel_bundle::values::initial)); namespace specialization_constants_via_kernel_bundle { @@ -300,7 +300,7 @@ void set_value(sycl::kernel_bundle& bundle) { " set_specialization_constant"); for (int i = 0; i < id::n_set; ++i) { // Prepare value to store - T value{user_def_types::init_value_helper::get(0)}; + T value{user_def_types::get_init_value(0)}; fill_init_values(value, values::reference(i)); bundle.template set_specialization_constant< @@ -323,11 +323,11 @@ bool check_value(specStorageT&& storage) { using namespace get_spec_const; // Prepare to read value - T value{user_def_types::init_value_helper::get(0)}; + T value{user_def_types::get_init_value(0)}; fill_init_values(value, values::empty); // Prepare to compare values - T expected{user_def_types::init_value_helper::get(0)}; + T expected{user_def_types::get_init_value(0)}; if constexpr (id::n_set == 0) { fill_init_values(expected, values::initial); } else { From f2ad8b4327af823794c89183e63eb2c61c20d59d Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Fri, 19 Jan 2024 03:44:47 -0800 Subject: [PATCH 4/6] Cleanup unnecessary casts --- tests/spec_constants/spec_constants_multiple.h | 15 ++++++--------- .../spec_constants_same_command_group_common.h | 5 ++--- .../spec_constants_via_handler_common.h | 10 ++++------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/tests/spec_constants/spec_constants_multiple.h b/tests/spec_constants/spec_constants_multiple.h index 5f8ea7556..1396f9567 100644 --- a/tests/spec_constants/spec_constants_multiple.h +++ b/tests/spec_constants/spec_constants_multiple.h @@ -114,15 +114,12 @@ class check_specialization_constants_multiple_for_type { if (!check_equal_values(ref1, result_vec[0].value) || !check_equal_values(ref2, result_vec[1].value) || !check_equal_values(ref3, result_vec[2].value) || - !check_equal_values( - T(user_def_types::get_init_value(def_values[3])), - result_vec[3].value) || - !check_equal_values( - T(user_def_types::get_init_value(def_values[4])), - result_vec[4].value) || - !check_equal_values( - T(user_def_types::get_init_value(def_values[5])), - result_vec[5].value)) + !check_equal_values(user_def_types::get_init_value(def_values[3]), + result_vec[3].value) || + !check_equal_values(user_def_types::get_init_value(def_values[4]), + result_vec[4].value) || + !check_equal_values(user_def_types::get_init_value(def_values[5]), + result_vec[5].value)) FAIL(log, "multiple spec const for " + type_name_string::get(type_name)); } diff --git a/tests/spec_constants/spec_constants_same_command_group_common.h b/tests/spec_constants/spec_constants_same_command_group_common.h index e4a4b8592..6c2ab3ed5 100644 --- a/tests/spec_constants/spec_constants_same_command_group_common.h +++ b/tests/spec_constants/spec_constants_same_command_group_common.h @@ -90,9 +90,8 @@ class check_specialization_constants_same_command_group { } if (!check_equal_values(ref_A, result1)) FAIL(log, "case 2 failed for value A for " + type_name); - if (!check_equal_values( - T(user_def_types::get_init_value(default_val)), - result2)) + if (!check_equal_values(user_def_types::get_init_value(default_val), + result2)) FAIL(log, "case 2 failed for default value for " + type_name); } } diff --git a/tests/spec_constants/spec_constants_via_handler_common.h b/tests/spec_constants/spec_constants_via_handler_common.h index 3e9837adc..87a883796 100644 --- a/tests/spec_constants/spec_constants_via_handler_common.h +++ b/tests/spec_constants/spec_constants_via_handler_common.h @@ -169,9 +169,8 @@ class check_spec_constant_with_handler_for_type { result = cgh.get_specialization_constant>(); }); } - if (!check_equal_values( - T(user_def_types::get_init_value(default_val)), - result)) + if (!check_equal_values(user_def_types::get_init_value(default_val), + result)) FAIL(log, "case " + std::to_string(case_num) + " for " + type_name_string::get(type_name)); } @@ -192,9 +191,8 @@ class check_spec_constant_with_handler_for_type { }); }); } - if (!check_equal_values( - T(user_def_types::get_init_value(default_val)), - result)) + if (!check_equal_values(user_def_types::get_init_value(default_val), + result)) FAIL(log, "case " + std::to_string(case_num) + " for " + type_name_string::get(type_name)); } From 62920406727c01628813327f1b08051be5157ceb Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Fri, 19 Jan 2024 03:46:48 -0800 Subject: [PATCH 5/6] apply clang-format --- tests/multi_ptr/multi_ptr_implicit_conversions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/multi_ptr/multi_ptr_implicit_conversions.h b/tests/multi_ptr/multi_ptr_implicit_conversions.h index 91adf3693..0a92b5158 100644 --- a/tests/multi_ptr/multi_ptr_implicit_conversions.h +++ b/tests/multi_ptr/multi_ptr_implicit_conversions.h @@ -127,8 +127,8 @@ class run_implicit_convert_tests { // for cases, when dest_multi_ptr_t equals to multi_ptr const T value_dest = *(reinterpret_cast(mptr_dest.get())); - res_acc[0] = (value_dest == - user_def_types::get_init_value(expected_val)); + res_acc[0] = + (value_dest == user_def_types::get_init_value(expected_val)); }; using kname = From e4e58e7869469676a0ada25bd4d6b455581be309 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Fri, 19 Jan 2024 06:30:57 -0800 Subject: [PATCH 6/6] Fix build with hipSYCL --- tests/common/type_list.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/common/type_list.h b/tests/common/type_list.h index 6ecf8d4c9..5c6dc344f 100644 --- a/tests/common/type_list.h +++ b/tests/common/type_list.h @@ -175,10 +175,12 @@ struct vec_marray_element_type> { using type = T; }; +#ifndef SYCL_CTS_COMPILING_WITH_HIPSYCL template struct vec_marray_element_type> { using type = T; }; +#endif // Returns instance of type T template