Skip to content

Commit ea1eba9

Browse files
Added size_t DPCTLDevice_Hash(DRef)
1 parent dcf00f6 commit ea1eba9

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,13 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
555555
DPCTL_API
556556
__dpctl_give DPCTLSyclDeviceRef
557557
DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef);
558+
559+
/*!
560+
* @brief Wrapper over
561+
* std::hash<sycl::device>'s operator()
562+
*
563+
* @param DRef Opaque pointer to a sycl::device
564+
* @return Returns hash value.
565+
*/
566+
DPCTL_API
567+
size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef);

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,3 +690,18 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
690690
}
691691
return wrap(Devices);
692692
}
693+
694+
size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef)
695+
{
696+
if (DRef) {
697+
auto D = unwrap(DRef);
698+
std::hash<device> hash_fn;
699+
return hash_fn(*D);
700+
}
701+
else {
702+
// todo: log error
703+
std::cerr << "Argument DRef is null"
704+
<< "/n";
705+
return 0;
706+
}
707+
}

dpctl-capi/tests/test_sycl_device_interface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCopy)
6868
DPCTLSyclDeviceRef Copied_DRef = nullptr;
6969
EXPECT_NO_FATAL_FAILURE(Copied_DRef = DPCTLDevice_Copy(DRef));
7070
EXPECT_TRUE(bool(Copied_DRef));
71+
EXPECT_TRUE(DPCTLDevice_AreEq(DRef, Copied_DRef));
72+
EXPECT_TRUE(DPCTLDevice_Hash(DRef) == DPCTLDevice_Hash(Copied_DRef));
7173
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(Copied_DRef));
7274
}
7375

0 commit comments

Comments
 (0)