Skip to content

Commit 889cf20

Browse files
Add DPCTLPlatformMgr_GetInfo function
1 parent a20344b commit 889cf20

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ cdef extern from "syclinterface/dpctl_sycl_platform_manager.h":
263263
DPCTLPlatformVectorRef,
264264
size_t index)
265265
cdef void DPCTLPlatformMgr_PrintInfo(const DPCTLSyclPlatformRef, size_t)
266+
cdef const char *DPCTLPlatformMgr_GetInfo(const DPCTLSyclPlatformRef, size_t)
266267

267268

268269
cdef extern from "syclinterface/dpctl_sycl_platform_interface.h":

libsyclinterface/include/dpctl_sycl_platform_manager.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ DPCTL_API
6464
void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
6565
size_t verbosity);
6666

67+
/*!
68+
* @brief Returns a set of platform info attributes as a string.
69+
*
70+
* The helper function is used to get metadata about a given platform. The
71+
* amount of information received is controlled by the verbosity level.
72+
*
73+
* Verbosity level 0: Returns only the name of the platform.
74+
* Verbosity level 1: Returns the name, version, vendor, backend, number of
75+
* devices in the platform.
76+
* Verbosity level 2: Returns everything in level 1 and also returns the name,
77+
* version, and filter string for each device in the
78+
* platform.
79+
*
80+
* @param PRef A #DPCTLSyclPlatformRef opaque pointer.
81+
* @param verbosity Verbosilty level to control how much information is
82+
* printed out.
83+
* @return A formatted C string capturing the information about the
84+
* sycl::platform argument.
85+
*/
86+
DPCTL_API
87+
__dpctl_give const char *
88+
DPCTLPlatformMgr_GetInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
89+
size_t verbosity);
90+
6791
/*! @} */
6892

6993
DPCTL_C_EXTERN_C_END

libsyclinterface/source/dpctl_sycl_platform_manager.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "dpctl_sycl_platform_manager.h"
2828
#include "Support/CBindingWrapping.h"
2929
#include "dpctl_error_handlers.h"
30+
#include "dpctl_string_utils.hpp"
3031
#include "dpctl_sycl_platform_interface.h"
3132
#include "dpctl_utils_helper.h"
3233
#include <CL/sycl.hpp>
@@ -41,7 +42,7 @@ namespace
4142
{
4243
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef);
4344

44-
void platform_print_info_impl(const platform &p, size_t verbosity)
45+
std::string platform_print_info_impl(const platform &p, size_t verbosity)
4546
{
4647
std::stringstream ss;
4748

@@ -96,7 +97,7 @@ void platform_print_info_impl(const platform &p, size_t verbosity)
9697
}
9798
}
9899

99-
std::cout << ss.str();
100+
return ss.str();
100101
}
101102

102103
} // namespace
@@ -111,10 +112,27 @@ void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
111112
{
112113
auto p = unwrap(PRef);
113114
if (p) {
114-
platform_print_info_impl(*p, verbosity);
115+
std::cout << platform_print_info_impl(*p, verbosity);
115116
}
116117
else {
117118
error_handler("Platform reference is NULL.", __FILE__, __func__,
118119
__LINE__);
119120
}
120121
}
122+
123+
__dpctl_give const char *
124+
DPCTLPlatformMgr_GetInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
125+
size_t verbosity)
126+
{
127+
const char *cstr_info = nullptr;
128+
auto p = unwrap(PRef);
129+
if (p) {
130+
auto infostr = platform_print_info_impl(*p, verbosity);
131+
cstr_info = dpctl::helper::cstring_from_string(infostr);
132+
}
133+
else {
134+
error_handler("Platform reference is NULL.", __FILE__, __func__,
135+
__LINE__);
136+
}
137+
return cstr_info;
138+
}

0 commit comments

Comments
 (0)