Skip to content

Commit a1a2a4a

Browse files
committed
support custom device type in filter strings
The filter selector accepts "custom", and filter_string of a custom device is "backend:custom:N".
1 parent 579b08f commit a1a2a4a

4 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎docs/doc_sources/api_reference/dpctl/filter_selector_string.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Supported values for ``DeviceType`` are:
4646

4747
* - accelerator
4848
- cpu
49+
- custom
4950
- gpu
5051

5152
Filter selector strings can be used as arguments to constructors of

‎dpctl/_sycl_device.pyx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ cdef str _device_type_to_filter_string_part(_device_type DTy):
258258
return "accelerator"
259259
elif DTy == _device_type._CPU:
260260
return "cpu"
261+
elif DTy == _device_type._CUSTOM:
262+
return "custom"
261263
elif DTy == _device_type._GPU:
262264
return "gpu"
263265
else:

‎libsyclinterface/source/dpctl_device_selection.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ device_type_from_token(const std::string &tok)
7979
return sycl::info::device_type::gpu;
8080
if (tok == "accelerator")
8181
return sycl::info::device_type::accelerator;
82+
if (tok == "custom")
83+
return sycl::info::device_type::custom;
8284
return std::nullopt;
8385
}
8486

‎libsyclinterface/tests/test_sycl_device_selector_interface.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ TEST_F(TestDeviceSelectorInterface, ChkDPCTLFilterSelectorList)
257257
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
258258
}
259259

260+
TEST_F(TestDeviceSelectorInterface, ChkDPCTLFilterSelectorCustom)
261+
{
262+
for (const char *fs : {"custom", "opencl:custom", "custom:0"}) {
263+
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
264+
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(fs));
265+
ASSERT_TRUE(DSRef != nullptr) << fs;
266+
for (auto D : sycl::device::get_devices()) {
267+
if (D.get_info<sycl::info::device::device_type>() ==
268+
sycl::info::device_type::custom)
269+
continue;
270+
auto DRef = dpctl::syclinterface::wrap<sycl::device>(&D);
271+
EXPECT_TRUE(DPCTLDeviceSelector_Score(DSRef, DRef) < 0) << fs;
272+
}
273+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
274+
}
275+
}
276+
260277
INSTANTIATE_TEST_SUITE_P(FilterSelectorCreation,
261278
TestFilterSelector,
262279
::testing::Values("opencl",

0 commit comments

Comments
 (0)