Skip to content

Commit c6d902e

Browse files
author
Diptorup Deb
committed
Add a unit test to ensure GetNumDevices() works as expected.
1 parent 683921f commit c6d902e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

dpctl-capi/tests/test_sycl_device_manager.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,57 @@ INSTANTIATE_TEST_SUITE_P(
137137
DPCTLSyclBackendType::DPCTL_OPENCL |
138138
DPCTLSyclDeviceType::DPCTL_GPU));
139139

140+
struct TestGetNumDevicesForDTy : public ::testing::TestWithParam<int>
141+
{
142+
size_t nDevices = 0;
143+
TestGetNumDevicesForDTy()
144+
{
145+
cl::sycl::info::device_type sycl_dty =
146+
DPCTL_DPCTLDeviceTypeToSyclDeviceType(
147+
DPCTLSyclDeviceType(GetParam()));
148+
149+
auto devices = cl::sycl::device::get_devices(sycl_dty);
150+
EXPECT_TRUE(devices.size() == DPCTLDeviceMgr_GetNumDevices(GetParam()));
151+
}
152+
};
153+
154+
INSTANTIATE_TEST_SUITE_P(
155+
GetDevices,
156+
TestGetNumDevicesForDTy,
157+
::testing::Values(DPCTLSyclDeviceType::DPCTL_ACCELERATOR,
158+
DPCTLSyclDeviceType::DPCTL_ALL,
159+
DPCTLSyclDeviceType::DPCTL_CPU,
160+
DPCTLSyclDeviceType::DPCTL_GPU,
161+
DPCTLSyclDeviceType::DPCTL_HOST_DEVICE));
162+
163+
struct TestGetNumDevicesForBTy : public ::testing::TestWithParam<int>
164+
{
165+
size_t nDevices = 0;
166+
TestGetNumDevicesForBTy()
167+
{
168+
cl::sycl::backend sycl_bty = DPCTL_DPCTLBackendTypeToSyclBackend(
169+
DPCTLSyclBackendType(GetParam()));
170+
171+
auto platforms = cl::sycl::platform::get_platforms();
172+
for (const auto &P : platforms) {
173+
if (P.get_backend() == sycl_bty) {
174+
auto devices = P.get_devices();
175+
EXPECT_TRUE(devices.size() ==
176+
DPCTLDeviceMgr_GetNumDevices(GetParam()));
177+
}
178+
}
179+
}
180+
};
181+
182+
INSTANTIATE_TEST_SUITE_P(
183+
GetDevices,
184+
TestGetNumDevicesForBTy,
185+
::testing::Values(DPCTLSyclBackendType::DPCTL_CUDA,
186+
DPCTLSyclBackendType::DPCTL_ALL_BACKENDS,
187+
DPCTLSyclBackendType::DPCTL_HOST,
188+
DPCTLSyclBackendType::DPCTL_LEVEL_ZERO,
189+
DPCTLSyclBackendType::DPCTL_OPENCL));
190+
140191
struct TestDPCTLDeviceVector : public ::testing::Test
141192
{
142193
};

0 commit comments

Comments
 (0)