Skip to content

Commit e09da24

Browse files
Yinghai Lufacebook-github-bot
Yinghai Lu
authored andcommitted
Support Offline Tensors through ONNXIFI layer
Summary: Previous import was b2ec1a8041879b7be98d81387a14cae895f952f4 Included changes: - **[97fe555](houseroad/foxi@97fe555)**: Add deferred weight reader pointer when initializing the graph (#15) <Yinghai Lu> - **[ba2faf7](houseroad/foxi@ba2faf7)**: Add status and timeout to events (#14) <Jack Montgomery> Reviewed By: ipiszy Differential Revision: D18231697 fbshipit-source-id: 7566e2438d2b57f0feaadcd51f55a03552adeab9
1 parent c8de4b0 commit e09da24

File tree

8 files changed

+33
-23
lines changed

8 files changed

+33
-23
lines changed

include/glow/Importer/CommonOperatorLoader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class CommonOperatorLoader : public ProtobufLoader {
8585
dims.push_back(in.shape[i]);
8686
}
8787

88+
// TODO(garret): create cached placeholder if in.isOffline is 1
89+
if (in.isOffline) {
90+
RETURN_ERR(strFormat("Cannot handle offline tensor %s yet", in.name));
91+
}
92+
8893
// Load unquantized tensor.
8994
if (in.quantizationParams == 0) {
9095
if (in.dataType == ONNXIFI_DATATYPE_FLOAT32) {

lib/Onnxifi/Base.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ class Graph {
127127
EventPtr outputEvent, onnxTraceEventList *traceEvents);
128128

129129
/// Init Glow graph based on the ONNX model \p onnxModel and
130-
/// static trained weights \p weightDescriptors.
131-
virtual onnxStatus
132-
initGraph(const void *onnxModel, size_t onnxModelSize, uint32_t weightCount,
133-
const onnxTensorDescriptorV1 *weightDescriptors) = 0;
130+
/// static trained weights \p weightDescriptors. Weights can be read in later
131+
/// by a \p deferedBlobReader.
132+
virtual onnxStatus initGraph(const void *onnxModel, size_t onnxModelSize,
133+
uint32_t weightCount,
134+
const onnxTensorDescriptorV1 *weightDescriptors,
135+
void *deferedBlobReader) = 0;
134136

135137
virtual onnxStatus run(std::unique_ptr<ExecutionContext> ctx,
136138
EventPtr outputEvent,

lib/Onnxifi/HostManagerOnnxifi.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ onnxStatus HostManagerBackend::removeNetwork(const Graph *graph) {
112112
return ONNXIFI_STATUS_SUCCESS;
113113
}
114114

115-
onnxStatus
116-
HostManagerGraph::initGraph(const void *onnxModel, size_t onnxModelSize,
117-
uint32_t weightCount,
118-
const onnxTensorDescriptorV1 *weightDescriptors) {
115+
onnxStatus HostManagerGraph::initGraph(
116+
const void *onnxModel, size_t onnxModelSize, uint32_t weightCount,
117+
const onnxTensorDescriptorV1 *weightDescriptors, void * /* unused */) {
119118

120119
netName_ = strFormat("onnxifi_function_%lu", makeUniqueGraphId());
121120

lib/Onnxifi/HostManagerOnnxifi.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ class HostManagerGraph : public Graph {
5858
static size_t makeUniqueGraphId();
5959

6060
/// Init Glow graph based on the ONNX model \p onnxModel and
61-
/// static trained weights \p weightDescriptors.
62-
onnxStatus
63-
initGraph(const void *onnxModel, size_t onnxModelSize, uint32_t weightCount,
64-
const onnxTensorDescriptorV1 *weightDescriptors) override;
61+
/// static trained weights \p weightDescriptors. Weights can be read in later
62+
/// by a \p deferedBlobReader.
63+
onnxStatus initGraph(const void *onnxModel, size_t onnxModelSize,
64+
uint32_t weightCount,
65+
const onnxTensorDescriptorV1 *weightDescriptors,
66+
void *deferedBlobReader) override;
6567

6668
/// Async run HostManagerGraph with the given ExecutionContext \p ctx then
6769
/// signal \p outputEvent when done. \p phNameToOnnxTensorOutputs is a mapping

lib/Onnxifi/InlineOnnxifi.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ void computeModelHash(const void *onnxModel, size_t onnxModelSize,
4343
}
4444
} // namespace
4545

46-
onnxStatus
47-
InlineGraph::initGraph(const void *onnxModel, size_t onnxModelSize,
48-
uint32_t weightCount,
49-
const onnxTensorDescriptorV1 *weightDescriptors) {
46+
onnxStatus InlineGraph::initGraph(
47+
const void *onnxModel, size_t onnxModelSize, uint32_t weightCount,
48+
const onnxTensorDescriptorV1 *weightDescriptors, void *deferedBlobReader) {
5049
function_ = executionEngine_.getModule().createFunction("function");
5150

5251
std::unique_ptr<ONNXIFIModelLoader> loader =

lib/Onnxifi/InlineOnnxifi.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ class InlineGraph : public Graph {
3131
: Graph(backendPtr), quantizationMode_(quantizationMode) {}
3232

3333
/// Init Glow graph based on the ONNX model \p onnxModel and
34-
/// static trained weights \p weightDescriptors.
35-
onnxStatus
36-
initGraph(const void *onnxModel, size_t onnxModelSize, uint32_t weightCount,
37-
const onnxTensorDescriptorV1 *weightDescriptors) override;
34+
/// static trained weights \p weightDescriptors. Weights can be read in later
35+
/// by a \p deferedBlobReader.
36+
onnxStatus initGraph(const void *onnxModel, size_t onnxModelSize,
37+
uint32_t weightCount,
38+
const onnxTensorDescriptorV1 *weightDescriptors,
39+
void *deferedBlobReader) override;
3840

3941
onnxStatus run(std::unique_ptr<ExecutionContext> ctx, EventPtr outputEvent,
4042
onnxTraceEventList *traceEvents) override;

lib/Onnxifi/onnxifiGlow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ EXTERNC ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
401401
GLOW_ONNXIFI_LIBRARY_FUNCTION_WRAPPER(onnxInitGraph)(
402402
onnxBackend backend, const uint64_t *auxPropertiesList,
403403
size_t onnxModelSize, const void *onnxModel, uint32_t weightsCount,
404-
const onnxTensorDescriptorV1 *weightDescriptors, onnxGraph *graph) {
404+
const onnxTensorDescriptorV1 *weightDescriptors, onnxGraph *graph,
405+
void *deferredBlobReader) {
405406
if (!onnxModel || (!weightDescriptors && weightsCount) || !graph) {
406407
return ONNXIFI_STATUS_INVALID_POINTER;
407408
}
@@ -427,7 +428,7 @@ GLOW_ONNXIFI_LIBRARY_FUNCTION_WRAPPER(onnxInitGraph)(
427428

428429
auto *glowGraph = manager.createGraph(glowBackend, quantizationMode);
429430
auto ret = glowGraph->initGraph(onnxModel, onnxModelSize, weightsCount,
430-
weightDescriptors);
431+
weightDescriptors, deferredBlobReader);
431432
if (ret != ONNXIFI_STATUS_SUCCESS) {
432433
manager.release(glowGraph);
433434
return ret;

thirdparty/foxi

0 commit comments

Comments
 (0)