ncs: github.com/milosgajdos83/ncs Index | Files

package ncs

import "github.com/milosgajdos83/ncs"

For more information about how to install the SDK go here: https://movidius.github.io/ncsdk/install.html

Index

Package Files

device.go fifo.go global.go graph.go ncs.go

Constants

const (
    // MaxNameSize is the maximum length of device or graph name size
    MaxNameSize = 28
    // ThermalBufferSize is the size of the temperature buffer as returned when querying device
    ThermalBufferSize = 100
    // DebugBufferSize is the size of the debug information buffer as returned by API
    DebugBufferSize = 120
    // VersionMaxSize is the max length of various version options (HW, firmewre etc.) as returned by API
    VersionMaxSize = 4
)

type Device Uses

type Device struct {
    // contains filtered or unexported fields
}

Device is Neural Compute Stick (NCS) device

func NewDevice Uses

func NewDevice(index int) (*Device, error)

NewDevice creates new NCS device handle and returns it.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncDeviceCreate.html

func (*Device) Close Uses

func (d *Device) Close() error

Close closes the communication channel with NCS device. It returns error if it fails to close the communication channel.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncDeviceClose.html

func (*Device) Destroy Uses

func (d *Device) Destroy() error

Destroy destroys NCS device handle and frees associated resources. This function must be called for every device that was initialized with NewDevice().

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncDeviceDestroy.html

func (*Device) GetOption Uses

func (d *Device) GetOption(opt DeviceOption) ([]byte, error)

GetOption queries the value of an option for the device and returns it encoded in a byte slice. It returns error if it fails to retrieve the option value.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncDeviceGetOption.html

func (*Device) GetOptionWithByteSize Uses

func (d *Device) GetOptionWithByteSize(opt DeviceOption, size uint) ([]byte, error)

GetOptionsWithSize queries NCS device options and returns it encoded in a byte slice of size elements. This function is similar to GetOption(), however as opposed to GetOption() which first queries the NCS device for the size of the requested options, it attempts to request the options data by specifying its size in raw bytes explicitly, hence it returns the queried options data faster. It returns error if it fails to retrieve the options or if the requested size of the options is invalid.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncDeviceGetOption.html

func (*Device) Open Uses

func (d *Device) Open() error

Open initializes NCS device and opens device communication channel. It returns error if it fails to open or initialize the communication channel with the device.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncDeviceOpen.html

type DeviceHWVersion Uses

type DeviceHWVersion int

DeviceHWVersion defines neural compute device hardware version

const (
    MA2450 DeviceHWVersion = iota
    MA2480
)

func (DeviceHWVersion) String Uses

func (hw DeviceHWVersion) String() string

String implements fmt.Stringer interface

type DeviceOption Uses

type DeviceOption int

DeviceOption defines NCS device options. The options starting with RW are both gettable and settable. The options starting with RO are only gettable.

const (
    // RODeviceThermalStats queries device temperatures in degrees Celsius.
    // This option returns []float64 array of max temperatures for the last ThermalBufferSize seconds.
    RODeviceThermalStats DeviceOption = (2000 + iota)
    // RODeviceThermalThrottling queries temperature throttling level.
    RODeviceThermalThrottle
    // RODeviceState queries the state of the device.
    RODeviceState
    // RODeviceMemoryUsed queries current memory in use on the device in bytes.
    RODeviceMemoryUsed
    // RODeviceMemorySize queries total memory available on the device in bytes.
    RODeviceMemorySize
    // RODeviceMaxFifoCount queries maximum number of FIFOs that can be allocated for the device.
    RODeviceMaxFifoCount
    // RODeviceAllocatedFifoCount queries number of FIFOs currently allocated for the device.
    RODeviceAllocatedFifoCount
    // RODeviceMaxMaxGraphCount queries the maximum number of graphs that can be allocated for the device.
    RODeviceMaxGraphCount
    // RODeviceAllocatedGraphCount queries the number of graphs currently allocated for the device.
    RODeviceAllocatedGraphCount
    // RODeviceClassLimit queries the highest device option class supported.
    RODeviceClassLimit
    // RODeviceFirmwareVersion queries the version of the firmware currently running on the device.
    RODeviceFirmwareVersion
    // RODeviceDebugInfo queries more detailed info when the result of API call is StatusMyriadError.
    RODeviceDebugInfo
    // RODeviceMVTensorVersion queries the version of the mvtensor library that was linked with the API.
    RODeviceMVTensorVersion
    // RODeviceName queries the internal name of the device.
    RODeviceName
    // RODeviceMaxExecutors is reserved for future use.
    RODeviceMaxExecutors
    // RODeviceHWVersion queries the hardware version of the device.
    RODeviceHWVersion
)

