Skip to content

[SYCL] Stop deriving ext::oneapi::filter_selector from device_selector - #23053

Open
KornevNikita wants to merge 2 commits into
intel:syclfrom
KornevNikita:filter-selector-no-device-selector
Open

[SYCL] Stop deriving ext::oneapi::filter_selector from device_selector#23053
KornevNikita wants to merge 2 commits into
intel:syclfrom
KornevNikita:filter-selector-no-device-selector

Conversation

@KornevNikita

@KornevNikita KornevNikita commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

device_selector is a deprecated SYCL 1.2.1 class that is going to be removed, so ext::oneapi::filter_selector shouldn't be tied to it.

Compute the set of matching devices once, when the selector is constructed, using the very same matching algorithm as before. operator() becomes a pure function: it rejects any device outside of that set and ranks the rest with default_selector_v. As a result:

  • filter_selector is an ordinary SYCL 2020 callable device selector, so the !std::is_base_of_v<ext::oneapi::filter_selector, DeviceSelector> special case is dropped from EnableIfSYCL2020DeviceSelectorInvocable and the device/platform/queue constructors accept it through the regular callable path;
  • GlobalHandler::getFilterMutex(), a global mutex that guarded the mutable state during select_device(), is removed;
  • the base class, and with it reset() and select_device(), are dropped under __INTEL_PREVIEW_BREAKING_CHANGES. There is nothing left for reset() to reset, and SYCL 2020 doesn't require a device selector to have either method - a device can be constructed from the selector directly. In the non-preview library both are kept, and marked __SYCL_DEPRECATED, so that its ABI is unchanged.

device_selector is a deprecated SYCL 1.2.1 class that is going to be removed,
so ext::oneapi::filter_selector shouldn't be tied to it.

It only derived from device_selector because its operator() wasn't reentrant:
filter_selector_impl accumulated per-invocation state (the number of devices
seen and the relative device number matched so far), so the selector had to
reset() itself between the invocations. That is what the select_device()
override was for, and it is what the pre-existing TODO in device_selector.cpp
asked to get rid of.

Compute the set of matching devices once, when the selector is constructed,
using the very same matching algorithm as before. operator() becomes a pure
function: it rejects any device outside of that set and ranks the rest with
default_selector_v. As a result:

* filter_selector is an ordinary SYCL 2020 callable device selector, so the
  !std::is_base_of_v<ext::oneapi::filter_selector, DeviceSelector> special case
  is dropped from EnableIfSYCL2020DeviceSelectorInvocable and the
  device/platform/queue constructors accept it through the regular callable
  path;
* GlobalHandler::getFilterMutex(), a global mutex that guarded the mutable
  state during select_device(), is removed;
* the base class, and with it reset() and select_device(), are dropped under
  __INTEL_PREVIEW_BREAKING_CHANGES. There is nothing left for reset() to reset,
  and SYCL 2020 doesn't require a device selector to have either method - a
  device can be constructed from the selector directly. In the non-preview
  library both are kept, and marked __SYCL_DEPRECATED, so that its ABI is
  unchanged.

Everything else is ABI-neutral: filter_selector_impl is an internal class held
behind a shared_ptr, and the mangling of operator()/reset()/select_device()
doesn't change as long as they stay virtual in the non-preview library.
sycl_symbols_linux.dump regenerated from the built libsycl.so is byte-identical
to the reference, sycl_symbols_windows.dump is untouched, and the vtable
layouts dumped with -fdump-vtable-layouts are identical for both
ext::oneapi::filter_selector and ONEAPI::filter_selector.

interop-image-get-native-mem.cpp was the only in-tree user of select_device(),
so construct the device from the selector there instead. That keeps the test
working when the E2E suite is run with test-preview-mode=True.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@KornevNikita

Copy link
Copy Markdown
Contributor Author

Existing tests passed.

@KornevNikita
KornevNikita marked this pull request as ready for review August 31, 2026 10:30
@KornevNikita
KornevNikita requested review from a team as code owners August 31, 2026 10:30
Comment thread sycl/include/sycl/device_selector.hpp
Filter.MatchesSeen++;
filter_selector_impl::filter_selector_impl(const std::string &Input) {
std::vector<filter> Filters;
for (const std::string &Filter : detail::tokenize(Input, ","))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of the change of tokenize output iteration?

void filter_selector::reset() const { impl->reset(); }

// filter_selectors not "Callable"
// because of the requirement that the filter_selector "reset()" itself

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please clarify where this requirement comes from? I don't see it in extension doc. I would like to better understand the requirements

@KornevNikita
KornevNikita force-pushed the filter-selector-no-device-selector branch from a4dd185 to 2c3358e Compare September 1, 2026 16:01
The previous commit dropped the

  !std::is_base_of_v<ext::oneapi::filter_selector, DeviceSelector>

clause from EnableIfSYCL2020DeviceSelectorInvocable altogether. Restore it
under #ifndef __INTEL_PREVIEW_BREAKING_CHANGES: filter_selector becomes a
standalone callable selector only in the preview mode, so outside of it the
exclusion still describes the intent, even though it is subsumed by the
!std::is_base_of_v<device_selector, DeviceSelector> clause that follows (in the
non-preview library filter_selector still derives from device_selector).

That also means the bullet in the previous commit message saying the special
case is gone applies to the preview mode only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@KornevNikita
KornevNikita force-pushed the filter-selector-no-device-selector branch from 2c3358e to 58bf7d4 Compare September 1, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants