From 15e506b86849baf09b6c406d9c29dda970ada3f6 Mon Sep 17 00:00:00 2001 From: Vasily Trikolich Date: Fri, 11 Jun 2021 12:57:15 +0300 Subject: [PATCH 1/6] Add new test for get_pointer_type and get_pointer_device USM API Provide verification to cooperation USM functions get_pointer_type and get_pointer_device with four memory allocation types: host, device, shared and non USM allocation. --- tests/usm/usm.h | 83 +++++++++++++++++++++++++ tests/usm/usm_fill_memset_memcpy.cpp | 11 +--- tests/usm/usm_get_pointer_queries.cpp | 87 +++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 tests/usm/usm.h create mode 100644 tests/usm/usm_get_pointer_queries.cpp diff --git a/tests/usm/usm.h b/tests/usm/usm.h new file mode 100644 index 000000000..0e3d47663 --- /dev/null +++ b/tests/usm/usm.h @@ -0,0 +1,83 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Common code for USM tests +// +*******************************************************************************/ + +#ifndef __SYCL_CTS_TEST_USM_USM_H +#define __SYCL_CTS_TEST_USM_USM_H + +#include "../common/common.h" +#include +#include + +namespace usm { + +/** @brief Return std::unique_ptr with allocated USM object + * @tparam USM allocation type + * @param queue sycl::queue class object + */ +template +auto allocate_usm_memory(const sycl::queue &queue, size_t num_elements = 1) { + const auto &device{queue.get_device()}; + const auto &context{queue.get_context()}; + + auto deleter = [=](elems_typeT *ptr) { sycl::free(ptr, context); }; + + if constexpr (alloc == sycl::usm::alloc::shared) { + std::unique_ptr usm_memory( + sycl::malloc_shared(num_elements, device, context), + deleter); + return usm_memory; + } else if constexpr (alloc == sycl::usm::alloc::device) { + std::unique_ptr usm_memory( + sycl::malloc_device(num_elements, queue), deleter); + return usm_memory; + } else if constexpr (alloc == sycl::usm::alloc::host) { + std::unique_ptr usm_memory( + sycl::malloc_host(num_elements, context), deleter); + return usm_memory; + } else { + static_assert(alloc != alloc, "Unknown USM allocation type"); + } +}; + +/** @brief Returns an aspect depending on the type of allocated memory + * @tparam alloc USM allocation type + * @retval SYCL aspect that corresponds to allocated memory + */ +template +auto get_aspect() { + if constexpr (alloc == sycl::usm::alloc::shared) { + return sycl::aspect::usm_shared_allocations; + } else if constexpr (alloc == sycl::usm::alloc::device) { + return sycl::aspect::usm_device_allocations; + } else if constexpr (alloc == sycl::usm::alloc::host) { + return sycl::aspect::usm_host_allocations; + } else { + static_assert(alloc != alloc, "Unknown USM allocation type"); + } +} + +/** @brief Return string's description depending on the type of allocated memory + * @tparam alloc USM allocation type + * @retval String description of allocated memory + */ +template +std::string_view get_allocation_decription() { + if constexpr (alloc == sycl::usm::alloc::shared) { + return "shared"; + } else if constexpr (alloc == sycl::usm::alloc::device) { + return "device"; + } else if constexpr (alloc == sycl::usm::alloc::host) { + return "host"; + } else { + static_assert(alloc != alloc, "Unknown USM allocation type"); + } +} + +} // namespace usm + +#endif // __SYCL_CTS_TEST_USM_USM_H diff --git a/tests/usm/usm_fill_memset_memcpy.cpp b/tests/usm/usm_fill_memset_memcpy.cpp index 90bdb5c38..094e8fef9 100644 --- a/tests/usm/usm_fill_memset_memcpy.cpp +++ b/tests/usm/usm_fill_memset_memcpy.cpp @@ -6,7 +6,7 @@ // *******************************************************************************/ -#include "../common/common.h" +#include "usm.h" #include #define TEST_NAME usm_fill_memset_memcpy @@ -41,13 +41,8 @@ class TEST_NAME : public sycl_cts::util::test_base { constexpr auto value_for_filling{1}; constexpr auto value_for_first_element_overwriting{10}; - auto deleter = [&q](int *data) { sycl::free(data, q.get_context()); }; - std::unique_ptr src( - sycl::malloc_shared(size, q.get_device(), q.get_context()), - deleter); - std::unique_ptr output( - sycl::malloc_shared(size, q.get_device(), q.get_context()), - deleter); + auto src {usm::allocate_usm_memory(q, count)}; + auto output {usm::allocate_usm_memory(q, count)}; sycl::event init_fill = q.submit([&](sycl::handler &cgh) { cgh.fill(src.get(), value_for_filling, count); diff --git a/tests/usm/usm_get_pointer_queries.cpp b/tests/usm/usm_get_pointer_queries.cpp new file mode 100644 index 000000000..936ff4a91 --- /dev/null +++ b/tests/usm/usm_get_pointer_queries.cpp @@ -0,0 +1,87 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Provide verification to cooperation USM functions get_pointer_type and +// get_pointer_device with four memory allocation types: host, device, shared +// and non USM allocation. +// +*******************************************************************************/ + +#include "usm.h" +#include + +#define TEST_NAME usm_get_pointer_queries + +namespace TEST_NAMESPACE { +using namespace sycl_cts; + +template +void run_check(const sycl::queue &queue, sycl_cts::util::logger &log) { + const auto &device{queue.get_device()}; + const auto &context{queue.get_context()}; + + auto str_usm_alloc_type{usm::get_allocation_decription()}; + + if (device.has(usm::get_aspect())) { + auto allocated_memory = usm::allocate_usm_memory(queue); + const auto value = sycl::get_pointer_type(allocated_memory.get(), context); + + if (alloc != value) { + FAIL(log, "sycl::get_pointer_type return " + + std::to_string(to_integral(value)) + + " type, expected sycl::usm::alloc::" + + std::string(str_usm_alloc_type) + " type"); + } + if (sycl::get_pointer_device(allocated_memory.get(), context) != device) { + FAIL(log, "sycl::get_pointer_device return invalid device for " + + std::string(str_usm_alloc_type) + " type"); + } + } else { + log.note("Device does not support " + std::string(str_usm_alloc_type) + + " allocation. Tests were skipped."); + } +} + +/** Test instance + */ +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 { + try { + auto queue{util::get_cts_object::queue()}; + + { + int non_usm_allocated_memory{}; + if (sycl::usm::alloc::unknown != + sycl::get_pointer_type(&non_usm_allocated_memory, + queue.get_context())) { + FAIL(log, + "sycl::get_pointer_type return not sycl::usm::alloc::unknown " + "type"); + } + } + + run_check(queue, log); + run_check(queue, log); + run_check(queue, log); + + } catch (const cl::sycl::exception &e) { + log_exception(log, e); + auto errorMsg = "a SYCL exception was caught: " + std::string(e.what()); + FAIL(log, errorMsg); + } + } +}; + +// construction of this proxy will register the above test +util::test_proxy proxy; +} // namespace TEST_NAMESPACE From bf245b8e30079eeaddacb6fff071b538d500221d Mon Sep 17 00:00:00 2001 From: Vasily Trikolich Date: Tue, 29 Jun 2021 12:31:08 +0300 Subject: [PATCH 2/6] Fix misprint in usm.h --- tests/usm/usm.h | 2 +- tests/usm/usm_get_pointer_queries.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/usm/usm.h b/tests/usm/usm.h index 0e3d47663..2bc0c1937 100644 --- a/tests/usm/usm.h +++ b/tests/usm/usm.h @@ -66,7 +66,7 @@ auto get_aspect() { * @retval String description of allocated memory */ template -std::string_view get_allocation_decription() { +std::string_view get_allocation_description() { if constexpr (alloc == sycl::usm::alloc::shared) { return "shared"; } else if constexpr (alloc == sycl::usm::alloc::device) { diff --git a/tests/usm/usm_get_pointer_queries.cpp b/tests/usm/usm_get_pointer_queries.cpp index 936ff4a91..fbf2825f4 100644 --- a/tests/usm/usm_get_pointer_queries.cpp +++ b/tests/usm/usm_get_pointer_queries.cpp @@ -21,7 +21,7 @@ void run_check(const sycl::queue &queue, sycl_cts::util::logger &log) { const auto &device{queue.get_device()}; const auto &context{queue.get_context()}; - auto str_usm_alloc_type{usm::get_allocation_decription()}; + auto str_usm_alloc_type{usm::get_allocation_description()}; if (device.has(usm::get_aspect())) { auto allocated_memory = usm::allocate_usm_memory(queue); From de3b97544e5b1a211363158dc610b67682232e0a Mon Sep 17 00:00:00 2001 From: vasilytric Date: Mon, 5 Jul 2021 17:39:55 +0300 Subject: [PATCH 3/6] Update usm.h file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Peter Žužek --- tests/usm/usm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/usm/usm.h b/tests/usm/usm.h index 2bc0c1937..20e994d5d 100644 --- a/tests/usm/usm.h +++ b/tests/usm/usm.h @@ -49,7 +49,7 @@ auto allocate_usm_memory(const sycl::queue &queue, size_t num_elements = 1) { * @retval SYCL aspect that corresponds to allocated memory */ template -auto get_aspect() { +constexpr auto get_aspect() { if constexpr (alloc == sycl::usm::alloc::shared) { return sycl::aspect::usm_shared_allocations; } else if constexpr (alloc == sycl::usm::alloc::device) { From 99e4bde4857aa058b01463aa6fdfeec04cb34ba4 Mon Sep 17 00:00:00 2001 From: Vasily Trikolich Date: Fri, 9 Jul 2021 12:03:16 +0300 Subject: [PATCH 4/6] Add constexpr to get_allocation_description() function's return type --- tests/usm/usm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/usm/usm.h b/tests/usm/usm.h index 20e994d5d..be2715584 100644 --- a/tests/usm/usm.h +++ b/tests/usm/usm.h @@ -66,7 +66,7 @@ constexpr auto get_aspect() { * @retval String description of allocated memory */ template -std::string_view get_allocation_description() { +constexpr std::string_view get_allocation_description() { if constexpr (alloc == sycl::usm::alloc::shared) { return "shared"; } else if constexpr (alloc == sycl::usm::alloc::device) { From 684a2ec24693c5aa64fd6b853c69c981ef9e3c9e Mon Sep 17 00:00:00 2001 From: Vasily Trikolich Date: Tue, 13 Jul 2021 12:57:44 +0300 Subject: [PATCH 5/6] Improve "static_assert" expression --- tests/usm/usm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/usm/usm.h b/tests/usm/usm.h index be2715584..8a7dcbc56 100644 --- a/tests/usm/usm.h +++ b/tests/usm/usm.h @@ -40,7 +40,7 @@ auto allocate_usm_memory(const sycl::queue &queue, size_t num_elements = 1) { sycl::malloc_host(num_elements, context), deleter); return usm_memory; } else { - static_assert(alloc != alloc, "Unknown USM allocation type"); + static_assert(false, "Unknown USM allocation type"); } }; From 22fe3759053dd9690e61710c83264f430065e7e0 Mon Sep 17 00:00:00 2001 From: Vasily Trikolich Date: Tue, 13 Jul 2021 16:44:58 +0300 Subject: [PATCH 6/6] Revert "Improve "static_assert" expression" This reverts commit 684a2ec24693c5aa64fd6b853c69c981ef9e3c9e. This commit added compilation brake changes. --- tests/usm/usm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/usm/usm.h b/tests/usm/usm.h index 8a7dcbc56..be2715584 100644 --- a/tests/usm/usm.h +++ b/tests/usm/usm.h @@ -40,7 +40,7 @@ auto allocate_usm_memory(const sycl::queue &queue, size_t num_elements = 1) { sycl::malloc_host(num_elements, context), deleter); return usm_memory; } else { - static_assert(false, "Unknown USM allocation type"); + static_assert(alloc != alloc, "Unknown USM allocation type"); } };