func (DeviceOption) Decode Uses

func (do DeviceOption) Decode(data []byte, count int) (interface{}, error)

Decode decodes options data encoded in raw bytes and returns it in its native type. The returned data can be asserted into its native type. If the data contains more than one element you need to specify the number of expected elements via count. It returns error if the data fails to be decoded into the option native type.

func (DeviceOption) String Uses

func (do DeviceOption) String() string

String implements fmt.Stringer interface for DeviceOption

func (DeviceOption) Value Uses

func (do DeviceOption) Value() int

Value returns option value as integer

type DeviceState Uses

type DeviceState int

DeviceState represents NCS device state

const (
    // DeviceCreated means NCS device handle has been created.
    DeviceCreated DeviceState = iota
    // DeviceOpened means NCS device handle has been opened.
    DeviceOpened
    // DeviceClosed means NCS device handle has been closed.
    DeviceClosed
)

func (DeviceState) String Uses

func (ds DeviceState) String() string

String implements fmt.Stringer interface

type DeviceThermalThrottle Uses

type DeviceThermalThrottle int

DeviceThermalThrottle defines thermal throttle level

const (
    // NoThrottle means no limit reached
    NoThrottle DeviceThermalThrottle = iota
    // LowerGuard means means lower guard temperature threshold of chip sensor has been reached
    // Short throttling time is in action between inferences to protect the device
    LowerGuard
    // UpperGuards means upper guard temperature of chip sensor has been reached
    // Long throttling time is in action between inferences to protect the device
    UpperGuard
)

func (DeviceThermalThrottle) String Uses

func (dt DeviceThermalThrottle) String() string

String implements fmt.Stringer interface

type Fifo Uses

type Fifo struct {
    // contains filtered or unexported fields
}

Fifo is NCSDK FIFO queue

func NewFifo Uses

func NewFifo(name string, t FifoType) (*Fifo, error)

NewFifo creates new FIFO queue with given name and returns it It returns error if it fails to create new queue

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoCreate.html

func (*Fifo) Allocate Uses

func (f *Fifo) Allocate(d *Device, td *TensorDesc, numElem uint) error

Allocate allocates memory for a FIFO for the specified device based on the number of elements the FIFO will hold and tensorDesc, which describes the expected shape of the FIFO’s elements It returns error when it fails to allocate FIFO

More information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoAllocate.html

func (*Fifo) Destroy Uses

func (f *Fifo) Destroy() error

Destroy destroys NCS FIFO handle and frees associated resources. This function must be called for every FIFO handle that was initialized with NewFifo()

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoDestroy.html

func (*Fifo) GetOption Uses

func (f *Fifo) GetOption(opt FifoOption) ([]byte, error)

GetOptions queries FIFO options and returns it encoded in a byte slice It returns error if it fails to retrieve the options

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoGetOption.html

func (*Fifo) GetOptionWithByteSize Uses

func (f *Fifo) GetOptionWithByteSize(opt FifoOption, size uint) ([]byte, error)

GetOptionsWithSize queries NCS fifo options and returns it encoded in a byte slice of size elements. This function is similar to GetOption(), however as opposed to GetOption() which first queries the NCS device for the size of the requested options, it attempts to request the options data by specifying its size in raw bytes explicitly, hence it returns the queried options data faster. It returns error if it fails to retrieve the options or if the requested size of the options is invalid.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoGetOption.html

func (*Fifo) ReadElem Uses

func (f *Fifo) ReadElem() (*Tensor, error)

ReadElem reads an element from a FIFO, usually the result of an inference as a tensor, along with the associated user-defined data If it fails to read the element it returns error

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoReadElem.html

func (*Fifo) RemoveElem Uses

func (f *Fifo) RemoveElem() error

RemoveElem removes an element from a FIFO If it fails to remove the element it returns error THIS FUNCTION IS NOT IMPLEMENTED YET

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoRemoveElem.html

func (*Fifo) WriteElem Uses

