Skip to content
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
259 commits
Select commit Hold shift + click to select a range
0411b61
adding missing condition for scratch space use
egfefey May 21, 2025
a2b7175
initial policy base plus round robin inheriting
egfefey May 21, 2025
a928d16
initial policy customization - policy base plus inherited round robin
egfefey May 21, 2025
6e517e7
fixed resource policy using the policy_base
egfefey May 21, 2025
9a65385
adding exception in select
egfefey May 21, 2025
22513bb
Deactivating policies beside RR for custom backend testing
egfefey Mar 14, 2025
fb965aa
default base + RR updates for default sycl backend
egfefey Mar 14, 2025
d442372
adding missed updated sycl_backend
egfefey Mar 14, 2025
8a8e8ff
updating fixed resource policy and test to use default sycl backend
egfefey Mar 17, 2025
d547a3e
updating dynamic load policy to use default sycl backend
egfefey Mar 17, 2025
f2573eb
updating the auto_tune policy to use the default sycl backend
egfefey Mar 21, 2025
0d26cbe
split submit into instument_before, function invocation and instrumen…
egfefey Mar 31, 2025
ef6e6e6
updating the backend traits with a scratch space for selection
egfefey Apr 17, 2025
9a62576
warning fix from previous push
egfefey Apr 17, 2025
b77e08a
adding missing condition for scratch space use
egfefey May 21, 2025
1c41842
initial policy base plus round robin inheriting
egfefey May 21, 2025
ad698d5
initial policy customization - policy base plus inherited round robin
egfefey May 21, 2025
6459df0
fixed resource policy using the policy_base
egfefey May 21, 2025
3ab72c9
adding exception in select
egfefey May 21, 2025
92a9ec6
Rebasing...
egfefey May 22, 2025
0d66c06
updates to enable non-sycl samples plus a traits check for wait
egfefey May 29, 2025
fa212c5
enabling fixed_resource_policy for non-sycl samples
egfefey May 29, 2025
b815741
initial update to enable dynamic_load_policy for non-sycl samples
egfefey Jun 16, 2025
5734ced
Adding wait_type
egfefey Jun 22, 2025
0ee2cf1
adding resource_type to the test
egfefey Jun 22, 2025
12e79d6
Update round_robin_policy.h
egfefey Jun 22, 2025
20afd0a
Update round_robin_policy.h
egfefey Jun 22, 2025
0e932ac
Update fixed_resource_policy.h
egfefey Jun 22, 2025
9e5cf88
Update test_fixed_resource_policy_inline.pass.cpp
egfefey Jun 22, 2025
fd8f893
Update dynamic_load_policy.h
egfefey Jun 22, 2025
d50db4f
Update dynamic_load_policy.h
egfefey Jun 22, 2025
1c3ec5f
Update test_dynamic_load_policy_inline.pass.cpp
egfefey Jun 22, 2025
609f5ec
Update test_dynamic_load_utils.h
egfefey Jun 29, 2025
0fcfbe3
Update dynamic_load_policy.h
egfefey Jun 30, 2025
c9ca52c
Update sycl_backend.h
egfefey Jun 30, 2025
3a1f0af
Update dynamic_load_policy.h
egfefey Jun 30, 2025
8987309
using default backend
egfefey Jul 1, 2025
e27e5c5
Update test_internal_sycl_scheduler.pass.cpp
egfefey Jul 1, 2025
db6e713
Update test_internal_sycl_scheduler.pass.cpp
egfefey Jul 1, 2025
739ee60
Update sycl_backend.h
egfefey Jul 1, 2025
6c23dfb
Update sycl_backend.h
egfefey Jul 2, 2025
2dee3c4
Update test_auto_tune_policy_sycl.pass.cpp
egfefey Jul 2, 2025
f13a117
Update test_auto_tune_policy_inline.pass.cpp
egfefey Jul 2, 2025
8a01c74
Update dynamic_selection_traits.h
egfefey Jul 2, 2025
9774feb
Update sycl_backend.h
egfefey Jul 2, 2025
e42354a
Update dynamic_selection_traits.h
egfefey Jul 2, 2025
3b7de9c
Update sycl_backend.h
egfefey Jul 2, 2025
f76d97d
adding first available policy
egfefey Aug 22, 2025
788ae0c
adding token policy
egfefey Sep 2, 2025
2a1f8c4
Dynamic Selection Adding ResourceAdapter to support queue* (#2367)
danhoeflinger Sep 10, 2025
8680771
fixes to use ResourceAdapter
danhoeflinger Sep 24, 2025
62837ad
removing static assertion
danhoeflinger Sep 24, 2025
5efa0ba
adding missing resource adapter
danhoeflinger Sep 24, 2025
bac3e7d
adding missing include
danhoeflinger Sep 24, 2025
bb4a145
updating auto_tune_policy to use adapter
egfefey Oct 9, 2025
5b4d628
enabling non-sycl round_robin tests
egfefey Oct 15, 2025
cc076a2
enabling non-sycl dynamic_load tests
egfefey Oct 15, 2025
f0d743e
checking for ext_oneapi_queue_profiling_tag support from the auto tun…
egfefey Oct 16, 2025
ca4f9ea
replacing instrument_before and after with a single submit
egfefey Oct 16, 2025
f4438bf
enabling fixed resource policy with the adapter update
egfefey Oct 20, 2025
9224a98
fix default submit implementation
danhoeflinger Oct 20, 2025
c161347
initial inline_backend update with int auto_tune tests
egfefey Oct 21, 2025
ee991fb
updates to remove select and convert to try_select, multiple submits
danhoeflinger Oct 21, 2025
56f84da
adjustments for tests removal of select
danhoeflinger Oct 21, 2025
c065309
fixes for customization tests
danhoeflinger Oct 21, 2025
0cf1abb
inline tests removal of select, adjust to use adapter
danhoeflinger Oct 21, 2025
28573d1
relocate report to internal namespace
danhoeflinger Oct 21, 2025
5a6ffb5
some fixes for sycl backend with adapter
danhoeflinger Oct 21, 2025
21404f0
update of documentation
danhoeflinger Oct 21, 2025
5d4776d
adding an end event to scratch_space and async_waiter in the sycl_bac…
egfefey Oct 22, 2025
f072513
minor fixes
danhoeflinger Oct 22, 2025
df2c3dc
adding qualifiers to report
danhoeflinger Oct 22, 2025
8d22b14
-> not .
danhoeflinger Oct 22, 2025
e88ecd9
improvments for scratch space, simplify async waiter
danhoeflinger Oct 23, 2025
3256af5
cleaning up public seleciton type / wait_type
danhoeflinger Oct 28, 2025
924b4e9
moving report-based resource filtering from auto_tune policy to backe…
egfefey Oct 30, 2025
7994657
adding assertions for supported reporting requirements
egfefey Oct 30, 2025
4e95417
clang-format
danhoeflinger Oct 30, 2025
5916d29
strip ::std -> std
danhoeflinger Oct 30, 2025
aa7872d
removing first_available_policy
danhoeflinger Oct 30, 2025
50f9805
remove unnecessary code
danhoeflinger Oct 30, 2025
2dbd011
comment fix
danhoeflinger Oct 30, 2025
4d19c23
always need default backend include
danhoeflinger Nov 3, 2025
82ef54e
make end event private
danhoeflinger Nov 3, 2025
b97f8fc
whitespace fix
danhoeflinger Nov 3, 2025
e7d61e8
removing some redundant test code
danhoeflinger Nov 3, 2025
d1dd570
always filter devices for profiling (not just default)
danhoeflinger Nov 4, 2025
3bc348b
using the internal helper contains_reporting_req_v for reporting requ…
egfefey Nov 4, 2025
bf1ae15
returning report info back to public namespace
danhoeflinger Nov 4, 2025
8f785a8
fixing reporting reqs passed to backend ctors
danhoeflinger Nov 4, 2025
0e9b283
removing token policy (temporarily)
danhoeflinger Nov 5, 2025
937a777
Merge remote-tracking branch 'origin/main' into dev/egfefey/custom_ba…
danhoeflinger Nov 5, 2025
0c0bcc8
adjustment to docs
danhoeflinger Nov 5, 2025
dff6883
adding free function for try_submit
danhoeflinger Nov 5, 2025
de67825
improve system around initialization
danhoeflinger Nov 5, 2025
5997a04
further fixes for ambiguity
danhoeflinger Nov 5, 2025
03ed63a
adding tests for default initialization of resources, other fixes
danhoeflinger Nov 5, 2025
e939df7
codespell fixes
danhoeflinger Nov 5, 2025
e41ef8d
clang format
danhoeflinger Nov 5, 2025
f9ce9a2
adding sycl_backend alias for backward compatibility
danhoeflinger Nov 5, 2025
43b1f93
fixing alias
danhoeflinger Nov 5, 2025
0a1d26a
code movement to minimize diff
danhoeflinger Nov 5, 2025
4a87d9d
clang format
danhoeflinger Nov 5, 2025
4c4ec94
remove unused variable
danhoeflinger Nov 5, 2025
372009d
example fixes nstreams_policies
danhoeflinger Nov 5, 2025
7befd04
Fix CRTP for auto_tune
danhoeflinger Nov 5, 2025
c032efb
fix examples
danhoeflinger Nov 5, 2025
8aa6084
clang format
danhoeflinger Nov 5, 2025
ba6acef
fixing tests for non-sycl backends
danhoeflinger Nov 5, 2025
650bd87
fixing ds inline backend for non sycl backends
danhoeflinger Nov 5, 2025
a5ea1c7
using declval to satisfy MSVC
danhoeflinger Nov 6, 2025
0411a10
clang format
danhoeflinger Nov 6, 2025
75b7eb4
Remove erroneous comment
danhoeflinger Nov 6, 2025
4f874f4
EOF endline
danhoeflinger Nov 6, 2025
26b9a07
fix for dynamic load policy lazy reporting
danhoeflinger Nov 6, 2025
4861281
remove overwrite of index
danhoeflinger Nov 10, 2025
7f3b4d3
std::optional -> std::shared_ptr
danhoeflinger Nov 10, 2025
60435d4
fix typo brace
danhoeflinger Nov 10, 2025
9af68a9
fix auto type
danhoeflinger Nov 10, 2025
0467d3c
switching devices to gpu
egfefey Nov 12, 2025
900d166
CTAD for round robin
egfefey Nov 12, 2025
ae2a546
simplify submit fallbacks and reduce redundancy
danhoeflinger Nov 12, 2025
ceea548
removing unnecessary trait
danhoeflinger Nov 12, 2025
889026b
minor cleanups (address feedback)
danhoeflinger Nov 12, 2025
f666870
bugfix to avoid returning reference shared ptr payload leaving scope
danhoeflinger Nov 12, 2025
586bd52
clang formatting
danhoeflinger Nov 12, 2025
b7a49f8
removing year from copyright
danhoeflinger Nov 12, 2025
a984902
formatting
danhoeflinger Nov 12, 2025
e1bdbcd
const function, remove auto
danhoeflinger Nov 12, 2025
364d1a3
restoring unintentional removal of template args
danhoeflinger Nov 13, 2025
a364a69
remove optional include
danhoeflinger Nov 13, 2025
2f0277b
fix static assertion language
danhoeflinger Nov 13, 2025
0a7cd4b
minor docs fixes
danhoeflinger Nov 13, 2025
d561386
remove optional include
danhoeflinger Nov 13, 2025
1d0ffdd
removing selection_type as return in docs
danhoeflinger Nov 13, 2025
99799c2
formatting
danhoeflinger Nov 13, 2025
2247cec
adding CTAD for dynamic_load_policy
egfefey Nov 13, 2025
e08ca68
removing thread
danhoeflinger Nov 13, 2025
e330649
remove CRTP from backend_base
danhoeflinger Nov 13, 2025
daffa53
protect impl functions and make base friend
danhoeflinger Nov 13, 2025
41536f2
formatting
danhoeflinger Nov 13, 2025
ca59727
adding adapter tests for auto_tune_policy
danhoeflinger Nov 13, 2025
ef2b6ee
addressing minor feedback
danhoeflinger Nov 14, 2025
629a2a2
Add comment for evaluation of backoff for try_submit
danhoeflinger Nov 14, 2025
75424ce
fixing customization tests for coverage
danhoeflinger Nov 14, 2025
ecb59c5
adding usage of sub variable to wait
danhoeflinger Nov 17, 2025
9584c0f
Adding test of failing selection
danhoeflinger Nov 17, 2025
de45407
formatting
danhoeflinger Nov 17, 2025
ceee9fd
adding CTAD for fixed_resource_policy
egfefey Nov 17, 2025
c6e4da9
adding a simple backoff after 100 tries
danhoeflinger Nov 17, 2025
5c95ee3
clang formatting
danhoeflinger Nov 17, 2025
6a177bb
adding CTAD for auto_tune_policy
egfefey Nov 18, 2025
a6ade91
improve error message
danhoeflinger Nov 18, 2025
7393b83
Update and improve documentation
danhoeflinger Nov 18, 2025
828f93f
passing adapter to policy constructor
danhoeflinger Nov 19, 2025
7c54b5c
fixing auto_tune_tests
danhoeflinger Nov 19, 2025
18b23e1
removing reliance on cpu device, formatting
danhoeflinger Nov 19, 2025
78afc05
removing requirement for fp64 in auto_tune
danhoeflinger Nov 19, 2025
85050bf
fixing issue with missing move ctor
danhoeflinger Nov 19, 2025
4343153
fixing issues with static_assert(false,...) with some compilers
danhoeflinger Nov 19, 2025
6f46ac5
undo overengineered perfect forwarding
danhoeflinger Nov 19, 2025
06f6eda
clang++ fix for ambiguous ctor
danhoeflinger Nov 19, 2025
b736655
reverting move wait type
danhoeflinger Nov 19, 2025
22d39c1
hide wait call in SFINAE
danhoeflinger Nov 19, 2025
49cd7b9
removing explicit
danhoeflinger Nov 19, 2025
7719774
Merge remote-tracking branch 'origin/main' into dev/egfefey/custom_ba…
danhoeflinger Nov 19, 2025
42e4f0a
fix for custom_backend language
danhoeflinger Nov 19, 2025
4a22a69
explicit template arg
danhoeflinger Nov 19, 2025
099494c
adding iterations for autotune
danhoeflinger Nov 19, 2025
99e3b44
formatting
danhoeflinger Nov 20, 2025
65410c2
increasing iteration count to make best resource more apparent
danhoeflinger Nov 20, 2025
55eee68
avoid warning by passing explicit Backend
danhoeflinger Nov 20, 2025
ad8ac03
auto_tune fixes
danhoeflinger Nov 20, 2025
58537fd
fix filtering for timing
danhoeflinger Nov 20, 2025
112d75a
adding ambiguity tests for fixed_resource_policy and auto_tune_policy
egfefey Nov 21, 2025
56f20b1
bugfix (add event before adding to list)
danhoeflinger Nov 21, 2025
e44ed7f
using profiling tags in ctad tests
danhoeflinger Nov 21, 2025
59d9adb
protecting non-profiling cases for 2023.2 and earlier
danhoeflinger Nov 21, 2025
e3eb212
fixing skip handling and formating
danhoeflinger Nov 21, 2025
918e009
use default selector for dynamic load
danhoeflinger Nov 21, 2025
153e380
try_submit relocated
danhoeflinger Nov 24, 2025
d03e768
switch from shared_ptr back to std::optional
danhoeflinger Nov 24, 2025
10b1768
use free function get_resources
danhoeflinger Nov 24, 2025
5cb17ad
restore selection_type as protected in docs
danhoeflinger Nov 24, 2025
633256e
rename try_select_impl->try_select
danhoeflinger Nov 24, 2025
ddc767b
rename initialize_impl -> initialize_state
danhoeflinger Nov 24, 2025
5bfcd1e
fixing reporting requirements
danhoeflinger Nov 24, 2025
298ad24
explicit mention of CRTP for policy_base
danhoeflinger Nov 24, 2025
25d811c
BaseResourceTypedefault_backend_impl -> core_resource_backend; BaseRe…
danhoeflinger Nov 24, 2025
9375279
static assertion to sycl_backend for wait_type
danhoeflinger Nov 25, 2025
f77b404
pre-filter queues for auto-tune
danhoeflinger Nov 25, 2025
0b6d1a9
adding missing include
danhoeflinger Nov 25, 2025
64436e0
fixing naming of __select_impl in docs
danhoeflinger Nov 25, 2025
d65259a
remove unnecessary aliases / wrapping
danhoeflinger Nov 25, 2025
787e9a6
bug fix for typename
danhoeflinger Nov 26, 2025
92baa49
improvements for traits, wait_type
danhoeflinger Nov 26, 2025
5b7a56a
formatting
danhoeflinger Nov 26, 2025
17bbbe6
remove test
danhoeflinger Nov 26, 2025
224ae9d
fixes for the toctree
danhoeflinger Nov 26, 2025
0766c26
fixing see also links
danhoeflinger Nov 26, 2025
6dc1a39
taking suggestion
danhoeflinger Nov 26, 2025
32e61f9
fix example away from using selection
danhoeflinger Nov 26, 2025
c5bcbf6
Update documentation/library_guide/dynamic_selection_api/functions.rst
danhoeflinger Nov 26, 2025
c381630
update and fix premade policies
danhoeflinger Nov 26, 2025
307c44c
address feedback
danhoeflinger Dec 1, 2025
3def477
remove incorrect forwarding
danhoeflinger Dec 1, 2025
12c6f8b
protect usage of profiling tags
danhoeflinger Dec 1, 2025
ffe846f
address feedback
danhoeflinger Dec 1, 2025
a4b47d5
accept suggestion
danhoeflinger Dec 1, 2025
9234fd1
focus on policy_base for customization of policies
danhoeflinger Dec 1, 2025
89cddb3
accept feedback
danhoeflinger Dec 1, 2025
bcadb28
fix nullptr -> nullopt
danhoeflinger Dec 1, 2025
2c46023
Add high level description of policy structure
danhoeflinger Dec 1, 2025
d7e7a14
minor improvements to general section
danhoeflinger Dec 1, 2025
0133833
adding selection_type information to docs
danhoeflinger Dec 1, 2025
daefbb1
restructure and remove verbose example
danhoeflinger Dec 1, 2025
0194aee
Relocating resource adapter section
danhoeflinger Dec 1, 2025
67a2721
move execution info to custom policies
danhoeflinger Dec 1, 2025
6404c8e
sycl backend supported execution info
danhoeflinger Dec 1, 2025
dd628f6
removing unnecessary sections
danhoeflinger Dec 1, 2025
57417af
cut down custom backend sections
danhoeflinger Dec 1, 2025
3fb649e
reference to lazy reporting from policy customization
danhoeflinger Dec 1, 2025
b3966c9
backend architecture section
danhoeflinger Dec 1, 2025
b4f13f4
improving scratch space description
danhoeflinger Dec 1, 2025
0b8d4cd
Rename section
danhoeflinger Dec 1, 2025
97fe6ed
improve looped vector operations
danhoeflinger Dec 2, 2025
ac2ef0e
further minor improvements
danhoeflinger Dec 2, 2025
2cdbc44
Merge remote-tracking branch 'origin/main' into dev/egfefey/custom_ba…
danhoeflinger Dec 2, 2025
932c23c
addressing documentation feedback
danhoeflinger Dec 2, 2025
88270c2
numbering constructors
danhoeflinger Dec 2, 2025
8c88013
preventing horizontal scroll
danhoeflinger Dec 2, 2025
d169d0b
capitalization
danhoeflinger Dec 2, 2025
298cb5d
better rendering for tables
danhoeflinger Dec 2, 2025
9c35db0
formatting attempt 2
danhoeflinger Dec 2, 2025
5841d93
shorten varname
danhoeflinger Dec 2, 2025
d725d71
final shortening
danhoeflinger Dec 2, 2025
f79d2ec
Formatting of note
danhoeflinger Dec 2, 2025
75cc08e
formatting for note
danhoeflinger Dec 2, 2025
6634057
removing unnecessary unwrap
danhoeflinger Dec 2, 2025
8d11efc
address feedback for custom policies
danhoeflinger Dec 2, 2025
ff0ccce
better formatting for note and text tweak
danhoeflinger Dec 2, 2025
d90fb57
removing extra space
danhoeflinger Dec 2, 2025
0ca493e
fixing std optional
danhoeflinger Dec 2, 2025
dd7f6ea
address minor feedback
danhoeflinger Dec 2, 2025
bad0f61
improve description of sycl backend
danhoeflinger Dec 2, 2025
4ed5c5f
improve sycl backend description
danhoeflinger Dec 2, 2025
e9a38bd
formatting and link convention
danhoeflinger Dec 2, 2025
2838394
fix formatting
danhoeflinger Dec 2, 2025
ab4cc27
remove table titles
danhoeflinger Dec 2, 2025
3654caf
adding information about sycl backend to function page
danhoeflinger Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 67 additions & 83 deletions documentation/library_guide/dynamic_selection_api/auto_tune_policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,50 @@ the profiling phase periodically.
.. code:: cpp

namespace oneapi::dpl::experimental {

template<typename Backend = sycl_backend>
class auto_tune_policy {
public:
// useful types
using resource_type = typename Backend::resource_type;
using wait_type = typename Backend::wait_type;

class selection_type {
template <typename ResourceType = sycl::queue, typename ResourceAdapter = oneapi::dpl::identity,
typename Backend = default_backend<ResourceType, ResourceAdapter>, typename... KeyArgs>
class auto_tune_policy
: public policy_base<auto_tune_policy<ResourceType, ResourceAdapter, Backend, KeyArgs...>,
ResourceAdapter, Backend, execution_info::task_time_t>
{
public:
auto_tune_policy<Backend> get_policy() const;
resource_type unwrap() const;
};

// constructors
auto_tune_policy(deferred_initialization_t);
auto_tune_policy(uint64_t resample_interval_in_milliseconds = 0);
auto_tune_policy(const std::vector<resource_type>& u,
uint64_t resample_interval_in_milliseconds = 0);

// deferred initializer
void initialize(uint64_t resample_interval_in_milliseconds = 0);
void initialize(const std::vector<resource_type>& u,
uint64_t resample_interval_in_milliseconds = 0);

// queries
auto get_resources() const;
auto get_submission_group();

// other implementation defined functions...
using resource_type = ResourceType;
using backend_type = Backend;

auto_tune_policy(deferred_initialization_t);
auto_tune_policy(uint64_t resample_interval_ms = 0);
auto_tune_policy(const std::vector<ResourceType>& u, ResourceAdapter adapter = {},
uint64_t resample_interval_ms = 0);

// deferred initializer
void initialize(uint64_t resample_interval_ms = 0);
void initialize(const std::vector<resource_type>& u,
uint64_t resample_interval_ms = 0);
// other implementation defined functions...
};

}

This policy can be used with all the dynamic selection functions, such as ``select``, ``submit``,
and ``submit_and_wait``. It can also be used with ``policy_traits``.

This policy can be used with all the dynamic selection :doc:`free functions <functions>`,
as well as with :ref:`policy traits <policy-traits>`.

Task Identification with KeyArgs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The template parameter pack ``KeyArgs`` allows the policy to track performance for submitted jobs.
By default (empty ``KeyArgs``), all invocations of the same function share performance history.
When ``KeyArgs`` are specified, the policy uses both the function pointer and the specified
arguments to create a unique key for tracking performance.

.. Note::

The number of ``KeyArgs`` types must exactly match the number of extra arguments
passed to the user function beyond the resource. This requirement is enforced at compile-time.

For example, ``auto_tune_policy<sycl::queue, oneapi::dpl::identity, default_backend, std::size_t>``
will track performance separately for each distinct ``std::size_t`` argument value, useful
when performance varies with problem size. Here, one ``KeyArg`` type corresponds to one extra
argument passed to the function after the ``sycl::queue``.

Example
-------
Expand Down Expand Up @@ -128,15 +136,15 @@ to choose the best resource for the given function. A simplified, expository
implementation of the selection algorithm follows:

.. code:: cpp

//not a public function, for exposition purposes only
template<typename Function, typename ...Args>
selection_type auto_tune_policy::select(Function&& f, Args&&...args) {
if (initialized_) {
auto k = make_task_key(f, args...);
auto tuner = get_tuner(k);
auto offset = tuner->get_resource_to_profile();
if (offset == use_best) {
return selection_type {*this, tuner->best_resource_, tuner};
return selection_type{*this, tuner->best_resource_, tuner};
} else {
auto r = resources_[offset];
return selection{*this, r, tuner};
Expand All @@ -162,18 +170,22 @@ Constructors

``auto_tune_policy`` provides three constructors.

.. list-table:: ``auto_tune_policy`` constructors
.. list-table::
:widths: 50 50
:header-rows: 1

* - Signature
- Description
* - ``auto_tune_policy(deferred_initialization_t);``
- Defers initialization. An ``initialize`` function must be called prior to use.
* - ``auto_tune_policy(uint64_t resample_interval_in_milliseconds = 0);``
* - | ``auto_tune_policy(``
| ``uint64_t resample_interval_ms = 0);``
- Initialized to use the default set of resources. An optional resampling interval can be provided.
* - ``auto_tune_policy(const std::vector<resource_type>& u, uint64_t resample_interval_in_milliseconds = 0);``
- Overrides the default set of resources. An optional resampling interval can be provided.
* - | ``auto_tune_policy(``
| ``const std::vector<ResourceType>& u,``
| ``ResourceAdapter adapter = {},``
| ``uint64_t resample_interval_ms = 0);``
- Overrides the default set of resources with an optional resource adapter. An optional resampling interval can be provided.

.. Note::

Expand All @@ -184,19 +196,22 @@ Constructors
Deferred Initialization
-----------------------

A ``auto_tune_policy`` that was constructed with deferred initialization must be
initialized by calling one its ``initialize`` member functions before it can be used
An ``auto_tune_policy`` that was constructed with deferred initialization must be
initialized by calling one of its ``initialize`` member functions before it can be used
to select or submit.

.. list-table:: ``auto_tune_policy`` constructors
.. list-table::
:widths: 50 50
:header-rows: 1

* - Signature
- Description
* - ``initialize(uint64_t resample_interval_in_milliseconds = 0);``
* - | ``initialize(``
| ``uint64_t resample_interval_ms = 0);``
- Initialize to use the default set of resources. An optional resampling interval can be provided.
* - ``initialize(const std::vector<resource_type>& u, uint64_t resample_interval_in_milliseconds = 0);``
* - | ``initialize(``
| ``const std::vector<resource_type>& u,``
| ``uint64_t resample_interval_ms = 0);``
- Overrides the default set of resources. An optional resampling interval can be provided.

.. Note::
Expand All @@ -208,13 +223,13 @@ to select or submit.
Queries
-------

A ``auto_tune_policy`` has ``get_resources`` and ``get_submission_group``
An ``auto_tune_policy`` has ``get_resources`` and ``get_submission_group``
member functions.

.. list-table:: ``auto_tune_policy`` constructors
.. list-table::
:widths: 50 50
:header-rows: 1

* - Signature
- Description
* - ``std::vector<resource_type> get_resources();``
Expand All @@ -224,37 +239,6 @@ member functions.

Reporting Requirements
----------------------

If a resource returned by ``select`` is used directly without calling
``submit`` or ``submit_and_wait``, it may be necessary to call ``report``
to provide feedback to the policy. The ``auto_tune_policy`` tracks the
performance of submissions on each device via callbacks that report
the execution time. The instrumentation to report these events is included
in the implementations of ``submit`` and ``submit_and_wait``. However, if you
use ``select`` and then submit work directly to the selected resource, it
is necessary to explicitly report these events.

.. list-table:: ``auto_tune_policy`` reporting requirements
:widths: 50 50
:header-rows: 1

* - ``execution_info``
- is reporting required?
* - ``task_submission``
- No
* - ``task_completion``
- No
* - ``task_time``
- Yes

In generic code, it is possible to perform compile-time checks to avoid
reporting overheads when reporting is not needed, while still writing
code that will work with any policy, as demonstrated below:

.. code:: cpp

auto s = select(my_policy);
if constexpr (report_info_v<decltype(s), execution_info::task_submission_t>)
{
s.report(execution_info::task_submission);
}
A ``auto_tune_policy`` requires the ``task_time`` reporting requirement. See the
:ref:`Execution Information <execution-information>` section for more information
about reporting requirements.
162 changes: 162 additions & 0 deletions documentation/library_guide/dynamic_selection_api/backends.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Backends
########

The dynamic selection API is an experimental feature in the |onedpl_long|
(|onedpl_short|) that selects an *execution resource* based on a chosen
*selection policy*. For the policies to work with different resource types.
the resource management and work submission mechanics are handled
separately by resource-specific *backends*.

A backend is responsible for:

1. **Resource Management** - storing and providing access to a set of resources
2. **Work Submission** - executing user functions on selected resources
3. **Synchronization** - waiting for submitted work to complete
4. **Instrumentation** - optionally reporting execution information (timing, completion)

Backends are typically not directly visible to application developers - they work
behind the scenes to enable policies to function.

SYCL Backend
------------

A sycl backend is provided to manage ``sycl::queue`` core resources, and ``sycl::queue``
is the default resource if none is provided or deduce-able from resource arguments.
The SYCL backend provides:

- Default initialization from available SYCL devices
- Event-based submission and waiting
- Optional profiling and timing instrumentation

When you construct a policy without specifying resources, it uses the SYCL
backend's default initialization:

.. code:: cpp
#include <oneapi/dpl/dynamic_selection>
namespace ex = oneapi::dpl::experimental;
// Uses SYCL backend with default device initialization
ex::round_robin_policy<> policy;
// Explicitly specifying SYCL queues
std::vector<sycl::queue> my_queues = { /* ... */ };
ex::round_robin_policy<sycl::queue> policy2{my_queues};
The SYCL backend supports the reporting for :ref:`Execution Information <execution-information>`
of ``task_submission``, ``task_completion``, and ``task_time``.

Backend Architecture
--------------------

The backend system uses a layered design to support multiple resource types:

**default_backend**: When you create a policy, ``default_backend`` automatically
determines the core resource type by applying any
:ref:`resource adapter <resource-adapters>` to your resource type. It then
delegates to the appropriate ``core_resource_backend`` specialization.

**core_resource_backend**: Specialized backend implementations exist for specific core
resource types (like ``sycl::queue``). A generic implementation is provided
for core resources without an explicitly specialized implementation which provides
a minimal amount of functionality:

- Basic resource storage and retrieval
- Simple work submission without instrumentation (No execution information reporting)

To use a custom resource type with full instrumentation support, you must create a
``core_resource_backend`` specialization.

Lazy Reporting
--------------
Comment on lines +75 to +76
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should name it "on-demand reporting" or similarly - at least in the documentation (while the API naming can be discussed / addressed later).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vossmjp Do you have an opinion here? This is not something new in the design, but just something we've documented. I have no strong opinions here, but there are a few places we would have to change it if we choose to.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, my comment is primarily about the documentation. And it's also minor and can be postponed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong objection to the change itself, but I'd prefer to defer all but essential changes at this point so we can get things merged.


.. _lazy_report:

For asynchronous execution, backends may use *lazy reporting* where
:ref:`Execution Information <execution-information>` is not immediately available.
The SYCL backend uses lazy reporting for ``task_completion`` and ``task_time``.

Policies that use execution information always call the backend's
``lazy_report()`` function before making selections, ensuring they have
up-to-date information about completed tasks.

This is transparent to application developers - the policy handles the details.

Backend Traits
--------------

Backend traits provide compile-time information about backend capabilities:

.. code:: cpp
namespace oneapi::dpl::experimental
{
template<typename Backend>
struct backend_traits {
// True if backend has explicit wait_type
static constexpr bool has_wait_type_v = /* ... */;
// If has_wait_type_v is True, specific type required from user functions.
// If has_wait_type_v is False, void (user functions must return waitable-type)
using wait_type = /* ... */;
// True if backend requires lazy_report() to be called
static constexpr bool lazy_report_v = /* ... */;
// Scratch space type for selection handles
template<typename... ReportReqs>
using selection_scratch_t = /* ... */;
};
}
These traits are primarily used by policy implementers, not application developers.

Wait Type Requirements
^^^^^^^^^^^^^^^^^^^^^^

Backends specify return type requirements for user-submitted functions through the
``wait_type`` member:

**Explicit wait_type**: If a backend defines a ``wait_type`` alias (e.g., ``using wait_type = sycl::event;``),
user functions **must** return that specific type. This is typically required when the backend
needs to instrument or track asynchronous operations.

**No explicit wait_type**: If a backend does not define a ``wait_type`` alias, user functions
may return any *waitable-type*. A waitable-type is any type with a ``wait()`` member function
that can be called to synchronize with the operation's completion.

The SYCL backend defines ``wait_type = sycl::event``, requiring user functions to return
``sycl::event`` for proper instrumentation and synchronization.

Selection Scratch Space
^^^^^^^^^^^^^^^^^^^^^^^

.. _selection_scratch_space:

Backends need storage space within selection handles to implement instrumentation.
The ``selection_scratch_t`` trait specifies what additional data a backend requires
based on the policy's reporting needs.

When a policy tracks execution information (like task timing or completion), the backend
needs to store temporary data with each selection. For example, the SYCL backend stores
an extra ``sycl::event`` for start-time profiling tags when ``task_time`` reporting is requested.

The backend populates and uses this scratch space during work submission and reporting.
For policies without reporting requirements, ``selection_scratch_t<>`` is empty,
adding no overhead.

Custom Backends
---------------

For advanced use cases, you can create custom backends to support new resource
types or provide specialized instrumentation. Custom backends are created by
specializing ``core_resource_backend`` for your resource type. For an example of
how to do this, look at ``core_resource_backend<sycl::queue, ...>``.

See Also
--------

- :doc:`policies` - Overview of selection policies
- :doc:`functions` - Free functions for working with backends and policies
Loading
Loading