Skip to content

Commit 066caf0

Browse files
committed
More C-API tests for composite devices
Rename some variables for consistency
1 parent f80caaa commit 066caf0

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

Diff for: dpctl/_sycl_device.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1765,11 +1765,11 @@ cdef class SyclDevice(_SyclDevice):
17651765
The composite :class:`dpctl.SyclDevice` instance for a
17661766
component device, or ``None`` for a non-component device.
17671767
"""
1768-
cdef DPCTLSyclDeviceRef cDRef = NULL
1769-
cDRef = DPCTLDevice_GetCompositeDevice(self._device_ref)
1770-
if (cDRef is NULL):
1768+
cdef DPCTLSyclDeviceRef CDRef = NULL
1769+
CDRef = DPCTLDevice_GetCompositeDevice(self._device_ref)
1770+
if (CDRef is NULL):
17711771
return None
1772-
return SyclDevice._create(cDRef)
1772+
return SyclDevice._create(CDRef)
17731773

17741774
def component_devices(self):
17751775
""" Returns a list of component devices contained in this SYCL device.

Diff for: libsyclinterface/tests/test_sycl_device_interface.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,18 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemCacheType)
539539
res == DPCTL_MEM_CACHE_TYPE_READ_WRITE));
540540
}
541541

542+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetCompositeDevice)
543+
{
544+
DPCTLSyclDeviceRef CDRef = nullptr;
545+
EXPECT_NO_FATAL_FAILURE(CDRef = DPCTLDevice_GetCompositeDevice(DRef));
546+
if (DPCTLDevice_HasAspect(DRef, DPCTLSyclAspectType::is_component)) {
547+
EXPECT_TRUE(CDRef != nullptr);
548+
}
549+
else {
550+
EXPECT_TRUE(CDRef == nullptr);
551+
}
552+
}
553+
542554
INSTANTIATE_TEST_SUITE_P(DPCTLDeviceFns,
543555
TestDPCTLSyclDeviceInterface,
544556
::testing::Values("opencl",
@@ -898,3 +910,18 @@ TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetSubGroupSizes)
898910
ASSERT_TRUE(sg_sizes == nullptr);
899911
ASSERT_TRUE(sg_sizes_len == 0);
900912
}
913+
914+
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetComponentDevices)
915+
{
916+
DPCTLDeviceVectorRef cDVRef = nullptr;
917+
EXPECT_NO_FATAL_FAILURE(cDVRef =
918+
DPCTLDevice_GetComponentDevices(Null_DRef));
919+
ASSERT_TRUE(cDVRef == nullptr);
920+
}
921+
922+
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetCompositeDevice)
923+
{
924+
DPCTLSyclDeviceRef CDRef = nullptr;
925+
EXPECT_NO_FATAL_FAILURE(CDRef = DPCTLDevice_GetCompositeDevice(Null_DRef));
926+
EXPECT_TRUE(CDRef == nullptr);
927+
}

Diff for: libsyclinterface/tests/test_sycl_platform_interface.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,28 @@ void check_platform_get_devices(__dpctl_keep const DPCTLSyclPlatformRef PRef)
113113
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef));
114114
}
115115

116+
void check_platform_get_composite_devices(
117+
__dpctl_keep const DPCTLSyclPlatformRef PRef)
118+
{
119+
DPCTLDeviceVectorRef CDVRef = nullptr;
120+
size_t nCDevices = 0;
121+
122+
EXPECT_NO_FATAL_FAILURE(CDVRef = DPCTLPlatform_GetCompositeDevices(PRef));
123+
EXPECT_TRUE(CDVRef != nullptr);
124+
EXPECT_NO_FATAL_FAILURE(nCDevices = DPCTLDeviceVector_Size(CDVRef));
125+
for (auto i = 0ul; i < nCDevices; ++i) {
126+
DPCTLSyclDeviceRef CDRef = nullptr;
127+
EXPECT_NO_FATAL_FAILURE(CDRef = DPCTLDeviceVector_GetAt(CDVRef, i));
128+
ASSERT_TRUE(CDRef != nullptr);
129+
ASSERT_TRUE(
130+
DPCTLDevice_HasAspect(CDRef, DPCTLSyclAspectType::is_composite));
131+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(CDRef));
132+
}
133+
134+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Clear(CDVRef));
135+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(CDVRef));
136+
}
137+
116138
} // namespace
117139

118140
struct TestDPCTLSyclPlatformInterface
@@ -308,6 +330,11 @@ TEST_P(TestDPCTLSyclPlatformInterface, ChkGetDevices)
308330
check_platform_get_devices(PRef);
309331
}
310332

333+
TEST_P(TestDPCTLSyclPlatformInterface, ChkGetCompositeDevices)
334+
{
335+
check_platform_get_composite_devices(PRef);
336+
}
337+
311338
TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetName) { check_platform_name(PRef); }
312339

313340
TEST_F(TestDPCTLSyclDefaultPlatform, ChkGetVendor)

0 commit comments

Comments
 (0)