func (f *Fifo) WriteElem(data []byte, metaData interface{}) error

WriteElem writes an element to a FIFO, usually an input tensor for inference along with some metadata If it fails to write the element it returns error

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoWriteElem.html

type FifoDataType Uses

type FifoDataType int

FifoDataType defines possible data types for FIFOs.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoDataType_t.html

const (
    // FifoFP16 data is in half precision (16 bit) floating point format (FP16).
    FifoFP16 FifoDataType = iota
    // FifoFP32 data is in full precision (32 bit) floating point format (FP32).
    FifoFP32
)

func (FifoDataType) String Uses

func (fd FifoDataType) String() string

String implements fmt.Stringer interface

type FifoOption Uses

type FifoOption int

FifoOption is FIFO option which can be used to query and set various FIFO properties. The options starting with RW are both gettable and settable. The options starting with RO are only gettable. All settable options except for RWFifoHostTensorDesc must be set before FIFO is allocated.

const (
    // RWFifoType configure the fifo type to either of FifoType options
    RWFifoType FifoOption = iota
    // RWFifoConsumerCount is number of consumers of elements before the element is removed
    RWFifoConsumerCount
    // RWFifoDataType configures fifo data type to either of FifoDataType options
    RWFifoDataType
    // RWFifoDontBlock configures to return StatusOutOfMemory instead of blocking
    RWFifoNoBlock
    // ROFifoCapacity allows to query number of maximum elements in the buffer
    ROFifoCapacity
    // ROFifoReadFillLevel allows to query number of tensors in the read buffer
    ROFifoReadFillLevel
    // ROFifoWriteFillLevel allows to query number of tensors in a write buffer
    ROFifoWriteFillLevel
    // ROFifoGraphTensorDescriptor allows to query the tensor descriptor of the FIFO
    ROFifoGraphTensorDesc
    // ROFifoState allows to query FifoState
    ROFifoState
    // ROFifoName allows to query FIFO name
    ROFifoName
    // ROFifoElemDataSize allows to query element data size in bytes
    ROFifoElemDataSize
    // RWFifoHostTensorDesc is tensor descriptor, defaults to none strided channel minor
    RWFifoHostTensorDesc
)

func (FifoOption) Decode Uses

func (fo FifoOption) Decode(data []byte, count int) (interface{}, error)

Decode decodes options data encoded in raw bytes and returns it in its native type. The returned data can be asserted into its native type. If the data contains more than one element you need to specify the number of expected elements via count. It returns error if the data fails to be decoded into the option native type.

func (FifoOption) String Uses

func (fo FifoOption) String() string

String implements fmt.Stringer interface

func (FifoOption) Value Uses

func (fo FifoOption) Value() int

Value returns option value as integer

type FifoOpts Uses

type FifoOpts struct {
    // Type is FIFO type
    Type FifoType
    // DataType is FIFO data type
    DataType FifoDataType
    // NumElem is a max number of elements that the FIFO will be able to contain
    NumElem int
}

FifoOpts specifies FIFO configuration options

type FifoQueue Uses

type FifoQueue struct {
    // In is an inbound queue
    In  *Fifo
    // Out is an outbound queue
    Out *Fifo
}

FifoQueue is a FIFO queue used for NCS inference.

type FifoState Uses

type FifoState int

FifoState represents FIFO state

const (
    // FifoCreated means FIFO has been created.
    FifoCreated FifoState = iota
    // FifoAllocated means FIFO has been allocated.
    FifoAllocated
)

func (FifoState) String Uses

func (fs FifoState) String() string

String implements fmt.Stringer interface

type FifoType Uses

type FifoType int

FifoType defines FIFO access types.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncFifoType_t.html

const (
    // FifoHostRO allows Read Only API access and Read-Write Graph access
    FifoHostRO FifoType = iota
    // FifoHostWO allows Write Only API acess and Read Only Graph access
    FifoHostWO
)

type Graph Uses

type Graph struct {
    // contains filtered or unexported fields
}

Graph is NCSDK neural network graph

func NewGraph Uses

func NewGraph(name string) (*Graph, error)

NewGraph creates new Graph with given name and returns it It returns error if it fails to create new graph

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphCreate.html

func (*Graph) Allocate Uses

func (g *Graph) Allocate(d *Device, graphData []byte) error

