class Fifo

Info Value
Package mvnc
Module mvncapi
Version 2.0
See also FifoOption, Device, Graph, Graph.allocate_with_fifos(), Graph.queue_inference_with_fifo_elem()

Overview

The Fifo class represents a first in, first out (FIFO) queue for network input and output.

Typically two instances of this class are created for each Graph - one for input and one for output.

Initialization

Create a Fifo instance:

fifo = mvncapi.Fifo(name, fifo_type)
Parameter Type Description
name str A name for the Fifo; this can be can be anything you like up to mvncapi.MAX_NAME_SIZE characters, or just an empty string.

The name can be retrieved later with Fifo.get_option().
fifo_type int A member of the FifoType enumeration.

The API must be able to write to input Fifos and read from output Fifos.

You can also create and allocate both an input Fifo and an output Fifo in one call with Graph.allocate_with_fifos().

When the Fifo has been successfully created the FifoState will be CREATED.

Methods

Method Description
allocate Allocate a Fifo queue for a particular device..
destroy Destroy the Fifo and free associated resources. The Fifo queue must be empty.
get_option Get the value of a FifoOption.
read_elem Read an element from the Fifo. The Fifo must be FifoType.HOST_RO.
remove_elem Not yet implemented.

Remove an element from a Fifo without returning it.
set_option Set the value of a FifoOption.
write_elem Send an input tensor to the Fifo queue. The Fifo must be FifoType.HOST_WO.

Typical Usage

See the Python API Overview for more information about typical API usage.

Raises

Exception with a status code from Status if underlying function calls return a status other than Status.OK.

Examples

"""Example Fifo usage with convenience functions."""
from mvnc import mvncapi

#
# Open a Device, create a Graph, and load graph data from file...
#

# Allocate the Graph and create and allocate two associate Fifos for input and output
input_fifo, output_fifo = graph.allocate_with_fifos(device, graph_buffer)

# Write an input tensor to the input Fifo and queue an inference
graph.queue_inference_with_fifo_elem(input_fifo, output_fifo, input_tensor, None, 'tensor1')

# Read the inference result tensor from the output Fifo
result_tensor, user_obj = output_fifo.read_elem()

#
# Do something with the result...
#

# Destroy the Fifos
input_fifo.destroy()
output_fifo.destroy()

#
# Perform other clean up...
#
"""Example Fifo usage without convenience functions."""
from mvnc import mvncapi

#
# Open a Device and allocate a Graph...
#

# Initialize two Fifos for input and output
input_fifo = mvncapi.Fifo('input1', mvncapi.FifoType.HOST_WO)
output_fifo = mvncapi.Fifo('output1', mvncapi.FifoType.HOST_RO)

# Get input and output TensorDescriptors from the graph
input_descriptor = graph.get_option(mvncapi.GraphOption.RO_INPUT_TENSOR_DESCRIPTORS)
output_descriptor = graph.get_option(mvncapi.GraphOption.RO_OUTPUT_TENSOR_DESCRIPTORS)

# Allocate the Fifo buffers
NUM_ELEMENTS = 2
input_fifo.allocate(device, input_descriptor[0], NUM_ELEMENTS)
output_fifo.allocate(device, output_descriptor[0], NUM_ELEMENTS)

# Write an input tensor to the input_fifo
input_fifo.write_elem(input_tensor, 'tensor1')

#
# Queue an inference with Graph.queue_inference()...
#

# Read the inference result tensor from the output Fifo
result_tensor, user_obj = output_fifo.read_elem()

#
# Do something with the result...
#

# Destroy the Fifos
input_fifo.destroy()
output_fifo.destroy()

#
# Perform other clean up...
#