|
| 1 | += sycl_ext_oneapi_throttled_wait |
| 2 | + |
| 3 | +:source-highlighter: coderay |
| 4 | +:coderay-linenums-mode: table |
| 5 | + |
| 6 | +// This section needs to be after the document title. |
| 7 | +:doctype: book |
| 8 | +:toc2: |
| 9 | +:toc: left |
| 10 | +:encoding: utf-8 |
| 11 | +:lang: en |
| 12 | +:dpcpp: pass:[DPC++] |
| 13 | +:endnote: —{nbsp}end{nbsp}note |
| 14 | + |
| 15 | +// Set the default source code type in this document to C++, |
| 16 | +// for syntax highlighting purposes. This is needed because |
| 17 | +// docbook uses c++ and html5 uses cpp. |
| 18 | +:language: {basebackend@docbook:c++:cpp} |
| 19 | + |
| 20 | + |
| 21 | +== Notice |
| 22 | + |
| 23 | +[%hardbreaks] |
| 24 | +Copyright (C) 2024 Intel Corporation. All rights reserved. |
| 25 | + |
| 26 | +Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks |
| 27 | +of The Khronos Group Inc. |
| 28 | +OpenCL(TM) is a trademark of Apple Inc. used by permission by Khronos. |
| 29 | + |
| 30 | + |
| 31 | +== Contact |
| 32 | + |
| 33 | +To report problems with this extension, please open a new issue at: |
| 34 | + |
| 35 | +https://github.com/intel/llvm/issues |
| 36 | + |
| 37 | + |
| 38 | +== Dependencies |
| 39 | + |
| 40 | +This extension is written against the SYCL 2020 revision 8 specification. |
| 41 | +All references below to the "core SYCL specification" or to section numbers in |
| 42 | +the SYCL specification refer to that revision. |
| 43 | + |
| 44 | + |
| 45 | +== Status |
| 46 | + |
| 47 | +This is an experimental extension specification, intended to provide early |
| 48 | +access to features and gather community feedback. Interfaces defined in |
| 49 | +this specification are implemented in DPC++, but they are not finalized |
| 50 | +and may change incompatibly in future versions of DPC++ without prior notice. |
| 51 | +*Shipping software products should not rely on APIs defined in |
| 52 | +this specification.* |
| 53 | + |
| 54 | + |
| 55 | +== Overview |
| 56 | + |
| 57 | +This extension adds simple APIs for an alternate "sleeping" wait implementation. |
| 58 | +This is for scenarios (such as IoT) where one might want to trade a bit of |
| 59 | +performance in exchange for having the host CPU be more available, not burning |
| 60 | +cycles intently waiting. |
| 61 | + |
| 62 | +== Specification |
| 63 | + |
| 64 | +=== Additional Inclusion |
| 65 | + |
| 66 | +As throttled_wait is presently an experimental extension, it requires an |
| 67 | +additional inclusion to use. |
| 68 | + |
| 69 | +```c++ |
| 70 | +#include <sycl/sycl.hpp> |
| 71 | +#include <sycl/ext/oneapi/experimental/throttled_wait.hpp> |
| 72 | + |
| 73 | +// now the extension API is available |
| 74 | +``` |
| 75 | + |
| 76 | +=== Feature test macro |
| 77 | + |
| 78 | +This extension provides a feature-test macro as described in the core SYCL |
| 79 | +specification. |
| 80 | +An implementation supporting this extension must predefine the macro |
| 81 | +`SYCL_EXT_ONEAPI_THROTTLED_WAIT` |
| 82 | +to one of the values defined in the table below. |
| 83 | +Applications can test for the existence of this macro to determine if |
| 84 | +the implementation supports this feature, or applications can test the macro's |
| 85 | +value to determine which of the extension's features the implementation |
| 86 | +supports. |
| 87 | + |
| 88 | +[%header,cols="1,5"] |
| 89 | +|=== |
| 90 | +|Value |
| 91 | +|Description |
| 92 | + |
| 93 | +|1 |
| 94 | +|The APIs of this experimental extension are not versioned, so the |
| 95 | + feature-test macro always has this value. |
| 96 | +|=== |
| 97 | + |
| 98 | +=== API of the extension |
| 99 | + |
| 100 | +This extension adds the following free functions, where sleep is one |
| 101 | +of the types supported by std::chrono::duration (e.g. |
| 102 | +std::chrono::milliseconds, std::chrono::microseconds, etc) |
| 103 | + |
| 104 | +For each of these calls, while waiting for the sycl object to |
| 105 | +complete, the host process sleeps for the sleep duration paramater. |
| 106 | + |
| 107 | + |
| 108 | +```c++ |
| 109 | +namespace sycl::ext::oneapi::experimental { |
| 110 | + |
| 111 | +template <typename Rep, typename Period> |
| 112 | +void ext_oneapi_throttled_wait(sycl::event& e, const std::chrono::duration<Rep, Period>& sleep); |
| 113 | + |
| 114 | +template <typename Rep, typename Period> |
| 115 | +void ext_oneapi_throttled_wait((std::vector<sycl::event>& eventList, const std::chrono::duration<Rep, Period>& sleep) |
| 116 | + |
| 117 | +template <typename Rep, typename Period> |
| 118 | +void ext_oneapi_throttled_wait_and_throw(sycl::event& e, const std::chrono::duration<Rep, Period>& sleep) |
| 119 | + |
| 120 | +template <typename Rep, typename Period> |
| 121 | +void ext_oneapi_throttled_wait_and_throw((std::vector<sycl::event>& eventList, const std::chrono::duration<Rep, Period>& sleep) |
| 122 | + |
| 123 | + |
| 124 | +} // namespace sycl::ext::oneapi::experimental |
| 125 | +``` |
| 126 | + |
| 127 | + |
| 128 | +== Example |
| 129 | + |
| 130 | +The following example demonstrates simple usage of this API. |
| 131 | + |
| 132 | +``` |
| 133 | +#include <sycl/sycl.hpp> |
| 134 | +#include <sycl/ext/oneapi/experimental/throttled_wait.hpp> |
| 135 | +namespace syclex = sycl::ext::oneapi::experimental; |
| 136 | + |
| 137 | +constexpr uint64_t N = 1000000000; // a very big N for looping. |
| 138 | + |
| 139 | +int main() { |
| 140 | + sycl::queue q; |
| 141 | + uint64_t a = 0; |
| 142 | + |
| 143 | + { |
| 144 | + sycl::buffer<uint64_t, 1> buf(&a, sycl::range<1>(1)); |
| 145 | + |
| 146 | + sycl::event e = q.submit([&](sycl::handler &cgh) { |
| 147 | + sycl::accessor acc(buf, cgh, sycl::read_write); |
| 148 | + cgh.single_task<class hello_world>([=]() { |
| 149 | + for(long i = 0; i < N; i++) { |
| 150 | + acc[0] = acc[0] + 1; |
| 151 | + } |
| 152 | + }); |
| 153 | + }); |
| 154 | +#ifdef SYCL_EXT_ONEAPI_THROTTLED_WAIT |
| 155 | + syclex::ext_oneapi_throttled_wait(e, std::chrono::milliseconds(100)); |
| 156 | +#else |
| 157 | + e.wait(); |
| 158 | +#endif |
| 159 | + } // buffer goes out of scope, data copied back to 'a'. |
| 160 | + |
| 161 | + std::cout << "a: " << a << std::endl; |
| 162 | + |
| 163 | + return 0; |
| 164 | +} |
| 165 | +``` |
0 commit comments