Skip to content
Permalink
Browse files

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
  • Loading branch information...
yinghai authored and facebook-github-bot committed Oct 31, 2019
1 parent c8de4b0 commit e09da24899241ba322cd758e043e4d4105c3ebdc
@@ -85,6 +85,11 @@ class CommonOperatorLoader : public ProtobufLoader {
dims.push_back(in.shape[i]);
}

// TODO(garret): create cached placeholder if in.isOffline is 1
if (in.isOffline) {
RETURN_ERR(strFormat("Cannot handle offline tensor %s yet", in.name));
}

// Load unquantized tensor.
if (in.quantizationParams == 0) {
if (in.dataType == ONNXIFI_DATATYPE_FLOAT32) {
@@ -127,10 +127,12 @@ class Graph {
EventPtr outputEvent, onnxTraceEventList *traceEvents);

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

virtual onnxStatus run(std::unique_ptr<ExecutionContext> ctx,
EventPtr outputEvent,
@@ -112,10 +112,9 @@ onnxStatus HostManagerBackend::removeNetwork(const Graph *graph) {
return ONNXIFI_STATUS_SUCCESS;
}

onnxStatus
HostManagerGraph::initGraph(const void *onnxModel, size_t onnxModelSize,
uint32_t weightCount,
const onnxTensorDescriptorV1 *weightDescriptors) {
onnxStatus HostManagerGraph::initGraph(
const void *onnxModel, size_t onnxModelSize, uint32_t weightCount,
const onnxTensorDescriptorV1 *weightDescriptors, void * /* unused */) {

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

@@ -58,10 +58,12 @@ class HostManagerGraph : public Graph {
static size_t makeUniqueGraphId();

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

/// Async run HostManagerGraph with the given ExecutionContext \p ctx then
/// signal \p outputEvent when done. \p phNameToOnnxTensorOutputs is a mapping
@@ -43,10 +43,9 @@ void computeModelHash(const void *onnxModel, size_t onnxModelSize,
}
} // namespace

onnxStatus
InlineGraph::initGraph(const void *onnxModel, size_t onnxModelSize,
uint32_t weightCount,
const onnxTensorDescriptorV1 *weightDescriptors) {
onnxStatus InlineGraph::initGraph(
const void *onnxModel, size_t onnxModelSize, uint32_t weightCount,
const onnxTensorDescriptorV1 *weightDescriptors, void *deferedBlobReader) {
function_ = executionEngine_.getModule().createFunction("function");

std::unique_ptr<ONNXIFIModelLoader> loader =
@@ -31,10 +31,12 @@ class InlineGraph : public Graph {
: Graph(backendPtr), quantizationMode_(quantizationMode) {}

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

onnxStatus run(std::unique_ptr<ExecutionContext> ctx, EventPtr outputEvent,
onnxTraceEventList *traceEvents) override;
@@ -401,7 +401,8 @@ EXTERNC ONNXIFI_PUBLIC ONNXIFI_CHECK_RESULT onnxStatus ONNXIFI_ABI
GLOW_ONNXIFI_LIBRARY_FUNCTION_WRAPPER(onnxInitGraph)(
onnxBackend backend, const uint64_t *auxPropertiesList,
size_t onnxModelSize, const void *onnxModel, uint32_t weightsCount,
const onnxTensorDescriptorV1 *weightDescriptors, onnxGraph *graph) {
const onnxTensorDescriptorV1 *weightDescriptors, onnxGraph *graph,
void *deferredBlobReader) {
if (!onnxModel || (!weightDescriptors && weightsCount) || !graph) {
return ONNXIFI_STATUS_INVALID_POINTER;
}
@@ -427,7 +428,7 @@ GLOW_ONNXIFI_LIBRARY_FUNCTION_WRAPPER(onnxInitGraph)(

auto *glowGraph = manager.createGraph(glowBackend, quantizationMode);
auto ret = glowGraph->initGraph(onnxModel, onnxModelSize, weightsCount,
weightDescriptors);
weightDescriptors, deferredBlobReader);
if (ret != ONNXIFI_STATUS_SUCCESS) {
manager.release(glowGraph);
return ret;
Submodule foxi updated 1 files
+12 −2 foxi/onnxifi.h

0 comments on commit e09da24

Please sign in to comment.
You can’t perform that action at this time.