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
- The initialized ncGraphHandle_t struct must be passed to this function or ncGraphAllocateWithFifos()/ncGraphAllocateWithFifosEx() before it can be passed to any API function other than ncGraphGetOption() or ncGraphSetOption(). When the graph has been allocated, the graph state will be NC_GRAPH_ALLOCATED.
- ncGraphAllocateWithFifos() or ncGraphAllocateWithFifosEx() can be used to easily initialize and allocate an input and an output FIFO in addition to allocating a graph to a device; these internally call ncFifoCreate() and ncFifoAllocate() for both ncFifoHandle_t structs and ncGraphAllocate() for the graph.
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);
}