Skip to content

Commit bfa8b33

Browse files
authored
[ONNXIFI]Add extension of onnxSetIOAndRunGraph (#1781)
* test ci * test ci * test ci * test ci * test ci * test ci * test ci * I think this is going to work * clean documentation
1 parent 875f7bb commit bfa8b33

File tree

2 files changed

+227
-0
lines changed

2 files changed

+227
-0
lines changed

onnx/onnxifi_ext.h

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
#ifndef ONNXIFI_EXT_H
2+
#define ONNXIFI_EXT_H 1
3+
4+
#include "onnx/onnxifi.h"
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
/**
11+
* Generic ONNXIFI extension function pointer.
12+
*
13+
* The caller should convert this generic function pointer to the function
14+
* pointer specific for an extension function type.
15+
*/
16+
typedef onnxStatus (ONNXIFI_ABI* onnxExtensionFunctionPointer)(void);
17+
18+
/* Function pointer declarations for dynamic loading */
19+
typedef ONNXIFI_CHECK_RESULT onnxStatus
20+
(ONNXIFI_ABI* onnxGetExtensionFunctionAddressFunction)(
21+
onnxBackendID backendID,
22+
const char* name,
23+
onnxExtensionFunctionPointer* function);
24+
25+
/**
26+
* Query function pointer for an ONNXIFI extension function.
27+
*
28+
* The returned function pointer is specific to the provided backend ID, and
29+
* MUST NOT be used with objects created for other backend IDs.
30+
*
31+
* This function is a part of onnx_extension_function extension. Backends which
32+
* implement this function MUST list "onnx_extension_function" in the result of
33+
* onnxGetBackendInfo with ONNXIFI_BACKEND_EXTENSIONS information type.
34+
*
35+
* @param backendID - ID of the backend to query for extension function.
36+
* @param[in] name - name of the extension function to query.
37+
* @param[out] function - pointer to a generic function pointer for an ONNXIFI
38+
* extension function. If the function fails, the
39+
* function pointer is initialized to NULL. The caller
40+
* MUST cast this function pointer to the type specific
41+
* for the extension function before use.
42+
*
43+
* @retval ONNXIFI_STATUS_SUCCESS The function call succeeded and the extension
44+
* function pointer is stored in the location
45+
* specified by function argument.
46+
* @retval ONNXIFI_STATUS_INVALID_ID The function call failed because backendID
47+
* is not an ONNXIFI backend ID.
48+
* @retval ONNXIFI_STATUS_INVALID_POINTER The function call failed because
49+
* name or function argument is NULL.
50+
* @retval ONNXIFI_STATUS_UNIDENTIFIED_NAME The function call failed because
51+
* the backend does not implement
52+
* the function identified by the name.
53+
* @retval ONNXIFI_STATUS_INTERNAL_ERROR The function call failed because the
54+
* backend experienced an unrecovered
55+
* internal error.
56+
* @retval ONNXIFI_STATUS_BACKEND_UNAVAILABLE The function call failed because
57+
* the backend was disconnected or
58+
* uninstalled from the system.
59+
*/
60+
61+
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
62+
onnxGetExtensionFunctionAddress(
63+
onnxBackendID backendID,
64+
const char* name,
65+
onnxExtensionFunctionPointer* function);
66+
67+
/* Extension function pointer declarations for dynamic loading */
68+
typedef ONNXIFI_CHECK_RESULT onnxStatus
69+
(ONNXIFI_ABI* onnxSetIOAndRunGraphFunction)(
70+
onnxGraph graph,
71+
uint32_t inputsCount,
72+
const onnxTensorDescriptorV1* inputDescriptors,
73+
uint32_t outputsCount,
74+
const onnxTensorDescriptorV1* outputDescriptors,
75+
onnxMemoryFenceV1* outputFence);
76+
77+
/**
78+
* A combination of onnxSetIO and onnxRunGraph, functionally equals to first run
79+
* onnxSetIO(graph, inputsCount, inputDescriptors, outputsCount,
80+
* outputDescriptors), then run onnxRunGraph(graph, inputFence, outputFence)
81+
* with an internal inputFence.
82+
*
83+
* As two separate functions, it is difficult to do atomic evaluation.
84+
* Therefore, we would like to unify this process and make it evaluable.
85+
*
86+
* @param graph - graph handle created by onnxInitGraph.
87+
* @param inputsCount - number of elements in the inputDescriptors array.
88+
* @param[in] inputDescriptors - descriptors of input tensors for the graph.
89+
* Elements of this array must provide a location
90+
* for each ValueInfoProto.name listed in
91+
* ModelProto.graph.input of the ONNX graph.
92+
* If inputsCount is non-zero, inputDescriptors
93+
* pointer must be non-NULL.
94+
* @param outputsCount - number of elements in the outputDescriptors array.
95+
* Must be greater than zero.
96+
* @param[in] outputDescriptors - descriptors of output tensors for the graph.
97+
* outputDescriptors pointer must be non-NULL.
98+
* Elements of this array must provide a location
99+
* for each ValueInfoProto.name listed in
100+
* ModelProto.graph.output of the ONNX graph.
101+
* @param[out] outputFence - synchronization primitive that signals when graph
102+
* outputs are ready to use by the caller. The type
103+
* of the synchronization primitive always must be
104+
* initialized by the caller. The type of the
105+
* synchronization primitive determines whether it
106+
* is initialized by the user before the call or by
107+
* the backend as a result of this call. Single-shot
108+
* synchronizatiom objects are initialized as a result
109+
* of the call. Reusable synchronization objects are
110+
* generally initialized by the user prior to the
111+
* call.
112+
*
113+
* @retval ONNXIFI_STATUS_SUCCESS The function call succeeded and the all graph
114+
* inputs and outputs were matched to a memory
115+
* location.
116+
* @retval ONNXIFI_STATUS_INVALID_GRAPH The function call failed because
117+
* graph is not an ONNXIFI graph handle.
118+
* @retval ONNXIFI_STATUS_INVALID_POINTER The function call failed because
119+
* outputDescriptors pointer is NULL or
120+
* inputDescriptors pointer is NULL while
121+
* inputsCount is non-zero.
122+
* @retval ONNXIFI_STATUS_INVALID_NAME The function call failed because one of
123+
* the names in tensor descriptors doesn't
124+
* match blob name in ModelProto.graph.input
125+
* or ModelProto.graph.output, or the same
126+
* name appears in more than one tensor
127+
* descriptor.
128+
* @retval ONNXIFI_STATUS_INVALID_SHAPE The function call failed because one of
129+
* the shape dimensions is 0.
130+
* @retval ONNXIFI_STATUS_INVALID_DATATYPE The function call failed because
131+
* one of the data types in
132+
* inputDescriptors or outputDescriptors
133+
* is unknown to the backend.
134+
* @retval ONNXIFI_STATUS_INVALID_MEMORY_TYPE The function call failed because
135+
* one of the memory types in
136+
* inputDescriptors or
137+
* outputDescriptors is unknown to
138+
* the backend.
139+
* @retval ONNXIFI_STATUS_INVALID_MEMORY_LOCATION The function call failed
140+
* because one of the memory
141+
* locations in inputDescriptors
142+
* or outputDescriptors is not
143+
* valid for the specified
144+
* memory type (e.g. NULL pointer
145+
* for ONNXIFI_MEMORY_TYPE_CPU).
146+
* @retval ONNXIFI_STATUS_UNSUPPORTED_TAG The function call failed because one
147+
* of the tags in inputDescriptors or
148+
* outputDescriptors is unknown to the
149+
* backend (tag does not match
150+
* ONNXIFI_TAG_TENSOR_DESCRIPTOR_V1).
151+
* @retval ONNXIFI_STATUS_UNSUPPORTED_SHAPE The function call failed because the
152+
* backend does not support the
153+
* tensor shapes in an input or output
154+
* of one of the operators. The
155+
* problematic tensor shapes could be
156+
* directly specified through
157+
* inputDescriptors or
158+
* outputDescriptors argument,
159+
* or inferred from the inputs by the
160+
* backend. This error code can be
161+
* returned when the backend supports
162+
* variable-size inputs and outputs,
163+
* and the problematic tensor shape was
164+
* provided in the ValueInfoProto as a
165+
* symbolic variable.
166+
* @retval ONNXIFI_STATUS_UNSUPPORTED_MEMORY_TYPE The function call failed
167+
* because the backend does not
168+
* support one of the memory
169+
* types in inputDescriptors or
170+
* outputDescriptors.
171+
* @retval ONNXIFI_STATUS_UNIDENTIFIED_NAME The function call failed because one
172+
* of the ValueInfoProto.name value in
173+
* ModelProto.graph.input or
174+
* ModelProto.graph.output doesn't have
175+
* a match in the inputDescriptors or
176+
* outputDescriptors.
177+
* @retval ONNXIFI_STATUS_MISMATCHING_SHAPE The function call failed because
178+
* the shapes specified through
179+
* inputDescriptors or
180+
* outputDescriptors argument are
181+
* inconsistent with the shapes
182+
* specified in the ONNX model graph.
183+
* @retval ONNXIFI_STATUS_MISMATCHING_DATATYPE The function call failed because
184+
* data types specified through
185+
* inputDescriptors or
186+
* outputDescriptors argument are
187+
* inconsistent with the data types
188+
* specified in the ONNX model
189+
* graph.
190+
* @retval ONNXIFI_STATUS_NO_SYSTEM_MEMORY The function call failed because the
191+
* backend could not allocate enough
192+
* system memory to parse, analyze, and
193+
* initialize the tensor locations.
194+
* @retval ONNXIFI_STATUS_NO_SYSTEM_RESOURCES The function call failed due to
195+
* insufficient non-memory system
196+
* resources (e.g. file handles) to
197+
* initialize the tensor locations.
198+
* @retval ONNXIFI_STATUS_NO_DEVICE_MEMORY The function call failed due to
199+
* insufficient backend-specific memory
200+
* to initialize the tensor locations.
201+
* @retval ONNXIFI_STATUS_NO_DEVICE_RESOURCES The function call failed due to
202+
* insufficient non-memory
203+
* backend-specific resources (e.g.
204+
* command queues) to initialize the
205+
* tensor locations.
206+
* @retval ONNXIFI_STATUS_BACKEND_UNAVAILABLE The function call failed because
207+
* the backend was disconnected or
208+
* uninstalled from the system.
209+
* @retval ONNXIFI_STATUS_INTERNAL_ERROR The function call failed because the
210+
* backend experienced an unrecovered
211+
* internal error.
212+
*/
213+
214+
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxSetIOAndRunGraph(
215+
onnxGraph graph,
216+
uint32_t inputsCount,
217+
const onnxTensorDescriptorV1* inputDescriptors,
218+
uint32_t outputsCount,
219+
const onnxTensorDescriptorV1* outputDescriptors,
220+
onnxMemoryFenceV1* outputFence);
221+
222+
#ifdef __cplusplus
223+
} /* extern "C" */
224+
#endif
225+
226+
#endif /* !defined(ONNXIFI_EXT_H) */

onnx/onnxifi_loader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define ONNXIFI_LOADER_H 1
33

44
#include "onnx/onnxifi.h"
5+
#include "onnx/onnxifi_ext.h"
56

67
#define ONNXIFI_LOADER_FUNCTION_COUNT 15
78

0 commit comments

Comments
 (0)