Skip to content

Commit a83d25a

Browse files
Fixed GetNumDevices tests, added support for conversion of DPCTL_ALL_BACKENDS to sycl
1 parent 4a51351 commit a83d25a

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

libsyclinterface/helper/source/dpctl_utils_helper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy)
9696
return backend::level_zero;
9797
case DPCTLSyclBackendType::DPCTL_OPENCL:
9898
return backend::opencl;
99+
case DPCTLSyclBackendType::DPCTL_ALL_BACKENDS:
100+
return backend::all;
99101
default:
100102
throw std::runtime_error("Unsupported backend type");
101103
}

libsyclinterface/tests/test_sycl_device_manager.cpp

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,30 @@ INSTANTIATE_TEST_SUITE_P(
139139

140140
struct TestGetNumDevicesForDTy : public ::testing::TestWithParam<int>
141141
{
142-
size_t nDevices = 0;
142+
int param;
143+
sycl::info::device_type sycl_dty;
144+
143145
TestGetNumDevicesForDTy()
144146
{
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()));
147+
param = GetParam();
148+
DPCTLSyclDeviceType DTy = DPCTLSyclDeviceType(param);
149+
sycl_dty = DPCTL_DPCTLDeviceTypeToSyclDeviceType(DTy);
151150
}
152151
};
153152

153+
TEST_P(TestGetNumDevicesForDTy, ChkGetNumDevices)
154+
{
155+
auto devices = sycl::device::get_devices(sycl_dty);
156+
size_t nDevices = 0;
157+
sycl::default_selector mRanker;
158+
for (const sycl::device &d : devices) {
159+
if (mRanker(d) < 0)
160+
continue;
161+
++nDevices;
162+
}
163+
EXPECT_TRUE(nDevices == DPCTLDeviceMgr_GetNumDevices(param));
164+
}
165+
154166
INSTANTIATE_TEST_SUITE_P(
155167
GetDevices,
156168
TestGetNumDevicesForDTy,
@@ -162,22 +174,33 @@ INSTANTIATE_TEST_SUITE_P(
162174

163175
struct TestGetNumDevicesForBTy : public ::testing::TestWithParam<int>
164176
{
165-
size_t nDevices = 0;
177+
int param;
178+
sycl::backend sycl_bty;
166179
TestGetNumDevicesForBTy()
167180
{
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()));
181+
param = GetParam();
182+
sycl_bty =
183+
DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType(param));
184+
}
185+
};
186+
187+
TEST_P(TestGetNumDevicesForBTy, ChkGetNumDevices)
188+
{
189+
auto platforms = cl::sycl::platform::get_platforms();
190+
size_t nDevices = 0;
191+
sycl::default_selector mRanker;
192+
for (const auto &P : platforms) {
193+
if ((P.get_backend() == sycl_bty) || (sycl_bty == sycl::backend::all)) {
194+
auto devices = P.get_devices();
195+
for (const sycl::device &d : devices) {
196+
if (mRanker(d) < 0)
197+
continue;
198+
++nDevices;
177199
}
178200
}
179201
}
180-
};
202+
EXPECT_TRUE(nDevices == DPCTLDeviceMgr_GetNumDevices(param));
203+
}
181204

182205
INSTANTIATE_TEST_SUITE_P(
183206
GetDevices,

0 commit comments

Comments
 (0)