Skip to content

Commit ba2fdcb

Browse files
authored
Merge pull request #5 from jackm321/add_trace_events
Add trace events interface
2 parents d1f45b1 + 7d42b12 commit ba2fdcb

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

foxi/onnxifi_dummy.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxSetIOAndRunGraph(
191191
const onnxTensorDescriptorV1* inputDescriptors,
192192
uint32_t outputsCount,
193193
const onnxTensorDescriptorV1* outputDescriptors,
194-
onnxMemoryFenceV1* outputFence) {
194+
onnxMemoryFenceV1* outputFence,
195+
onnxTraceEventList* traceEvents) {
196+
return ONNXIFI_STATUS_SUCCESS;
197+
}
198+
199+
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
200+
onnxReleaseTraceEvents(onnxTraceEventList* traceEvents) {
195201
return ONNXIFI_STATUS_SUCCESS;
196202
}

foxi/onnxifi_ext.h

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,45 @@
77
extern "C" {
88
#endif
99

10+
typedef struct onnxTraceEvent {
11+
/**
12+
* Human readable name for the event, will be used to match up begin and end
13+
* of an event duration.
14+
*/
15+
const char *eventName;
16+
17+
/**
18+
* Type of the event, can be one of the following:
19+
* 'B': Beginning of event
20+
* 'E': End of event
21+
*/
22+
char eventType;
23+
24+
/**
25+
* Time of the event, in milliseconds since epoch.
26+
*/
27+
uint64_t timestamp;
28+
29+
/**
30+
* Thread Id for this event. All events with the same tid will be grouped
31+
* together in the trace.
32+
*/
33+
uint32_t tid;
34+
} onnxTraceEvent;
35+
36+
typedef struct onnxTraceEventList {
37+
/**
38+
* The number of events in traceEvents.
39+
*/
40+
uint64_t numEvents;
41+
42+
/**
43+
* A pointer to an array of pointers to onnxTraceEvents allocated by the onnx
44+
* backend, the length of which is indicated by numEvents.
45+
*/
46+
onnxTraceEvent **traceEvents;
47+
} onnxTraceEventList;
48+
1049
/**
1150
* Generic ONNXIFI extension function pointer.
1251
*
@@ -109,6 +148,11 @@ typedef ONNXIFI_CHECK_RESULT onnxStatus
109148
* of the call. Reusable synchronization objects are
110149
* generally initialized by the user prior to the
111150
* call.
151+
* @param[out] traceEvents - optional pointer to onnxTraceEventList that can be
152+
* NULL. If non-NULL then the backend is requested to
153+
* populate the onnxTraceEventList with trace events
154+
* describing the timeline of events that occurred
155+
* while running the graph.
112156
*
113157
* @retval ONNXIFI_STATUS_SUCCESS The function call succeeded and the all graph
114158
* inputs and outputs were matched to a memory
@@ -217,7 +261,26 @@ ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxSetIOAndRunGraph(
217261
const onnxTensorDescriptorV1* inputDescriptors,
218262
uint32_t outputsCount,
219263
const onnxTensorDescriptorV1* outputDescriptors,
220-
onnxMemoryFenceV1* outputFence);
264+
onnxMemoryFenceV1* outputFence,
265+
onnxTraceEventList* traceEvents);
266+
267+
/**
268+
* Release the onnxTraceEvents contained in traceEvents.
269+
*
270+
* @param traceEvents - a list of onnxTraceEvents to be released.
271+
*
272+
* @retval ONNXIFI_STATUS_SUCCESS The function call succeeded and the
273+
* onnxTraceEvents resources were released to the
274+
* operating system.
275+
* @retval ONNXIFI_STATUS_INVALID_POINTER The function call failed because
276+
* onnxTraceEventList pointer is NULL.
277+
* @retval ONNXIFI_STATUS_INTERNAL_ERROR The function call failed because the
278+
* backend experienced an unrecovered
279+
* internal error.
280+
*/
281+
282+
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
283+
onnxReleaseTraceEvents(onnxTraceEventList* traceEvents);
221284

222285
#ifdef __cplusplus
223286
} /* extern "C" */

0 commit comments

Comments
 (0)