File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -116,4 +116,15 @@ size_t DPCTLDeviceMgr_GetNumDevices(int device_identifier);
116116DPCTL_API
117117void DPCTLDeviceMgr_PrintDeviceInfo (__dpctl_keep const DPCTLSyclDeviceRef DRef);
118118
119+ /* !
120+ * @brief Gives the index of the given device in the vector returned get_devices
121+ * for the platform associated with DRef for the device type of DRef.
122+ *
123+ * @param DRef A #DPCTLSyclDeviceRef opaque pointer.
124+ * @ingroup DeviceManager
125+ */
126+ DPCTL_API
127+ int64_t
128+ DPCTLDeviceMgr_GetRelativeId (__dpctl_keep const DPCTLSyclDeviceRef DRef);
129+
119130DPCTL_C_EXTERN_C_END
Original file line number Diff line number Diff line change @@ -194,3 +194,22 @@ void DPCTLDeviceMgr_PrintDeviceInfo(__dpctl_keep const DPCTLSyclDeviceRef DRef)
194194 std::cout << " Device is not valid (NULL). Cannot print device info.\n " ;
195195 }
196196}
197+
198+ int64_t DPCTLDeviceMgr_GetRelativeId (__dpctl_keep const DPCTLSyclDeviceRef DRef)
199+ {
200+ auto Device = unwrap (DRef);
201+
202+ if (Device) {
203+ auto p = Device->get_platform ();
204+ auto dt = Device->get_info <sycl::info::device::device_type>();
205+ auto dev_vec = p.get_devices (dt);
206+ int64_t id = 0 ;
207+ for (auto &d_i : dev_vec) {
208+ if (*Device == d_i)
209+ return id;
210+ ++id;
211+ }
212+ return -1 ;
213+ }
214+ return -1 ;
215+ }
Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ struct TestDPCTLDeviceManager : public ::testing::TestWithParam<const char *>
5656 }
5757};
5858
59+ TEST_P (TestDPCTLDeviceManager, Chk_GetRelativeId)
60+ {
61+ int64_t rel_id = -1 ;
62+ EXPECT_NO_FATAL_FAILURE (rel_id = DPCTLDeviceMgr_GetRelativeId (DRef));
63+ EXPECT_FALSE (rel_id == -1 );
64+ }
65+
5966TEST_P (TestDPCTLDeviceManager, Chk_PrintDeviceInfo)
6067{
6168 EXPECT_NO_FATAL_FAILURE (DPCTLDeviceMgr_PrintDeviceInfo (DRef));
You can’t perform that action at this time.
0 commit comments