Skip to content

Commit d61d6ae

Browse files
danhoeflingeregfefeyCopilotakukanov
authored
[Dynamic Selection] Customization of Backends and Policies (#2508)
* adding missing condition for scratch space use * initial policy base plus round robin inheriting * initial policy customization - policy base plus inherited round robin * fixed resource policy using the policy_base * adding exception in select * Deactivating policies beside RR for custom backend testing * default base + RR updates for default sycl backend * adding missed updated sycl_backend * updating fixed resource policy and test to use default sycl backend * updating dynamic load policy to use default sycl backend * updating the auto_tune policy to use the default sycl backend * split submit into instument_before, function invocation and instrument after, also removed submit from the sycl_backend. Now uses the base implementation * updating the backend traits with a scratch space for selection * warning fix from previous push * adding missing condition for scratch space use * initial policy base plus round robin inheriting * initial policy customization - policy base plus inherited round robin * fixed resource policy using the policy_base * adding exception in select * updates to enable non-sycl samples plus a traits check for wait * enabling fixed_resource_policy for non-sycl samples * initial update to enable dynamic_load_policy for non-sycl samples * Adding wait_type * adding resource_type to the test * Update round_robin_policy.h * Update round_robin_policy.h * Update fixed_resource_policy.h * Update test_fixed_resource_policy_inline.pass.cpp * Update dynamic_load_policy.h * Update dynamic_load_policy.h * Update test_dynamic_load_policy_inline.pass.cpp * Update test_dynamic_load_utils.h * Update dynamic_load_policy.h * Update sycl_backend.h * Update dynamic_load_policy.h * using default backend * Update test_internal_sycl_scheduler.pass.cpp * Update test_internal_sycl_scheduler.pass.cpp * Update sycl_backend.h * Update sycl_backend.h * Update test_auto_tune_policy_sycl.pass.cpp * Update test_auto_tune_policy_inline.pass.cpp * Update dynamic_selection_traits.h * Update sycl_backend.h * Update dynamic_selection_traits.h * Update sycl_backend.h * adding first available policy * adding token policy * Dynamic Selection Adding ResourceAdapter to support queue* (#2367) Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixes to use ResourceAdapter Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing static assertion Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding missing resource adapter Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding missing include Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * updating auto_tune_policy to use adapter * enabling non-sycl round_robin tests * enabling non-sycl dynamic_load tests * checking for ext_oneapi_queue_profiling_tag support from the auto tune policy * replacing instrument_before and after with a single submit * enabling fixed resource policy with the adapter update * fix default submit implementation Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * initial inline_backend update with int auto_tune tests * updates to remove select and convert to try_select, multiple submits Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adjustments for tests removal of select Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixes for customization tests Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * inline tests removal of select, adjust to use adapter Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * relocate report to internal namespace Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * some fixes for sycl backend with adapter Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * update of documentation Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding an end event to scratch_space and async_waiter in the sycl_backend * minor fixes Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding qualifiers to report Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * -> not . formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improvments for scratch space, simplify async waiter Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * cleaning up public seleciton type / wait_type Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * moving report-based resource filtering from auto_tune policy to backend + report-based filtering updates to dynamic_load_policy * adding assertions for supported reporting requirements * clang-format Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * strip ::std -> std Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing first_available_policy Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove unnecessary code Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * comment fix Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * always need default backend include Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * make end event private Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * whitespace fix Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing some redundant test code Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * always filter devices for profiling (not just default) Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * using the internal helper contains_reporting_req_v for reporting requirement check * returning report info back to public namespace Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing reporting reqs passed to backend ctors Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing token policy (temporarily) Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adjustment to docs Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding free function for try_submit Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improve system around initialization Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * further fixes for ambiguity Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding tests for default initialization of resources, other fixes Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * codespell fixes Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * clang format Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding sycl_backend alias for backward compatibility Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing alias Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * code movement to minimize diff Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * clang format Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove unused variable Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * example fixes nstreams_policies Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Fix CRTP for auto_tune Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix examples Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * clang format Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing tests for non-sycl backends Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing ds inline backend for non sycl backends Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * using declval to satisfy MSVC Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * clang format Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Remove erroneous comment Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * EOF endline Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix for dynamic load policy lazy reporting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove overwrite of index Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * std::optional -> std::shared_ptr Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix typo brace Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix auto type Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * switching devices to gpu * CTAD for round robin * simplify submit fallbacks and reduce redundancy Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing unnecessary trait Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * minor cleanups (address feedback) Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * bugfix to avoid returning reference shared ptr payload leaving scope Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * clang formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing year from copyright Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * const function, remove auto Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * restoring unintentional removal of template args Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove optional include Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix static assertion language Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * minor docs fixes Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove optional include Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing selection_type as return in docs Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding CTAD for dynamic_load_policy * removing thread Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove CRTP from backend_base Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * protect impl functions and make base friend Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding adapter tests for auto_tune_policy Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * addressing minor feedback Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Add comment for evaluation of backoff for try_submit Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing customization tests for coverage Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding usage of sub variable to wait Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Adding test of failing selection Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding CTAD for fixed_resource_policy * adding a simple backoff after 100 tries Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * clang formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding CTAD for auto_tune_policy * improve error message Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Update and improve documentation add information on try_submit add custom_policies page add backend page and custom_backends page Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * passing adapter to policy constructor Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing auto_tune_tests Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing reliance on cpu device, formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing requirement for fp64 in auto_tune Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing issue with missing move ctor Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing issues with static_assert(false,...) with some compilers Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * undo overengineered perfect forwarding Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * clang++ fix for ambiguous ctor Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * reverting move wait type Simplify for what should be a very lightweight type (wait type) Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * hide wait call in SFINAE Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing explicit Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix for custom_backend language Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * explicit template arg Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding iterations for autotune Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * increasing iteration count to make best resource more apparent Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * avoid warning by passing explicit Backend Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * auto_tune fixes Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix filtering for timing Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding ambiguity tests for fixed_resource_policy and auto_tune_policy * bugfix (add event before adding to list) Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * using profiling tags in ctad tests Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * protecting non-profiling cases for 2023.2 and earlier Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing skip handling and formating Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * use default selector for dynamic load Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * try_submit relocated Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * switch from shared_ptr back to std::optional Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * use free function get_resources Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * restore selection_type as protected in docs Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * rename try_select_impl->try_select Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * rename initialize_impl -> initialize_state Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing reporting requirements Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * explicit mention of CRTP for policy_base Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * BaseResourceTypedefault_backend_impl -> core_resource_backend; BaseResourceType->CoreResourceType Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * static assertion to sycl_backend for wait_type Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * pre-filter queues for auto-tune Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding missing include Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing naming of __select_impl in docs Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove unnecessary aliases / wrapping Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * bug fix for typename Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improvements for traits, wait_type Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove test Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixes for the toctree Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing see also links Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * taking suggestion Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix example away from using selection Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Update documentation/library_guide/dynamic_selection_api/functions.rst Co-authored-by: Alexey Kukanov <alexey.kukanov@intel.com> * update and fix premade policies Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * address feedback Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove incorrect forwarding Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * protect usage of profiling tags Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * address feedback Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * accept suggestion Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * focus on policy_base for customization of policies Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * accept feedback Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix nullptr -> nullopt Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Add high level description of policy structure Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * minor improvements to general section Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding selection_type information to docs Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * restructure and remove verbose example Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Relocating resource adapter section Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * move execution info to custom policies Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * sycl backend supported execution info Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing unnecessary sections Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * cut down custom backend sections Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * reference to lazy reporting from policy customization Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * backend architecture section Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improving scratch space description Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Rename section Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improve looped vector operations Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * further minor improvements Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * addressing documentation feedback Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * numbering constructors Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * preventing horizontal scroll Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * capitalization Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * better rendering for tables Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting attempt 2 Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * shorten varname Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * final shortening Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * Formatting of note Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting for note Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing unnecessary unwrap Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * address feedback for custom policies Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * better formatting for note and text tweak Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * removing extra space Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fixing std optional Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * address minor feedback Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improve description of sycl backend Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improve sycl backend description Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * formatting and link convention Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * fix formatting Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * remove table titles Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * adding information about sycl backend to function page Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> --------- Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> Signed-off-by: Dan Hoeflinger Co-authored-by: Elvis Fefey <elvis.g.fefey@intel.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Alexey Kukanov <alexey.kukanov@intel.com>
1 parent c3ce893 commit d61d6ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3119
-2558
lines changed

documentation/library_guide/dynamic_selection_api/auto_tune_policy.rst

Lines changed: 67 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,50 @@ the profiling phase periodically.
2020
.. code:: cpp
2121
2222
namespace oneapi::dpl::experimental {
23-
24-
template<typename Backend = sycl_backend>
25-
class auto_tune_policy {
26-
public:
27-
// useful types
28-
using resource_type = typename Backend::resource_type;
29-
using wait_type = typename Backend::wait_type;
30-
31-
class selection_type {
23+
template <typename ResourceType = sycl::queue, typename ResourceAdapter = oneapi::dpl::identity,
24+
typename Backend = default_backend<ResourceType, ResourceAdapter>, typename... KeyArgs>
25+
class auto_tune_policy
26+
: public policy_base<auto_tune_policy<ResourceType, ResourceAdapter, Backend, KeyArgs...>,
27+
ResourceAdapter, Backend, execution_info::task_time_t>
28+
{
3229
public:
33-
auto_tune_policy<Backend> get_policy() const;
34-
resource_type unwrap() const;
35-
};
36-
37-
// constructors
38-
auto_tune_policy(deferred_initialization_t);
39-
auto_tune_policy(uint64_t resample_interval_in_milliseconds = 0);
40-
auto_tune_policy(const std::vector<resource_type>& u,
41-
uint64_t resample_interval_in_milliseconds = 0);
42-
43-
// deferred initializer
44-
void initialize(uint64_t resample_interval_in_milliseconds = 0);
45-
void initialize(const std::vector<resource_type>& u,
46-
uint64_t resample_interval_in_milliseconds = 0);
47-
48-
// queries
49-
auto get_resources() const;
50-
auto get_submission_group();
51-
52-
// other implementation defined functions...
30+
using resource_type = ResourceType;
31+
using backend_type = Backend;
32+
33+
auto_tune_policy(deferred_initialization_t);
34+
auto_tune_policy(uint64_t resample_interval_ms = 0);
35+
auto_tune_policy(const std::vector<ResourceType>& u, ResourceAdapter adapter = {},
36+
uint64_t resample_interval_ms = 0);
37+
38+
// deferred initializer
39+
void initialize(uint64_t resample_interval_ms = 0);
40+
void initialize(const std::vector<resource_type>& u,
41+
uint64_t resample_interval_ms = 0);
42+
// other implementation defined functions...
5343
};
54-
44+
5545
}
56-
57-
This policy can be used with all the dynamic selection functions, such as ``select``, ``submit``,
58-
and ``submit_and_wait``. It can also be used with ``policy_traits``.
46+
47+
This policy can be used with all the dynamic selection :doc:`free functions <functions>`,
48+
as well as with :ref:`policy traits <policy-traits>`.
49+
50+
Task Identification with KeyArgs
51+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
53+
The template parameter pack ``KeyArgs`` allows the policy to track performance for submitted jobs.
54+
By default (empty ``KeyArgs``), all invocations of the same function share performance history.
55+
When ``KeyArgs`` are specified, the policy uses both the function pointer and the specified
56+
arguments to create a unique key for tracking performance.
57+
58+
.. Note::
59+
60+
The number of ``KeyArgs`` types must exactly match the number of extra arguments
61+
passed to the user function beyond the resource. This requirement is enforced at compile-time.
62+
63+
For example, ``auto_tune_policy<sycl::queue, oneapi::dpl::identity, default_backend, std::size_t>``
64+
will track performance separately for each distinct ``std::size_t`` argument value, useful
65+
when performance varies with problem size. Here, one ``KeyArg`` type corresponds to one extra
66+
argument passed to the function after the ``sycl::queue``.
5967

6068
Example
6169
-------
@@ -129,14 +137,15 @@ implementation of the selection algorithm follows:
129137

130138
.. code:: cpp
131139
140+
//not a public function, for exposition purposes only
132141
template<typename Function, typename ...Args>
133142
selection_type auto_tune_policy::select(Function&& f, Args&&...args) {
134143
if (initialized_) {
135144
auto k = make_task_key(f, args...);
136145
auto tuner = get_tuner(k);
137146
auto offset = tuner->get_resource_to_profile();
138147
if (offset == use_best) {
139-
return selection_type {*this, tuner->best_resource_, tuner};
148+
return selection_type{*this, tuner->best_resource_, tuner};
140149
} else {
141150
auto r = resources_[offset];
142151
return selection{*this, r, tuner};
@@ -162,18 +171,22 @@ Constructors
162171

163172
``auto_tune_policy`` provides three constructors.
164173

165-
.. list-table:: ``auto_tune_policy`` constructors
174+
.. list-table::
166175
:widths: 50 50
167176
:header-rows: 1
168-
177+
169178
* - Signature
170179
- Description
171180
* - ``auto_tune_policy(deferred_initialization_t);``
172181
- Defers initialization. An ``initialize`` function must be called prior to use.
173-
* - ``auto_tune_policy(uint64_t resample_interval_in_milliseconds = 0);``
182+
* - | ``auto_tune_policy(``
183+
| ``uint64_t resample_interval_ms = 0);``
174184
- Initialized to use the default set of resources. An optional resampling interval can be provided.
175-
* - ``auto_tune_policy(const std::vector<resource_type>& u, uint64_t resample_interval_in_milliseconds = 0);``
176-
- Overrides the default set of resources. An optional resampling interval can be provided.
185+
* - | ``auto_tune_policy(``
186+
| ``const std::vector<ResourceType>& u,``
187+
| ``ResourceAdapter adapter = {},``
188+
| ``uint64_t resample_interval_ms = 0);``
189+
- Overrides the default set of resources with an optional resource adapter. An optional resampling interval can be provided.
177190

178191
.. Note::
179192

@@ -184,19 +197,22 @@ Constructors
184197
Deferred Initialization
185198
-----------------------
186199

187-
A ``auto_tune_policy`` that was constructed with deferred initialization must be
188-
initialized by calling one its ``initialize`` member functions before it can be used
200+
An ``auto_tune_policy`` that was constructed with deferred initialization must be
201+
initialized by calling one of its ``initialize`` member functions before it can be used
189202
to select or submit.
190203

191-
.. list-table:: ``auto_tune_policy`` constructors
204+
.. list-table::
192205
:widths: 50 50
193206
:header-rows: 1
194-
207+
195208
* - Signature
196209
- Description
197-
* - ``initialize(uint64_t resample_interval_in_milliseconds = 0);``
210+
* - | ``initialize(``
211+
| ``uint64_t resample_interval_ms = 0);``
198212
- Initialize to use the default set of resources. An optional resampling interval can be provided.
199-
* - ``initialize(const std::vector<resource_type>& u, uint64_t resample_interval_in_milliseconds = 0);``
213+
* - | ``initialize(``
214+
| ``const std::vector<resource_type>& u,``
215+
| ``uint64_t resample_interval_ms = 0);``
200216
- Overrides the default set of resources. An optional resampling interval can be provided.
201217

202218
.. Note::
@@ -208,13 +224,13 @@ to select or submit.
208224
Queries
209225
-------
210226

211-
A ``auto_tune_policy`` has ``get_resources`` and ``get_submission_group``
227+
An ``auto_tune_policy`` has ``get_resources`` and ``get_submission_group``
212228
member functions.
213229

214-
.. list-table:: ``auto_tune_policy`` constructors
230+
.. list-table::
215231
:widths: 50 50
216232
:header-rows: 1
217-
233+
218234
* - Signature
219235
- Description
220236
* - ``std::vector<resource_type> get_resources();``
@@ -224,37 +240,6 @@ member functions.
224240

225241
Reporting Requirements
226242
----------------------
227-
228-
If a resource returned by ``select`` is used directly without calling
229-
``submit`` or ``submit_and_wait``, it may be necessary to call ``report``
230-
to provide feedback to the policy. The ``auto_tune_policy`` tracks the
231-
performance of submissions on each device via callbacks that report
232-
the execution time. The instrumentation to report these events is included
233-
in the implementations of ``submit`` and ``submit_and_wait``. However, if you
234-
use ``select`` and then submit work directly to the selected resource, it
235-
is necessary to explicitly report these events.
236-
237-
.. list-table:: ``auto_tune_policy`` reporting requirements
238-
:widths: 50 50
239-
:header-rows: 1
240-
241-
* - ``execution_info``
242-
- is reporting required?
243-
* - ``task_submission``
244-
- No
245-
* - ``task_completion``
246-
- No
247-
* - ``task_time``
248-
- Yes
249-
250-
In generic code, it is possible to perform compile-time checks to avoid
251-
reporting overheads when reporting is not needed, while still writing
252-
code that will work with any policy, as demonstrated below:
253-
254-
.. code:: cpp
255-
256-
auto s = select(my_policy);
257-
if constexpr (report_info_v<decltype(s), execution_info::task_submission_t>)
258-
{
259-
s.report(execution_info::task_submission);
260-
}
243+
A ``auto_tune_policy`` requires the ``task_time`` reporting requirement. See the
244+
:ref:`Execution Information <execution-information>` section for more information
245+
about reporting requirements.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
Backends
2+
########
3+
4+
The dynamic selection API is an experimental feature in the |onedpl_long|
5+
(|onedpl_short|) that selects an *execution resource* based on a chosen
6+
*selection policy*. For the policies to work with different resource types.
7+
the resource management and work submission mechanics are handled
8+
separately by resource-specific *backends*.
9+
10+
A backend is responsible for:
11+
12+
1. **Resource Management** - storing and providing access to a set of resources
13+
2. **Work Submission** - executing user functions on selected resources
14+
3. **Synchronization** - waiting for submitted work to complete
15+
4. **Instrumentation** - optionally reporting execution information (timing, completion)
16+
17+
Backends are typically not directly visible to application developers - they work
18+
behind the scenes to enable policies to function.
19+
20+
SYCL Backend
21+
------------
22+
23+
A SYCL backend specialization of ``core_resource_backend`` is provided to support
24+
``sycl::queue`` resources.
25+
26+
The SYCL backend provides:
27+
28+
- Default initialization, which automatically discovers all available SYCL devices and creates queues
29+
- Event-based submission and waiting
30+
- Optional profiling and timing instrumentation
31+
32+
If no list of resources or explicit resource type is provided upon policy
33+
construction, the SYCL backend is the default, and ``sycl::queue`` is the
34+
resource type.
35+
36+
.. code:: cpp
37+
38+
#include <oneapi/dpl/dynamic_selection>
39+
40+
namespace ex = oneapi::dpl::experimental;
41+
42+
// Uses SYCL backend with default device initialization
43+
ex::round_robin_policy<> policy;
44+
45+
// Explicitly specifying SYCL queues
46+
std::vector<sycl::queue> my_queues = { /* ... */ };
47+
ex::round_robin_policy<sycl::queue> policy2{my_queues};
48+
49+
The SYCL backend supports the reporting for :ref:`Execution Information <execution-information>`
50+
of ``task_submission``, ``task_completion``, and ``task_time``.
51+
52+
User functions submitted to the SYCL backend must return a ``sycl::event``, which is
53+
its :ref:`wait type <wait-type>`.
54+
55+
Backend Architecture
56+
--------------------
57+
58+
The backend system uses a layered design to support multiple resource types:
59+
60+
**default_backend**: When you create a policy, ``default_backend`` automatically
61+
determines the core resource type by applying any
62+
:ref:`resource adapter <resource-adapters>` to your resource type. It then
63+
delegates to the appropriate ``core_resource_backend`` specialization.
64+
65+
**core_resource_backend**: Specialized backend implementations exist for specific core
66+
resource types (like ``sycl::queue``). For a resource type without an explicitly specialized
67+
implementation, a generic implementation provides the minimally necessary functionality:
68+
69+
- Basic resource storage and retrieval
70+
- Simple work submission without instrumentation (No execution information reporting)
71+
72+
To use a custom resource type with full instrumentation support, you must create a
73+
``core_resource_backend`` specialization.
74+
75+
Lazy Reporting
76+
--------------
77+
78+
.. _lazy-report:
79+
80+
For asynchronous execution, backends may use *lazy reporting* where
81+
:ref:`Execution Information <execution-information>` is not immediately available.
82+
The SYCL backend uses lazy reporting for ``task_completion`` and ``task_time``.
83+
84+
Policies that use execution information always call the backend's
85+
``lazy_report()`` function before making selections, ensuring they have
86+
up-to-date information about completed tasks.
87+
88+
This is transparent to application developers - the policy handles the details.
89+
90+
Backend Traits
91+
--------------
92+
93+
Backend traits provide compile-time information about backend capabilities:
94+
95+
.. code:: cpp
96+
97+
namespace oneapi::dpl::experimental
98+
{
99+
template<typename Backend>
100+
struct backend_traits {
101+
102+
// True if backend has explicit wait_type
103+
static constexpr bool has_wait_type_v = /* ... */;
104+
105+
// If has_wait_type_v is True, specific type required from user functions.
106+
// If has_wait_type_v is False, void (user functions must return waitable-type)
107+
using wait_type = /* ... */;
108+
109+
// True if backend requires lazy_report() to be called
110+
static constexpr bool lazy_report_v = /* ... */;
111+
112+
// Scratch space type for selection handles
113+
template<typename... ReportReqs>
114+
using selection_scratch_t = /* ... */;
115+
};
116+
}
117+
118+
These traits are primarily used by policy implementers, not application developers.
119+
120+
Wait Type Requirements
121+
^^^^^^^^^^^^^^^^^^^^^^
122+
123+
.. _wait-type:
124+
125+
Backends specify return type requirements for user-submitted functions through the
126+
``wait_type`` member:
127+
128+
**Explicit wait_type**: If a backend defines a ``wait_type`` alias (e.g., ``using wait_type = sycl::event;``),
129+
user functions **must** return that specific type. This is typically required when the backend
130+
needs to instrument or track asynchronous operations.
131+
132+
**No explicit wait_type**: If a backend does not define a ``wait_type`` alias, user functions
133+
may return any *waitable-type*. A waitable-type is any type with a ``wait()`` member function
134+
that can be called to synchronize with the operation's completion.
135+
136+
The SYCL backend defines ``wait_type = sycl::event``, requiring user functions to return
137+
``sycl::event`` for proper instrumentation and synchronization.
138+
139+
Selection Scratch Space
140+
^^^^^^^^^^^^^^^^^^^^^^^
141+
142+
.. _selection-scratch-space:
143+
144+
Backends need storage space within selection handles to implement instrumentation.
145+
The ``selection_scratch_t`` trait specifies what additional data a backend requires
146+
based on the policy's reporting needs.
147+
148+
When a policy tracks execution information (like task timing or completion), the backend
149+
needs to store temporary data with each selection. For example, the SYCL backend stores
150+
an extra ``sycl::event`` for start-time profiling tags when ``task_time`` reporting is requested.
151+
152+
The backend populates and uses this scratch space during work submission and reporting.
153+
For policies without reporting requirements, ``selection_scratch_t<>`` is empty,
154+
adding no overhead.
155+
156+
Custom Backends
157+
---------------
158+
159+
For advanced use cases, you can create custom backends to support new resource
160+
types or provide specialized instrumentation. Custom backends are created by
161+
specializing ``core_resource_backend`` for your resource type. For an example of
162+
how to do this, look at ``core_resource_backend<sycl::queue, ...>``.
163+
164+
See Also
165+
--------
166+
167+
- :doc:`policies` - Overview of selection policies
168+
- :doc:`functions` - Free functions for working with backends and policies

0 commit comments

Comments
 (0)