From a032e66ea9772b366cbf4196ffb34c22099f18ad Mon Sep 17 00:00:00 2001 From: Romanov AndreyX Date: Wed, 12 Jan 2022 15:59:29 +0700 Subject: [PATCH] Added tests for multi_ptr accessor constructor --- tests/common/get_cts_string.h | 162 ++++++++++++++++++ .../multi_ptr_accessor_constructor.h | 147 ++++++++++++++++ .../multi_ptr_accessor_constructor_core.cpp | 44 +++++ .../multi_ptr_accessor_constructor_fp16.cpp | 52 ++++++ .../multi_ptr_accessor_constructor_fp64.cpp | 50 ++++++ tests/multi_ptr/multi_ptr_common.h | 62 ++++++- 6 files changed, 515 insertions(+), 2 deletions(-) create mode 100644 tests/common/get_cts_string.h create mode 100644 tests/multi_ptr/multi_ptr_accessor_constructor.h create mode 100644 tests/multi_ptr/multi_ptr_accessor_constructor_core.cpp create mode 100644 tests/multi_ptr/multi_ptr_accessor_constructor_fp16.cpp create mode 100644 tests/multi_ptr/multi_ptr_accessor_constructor_fp64.cpp diff --git a/tests/common/get_cts_string.h b/tests/common/get_cts_string.h new file mode 100644 index 000000000..765170c1c --- /dev/null +++ b/tests/common/get_cts_string.h @@ -0,0 +1,162 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Provides tools for string representation for some types +// +*******************************************************************************/ + +#ifndef __SYCLCTS_TESTS_COMMON_GET_CTS_STRING_H +#define __SYCLCTS_TESTS_COMMON_GET_CTS_STRING_H + +#include "common.h" + +namespace sycl_cts { +namespace get_cts_string { + +enum class verbosity { brief = 0, detail }; + +/** @brief Stringify bool value + * @tparam bool flag Value to convert + * @retval String with interpretation of bool + */ +inline std::string for_bool(bool flag) { return flag ? "true" : "false"; } + +/** @brief Return string's description depending on the type of bundle_state and + * verbosity level + * @tparam State bundle state + * @tparam Level verbosity level + * @retval string's description of bundle state + */ +template +inline std::string for_bundle_state() { + std::string result; + if constexpr (State == sycl::bundle_state::input) { + result += "input"; + } else if constexpr (State == sycl::bundle_state::object) { + result += "object"; + } else if constexpr (State == sycl::bundle_state::executable) { + result += "executable"; + } else { + static_assert(State != State, "incorrect kernel bundle state"); + } + + if constexpr (Level > verbosity::brief) { + result += " kernel bundle state"; + } + + return result; +} + +/** @brief Return string's description depending on the type of address space + * @tparam AddressSpace type of address space that needs to be converted to + * string + * @retval String description of given address space + */ +template +inline std::string_view for_address_space() { + if constexpr (AddressSpace == sycl::access::address_space::global_space) { + return "global_space"; + } else if constexpr (AddressSpace == + sycl::access::address_space::local_space) { + return "local_space"; + } else if constexpr (AddressSpace == + sycl::access::address_space::private_space) { + return "private_space"; + } else if constexpr (AddressSpace == + sycl::access::address_space::generic_space) { + return "generic_space"; + } else if constexpr (AddressSpace == + sycl::access::address_space::constant_space) { + return "constant_space(deprecated)"; + } else { + static_assert(AddressSpace != AddressSpace, "Unknown address space type"); + } +} + +/** @brief Return string's description depending on the type of decorated + * @tparam Decorated value that needs to be converted to string + * @retval String description of address space + */ +template +inline std::string_view for_decorated() { + if constexpr (Decorated == sycl::access::decorated::yes) { + return "yes"; + } else if constexpr (Decorated == sycl::access::decorated::no) { + return "no"; + } else if constexpr (Decorated == sycl::access::decorated::legacy) { + return "legacy"; + } else { + static_assert(Decorated != Decorated, "Unknown decorated type"); + } +} + +/** @brief Return string's description depending on the type of Mode + * @tparam Mode value that needs to be converted to string + * @retval String description of mode + */ +template +inline std::string_view for_mode() { + if constexpr (Mode == sycl::access::mode::read) { + return "read"; + } else if constexpr (Mode == sycl::access::mode::read_write) { + return "read_write"; + } else if constexpr (Mode == sycl::access::mode::write) { + return "write"; + } else if constexpr (Mode == sycl::access::mode::atomic) { + return "atomic(deprecated)"; + } else if constexpr (Mode == sycl::access::mode::discard_read_write) { + return "discard_read_write(deprecated)"; + } else if constexpr (Mode == sycl::access::mode::discard_write) { + return "discard_write(deprecated)"; + } else { + static_assert(Mode != Mode, "Unknown mode type"); + } +} + +/** @brief Return string's description depending on the type of Target + * @tparam Target value that needs to be converted to string + * @retval String description of target + */ +template +inline std::string_view for_target() { + if constexpr (Target == sycl::access::target::constant_buffer) { + return "constant_buffer"; + } else if constexpr (Target == sycl::access::target::device) { + return "device"; + } else if constexpr (Target == sycl::access::target::host_buffer) { + return "host_buffer"; + } else if constexpr (Target == sycl::access::target::host_image) { + return "host_image"; + } else if constexpr (Target == sycl::access::target::image) { + return "image"; + } else if constexpr (Target == sycl::access::target::image_array) { + return "image_array"; + } else if constexpr (Target == sycl::access::target::local) { + return "local"; + } else if (Target == sycl::access::target::global_buffer) { + return "global_buffer(deprecated)"; + } else { + static_assert(Target != Target, "Unknown target type"); + } +} + +/** @brief Return string's description depending on the type of isPlaceHolder + * @tparam isPlaceHolder value that needs to be converted to string + * @retval String description of placeholder + */ +template +inline std::string_view for_placeholder() { + if constexpr (placeholder == sycl::access::placeholder::false_t) { + return "false_t"; + } else if constexpr (placeholder == sycl::access::placeholder::true_t) { + return "true_t"; + } else { + static_assert(placeholder != placeholder, "Unknown placeholder type"); + } +} + +} // namespace get_cts_string +} // namespace sycl_cts + +#endif // __SYCLCTS_TESTS_COMMON_GET_CTS_STRING_H diff --git a/tests/multi_ptr/multi_ptr_accessor_constructor.h b/tests/multi_ptr/multi_ptr_accessor_constructor.h new file mode 100644 index 000000000..58c637067 --- /dev/null +++ b/tests/multi_ptr/multi_ptr_accessor_constructor.h @@ -0,0 +1,147 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Provides tests for multi_ptr accessor constructors +// +*******************************************************************************/ +#ifndef __SYCLCTS_TESTS_MULTI_PTR_ACCESSOR_CONSTRUCTORS_H +#define __SYCLCTS_TESTS_MULTI_PTR_ACCESSOR_CONSTRUCTORS_H + +#include "../common/common.h" +#include "../common/get_cts_object.h" +#include "../common/get_cts_string.h" +#include "../common/type_list.h" + +namespace multi_ptr_accessor_constructors { +template +struct multi_ptr_kernel_name; + +/** @brief Provides text description of the test case on a failure + * @tparam Space sycl::access::address_space value + * @tparam Mode sycl::access::mode value + * @tparam Target sycl::access::target value + */ +template +std::string get_case_description(const std::string& info, + const std::string& type_name) { + static std::string overload{ + "multi_ptr(accsessor)"}; + std::string addr_space{sycl_cts::get_cts_string::for_address_space()}; + std::string dimension_str{std::to_string(dimension)}; + std::string mode{sycl_cts::get_cts_string::for_mode()}; + std::string target{sycl_cts::get_cts_string::for_target()}; + std::string message{info + " of get() for " + overload + " with tparams: <" + + type_name + "> <" + dimension_str + "> <" + addr_space + + "> <" + mode + "> <" + target + ">" + + "> and type: " + type_name}; + return message; +} + +/** @brief Provides verification of multi_ptr accessor constructors with + * template parameters given + * @tparam T Variable type for type coverage + * @tparam Space sycl::access::address_space value + * @tparam Mode sycl::access::mode value + */ +template +void run_tests(sycl_cts::util::logger& log, const std::string& type_name) { + using namespace sycl_cts; + using multi_ptr_t = sycl::multi_ptr; + // Kernel name + using kernel = multi_ptr_kernel_name; + + // result values + bool same_type = false; + bool same_value = false; + + // default value + T init_value = user_def_types::get_init_value_helper(10); + + auto queue = util::get_cts_object::queue(); + + { + auto init_val_range = + sycl_cts::util::get_cts_object::range::get(1, 1, 1); + sycl::buffer same_type_buf(&same_type, sycl::range<1>(1)); + sycl::buffer same_value_buf(&same_value, sycl::range<1>(1)); + sycl::buffer init_val_buffer(&init_value, init_val_range); + queue.submit([&](sycl::handler& cgh) { + auto same_type_acc = + same_type_buf.template get_access(cgh); + auto same_value_acc = + same_value_buf.template get_access(cgh); + auto accessor_instance = init_val_buffer.template get_access(cgh); + + cgh.single_task([=] { + // Creating multi_ptr object with accessor constructor + multi_ptr_t mptr(accessor_instance); + + auto id = util::get_cts_object::id::get(0, 0, 0); + // Check that mptr points at same value as accessor + same_value_acc[0] = (*(mptr.get()) == accessor_instance[id]); + + // Check that type of value is correct + same_type_acc[0] = + std::is_same_v; + }); + }); + } + if (!same_type) { + FAIL(log, (get_case_description( + "Incorrect type", type_name))); + } + if (!same_value) { + FAIL(log, (get_case_description( + "Incorrect value", type_name))); + } +} + +/** @brief Run tests for all combinations of access mode + */ +template +void run_tests_for_dimension(sycl_cts::util::logger& log, + const std::string& type_name) { + run_tests(log, type_name); + run_tests(log, type_name); + run_tests(log, + type_name); +} + +/** @brief Run tests for all combinations of dimensions + */ +template +void run_tests_for_space(sycl_cts::util::logger& log, + const std::string& type_name) { + run_tests_for_dimension(log, type_name); + run_tests_for_dimension(log, type_name); + run_tests_for_dimension(log, type_name); +} + +/** @brief Provides verification of multi_ptr global_space and generic_space + * accessor constructor for specific type given + * @tparam T Specific type of multi ptr data to use + */ +template +class check_multi_ptr_accessor_constructor_for_type { + public: + void operator()(sycl_cts::util::logger& log, const std::string& type_name) { + using namespace sycl::access; + // Accroding to spec of multi_ptr, constructor can take only + // global_space and generic_space accessors + run_tests_for_space(log, type_name); + run_tests_for_space(log, type_name); + } +}; + +} // namespace multi_ptr_accessor_constructors + +#endif // __SYCLCTS_TESTS_MULTI_PTR_ACCESSOR_CONSTRUCTORS_H diff --git a/tests/multi_ptr/multi_ptr_accessor_constructor_core.cpp b/tests/multi_ptr/multi_ptr_accessor_constructor_core.cpp new file mode 100644 index 000000000..d5253ed46 --- /dev/null +++ b/tests/multi_ptr/multi_ptr_accessor_constructor_core.cpp @@ -0,0 +1,44 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Provides tests for multi_ptr accessor constructor +// +*******************************************************************************/ + +#include "../common/common.h" +#include "../common/type_coverage.h" +#include "multi_ptr_accessor_constructor.h" +#include "multi_ptr_common.h" + +#define TEST_NAME multi_ptr_accessor_constructor_core + +namespace TEST_NAMESPACE { +using namespace sycl_cts; + +/** test multi_ptr accessor constructor + */ +class TEST_NAME : public sycl_cts::util::test_base { + public: + /** return information about this test + */ + void get_info(test_base::info &out) const override { + set_test_info(out, TOSTRING(TEST_NAME), TEST_FILE); + } + + /** execute the test + */ + void run(util::logger &log) override { + using namespace multi_ptr_accessor_constructors; + auto types = multi_ptr_common::get_types(); + auto composite_types = multi_ptr_common::get_composite_types(); + for_all_types(types, log); + for_all_types( + composite_types, log); + } +}; + +// construction of this proxy will register the above test +util::test_proxy proxy; + +} // namespace TEST_NAMESPACE diff --git a/tests/multi_ptr/multi_ptr_accessor_constructor_fp16.cpp b/tests/multi_ptr/multi_ptr_accessor_constructor_fp16.cpp new file mode 100644 index 000000000..82628aeab --- /dev/null +++ b/tests/multi_ptr/multi_ptr_accessor_constructor_fp16.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Provides tests for multi_ptr accessor constructor for sycl::half +// +*******************************************************************************/ + +#include "../../util/extensions.h" +#include "../common/common.h" +#include "../common/type_coverage.h" +#include "multi_ptr_accessor_constructor.h" + +#define TEST_NAME multi_ptr_accessor_constructor_fp16 + +namespace TEST_NAMESPACE { +using namespace sycl_cts; + +/** test multi_ptr accessor constructor + */ +class TEST_NAME : public sycl_cts::util::test_base { + public: + /** return information about this test + */ + void get_info(test_base::info &out) const override { + set_test_info(out, TOSTRING(TEST_NAME), TEST_FILE); + } + + /** execute the test + */ + void run(util::logger &log) override { + using namespace multi_ptr_accessor_constructors; + + auto queue = util::get_cts_object::queue(); + + using avaliability = + util::extensions::availability; + if (!avaliability::check(queue, log)) { + log.skip( + "Device does not support half precision floating point operations"); + return; + } + + check_multi_ptr_accessor_constructor_for_type{}(log, + "sycl::half"); + } +}; + +// construction of this proxy will register the above test +util::test_proxy proxy; + +} // namespace TEST_NAMESPACE diff --git a/tests/multi_ptr/multi_ptr_accessor_constructor_fp64.cpp b/tests/multi_ptr/multi_ptr_accessor_constructor_fp64.cpp new file mode 100644 index 000000000..3cc778f9a --- /dev/null +++ b/tests/multi_ptr/multi_ptr_accessor_constructor_fp64.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Provides tests for multi_ptr accessor constructor for double +// +*******************************************************************************/ + +#include "../../util/extensions.h" +#include "../common/common.h" +#include "../common/type_coverage.h" +#include "multi_ptr_accessor_constructor.h" + +#define TEST_NAME multi_ptr_accessor_constructor_fp64 + +namespace TEST_NAMESPACE { +using namespace sycl_cts; + +/** test multi_ptr accessor constructor + */ +class TEST_NAME : public sycl_cts::util::test_base { + public: + /** return information about this test + */ + void get_info(test_base::info &out) const override { + set_test_info(out, TOSTRING(TEST_NAME), TEST_FILE); + } + + /** execute the test + */ + void run(util::logger &log) override { + using namespace multi_ptr_accessor_constructors; + + auto queue = util::get_cts_object::queue(); + using avaliability = + util::extensions::availability; + if (!avaliability::check(queue, log)) { + log.skip( + "Device does not support double precision floating point operations"); + return; + } + + check_multi_ptr_accessor_constructor_for_type{}(log, "double"); + } +}; + +// construction of this proxy will register the above test +util::test_proxy proxy; + +} // namespace TEST_NAMESPACE diff --git a/tests/multi_ptr/multi_ptr_common.h b/tests/multi_ptr/multi_ptr_common.h index 10d5be9b5..04fcf226c 100644 --- a/tests/multi_ptr/multi_ptr_common.h +++ b/tests/multi_ptr/multi_ptr_common.h @@ -10,9 +10,67 @@ #define SYCL_CTS_TEST_MULTI_PTR_MULTI_PTR_COMMON_H #include "../common/common.h" +#include "../common/type_coverage.h" namespace multi_ptr_common { +/** @brief Legacy multi_ptr alias to enforce the access::decorated::legacy + * usage with no dependency on default multi_ptr template parameter + * values + */ +template +using multi_ptr_legacy = + sycl::multi_ptr; + +template +using global_ptr_legacy = + multi_ptr_legacy; + +template +using private_ptr_legacy = + multi_ptr_legacy; + +template +using local_ptr_legacy = + multi_ptr_legacy; + +template +using constant_ptr_legacy = + multi_ptr_legacy; + +/** @brief Factory method to enforce the same coverage for constructors and API + */ +inline auto get_types() { +#ifdef SYCL_CTS_FULL_CONFORMANCE + return named_type_pack{ + "bool", "float", + "double", "char", + "signed char", "unsigned char", + "short", "unsigned short", + "int", "unsigned int", + "long", "unsigned long", + "long long", "unsigned long long"}; +#else + return named_type_pack{"int", "float"}; +#endif // SYCL_CTS_FULL_CONFORMANCE +} + +// custom data types that will be used in type coverage +inline auto get_composite_types() { +#ifdef SYCL_CTS_FULL_CONFORMANCE + return named_type_pack( + {"no_cnstr", "def_cnstr", "no_def_cnstr"}); +#else + return named_type_pack({"def_cnstr"}); +#endif // SYCL_CTS_FULL_CONFORMANCE +} + template void silence_warnings(argsT...) { // Just to avoid compiler warnings on unused variables @@ -25,7 +83,7 @@ struct check_void_pointer { using data_t = typename std::remove_const::type; template - void operator()(argsT&&... args) { + void operator()(argsT &&...args) { action{}(std::forward(args)..., "void"); action{}(std::forward(args)..., "void"); } @@ -38,7 +96,7 @@ struct check_pointer { using data_t = typename std::remove_const::type; template - void operator()(argsT&&... args) { + void operator()(argsT &&...args) { action{}(std::forward(args)...); action{}(std::forward(args)...); }