-
Notifications
You must be signed in to change notification settings - Fork 115
[Dynamic Selection] Customization of Backends and Policies #2508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 237 commits
0411b61
a2b7175
a928d16
6e517e7
9a65385
22513bb
fb965aa
d442372
8a8e8ff
d547a3e
f2573eb
0d26cbe
ef6e6e6
9a62576
b77e08a
1c41842
ad698d5
6459df0
3ab72c9
92a9ec6
0d66c06
fa212c5
b815741
5734ced
0ee2cf1
12e79d6
20afd0a
0e932ac
9e5cf88
fd8f893
d50db4f
1c3ec5f
609f5ec
0fcfbe3
c9ca52c
3a1f0af
8987309
e27e5c5
db6e713
739ee60
6c23dfb
2dee3c4
f13a117
8a01c74
9774feb
e42354a
3b7de9c
f76d97d
788ae0c
2a1f8c4
8680771
62837ad
5efa0ba
bac3e7d
bb4a145
5b4d628
cc076a2
f0d743e
ca4f9ea
f4438bf
9224a98
c161347
ee991fb
56f84da
c065309
0cf1abb
28573d1
5a6ffb5
21404f0
5d4776d
f072513
df2c3dc
8d22b14
e88ecd9
3256af5
924b4e9
7994657
4e95417
5916d29
aa7872d
50f9805
2dbd011
4d19c23
82ef54e
b97f8fc
e7d61e8
d1dd570
3bc348b
bf1ae15
8f785a8
0e9b283
937a777
0c0bcc8
dff6883
de67825
5997a04
03ed63a
e939df7
e41ef8d
f9ce9a2
43b1f93
0a1d26a
4a87d9d
4c4ec94
372009d
7befd04
c032efb
8aa6084
ba6acef
650bd87
a5ea1c7
0411a10
75b7eb4
4f874f4
26b9a07
4861281
7f3b4d3
60435d4
9af68a9
0467d3c
900d166
ae2a546
ceea548
889026b
f666870
586bd52
b7a49f8
a984902
e1bdbcd
364d1a3
a364a69
2f0277b
0a7cd4b
d561386
1d0ffdd
99799c2
2247cec
e08ca68
e330649
daffa53
41536f2
ca59727
ef2b6ee
629a2a2
75424ce
ecb59c5
9584c0f
de45407
ceee9fd
c6e4da9
5c95ee3
6a177bb
a6ade91
7393b83
828f93f
7c54b5c
18b23e1
78afc05
85050bf
4343153
6f46ac5
06f6eda
b736655
22d39c1
49cd7b9
7719774
42e4f0a
4a22a69
099494c
99e3b44
65410c2
55eee68
ad8ac03
58537fd
112d75a
56f20b1
e44ed7f
59d9adb
e3eb212
918e009
153e380
d03e768
10b1768
5cb17ad
633256e
ddc767b
5bfcd1e
298ad24
25d811c
9375279
f77b404
0b6d1a9
64436e0
d65259a
787e9a6
92baa49
5b7a56a
17bbbe6
224ae9d
0766c26
6dc1a39
32e61f9
c5bcbf6
c381630
307c44c
3def477
12c6f8b
ffe846f
a4b47d5
9234fd1
89cddb3
bcadb28
2c46023
d7e7a14
0133833
daefbb1
0194aee
67a2721
6404c8e
dd628f6
57417af
3fb649e
b3966c9
b4f13f4
0b8d4cd
97fe6ed
ac2ef0e
2cdbc44
932c23c
88270c2
8c88013
d169d0b
298cb5d
9c35db0
5841d93
d725d71
f79d2ec
75cc08e
6634057
8d11efc
ff0ccce
d90fb57
0ca493e
dd7f6ea
bad0f61
4ed5c5f
e9a38bd
2838394
ab4cc27
3654caf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
akukanov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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: | ||
danhoeflinger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Uh oh!
There was an error while loading. Please reload this page.