Skip to content

Commit

Permalink
sync to ONNX cb544d07cc022e3fe83622fda9b2b1fa00b75b89 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
houseroad authored Feb 23, 2019
1 parent 520e8e1 commit f817be1
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 6 deletions.
58 changes: 58 additions & 0 deletions foxi/onnxifi_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <math.h>

#include "foxi/onnxifi.h"
#include "foxi/onnxifi_ext.h"

/*
* ONNXIFI Functions
*/

ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
onnxGetBackendIDs(onnxBackendID* backendIDs, size_t* numBackends) {
Expand Down Expand Up @@ -136,3 +141,56 @@ ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
onnxReleaseGraph(onnxGraph graph) {
return ONNXIFI_STATUS_SUCCESS;
}

/*
* ONNXIFI Extension Functions
*/

/*
* This is the function list and the number of functions in onnxifi_ext
* we have in this backend. It should be a subset of ALL_EXT_FUNCTION_LIST
* in onnxifi_ext.h
*/
const int extension_function_number = 2;
const char* extension_function_list[] = {"onnxGetExtensionFunctionAddress",
"onnxSetIOAndRunGraph"};

ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
onnxGetExtensionFunctionAddress(
onnxBackendID backendID,
const char* name,
onnxExtensionFunctionPointer* function) {
if (name == NULL || function == NULL) {
return ONNXIFI_STATUS_INVALID_POINTER;
}
*function = NULL;
int i;
for (i = 0; i < extension_function_number; i++) {
/* target function found */
if (strcmp(name, extension_function_list[i]) == 0) {
switch (i) {
case 0:
*function = &onnxGetExtensionFunctionAddress;
break;
case 1:
*function = &onnxSetIOAndRunGraph;
break;
}
}
}

if (*function == NULL) {
return ONNXIFI_STATUS_UNIDENTIFIED_NAME;
}
return ONNXIFI_STATUS_SUCCESS;
}

ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxSetIOAndRunGraph(
onnxGraph graph,
uint32_t inputsCount,
const onnxTensorDescriptorV1* inputDescriptors,
uint32_t outputsCount,
const onnxTensorDescriptorV1* outputDescriptors,
onnxMemoryFenceV1* outputFence) {
return ONNXIFI_STATUS_SUCCESS;
}
8 changes: 8 additions & 0 deletions foxi/onnxifi_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
extern "C" {
#endif

/*
* This is the super set of all extension functions we support in onnxifi.
* All backend should support a subset of function of this list.
*/
static const int ALL_EXT_FUNCTION_NUMBER = 2;
static const char* ALL_EXT_FUNCTION_LIST[] = {"onnxGetExtensionFunctionAddress",
"onnxSetIOAndRunGraph"};

/**
* Generic ONNXIFI extension function pointer.
*
Expand Down
6 changes: 5 additions & 1 deletion foxi/onnxifi_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ static const char onnxifi_function_names[] =
"onnxInitGraph\0"
"onnxSetGraphIO\0"
"onnxRunGraph\0"
"onnxReleaseGraph\0";
"onnxReleaseGraph\0"
#ifdef ONNXIFI_ENABLE_EXT
"onnxGetExtensionFunctionAddress\0"
#endif
;

int ONNXIFI_ABI onnxifi_load(
uint32_t flags,
Expand Down
7 changes: 7 additions & 0 deletions foxi/onnxifi_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#include "foxi/onnxifi.h"
#include "foxi/onnxifi_ext.h"

#ifdef ONNXIFI_ENABLE_EXT
#define ONNXIFI_LOADER_FUNCTION_COUNT 16
#else
#define ONNXIFI_LOADER_FUNCTION_COUNT 15
#endif

#define ONNXIFI_LOADER_FLAG_VERSION_MASK 0xFF
#define ONNXIFI_LOADER_FLAG_VERSION_1_0 0x01
Expand Down Expand Up @@ -49,6 +53,9 @@ struct onnxifi_library {
onnxSetGraphIOFunction onnxSetGraphIO;
onnxRunGraphFunction onnxRunGraph;
onnxReleaseGraphFunction onnxReleaseGraph;
#ifdef ONNXIFI_ENABLE_EXT
onnxGetExtensionFunctionAddressFunction onnxGetExtensionFunctionAddress;
#endif
};
void* functions[ONNXIFI_LOADER_FUNCTION_COUNT];
};
Expand Down
10 changes: 5 additions & 5 deletions foxi/onnxifi_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* ONNX wrapper api discovers vendor-specific implementations installed in
* the system and exposes them under a single interface.
*
*
*
*
*
*/

#include <stdlib.h>
Expand All @@ -24,17 +24,17 @@
#include <foxi/onnxifi_loader.h>

#if defined(_WIN32)
#define ONNXIFI_FILENAME_WILDCARD L"\\foxi-*.dll"
#define ONNXIFI_FILENAME_WILDCARD L"\\onnxifi-*.dll"
#define ONNXIFI_FILENAME_WILDCARD_LENGTH 14
#elif defined(__APPLE__)
/* Minimum filename: "libonnxifi-?.dylib" */
#define ONNXIFI_FILENAME_MIN 18
#define ONNXIFI_FILENAME_PREFIX "foxi-"
#define ONNXIFI_FILENAME_PREFIX "libonnxifi-"
#define ONNXIFI_FILENAME_SUFFIX ".dylib"
#else
/* Minimum filename: "libonnxifi-?.so" */
#define ONNXIFI_FILENAME_MIN 15
#define ONNXIFI_FILENAME_PREFIX "foxi-"
#define ONNXIFI_FILENAME_PREFIX "libonnxifi-"
#define ONNXIFI_FILENAME_SUFFIX ".so"
#endif

Expand Down

0 comments on commit f817be1

Please sign in to comment.