]> git.ipfire.org Git - thirdparty/gcc.git/blob - liboffloadmic/include/coi/source/COIEvent_source.h
backport: Makefile.am (myo_inc_dir): Remove.
[thirdparty/gcc.git] / liboffloadmic / include / coi / source / COIEvent_source.h
1 /*
2 * Copyright 2010-2016 Intel Corporation.
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation, version 2.1.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA.
17 *
18 * Disclaimer: The codes contained in these modules may be specific
19 * to the Intel Software Development Platform codenamed Knights Ferry,
20 * and the Intel product codenamed Knights Corner, and are not backward
21 * compatible with other Intel products. Additionally, Intel will NOT
22 * support the codes or instruction set in future products.
23 *
24 * Intel offers no warranty of any kind regarding the code. This code is
25 * licensed on an "AS IS" basis and Intel is not obligated to provide
26 * any support, assistance, installation, training, or other services
27 * of any kind. Intel is also not obligated to provide any updates,
28 * enhancements or extensions. Intel specifically disclaims any warranty
29 * of merchantability, non-infringement, fitness for any particular
30 * purpose, and any other warranty.
31 *
32 * Further, Intel disclaims all liability of any kind, including but
33 * not limited to liability for infringement of any proprietary rights,
34 * relating to the use of the code, even if Intel is notified of the
35 * possibility of such liability. Except as expressly stated in an Intel
36 * license agreement provided with this code and agreed upon with Intel,
37 * no license, express or implied, by estoppel or otherwise, to any
38 * intellectual property rights is granted herein.
39 */
40
41 #ifndef _COIEVENT_SOURCE_H
42 #define _COIEVENT_SOURCE_H
43
44 /** @ingroup COIEvent
45 * @addtogroup COIEventSource
46 @{
47 * @file source/COIEvent_source.h
48 */
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50
51 #include "../common/COITypes_common.h"
52 #include "../common/COIResult_common.h"
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 #endif // DOXYGEN_SHOULD_SKIP_THIS
58 ///////////////////////////////////////////////////////////////////////////////
59 ///
60 /// Special case event values which can be passed in to APIs to specify
61 /// how the API should behave. In COIBuffer APIs passing in NULL for the
62 /// completion event is the equivalent of passing COI_EVENT_SYNC.
63 /// Note that passing COI_EVENT_ASYNC can be used when the caller wishes the
64 /// operation to be performed asynchronously but does not care when the
65 /// operation completes. This can be useful for operations that by definition
66 /// must complete in order (DMAs, run functions on a single pipeline). If
67 /// the caller does care when the operation completes then they should pass
68 /// in a valid completion event which they can later wait on.
69 ///
70 #define COI_EVENT_ASYNC ((COIEVENT*)1)
71 #define COI_EVENT_SYNC ((COIEVENT*)2)
72
73 //////////////////////////////////////////////////////////////////////////////
74 ///
75 /// This can be used to initialize a COIEVENT to a known invalid state.
76 /// This is not required to use, but can be useful in some cases
77 /// if a program is unsure if the event will be initialized by the runtime.
78 /// Simply set the event to this value: COIEVENT event = COI_EVENT_INITIALIZER;
79 ///
80 #define COI_EVENT_INITIALIZER { { 0, -1 } }
81
82
83 ///////////////////////////////////////////////////////////////////////////////
84 ///
85 /// Wait for an arbitrary number of COIEVENTs to be signaled as completed,
86 /// eg when the run function or asynchronous map call associated with an event
87 /// has finished execution.
88 /// If the user sets in_WaitForAll = True and not all of the events are
89 /// signaled when the timeout period is reached then COI_TIME_OUT_REACHED will
90 /// be returned.
91 /// If the user sets in_WaitForAll = False then if at least one event is
92 /// signaled when the timeout is reached then COI_SUCCESS is returned.
93 ///
94 /// @param in_NumEvents
95 /// [in] The number of events to wait for.
96 ///
97 /// @param in_pEvents
98 /// [in] The array of COIEVENT handles to wait for.
99 ///
100 /// @param in_Timeout
101 /// [in] The time in milliseconds to wait for the event. 0 polls
102 /// and returns immediately, -1 blocks indefinitely.
103 ///
104 /// @param in_WaitForAll
105 /// [in] Boolean value specifying behavior. If true, wait for all
106 /// events to be signaled, or for timeout, whichever happens first.
107 /// If false, return when any event is signaled, or at timeout.
108 ///
109 /// @param out_pNumSignaled
110 /// [out] The number of events that were signaled. If in_NumEvents
111 /// is 1 or in_WaitForAll = True, this parameter is optional.
112 ///
113 /// @param out_pSignaledIndices
114 /// [out] Pointer to an array of indices into the original event
115 /// array. Those denoted have been signaled. The user must provide an
116 /// array that is no smaller than the in_Events array. If in_NumEvents
117 /// is 1 or in_WaitForAll = True, this parameter is optional.
118 ///
119 /// @return COI_SUCCESS once an event has been signaled completed.
120 ///
121 /// @return COI_TIME_OUT_REACHED if the events are still in use when the
122 /// timeout is reached or timeout is zero (a poll).
123 ///
124 /// @return COI_OUT_OF_RANGE if a negative value other than -1 is passed in to
125 /// the in_Timeout parameter.
126 ///
127 /// @return COI_OUT_OF_RANGE if in_NumEvents is 0.
128 ///
129 /// @return COI_INVALID_POINTER if in_pEvents is NULL.
130 ///
131 /// @return COI_ARGUMENT_MISMATCH if in_NumEvents > 1 and if in_WaitForAll
132 /// is not true and out_pSignaled or out_pSignaledIndicies are NULL.
133 ///
134 /// @return COI_ARGUMENT_MISMATCH if out_pNumSignaled is not NULL
135 /// and out_pSignaledIndices is NULL (or vice versa).
136 ///
137 /// @return COI_EVENT_CANCELED if while waiting on a user event, it gets
138 /// unregistered this returns COI_EVENT_CANCELED
139 ///
140 /// @return COI_PROCESS_DIED if the remote process died. See COIProcessDestroy
141 /// for more details.
142 ///
143 /// @return COI_<REAL ERROR> if only a single event is passed in, and that event
144 /// failed, COI will attempt to return the real error code that caused
145 /// the original operation to fail, otherwise COI_PROCESS_DIED is reported.
146 ///
147 COIACCESSAPI
148 COIRESULT
149 COIEventWait(
150 uint16_t in_NumEvents,
151 const COIEVENT *in_pEvents,
152 int32_t in_TimeoutMilliseconds,
153 uint8_t in_WaitForAll,
154 uint32_t *out_pNumSignaled,
155 uint32_t *out_pSignaledIndices);
156
157
158
159 ///////////////////////////////////////////////////////////////////////////////
160 ///
161 /// Register a User COIEVENT so that it can be fired. Registered event is
162 /// a one shot User event; in other words once signaled it cannot be used
163 /// again for signaling. You have to unregister and register again to enable
164 /// signaling. An event will be reset if it is re-registered without
165 /// unregistering, resulting in loss of all outstanding signals.
166 ///
167 /// @param out_pEvent
168 /// [out] Pointer to COIEVENT handle being Registered
169 ///
170 /// @return COI_SUCCESS an event is successfully registered
171 ///
172 /// @return COI_INVALID_POINTER if out_pEvent is NULL
173 ///
174 COIACCESSAPI
175 COIRESULT
176 COIEventRegisterUserEvent(
177 COIEVENT *out_pEvent);
178
179
180 ///////////////////////////////////////////////////////////////////////////////
181 ///
182 /// Unregister a User COIEVENT. Unregistering a unsignaled event is similar
183 /// to firing an event. Except Calling COIEventWait on an event that is
184 /// being unregistered returns COI_EVENT_CANCELED
185 ///
186 /// @param in_Event
187 /// [in] Event Handle to be unregistered.
188 ///
189 /// @return COI_INVALID_HANDLE if in_Event is not a UserEvent
190 ///
191 /// @return COI_SUCCESS if an event is successfully unregistered
192 ///
193 COIACCESSAPI
194 COIRESULT
195 COIEventUnregisterUserEvent(
196 COIEVENT in_Event);
197
198
199 //////////////////////////////////////////////////////////////////////////////
200 ///
201 /// A callback that will be invoked to notify the user of an internal
202 /// runtime event completion.
203 ///
204 /// As with any callback mechanism it is up to the user to make sure that
205 /// there are no possible deadlocks due to reentrancy (ie the callback being
206 /// invoked in the same context that triggered the notification) and also
207 /// that the callback does not slow down overall processing. If the user
208 /// performs too much work within the callback it could delay further
209 /// processing. The callback will be invoked prior to the signaling of
210 /// the corresponding COIEvent. For example, if a user is waiting
211 /// for a COIEvent associated with a run function completing they will
212 /// receive the callback before the COIEvent is marked as signaled.
213 ///
214 /// @param in_Event
215 /// [in] The completion event that is associated with the
216 /// operation that is being notified.
217 ///
218 /// @param in_Result
219 /// [in] The COIRESULT of the operation.
220 ///
221 /// @param in_UserData
222 /// [in] Opaque data that was provided when the callback was
223 /// registered. Intel(R) Coprocessor Offload Infrastructure
224 /// (Intel(R) COI) simply passes this back to the user so that
225 /// they can interpret it as they choose.
226 ///
227 typedef void (*COI_EVENT_CALLBACK)(
228 COIEVENT in_Event,
229 const COIRESULT in_Result,
230 const void *in_UserData);
231
232
233
234 //////////////////////////////////////////////////////////////////////////////
235 ///
236 /// Registers any COIEVENT to receive a one time callback, when the event
237 /// is marked complete in the offload runtime. If the event has completed
238 /// before the COIEventRegisterCallback() is called then the callback will
239 /// immediately be invoked by the calling thread. When the event is
240 /// registered before the event completes, the runtime gaurantees that
241 /// the callback will be invoked before COIEventWait() is notified of
242 /// the same event completing. In well written user code, this may provide
243 /// a slight performance advantage.
244 ///
245 /// Users should treat the callback much like an interrupt routine, in regards
246 /// of performance. Specifically designing the callback to be as short and
247 /// non blocking as possible. Since the thread that runs the callback is
248 /// non deterministic blocking or stalling of the callback, may have severe
249 /// performance impacts on the offload runtime. Thus, it is important to not
250 /// create deadlocks between the callback and other signaling/waiting
251 /// mechanisms. It is recommended to never invoke COIEventWait() inside
252 /// a callback function, as this could lead to immediate deadlocks.
253 ///
254 /// It is important to note that the runtime cannot distinguish between
255 /// already triggered events and invalid events. Thus the user needs to pass
256 /// in a valid event, or the callback will be invoked immediately.
257 /// Failed events will still receive a callback and the user can query
258 /// COIEventWait() after the callback for the failed return code.
259 ///
260 /// If more than one callback is registered for the same event, only the
261 /// single most current callback will be used, i.e. the older one will
262 /// be replaced.
263 ///
264 /// @param in_Event
265 /// [in] A valid single event handle to be registered to receive a callback.
266 ///
267 /// @param in_Callback
268 /// [in] Pointer to a user function used to signal an
269 /// event completion.
270 ///
271 /// @param in_UserData
272 /// [in] Opaque data to pass to the callback when it is invoked.
273 ///
274 /// @param in_Flags
275 /// [in] Reserved parameter for future expansion, required to be zero for now.
276 ///
277 /// @return COI_INVALID_HANDLE if in_Event is not a valid COIEVENT
278 ///
279 /// @return COI_INVALID_HANDLE if in_Callback is not a valid pointer.
280 ///
281 /// @return COI_ARGUMENT_MISMATCH if the in_Flags is not zero.
282 ///
283 /// @return COI_SUCCESS an event is successfully registered
284 ///
285 COIACCESSAPI
286 COIRESULT
287 COIEventRegisterCallback(
288 const COIEVENT in_Event,
289 COI_EVENT_CALLBACK in_Callback,
290 const void *in_UserData,
291 const uint64_t in_Flags);
292
293
294
295 #ifdef __cplusplus
296 } /* extern "C" */
297 #endif
298
299 #endif /* _COIEVENT_SOURCE_H */
300
301 /*! @} */