Skip to content

Commit cf20bc4

Browse files
Implement DPCTLPlatform_AreEq(PRef1, PRef1), DPCTLPlatform_Hash(PRef)
Added declaration, doxygen docs, implementation and tests.
1 parent b055ff9 commit cf20bc4

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

libsyclinterface/include/dpctl_sycl_platform_interface.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ DPCTL_C_EXTERN_C_BEGIN
3939
* @defgroup PlatformInterface Platform class C wrapper
4040
*/
4141

42+
/*!
43+
* @brief Checks if two DPCTLSyclPlatformRef objects point to the same
44+
* sycl::platform.
45+
*
46+
* @param PRef1 First opaque pointer to a ``sycl::platform``.
47+
* @param PRef2 Second opaque pointer to a ``sycl::platform``.
48+
* @return True if the underlying sycl::platform are same, false otherwise.
49+
* @ingroup PlatformInterface
50+
*/
51+
DPCTL_API
52+
bool DPCTLPlatform_AreEq(__dpctl_keep const DPCTLSyclPlatformRef PRef1,
53+
__dpctl_keep const DPCTLSyclPlatformRef PRef2);
54+
4255
/*!
4356
* @brief Returns a copy of the DPCTLSyclPlatformRef object.
4457
*
@@ -155,4 +168,14 @@ DPCTL_API
155168
__dpctl_give DPCTLSyclContextRef
156169
DPCTLPlatform_GetDefaultContext(__dpctl_keep const DPCTLSyclPlatformRef PRef);
157170

171+
/*!
172+
* @brief Wrapper over std::hash<sycl::platform>'s operator()
173+
*
174+
* @param PRef The DPCTLSyclPlatformRef pointer.
175+
* @return Hash value of the underlying ``sycl::platform`` instance.
176+
* @ingroup PlatformInterface
177+
*/
178+
DPCTL_API
179+
size_t DPCTLPlatform_Hash(__dpctl_keep DPCTLSyclPlatformRef CtxRef);
180+
158181
DPCTL_C_EXTERN_C_END

libsyclinterface/source/dpctl_sycl_platform_interface.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,27 @@ DPCTLPlatform_GetDefaultContext(__dpctl_keep const DPCTLSyclPlatformRef PRef)
234234
return nullptr;
235235
}
236236
}
237+
238+
bool DPCTLPlatform_AreEq(__dpctl_keep const DPCTLSyclPlatformRef PRef1,
239+
__dpctl_keep const DPCTLSyclPlatformRef PRef2)
240+
{
241+
auto P1 = unwrap<platform>(PRef1);
242+
auto P2 = unwrap<platform>(PRef2);
243+
if (P1 && P2)
244+
return *P1 == *P2;
245+
else
246+
return false;
247+
}
248+
249+
size_t DPCTLPlatform_Hash(__dpctl_keep const DPCTLSyclPlatformRef PRef)
250+
{
251+
if (PRef) {
252+
auto P = unwrap<platform>(PRef);
253+
std::hash<platform> hash_fn;
254+
return hash_fn(*P);
255+
}
256+
else {
257+
error_handler("Argument PRef is null.", __FILE__, __func__, __LINE__);
258+
return 0;
259+
}
260+
}

libsyclinterface/tests/test_sycl_platform_interface.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,23 @@ TEST_P(TestDPCTLSyclPlatformInterface, ChkPrintInfoNullArg)
264264
EXPECT_NO_FATAL_FAILURE(DPCTLPlatformMgr_PrintInfo(Null_PRef, 0));
265265
}
266266

267+
TEST_P(TestDPCTLSyclPlatformInterface, ChkAreEq)
268+
{
269+
DPCTLSyclPlatformRef PRef_Copy = nullptr;
270+
271+
EXPECT_NO_FATAL_FAILURE(PRef_Copy = DPCTLPlatform_Copy(PRef));
272+
273+
ASSERT_TRUE(DPCTLPlatform_AreEq(PRef, PRef_Copy));
274+
EXPECT_TRUE(DPCTLContext_Hash(PRef) == DPCTLContext_Hash(PRef_Copy));
275+
}
276+
277+
TEST_P(TestDPCTLSyclPlatformInterface, ChkAreEqNullArg)
278+
{
279+
DPCTLSyclPlatformRef Null_PRef = nullptr;
280+
ASSERT_FALSE(DPCTLPlatform_AreEq(PRef, Null_PRef));
281+
ASSERT_TRUE(DPCTLPlatform_Hash(Null_PRef) == 0);
282+
}
283+
267284
TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetName)
268285
{
269286
check_platform_name(PRef);

0 commit comments

Comments
 (0)