ncGraphAllocate()

Info Value
Header mvnc.h
Library libmvnc.so
Version 2.0
See also struct ncGraphHandle_t, ncGraphCreate(), ncGraphDestroy(), ncGraphAllocateWithFifos(), ncGraphAllocateWithFifosEx()

Overview

This function allocates a network graph to the specified device. Each graph can only be allocated to a single device.

Upon successful return from this function, the graph will be ready to perform inferences.

ncGraphDestroy() frees the memory allocated with this function.

Prototype

ncStatus_t ncGraphAllocate(struct ncDeviceHandle_t *deviceHandle,
                           struct ncGraphHandle_t *graphHandle,
                           const void *graphBuffer, unsigned int graphBufferLength);

Parameters

Name Type Description
deviceHandle struct ncDeviceHandle_t* A pointer to an initialized and opened ncDeviceHandle_t struct for the device to which the graph will be allocated. The device state must be NC_DEVICE_OPENED.
graphHandle struct ncGraphHandle_t* A pointer to an initialized ncGraphHandle_t struct for the graph that will be allocated. The graph state must be NC_GRAPH_CREATED.
graphBuffer const void* A pointer to a buffer that contains raw data read from a neural network graph file that was created with the NCSDK mvNCCompile tool.
graphBufferLength unsigned int The size, in bytes, of the buffer allocated to the graphBuffer parameter.

Return

An appropriate value from the ncStatus_t enumeration.

Notes

Example

#include <stdio.h>
#include <stdlib.h>
#include <mvnc.h>

int main(int argc, char** argv)
{
    ncStatus_t retCode;
    struct ncDeviceHandle_t* deviceHandlePtr;
    struct ncGraphHandle_t* graphHandlePtr;
    
    ncDeviceCreate(0, &deviceHandlePtr);
    ncDeviceOpen(deviceHandlePtr);
    ncGraphCreate("My Graph", &graphHandlePtr);
    
    unsigned int graphSizeInBytes = 0;
    void* graphInMemoryPtr = LoadGraphFile("./graph", &graphSizeInBytes);

    retCode = ncGraphAllocate(deviceHandlePtr, graphHandlePtr, graphInMemoryPtr, graphSizeInBytes);
    if (retCode != NC_OK)
    {   
        // Could not allocate graph 
        printf("Error allocating graph [%d]\n", retCode);
    }
    else
    {
        // Graph is allocated and can be used for inference now.
        printf("Graph allocated OK!\n");
    }

    // clean up the graph and device
    ncGraphDestroy(&graphHandlePtr);
    ncDeviceClose(deviceHandlePtr);
    ncDeviceDestroy(&deviceHandlePtr);
}