Allocate allocates a graph on NCS device. This function sends graphData to NCS device. It does not allocate input or output FIFO queues. You have to either allocate them separately or use either AllocateWithFifosDefault() or AllocateWithFifosOpts() functions whcih conveniently create and allocate the FIFO queues. It returns error if it fails to allocate the graph on the device

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphAllocate.html

func (*Graph) AllocateWithFifosDefault Uses

func (g *Graph) AllocateWithFifosDefault(d *Device, graphData []byte) (*FifoQueue, error)

AllocateWithFifosDefault allocates a graph and creates and allocates FIFO queues with default parameters for inference. Both FIFOs have FifoDataType set to FifoFP32. Inbound FIFO queue is initialized with FifoHostWO type and outbound FIFO queue with FifoHostRO type. It returns FifoQueue or error if it fails to allocate the graph.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphAllocateWithFifos.html

func (*Graph) AllocateWithFifosOpts Uses

func (g *Graph) AllocateWithFifosOpts(d *Device, graphData []byte, inOpts *FifoOpts, outOpts *FifoOpts) (*FifoQueue, error)

AllocateWithFifosOpts allocates a graph and creates and allocates FIFO queues for inference. This function is similar to AllocateWithFifosDefault, but rather than initializing FIFOs with default values it accepts parameters that allow to specify FIFO queue parameters

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphAllocateWithFifosEx.html

func (*Graph) Destroy Uses

func (g *Graph) Destroy() error

Destroy destroys NCS graph handle and frees associated resources. This function must be called for every graph that was initialized with NewGraph().

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphDestroy.html

func (*Graph) GetOption Uses

func (g *Graph) GetOption(opt GraphOption) ([]byte, error)

GetOption queries the value of an option for a graph and returns it encoded in a byte slice It returns error if it failed to retrieve the option value

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphGetOption.html

func (*Graph) GetOptionWithByteSize Uses

func (g *Graph) GetOptionWithByteSize(opt GraphOption, size uint) ([]byte, error)

GetOptionsWithSize queries NCS grapg options and returns it encoded in a byte slice of size elements. This function is similar to GetOption(), however as opposed to GetOption() which first queries the NCS device for the size of the requested options, it attempts to request the options data by specifying its size in raw bytes explicitly, hence it returns the queried options data faster. It returns error if it fails to retrieve the options or if the requested size of the options is invalid.

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphGetOption.html

func (*Graph) QueueInference Uses

func (g *Graph) QueueInference(f *FifoQueue) error

QueueInference queues data for inference to be processed by a graph with specified input and output FIFOs If it fails to queue the data tensor it returns error

For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphQueueInference.html

func (*Graph) QueueInferenceWithFifoElem Uses

func (g *Graph) QueueInferenceWithFifoElem(f *FifoQueue, data []byte, metaData interface{}) error

QueueInferenceWithFifoElem writes an element to a FIFO, usually an input tensor for inference, and queues an inference to be processed by a graph. This is a convenient way to write an input tensor and queue an inference in one call If it fails to queue the data tensor it returns error For more information: https://movidius.github.io/ncsdk/ncapi/ncapi2/c_api/ncGraphQueueInferenceWithFifoElem.html

type GraphOption Uses

type GraphOption int

GraphOption defines graph options The options starting with RW are both gettable and settable The options starting with RO are only gettable

const (
    // ROGraphState is current state of the graph
    ROGraphState GraphOption = (1000 + iota)
    // ROGraphInferenceTime times taken per graph layer for the last inference in milliseconds
    ROGraphInferenceTime
    // ROGraphInputCount is number of inputs expected by the graph
    ROGraphInputCount
    // ROGraphOutputCount is he number of outputs expected by the graph.
    ROGraphOutputCount
    // ROGraphInputTensorDesc is an array of TensorDesc's, which describe the graph inputs in order
    ROGraphInputTensorDesc
    // ROGraphOutputTensorDesc is array of TensorDesc's, which describe the graph outputs in order
    ROGraphOutputTensorDesc
    // ROGraphDebugInfo provides more details when the result of a function call was StatusMyriadError
    ROGraphDebugInfo
    // ROGraphName is the name of the graph
    ROGraphName
    // ROGraphOptionClassLimit returns the highest option class supported
    ROGraphOptionClassLimit
    // ROGraphVersion is graph version
    ROGraphVersion
    // RWGraphExecutorsCount is not implemented yet
    RWGraphExecutorsCount
    // ROGraphInferenceTimeSize size of array for ROGraphInferenceTime option
    ROGraphInferenceTimeSize
)

