-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* onnxifi dummy backend * msvcrtd * Revert "msvcrtd" This reverts commit 7706a01. * shared lib not allowed * Revert "shared lib not allowed" This reverts commit 889da5a. * msvc support for onnxifi_loader.lib & onnxifi_dummy.lib * msvc * formatted * path corrected * indent, top_dir and backendIDs * change backedn nums to 1 * added NULL pointer exception handling * new interface supported
- Loading branch information
1 parent
16a85cc
commit 61b4ef2
Showing
8 changed files
with
552 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Dummy implementation of ONNX backend interface for manual test. | ||
* Prints the name of the called function and backend name on each call. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <math.h> | ||
|
||
#include "onnxifi.h" | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxGetBackendIDs(onnxBackendID* backendIDs, size_t* numBackends) { | ||
if (backendIDs == NULL || numBackends == NULL) { | ||
return ONNXIFI_STATUS_INVALID_POINTER; | ||
} | ||
*numBackends = 1; | ||
*backendIDs = 0; | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxReleaseBackendID(onnxBackendID backendID) { | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxGetBackendInfo( | ||
onnxBackendID backendID, | ||
onnxBackendInfo infoType, | ||
void* infoValue, | ||
size_t* infoValueSize) { | ||
if (infoValueSize == NULL) { | ||
return ONNXIFI_STATUS_INVALID_POINTER; | ||
} | ||
if (infoValue != NULL) { | ||
*infoValueSize = *infoValueSize > 10 ? 10 : *infoValueSize; | ||
memset(infoValue, 0, *infoValueSize); | ||
} else { | ||
*infoValueSize = sizeof(uint64_t); | ||
} | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxGetBackendCompatibility( | ||
onnxBackendID backendID, | ||
size_t onnxModelSize, | ||
const void* onnxModel) { | ||
if (onnxModel == NULL && onnxModelSize != 0){ | ||
return ONNXIFI_STATUS_INVALID_POINTER; | ||
} | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxInitBackend( | ||
onnxBackendID backendID, | ||
const uint64_t* auxpropertiesList, | ||
onnxBackend* backend) { | ||
if (backend == NULL) { | ||
return ONNXIFI_STATUS_INVALID_POINTER; | ||
} | ||
*backend = NULL; | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxReleaseBackend(onnxBackend backend) { | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxInitEvent(onnxBackend backend, onnxEvent* event) { | ||
if (event == NULL) { | ||
return ONNXIFI_STATUS_INVALID_POINTER; | ||
} | ||
*event = NULL; | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxSignalEvent(onnxEvent event) { | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxWaitEvent(onnxEvent event) { | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxReleaseEvent(onnxEvent event) { | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxInitGraph( | ||
onnxBackend backend, | ||
size_t onnxModelSize, | ||
const void* onnxModel, | ||
uint32_t weightCount, | ||
const onnxTensorDescriptorV1* weightDescriptors, | ||
onnxGraph* graph) { | ||
if (graph == NULL) { | ||
return ONNXIFI_STATUS_INVALID_POINTER; | ||
} | ||
*graph = NULL; | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxSetGraphIO( | ||
onnxGraph graph, | ||
uint32_t inputsCount, | ||
const onnxTensorDescriptorV1* inputDescriptors, | ||
uint32_t outputsCount, | ||
const onnxTensorDescriptorV1* outputDescriptors) { | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI onnxRunGraph( | ||
onnxGraph graph, | ||
const onnxMemoryFenceV1* inputFence, | ||
onnxMemoryFenceV1* outputFence) { | ||
if (outputFence == NULL) { | ||
return ONNXIFI_STATUS_INVALID_POINTER; | ||
} | ||
outputFence->type = ONNXIFI_SYNCHRONIZATION_EVENT; | ||
outputFence->event = NULL; | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} | ||
|
||
ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI | ||
onnxReleaseGraph(onnxGraph graph) { | ||
return ONNXIFI_STATUS_SUCCESS; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <iostream> | ||
|
||
#include "gtest/gtest.h" | ||
#include "onnx/onnxifi_loader.h" | ||
#include "onnx/onnxifi.h" | ||
|
||
#if defined(__APPLE__) | ||
#define ONNXIFI_DUMMY_LIBRARY "libonnxifi_dummy.dylib" | ||
#elif defined(_WIN32) | ||
#define ONNXIFI_DUMMY_LIBRARY L"onnxifi_dummy.dll" | ||
#else | ||
#define ONNXIFI_DUMMY_LIBRARY "libonnxifi_dummy.so" | ||
#endif | ||
|
||
|
||
namespace ONNX_NAMESPACE | ||
{ | ||
namespace Test | ||
{ | ||
TEST(OnnxifiLoadTest, OnnxifiDummyBackend) | ||
{ | ||
|
||
#define EXPECT_EQ_OSS(X) EXPECT_EQ(X, ONNXIFI_STATUS_SUCCESS) | ||
onnxifi_library dummy_backend; | ||
EXPECT_TRUE(onnxifi_load(1, ONNXIFI_DUMMY_LIBRARY, &dummy_backend)); | ||
|
||
onnxBackendID backendID; | ||
onnxBackend backend; | ||
onnxEvent event; | ||
onnxGraph graph; | ||
|
||
//Testing onnxGetBackendIDs | ||
size_t numBackends = -1; | ||
|
||
EXPECT_EQ_OSS(dummy_backend.onnxGetBackendIDs( | ||
&backendID, &numBackends)); | ||
EXPECT_EQ(numBackends, 1); | ||
|
||
//Testing onnxReleaseBackendID | ||
EXPECT_EQ_OSS( | ||
dummy_backend.onnxReleaseBackendID(backendID)); | ||
|
||
// Testing onnxGetBackendInfo | ||
onnxBackendInfo infoType = 0; | ||
char infoValue[11] = "abc"; | ||
size_t infoValueSize = 3; | ||
|
||
EXPECT_EQ_OSS(dummy_backend.onnxGetBackendInfo( | ||
backendID, infoType, infoValue, &infoValueSize)); | ||
EXPECT_EQ(infoValue[0], 0); | ||
|
||
//Testing onnxGetBackendCompatibility | ||
char onnxModel[] = ""; | ||
size_t onnxModelSize = 0; | ||
EXPECT_EQ_OSS(dummy_backend.onnxGetBackendCompatibility(backendID, onnxModelSize, onnxModel)); | ||
|
||
//Testing onnxInitBackend | ||
uint64_t auxpropertiesList = 0; | ||
EXPECT_EQ_OSS(dummy_backend.onnxInitBackend(backendID, &auxpropertiesList, &backend)); | ||
|
||
//Testing onnxReleaseBackend | ||
EXPECT_EQ_OSS(dummy_backend.onnxReleaseBackend(backend)); | ||
|
||
//Testing onnxInitEvent | ||
EXPECT_EQ_OSS(dummy_backend.onnxInitEvent(backend, &event)); | ||
|
||
//Testing onnxSignalEvent | ||
EXPECT_EQ_OSS(dummy_backend.onnxSignalEvent(event)); | ||
|
||
//Testing onnxWaitEvent | ||
EXPECT_EQ_OSS(dummy_backend.onnxWaitEvent(event)); | ||
|
||
//Testing onnxReleaseEvent | ||
EXPECT_EQ_OSS(dummy_backend.onnxReleaseEvent(event)); | ||
|
||
//Testing onnxInitGraph | ||
uint32_t weightCount = 1; | ||
onnxTensorDescriptorV1 weightDescriptors; | ||
EXPECT_EQ_OSS(dummy_backend.onnxInitGraph(backend, onnxModelSize, &onnxModel, weightCount, &weightDescriptors, &graph)); | ||
|
||
//Testing onnxInitGraph | ||
uint32_t inputsCount = 1; | ||
onnxTensorDescriptorV1 inputDescriptors; | ||
uint32_t outputsCount = 1; | ||
onnxTensorDescriptorV1 outputDescriptors; | ||
EXPECT_EQ_OSS(dummy_backend.onnxSetGraphIO(graph, inputsCount, &inputDescriptors, outputsCount, &outputDescriptors)); | ||
|
||
//Testing onnxRunGraph | ||
onnxMemoryFenceV1 inputFence, outputFence; | ||
EXPECT_EQ_OSS(dummy_backend.onnxRunGraph(graph, &inputFence, &outputFence)); | ||
EXPECT_EQ(outputFence.type, ONNXIFI_SYNCHRONIZATION_EVENT); | ||
|
||
//Testing onnxReleaseGraph | ||
EXPECT_EQ_OSS(dummy_backend.onnxReleaseGraph(graph)); | ||
|
||
#undef EXPECT_EQ_OSS | ||
} | ||
|
||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters