ncFifoAllocate()

Info Value
Header mvnc.h
Library libmvnc.so
Version 2.0
See also struct ncFifoHandle_t, ncFifoCreate(), ncFifoDestroy()

Overview

This function allocates memory for a FIFO for the specified device based on the number of elements the FIFO will hold and a ncTensorDescriptor_t struct, which describes the expected shape of the FIFO’s elements. Each FIFO can only be allocated to a single device.

Upon successful return from this function, the FIFO will be ready for reading/writing.

ncFifoDestroy() frees the memory allocated with this function.

Prototype

ncStatus_t ncFifoAllocate(struct ncFifoHandle_t* fifo, struct ncDeviceHandle_t* device,
                        struct ncTensorDescriptor_t* tensorDesc, unsigned int numElem);

Parameters

Name Type Description
fifo struct ncFifoHandle_t* A pointer to an initialized ncFifoHandle_t struct for the FIFO that will be allocated. The FIFO state must be NC_FIFO_CREATED.
device struct ncDeviceHandle_t* A pointer to an initialized and opened ncDeviceHandle_t struct for the device to which the FIFO will be allocated. The device state must be NC_DEVICE_OPENED.
tensorDesc struct ncTensorDescriptor_t* A pointer to an ncTensorDescriptor_t struct that describes the expected shape of the elements of the FIFO. You should use ncGraphGetOption() to get arrays of input or output ncTensorDescriptor_t structs that are appropriate for the associated graph.
numElem unsigned int The maximum number of elements that the FIFO will be able to contain.

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 = NULL;
    struct ncGraphHandle_t* graphHandlePtr = NULL;
    struct ncFifoHandle_t* inFifoHandlePtr = NULL;
    struct ncTensorDescriptor_t inTensorDesc;
    unsigned int optionSize;
    unsigned int graphSizeInBytes = 0;
    void* graphInMemoryPtr = NULL;

    ncDeviceCreate(0, &deviceHandlePtr);
    ncDeviceOpen(deviceHandlePtr);
    ncGraphCreate("My Graph", &graphHandlePtr);
    graphInMemoryPtr = LoadGraphFile("./graph", &graphSizeInBytes);
    ncGraphAllocate(deviceHandlePtr, graphHandlePtr, graphInMemoryPtr, graphSizeInBytes);
    free(graphInMemoryPtr);
    
    ncFifoCreate("MY Input FIFO", NC_FIFO_HOST_WO, &inFifoHandlePtr);

    // if we know there is only one input descriptor for the graph we can get it like this
    optionSize = sizeof(ncTensorDescriptor_t);
    ncGraphGetOption(graphHandlePtr, NC_RO_GRAPH_INPUT_TENSOR_DESCRIPTORS, &inTensorDesc, &optionSize);

    ncFifoAllocate(inFifoHandlePtr, deviceHandlePtr, &inTensorDesc, 2);
    if (retCode != NC_OK)
    {   // Could not allocate FIFO 
        printf("Error allocating FIFO [%d]\n", retCode);
    }
    else
    {
        // FIFO created write only FIFO.  
        // Now allocate it and then Write graph input to it and then queue inferences. 
        printf("FIFO created OK!\n");
    }

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