From 1442351efb64311609e008b99e165e3f6ee1971f Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Thu, 9 Nov 2023 14:21:21 +0000 Subject: [PATCH 1/3] [NFC] USM test device support refactored The USM API tests previously each had a "supports_device" method that either returned true or checked whether a specific USM allocation type was supported. This change moves that duplicated code to two inheritable classes that provide those methods instead. --- tests/usm/usm_api.h | 76 +++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/tests/usm/usm_api.h b/tests/usm/usm_api.h index 46ed50a5a..876a330e2 100644 --- a/tests/usm/usm_api.h +++ b/tests/usm/usm_api.h @@ -217,11 +217,35 @@ void check_values(const T *begin, const ReferenceIt &reference) { } } +/** @brief Trait for tests that have no additional device requirements + * + * Tests implementing this trait do not require any device support beyond + * the destination memory location. + */ +struct noAdditionalDeviceRequirements { + static bool supports_device(sycl_cts::util::logger& log, + const sycl::queue& queue) { + return true; + } +}; +/** @brief Trait for tests that require support for a given USM alloc type + * + * Tests implementing this trait require device support for a specific + * type of allocation (e.g. as a source memory location). + */ +template +struct requiresUsmAllocationSupport { + static bool supports_device(sycl_cts::util::logger& log, + const sycl::queue& queue) { + return check_device_support(log, queue); + } +}; + /** @brief Provides generic copy test logic for memcpy() and copy() tests * @tparam sourceAllocation Allocation type to use for data source */ template -class copyGeneric { +class copyGeneric : public requiresUsmAllocationSupport { protected: using storage_t = storage; const typename storage_t::type source; @@ -251,13 +275,6 @@ class copy : public copyGeneric { */ static constexpr bool has_non_usm_support() { return true; } - /** @brief This test only works on devices with `sourceAllocation` support - */ - static bool supports_device(sycl_cts::util::logger& log, - const sycl::queue& queue) { - return check_device_support(log, queue); - } - template static std::string description() { return "copy from " + get_allocation_decription() + @@ -283,13 +300,6 @@ class memcpy : public copyGeneric { */ static constexpr bool has_non_usm_support() { return true; } - /** @brief This test only works on devices with `sourceAllocation` support - */ - static bool supports_device(sycl_cts::util::logger& log, - const sycl::queue& queue) { - return check_device_support(log, queue); - } - template static std::string description() { return "memcpy from " + get_allocation_decription() + @@ -326,7 +336,7 @@ using memcpy_from_shared = detail::memcpy; /** @brief Provides test logic for the fill() member function tests */ template -class fill { +class fill : public detail::noAdditionalDeviceRequirements { const T value; public: @@ -336,13 +346,6 @@ class fill { */ static constexpr bool has_non_usm_support() { return false; } - /** @brief This test doesn't have any device requirements - */ - static bool supports_device(sycl_cts::util::logger& log, - const sycl::queue& queue) { - return true; - } - template static std::string description() { return "fill using " + get_allocation_decription(); @@ -364,7 +367,7 @@ class fill { /** @brief Provides test logic for the memset() member function tests */ template -class memset { +class memset : public detail::noAdditionalDeviceRequirements { const int value; public: @@ -376,13 +379,6 @@ class memset { */ static constexpr bool has_non_usm_support() { return false; } - /** @brief This test doesn't have any device requirements - */ - static bool supports_device(sycl_cts::util::logger& log, - const sycl::queue& queue) { - return true; - } - template static std::string description() { return "memset using " + get_allocation_decription(); @@ -404,7 +400,7 @@ class memset { /** @brief Provides test logic for the prefetch() member function tests */ template -class prefetch { +class prefetch : public detail::noAdditionalDeviceRequirements { public: static constexpr size_t size = count * sizeof(T); @@ -414,13 +410,6 @@ class prefetch { */ static constexpr bool has_non_usm_support() { return false; } - /** @brief This test doesn't have any device requirements - */ - static bool supports_device(sycl_cts::util::logger& log, - const sycl::queue& queue) { - return true; - } - template static std::string description() { return "prefetch using " + get_allocation_decription(); @@ -439,7 +428,7 @@ class prefetch { /** @brief Provides test logic for the mem_advise() member function tests */ template -class mem_advise { +class mem_advise : public detail::noAdditionalDeviceRequirements { public: static constexpr size_t size = count * sizeof(T); @@ -449,13 +438,6 @@ class mem_advise { */ static constexpr bool has_non_usm_support() { return false; } - /** @brief This test doesn't have any device requirements - */ - static bool supports_device(sycl_cts::util::logger& log, - const sycl::queue& queue) { - return true; - } - template static std::string description() { return "mem_advise using " + get_allocation_decription(); From 9003c4eb948ce050ebe1cdd8c2e3a38a711b5af1 Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Thu, 9 Nov 2023 16:47:39 +0000 Subject: [PATCH 2/3] Update tests/usm/usm_api.h Co-authored-by: Ronan Keryell --- tests/usm/usm_api.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/usm/usm_api.h b/tests/usm/usm_api.h index 876a330e2..cc2bf41a4 100644 --- a/tests/usm/usm_api.h +++ b/tests/usm/usm_api.h @@ -223,11 +223,12 @@ void check_values(const T *begin, const ReferenceIt &reference) { * the destination memory location. */ struct noAdditionalDeviceRequirements { - static bool supports_device(sycl_cts::util::logger& log, - const sycl::queue& queue) { + static bool supports_device(sycl_cts::util::logger&, + const sycl::queue&) { return true; } }; + /** @brief Trait for tests that require support for a given USM alloc type * * Tests implementing this trait require device support for a specific From bd3c9bb733c86385f131ac985c290467fe2df291 Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Fri, 10 Nov 2023 15:54:32 +0000 Subject: [PATCH 3/3] Clang format --- tests/usm/usm_api.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/usm/usm_api.h b/tests/usm/usm_api.h index cc2bf41a4..c1c60a163 100644 --- a/tests/usm/usm_api.h +++ b/tests/usm/usm_api.h @@ -223,8 +223,7 @@ void check_values(const T *begin, const ReferenceIt &reference) { * the destination memory location. */ struct noAdditionalDeviceRequirements { - static bool supports_device(sycl_cts::util::logger&, - const sycl::queue&) { + static bool supports_device(sycl_cts::util::logger&, const sycl::queue&) { return true; } };