func (GraphOption) Decode Uses

func (g GraphOption) Decode(data []byte, count int) (interface{}, error)

Decode decodes options data encoded in raw bytes and returns it in its native type. The returned data then can be asserted into its native type. If the data contains more than one element you need to specify the number of expected elements via count. It returns error if the data fails to be decoded into the option native type.

func (GraphOption) String Uses

func (g GraphOption) String() string

String implements fmt.Stringer interface for GraphOption

func (GraphOption) Value Uses

func (g GraphOption) Value() int

Value returns option value as integer

type GraphState Uses

type GraphState int

GraphState defines states of a network graph

const (
    // GraphCreated means the graph has been created, but it may not be initialized
    GraphCreated GraphState = iota
    // GraphAllocated means the graph has been initialized, and the graph has been allocated for a device
    GraphAllocated
    // GraphWaitingForInput means the graph is waiting for input.
    GraphWaitingForInput
    // GraphRunning means the graph is currently running an inference
    GraphRunning
)

func (GraphState) String Uses

func (gs GraphState) String() string

String implements fmt.Stringer interface for GraphState

type Option Uses

type Option interface {
    // Value returns Option value as its integer code
    Value() int
    // Decode decodes raw byte slice option data as returned from NCS
    Decode([]byte, int) (interface{}, error)
}

Option is NCS option

type Status Uses

type Status int

Status is the NCSDK API status code as returned by most API calls. It usually reports the status of the Neural Compute Stick.

const (
    // StatusOK means the API function call worked as expected
    StatusOK Status = -iota
    // StatusBusy means device is busy, retry later.
    StatusBusy
    // StatusError means an unexpected error was encountered during the API function call.
    StatusError
    // StatusOutOfMemory means the host is out of memory.
    StatusOutOfMemory
    // StatusDeviceNotFound means no device has been found at the given index or name.
    StatusDeviceNotFound
    // StatusInvalidParameters means at least one of the given parameters is wrong.
    StatusInvalidParameters
    // StatusTimeout means there was a timeout in the communication with the device.
    StatusTimeout
    // StatusCmdNotFound means the file to boot the device was not found.
    StatusCmdNotFound
    // StatusNotAllocated means the graph or fifo has not been allocated..
    StatusNotAllocated
    // StatusUnauthorized means an unauthorized operation has been attempted.
    StatusUnauthorized
    // StatusUnsupportedGraphFile means the graph file version is not supported.
    StatusUnsupportedGraphFile
    // StatusUnsupportedConfigFile is reserved for future use.
    StatusUnsupportedConfigFile
    // StatusUnsupportedFeature means the operation used a feature unsupported by this firmware version.
    StatusUnsupportedFeature
    // StatusMyriadError when an error has been reported by device, use MVNC_DEBUG_INFO.
    StatusMyriadError
    // StatusInvalidDataLength means an invalid data length has been passed when getting or setting an option.
    StatusInvalidDataLength
    // StatusInvalidHandle means an invalid handle has been passed to a function.
    StatusInvalidHandle
)

func (Status) String Uses

func (s Status) String() string

String method implements fmt.Stringer interface

type Tensor Uses

type Tensor struct {
    // Data contains raw tensor data
    Data []byte
    // MetaData contains tensor metadata
    MetaData interface{}
}

Tensor is graph tensor as returned from NCS

type TensorDesc Uses

type TensorDesc struct {
    // BatchSize contains number of elements.
    BatchSize uint
    // Channels contains number of channels (when dealing with digital images).
    Channels uint
    // Width is data width (i.e. number of matrix columns).
    Width uint
    // Height is data height (i.e. number of matrix rows).
    Height uint
    // Size is the total data size in the tensor.
    Size uint
    // CStride is channel stride (Stride in the channels' dimension).
    CStride uint
    // WStride is width stride (Stride in the horizontal dimension).
    WStride uint
    // HStride is height stride (Stride in the vertical dimension).
    HStride uint
    // DataType is data type of the tensor.
    DataType FifoDataType
}

TensorDesc describes NCS graph inputs and outputs

Package ncs imports 5 packages (graph). Updated 2018-10-08. Refresh now. Tools for package owners.