|
| 1 | +# Automatic placeholder requirements |
| 2 | + |
| 3 | +| Proposal ID | CP028 | |
| 4 | +|-------------|--------| |
| 5 | +| Name | Automatic placeholder requirements | |
| 6 | +| Date of Creation | 17 April 2020 | |
| 7 | +| Revision | 0.1 | |
| 8 | +| Latest Update | 28 April 2020 | |
| 9 | +| Target | SYCL Next (after 1.2.1) | |
| 10 | +| Current Status | _Work in Progress_ | |
| 11 | +| Reply-to | Peter Žužek <[email protected]> | |
| 12 | +| Original author | Peter Žužek <[email protected]> | |
| 13 | +| Contributors | Gordon Brown <[email protected]>, Ruyman Reyes <[email protected]> | |
| 14 | + |
| 15 | +## Overview |
| 16 | + |
| 17 | +This proposal allows placeholders to be automatically registered |
| 18 | +when used in explicit memory functions. |
| 19 | +It also provides convenience versions of those functions on the `queue` class. |
| 20 | + |
| 21 | +## Revisions |
| 22 | + |
| 23 | +### 0.1 |
| 24 | + |
| 25 | +* Initial proposal |
| 26 | + |
| 27 | +## Motivation |
| 28 | + |
| 29 | +[A separate proposal](https://github.com/codeplaysoftware/standards-proposals/pull/122) |
| 30 | +deprecated `accessor::placeholder`, |
| 31 | +making it easier to construct placeholder accessors. |
| 32 | + |
| 33 | +An example on how this can be used to copy data |
| 34 | +from an accessor to a host pointer: |
| 35 | + |
| 36 | +```cpp |
| 37 | +// Assume buf of type buffer<int, 1> |
| 38 | +// Assume hostPtr of type int* |
| 39 | + |
| 40 | +// Create the placeholder |
| 41 | +accessor<int, 1, access::mode::read> acc{buf}; |
| 42 | + |
| 43 | +queue q; |
| 44 | +q.submit([&](handler& cgh){ |
| 45 | + // Register placeholder with the command group |
| 46 | + cgh.require(acc); |
| 47 | + |
| 48 | + // Perform the copy |
| 49 | + cgh.copy(acc, hostPtr); |
| 50 | +}); |
| 51 | +``` |
| 52 | + |
| 53 | +At the point of calling `cgh.copy` the SYCL runtime knows where data is requested. |
| 54 | +Calling `cgh.require` shouldn't really be necessary at that point |
| 55 | +because the `copy` function could just call `require` on its own. |
| 56 | +That would allow us to simplify the command group: |
| 57 | + |
| 58 | +```cpp |
| 59 | +q.submit([&](handler& cgh){ |
| 60 | + // Perform the copy |
| 61 | + cgh.copy(acc, hostPtr); |
| 62 | +}); |
| 63 | +``` |
| 64 | + |
| 65 | +Everything is automatically handled by the SYCL runtime. |
| 66 | +However, we could go one step further, |
| 67 | +and provide convenience member functions on the queue, |
| 68 | +allowing us to skip the submission lambda |
| 69 | +(just like the new queue member functions in the |
| 70 | +[USM proposal](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc)): |
| 71 | + |
| 72 | +```cpp |
| 73 | +// Perform the copy |
| 74 | +q.copy(acc, hostPtr); |
| 75 | +``` |
| 76 | + |
| 77 | +## Changes |
| 78 | + |
| 79 | +In the accessor section, |
| 80 | +add the following paragraph: |
| 81 | + |
| 82 | +```latex |
| 83 | +Any member function of the \codeinline{queue} or the \codeinline{handler} |
| 84 | +that accepts an \codeinline{accessor} automatically creates |
| 85 | +a \textbf{requirement} for the command group. |
| 86 | +This is not true for member functions that enqueue a kernel - |
| 87 | +\codeinline{single_task}, \codeinline{parallel_for}, \codeinline{parallel_for_work_group} - |
| 88 | +in those cases it is still required to manually register the placeholder |
| 89 | +with the command group. |
| 90 | +``` |
| 91 | + |
| 92 | +In the section on explicit memory, |
| 93 | +add the following paragraph: |
| 94 | + |
| 95 | +```latex |
| 96 | +The same members functions listed in Table~\ref{table.members.handler.copy} |
| 97 | +are also available as member functions of the \codeinline{queue} class, |
| 98 | +but they can only accept \keyword{placeholder} accessors. |
| 99 | +``` |
| 100 | + |
| 101 | +## Limitations |
| 102 | + |
| 103 | +There is a temptation to extend this automatic registration |
| 104 | +to member functions of the `handler` that perform kernel enqueues: |
| 105 | +`single_task`, `parallel_for`, `parallel_for_work_group`. |
| 106 | +However, that might prove a bit more difficult |
| 107 | +because the accessors are captured inside a function object |
| 108 | +and C++ doesn't yet provide proper facilities for inspecting that object - |
| 109 | +static reflection would be needed. |
| 110 | +Therefore it is our concern that extending the proposal to kernel enqueues |
| 111 | +may not be implementable on the SYCL host device. |
0 commit comments