From 889cf202b325195242a81ecb5988d8c17280d4aa Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 28 Mar 2022 15:08:01 +0300 Subject: [PATCH 1/4] Add DPCTLPlatformMgr_GetInfo function --- dpctl/_backend.pxd | 1 + .../include/dpctl_sycl_platform_manager.h | 24 +++++++++++++++++++ .../source/dpctl_sycl_platform_manager.cpp | 24 ++++++++++++++++--- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 8a666b045b..54ec8e134d 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -263,6 +263,7 @@ cdef extern from "syclinterface/dpctl_sycl_platform_manager.h": DPCTLPlatformVectorRef, size_t index) cdef void DPCTLPlatformMgr_PrintInfo(const DPCTLSyclPlatformRef, size_t) + cdef const char *DPCTLPlatformMgr_GetInfo(const DPCTLSyclPlatformRef, size_t) cdef extern from "syclinterface/dpctl_sycl_platform_interface.h": diff --git a/libsyclinterface/include/dpctl_sycl_platform_manager.h b/libsyclinterface/include/dpctl_sycl_platform_manager.h index c456941760..c0f54f60bb 100644 --- a/libsyclinterface/include/dpctl_sycl_platform_manager.h +++ b/libsyclinterface/include/dpctl_sycl_platform_manager.h @@ -64,6 +64,30 @@ DPCTL_API void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef, size_t verbosity); +/*! + * @brief Returns a set of platform info attributes as a string. + * + * The helper function is used to get metadata about a given platform. The + * amount of information received is controlled by the verbosity level. + * + * Verbosity level 0: Returns only the name of the platform. + * Verbosity level 1: Returns the name, version, vendor, backend, number of + * devices in the platform. + * Verbosity level 2: Returns everything in level 1 and also returns the name, + * version, and filter string for each device in the + * platform. + * + * @param PRef A #DPCTLSyclPlatformRef opaque pointer. + * @param verbosity Verbosilty level to control how much information is + * printed out. + * @return A formatted C string capturing the information about the + * sycl::platform argument. + */ +DPCTL_API +__dpctl_give const char * +DPCTLPlatformMgr_GetInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef, + size_t verbosity); + /*! @} */ DPCTL_C_EXTERN_C_END diff --git a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp index 90dcf0ee71..b1778259ed 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp @@ -27,6 +27,7 @@ #include "dpctl_sycl_platform_manager.h" #include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" +#include "dpctl_string_utils.hpp" #include "dpctl_sycl_platform_interface.h" #include "dpctl_utils_helper.h" #include @@ -41,7 +42,7 @@ namespace { DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef); -void platform_print_info_impl(const platform &p, size_t verbosity) +std::string platform_print_info_impl(const platform &p, size_t verbosity) { std::stringstream ss; @@ -96,7 +97,7 @@ void platform_print_info_impl(const platform &p, size_t verbosity) } } - std::cout << ss.str(); + return ss.str(); } } // namespace @@ -111,10 +112,27 @@ void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef, { auto p = unwrap(PRef); if (p) { - platform_print_info_impl(*p, verbosity); + std::cout << platform_print_info_impl(*p, verbosity); } else { error_handler("Platform reference is NULL.", __FILE__, __func__, __LINE__); } } + +__dpctl_give const char * +DPCTLPlatformMgr_GetInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef, + size_t verbosity) +{ + const char *cstr_info = nullptr; + auto p = unwrap(PRef); + if (p) { + auto infostr = platform_print_info_impl(*p, verbosity); + cstr_info = dpctl::helper::cstring_from_string(infostr); + } + else { + error_handler("Platform reference is NULL.", __FILE__, __func__, + __LINE__); + } + return cstr_info; +} From b553fdef231b6ccd81d77cfaba3f7d191dde86a0 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 28 Mar 2022 15:08:56 +0300 Subject: [PATCH 2/4] Fix lsplatform function to use DPCTLPlatformMgr_GetInfo --- dpctl/_sycl_platform.pyx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dpctl/_sycl_platform.pyx b/dpctl/_sycl_platform.pyx index 8cd057dcd5..6e3fad07c8 100644 --- a/dpctl/_sycl_platform.pyx +++ b/dpctl/_sycl_platform.pyx @@ -34,6 +34,7 @@ from ._backend cimport ( # noqa: E211 DPCTLPlatform_GetPlatforms, DPCTLPlatform_GetVendor, DPCTLPlatform_GetVersion, + DPCTLPlatformMgr_GetInfo, DPCTLPlatformMgr_PrintInfo, DPCTLPlatformVector_Delete, DPCTLPlatformVector_GetAt, @@ -323,6 +324,7 @@ def lsplatform(verbosity=0): cdef DPCTLPlatformVectorRef PVRef = NULL cdef size_t v = 0 cdef size_t size = 0 + cdef const char * info_str = NULL cdef DPCTLSyclPlatformRef PRef = NULL if not isinstance(verbosity, int): @@ -347,8 +349,11 @@ def lsplatform(verbosity=0): if v != 0: print("Platform ", i, "::") PRef = DPCTLPlatformVector_GetAt(PVRef, i) - DPCTLPlatformMgr_PrintInfo(PRef, v) + info_str = DPCTLPlatformMgr_GetInfo(PRef,v) + py_info = info_str + DPCTLCString_Delete(info_str) DPCTLPlatform_Delete(PRef) + print(py_info.decode("utf-8"),end='') DPCTLPlatformVector_Delete(PVRef) From 34b4d4f35c45515f183646c48f3a9eca3eb3eec1 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Mon, 28 Mar 2022 10:42:32 -0500 Subject: [PATCH 3/4] Added tests for DPCTLPlatformMgr_GetInfo --- .../tests/test_sycl_platform_interface.cpp | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/libsyclinterface/tests/test_sycl_platform_interface.cpp b/libsyclinterface/tests/test_sycl_platform_interface.cpp index dc874b317e..3a45cfe149 100644 --- a/libsyclinterface/tests/test_sycl_platform_interface.cpp +++ b/libsyclinterface/tests/test_sycl_platform_interface.cpp @@ -224,6 +224,14 @@ TEST_P(TestDPCTLSyclPlatformInterface, ChkCopyNullArg) EXPECT_NO_FATAL_FAILURE(DPCTLPlatform_Delete(Copied_PRef)); } +TEST_P(TestDPCTLSyclPlatformInterface, ChkGetInfo) +{ + const char *info_str = nullptr; + EXPECT_NO_FATAL_FAILURE(info_str = DPCTLPlatformMgr_GetInfo(PRef, 0)); + ASSERT_TRUE(info_str != nullptr); + EXPECT_NO_FATAL_FAILURE(DPCTLCString_Delete(info_str)); +} + TEST_P(TestDPCTLSyclPlatformInterface, ChkPrintInfo) { EXPECT_NO_FATAL_FAILURE(DPCTLPlatformMgr_PrintInfo(PRef, 0)); @@ -255,6 +263,38 @@ TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetBackend) check_platform_backend(PRef); } +TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetInfo0) +{ + const char *info_str = nullptr; + EXPECT_NO_FATAL_FAILURE(info_str = DPCTLPlatformMgr_GetInfo(PRef, 0)); + ASSERT_TRUE(info_str != nullptr); + EXPECT_NO_FATAL_FAILURE(DPCTLCString_Delete(info_str)); +} + +TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetInfo1) +{ + const char *info_str = nullptr; + EXPECT_NO_FATAL_FAILURE(info_str = DPCTLPlatformMgr_GetInfo(PRef, 1)); + ASSERT_TRUE(info_str != nullptr); + EXPECT_NO_FATAL_FAILURE(DPCTLCString_Delete(info_str)); +} + +TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetInfo2) +{ + const char *info_str = nullptr; + EXPECT_NO_FATAL_FAILURE(info_str = DPCTLPlatformMgr_GetInfo(PRef, 2)); + ASSERT_TRUE(info_str != nullptr); + EXPECT_NO_FATAL_FAILURE(DPCTLCString_Delete(info_str)); +} + +TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetInfo3) +{ + const char *info_str = nullptr; + EXPECT_NO_FATAL_FAILURE(info_str = DPCTLPlatformMgr_GetInfo(PRef, 3)); + ASSERT_TRUE(info_str != nullptr); + EXPECT_NO_FATAL_FAILURE(DPCTLCString_Delete(info_str)); +} + TEST_F(TestDPCTLSyclDefaultPlatform, ChkPrintInfo0) { EXPECT_NO_FATAL_FAILURE(DPCTLPlatformMgr_PrintInfo(PRef, 0)); From 49e34198d360ab6e59e5aa859000c9c9a01d2536 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 28 Mar 2022 13:58:08 -0500 Subject: [PATCH 4/4] Added tests for handlign of null PRef in DPCTLPlatformMgr_GetInfo --- libsyclinterface/tests/test_sycl_platform_interface.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libsyclinterface/tests/test_sycl_platform_interface.cpp b/libsyclinterface/tests/test_sycl_platform_interface.cpp index 3a45cfe149..594d4856e2 100644 --- a/libsyclinterface/tests/test_sycl_platform_interface.cpp +++ b/libsyclinterface/tests/test_sycl_platform_interface.cpp @@ -295,6 +295,14 @@ TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetInfo3) EXPECT_NO_FATAL_FAILURE(DPCTLCString_Delete(info_str)); } +TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetInfoNull) +{ + const char *info_str = nullptr; + DPCTLSyclPlatformRef NullPRef = nullptr; + EXPECT_NO_FATAL_FAILURE(info_str = DPCTLPlatformMgr_GetInfo(NullPRef, 0)); + ASSERT_TRUE(info_str == nullptr); +} + TEST_F(TestDPCTLSyclDefaultPlatform, ChkPrintInfo0) { EXPECT_NO_FATAL_FAILURE(DPCTLPlatformMgr_PrintInfo(PRef, 0));