Skip to content

Commit f817be1

Browse files
authored
sync to ONNX cb544d07cc022e3fe83622fda9b2b1fa00b75b89 (#2)
1 parent 520e8e1 commit f817be1

File tree

5 files changed

+83
-6
lines changed

5 files changed

+83
-6
lines changed

foxi/onnxifi_dummy.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include <math.h>
88

99
#include "foxi/onnxifi.h"
10+
#include "foxi/onnxifi_ext.h"
11+
12+
/*
13+
* ONNXIFI Functions
14+
*/
1015

1116
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
1217
onnxGetBackendIDs(onnxBackendID* backendIDs, size_t* numBackends) {
@@ -136,3 +141,56 @@ ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
136141
onnxReleaseGraph(onnxGraph graph) {
137142
return ONNXIFI_STATUS_SUCCESS;
138143
}
144+
145+
/*
146+
* ONNXIFI Extension Functions
147+
*/
148+
149+
/*
150+
* This is the function list and the number of functions in onnxifi_ext
151+
* we have in this backend. It should be a subset of ALL_EXT_FUNCTION_LIST
152+
* in onnxifi_ext.h
153+
*/
154+
const int extension_function_number = 2;
155+
const char* extension_function_list[] = {"onnxGetExtensionFunctionAddress",
156+
"onnxSetIOAndRunGraph"};
157+
158+
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
159+
onnxGetExtensionFunctionAddress(
160+
onnxBackendID backendID,
161+
const char* name,
162+
onnxExtensionFunctionPointer* function) {
163+
if (name == NULL || function == NULL) {
164+
return ONNXIFI_STATUS_INVALID_POINTER;
165+
}
166+
*function = NULL;
167+
int i;
168+
for (i = 0; i < extension_function_number; i++) {
169+
/* target function found */
170+
if (strcmp(name, extension_function_list[i]) == 0) {
171+
switch (i) {
172+
case 0:
173+
*function = &onnxGetExtensionFunctionAddress;
174+
break;
175+
case 1:
176+
*function = &onnxSetIOAndRunGraph;
177+
break;
178+
}
179+
}
180+
}
181+
182+
if (*function == NULL) {
183+
return ONNXIFI_STATUS_UNIDENTIFIED_NAME;
184+
}
185+
return ONNXIFI_STATUS_SUCCESS;
186+
}
187+
188+
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxSetIOAndRunGraph(
189+
onnxGraph graph,
190+
uint32_t inputsCount,
191+
const onnxTensorDescriptorV1* inputDescriptors,
192+
uint32_t outputsCount,
193+
const onnxTensorDescriptorV1* outputDescriptors,
194+
onnxMemoryFenceV1* outputFence) {
195+
return ONNXIFI_STATUS_SUCCESS;
196+
}

foxi/onnxifi_ext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
extern "C" {
88
#endif
99

10+
/*
11+
* This is the super set of all extension functions we support in onnxifi.
12+
* All backend should support a subset of function of this list.
13+
*/
14+
static const int ALL_EXT_FUNCTION_NUMBER = 2;
15+
static const char* ALL_EXT_FUNCTION_LIST[] = {"onnxGetExtensionFunctionAddress",
16+
"onnxSetIOAndRunGraph"};
17+
1018
/**
1119
* Generic ONNXIFI extension function pointer.
1220
*

foxi/onnxifi_loader.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ static const char onnxifi_function_names[] =
4848
"onnxInitGraph\0"
4949
"onnxSetGraphIO\0"
5050
"onnxRunGraph\0"
51-
"onnxReleaseGraph\0";
51+
"onnxReleaseGraph\0"
52+
#ifdef ONNXIFI_ENABLE_EXT
53+
"onnxGetExtensionFunctionAddress\0"
54+
#endif
55+
;
5256

5357
int ONNXIFI_ABI onnxifi_load(
5458
uint32_t flags,

foxi/onnxifi_loader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
#include "foxi/onnxifi.h"
55
#include "foxi/onnxifi_ext.h"
66

7+
#ifdef ONNXIFI_ENABLE_EXT
8+
#define ONNXIFI_LOADER_FUNCTION_COUNT 16
9+
#else
710
#define ONNXIFI_LOADER_FUNCTION_COUNT 15
11+
#endif
812

913
#define ONNXIFI_LOADER_FLAG_VERSION_MASK 0xFF
1014
#define ONNXIFI_LOADER_FLAG_VERSION_1_0 0x01
@@ -49,6 +53,9 @@ struct onnxifi_library {
4953
onnxSetGraphIOFunction onnxSetGraphIO;
5054
onnxRunGraphFunction onnxRunGraph;
5155
onnxReleaseGraphFunction onnxReleaseGraph;
56+
#ifdef ONNXIFI_ENABLE_EXT
57+
onnxGetExtensionFunctionAddressFunction onnxGetExtensionFunctionAddress;
58+
#endif
5259
};
5360
void* functions[ONNXIFI_LOADER_FUNCTION_COUNT];
5461
};

foxi/onnxifi_wrapper.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* ONNX wrapper api discovers vendor-specific implementations installed in
33
* the system and exposes them under a single interface.
44
*
5-
*
6-
*
5+
*
6+
*
77
*/
88

99
#include <stdlib.h>
@@ -24,17 +24,17 @@
2424
#include <foxi/onnxifi_loader.h>
2525

2626
#if defined(_WIN32)
27-
#define ONNXIFI_FILENAME_WILDCARD L"\\foxi-*.dll"
27+
#define ONNXIFI_FILENAME_WILDCARD L"\\onnxifi-*.dll"
2828
#define ONNXIFI_FILENAME_WILDCARD_LENGTH 14
2929
#elif defined(__APPLE__)
3030
/* Minimum filename: "libonnxifi-?.dylib" */
3131
#define ONNXIFI_FILENAME_MIN 18
32-
#define ONNXIFI_FILENAME_PREFIX "foxi-"
32+
#define ONNXIFI_FILENAME_PREFIX "libonnxifi-"
3333
#define ONNXIFI_FILENAME_SUFFIX ".dylib"
3434
#else
3535
/* Minimum filename: "libonnxifi-?.so" */
3636
#define ONNXIFI_FILENAME_MIN 15
37-
#define ONNXIFI_FILENAME_PREFIX "foxi-"
37+
#define ONNXIFI_FILENAME_PREFIX "libonnxifi-"
3838
#define ONNXIFI_FILENAME_SUFFIX ".so"
3939
#endif
4040

0 commit comments

Comments
 (0)