API Reference¶
Configuration¶
-
class tidl
::
Configuration
¶ Specifies the configuration required for a network.
The Configuration object is used to specify various parameters required for network execution. Applications can directly initialize fields in an instance of Configuration or use the ReadFromFile method to read the configuration from a file.
Public Functions
-
tidl::Configuration
Configuration
()¶ Default constructor.
-
bool tidl::Configuration
Validate
() const¶ Validate the fields in the configuration object.
-
void tidl::Configuration
Print
(std::ostream &os = std::cout) const¶ Debug - Print the configuration.
-
bool tidl::Configuration
ReadFromFile
(const std::string &file_name)¶ Read a configuration from the specified file and validate.
Public Members
-
int tidl::Configuration
numFrames
¶ Number of frames of input data (can be 0 if data is not read from file)
-
int tidl::Configuration
inHeight
¶ Height of the input image. Used by the API, must be specified.
-
int tidl::Configuration
inWidth
¶ Width of the input image. Used by the API, must be specified.
-
int tidl::Configuration
inNumChannels
¶ Number of channels in the input frame (e.g. 3 for BGR) Used by the API, must be specified.
-
int tidl::Configuration
preProcType
¶ Pre-processing type applied to the input frame Specific to each network, can take values from 0 to 4, default is 0 0 -> Caffe-Jacinto models 1 -> Caffe models (SqueezeNet) 2 -> TensorFlow (Inception, MobileNet) 3 -> CIFAR 10 4 -> JdetNet
-
bool tidl::Configuration
runFullNet
¶ Force to run all layers, regardless of layersGroupId partitioning.
-
size_t tidl::Configuration
NETWORK_HEAP_SIZE
¶ Size of the device side network heap This heap is used for allocating memory required to run the network on the device. One per Execution Object.
-
size_t tidl::Configuration
PARAM_HEAP_SIZE
¶ Size of the device side heap used for parameter data. The size depends on the size of the parameter binary file. The constructor for
Configuration
sets PARAM_HEAP_SIZE to 9MB. There is one parameter heap for each instance ofExecutor
.
-
std::string tidl::Configuration
inData
¶ Path to the input image file. This field is not used by the TIDL API itself. It can be used by applications to load an input image into a buffer. Can be empty if the application uses frameworks such as OpenCV to read images. Refer examples/test/main.cpp for usage.
-
std::string tidl::Configuration
outData
¶ Path to the output image file. This field is not used by the TIDL API itself. It can be used by applications to specify a name for the output file. Can be empty if the application uses frameworks such as OpenCV to read images. Refer examples/test/main.cpp for usage.
-
std::string tidl::Configuration
netBinFile
¶ Path to the TIDL network binary file. Used by the API, must be specified.
-
std::string tidl::Configuration
paramsBinFile
¶ Path to the TIDL parameter binary file Used by the API, must be specified.
-
std::map<int, int> tidl::Configuration
layerIndex2LayerGroupId
¶ Map of layer index to layer group id. Used to override layer group assigment for layers. Any layer not specified in this map will retain its existing mapping.
-
bool tidl::Configuration
enableOutputTrace
¶ Enable tracing of output buffers associated with each layer.
-
bool tidl::Configuration
enableApiTrace
¶ Debug - Generates a trace of host and device function calls.
-
bool tidl::Configuration
showHeapStats
¶ Debug - Shows total size of PARAM and NETWORK heaps. Also shows bytes available after all allocations. Can be used to adjust the heap size.
-
int tidl::Configuration
quantHistoryParam1
¶ Weight in percentage applied to previously processed input frame during application startup (first 10 frames of input).
TIDL maintains range statistics for previously processed frames. It quantizes the current inference activations using these range statistics from previous inputs (weighted average range). Therefore, the results observed when the input is processed on the device will not be identical to that observed during the import stage. Parameters to control quantization:
-
int tidl::Configuration
quantHistoryParam2
¶ Weight in percentage applied to previously processed input frames after the first 10 input frames.
-
int tidl::Configuration
quantMargin
¶ Margin added to the average in percentage.
-
std::vector<int> tidl::Configuration
inConvType
¶ subgraph data conversion type at subgraph inputs 0: float <-> Q, 1: float <-> float, 2: Q <-> Q
-
std::vector<int> tidl::Configuration
inIsSigned
¶ subgraph is signed data at subgraph inputs
-
std::vector<float> tidl::Configuration
inScaleF2Q
¶ subgraph scaleF2Q factor at subgraph inputs
-
std::vector<int> tidl::Configuration
inIsNCHW
¶ subgraph is external tensor NCHW layout at subgraph inputs
-
std::vector<int> tidl::Configuration
outConvType
¶ subgraph data conversion type at subgraph outputs 0: float <-> Q, 1: float <-> float, 2: Q <-> Q
-
std::vector<int> tidl::Configuration
outIsSigned
¶ subgraph is signed data at subgraph outputs
-
std::vector<float> tidl::Configuration
outScaleF2Q
¶ subgraph scaleF2Q factor at subgraph outputs
-
std::vector<int> tidl::Configuration
outIsNCHW
¶ subgraph is external tensor NCHW layout at subgraph outputs
-
tidl::Configuration
Configuration file¶
TIDL API allows the user to create a Configuration object by reading from a file or by initializing it directly. Configuration settings supported by Configuration::ReadFromFile
:
- numFrames
- inWidth
- inHeight
- inNumChannels
- preProcType
- layerIndex2LayerGroupId
- inData
- outData
- netBinFile
- paramsBinFile
- quantHistoryParam1
- quantHistoryParam2
- quantMargin
- enableTrace
An example configuration file:
numFrames = 1
preProcType = 0
inData = ../test/testvecs/input/preproc_0_224x224.y
outData = stats_tool_out.bin
netBinFile = ../test/testvecs/config/tidl_models/tidl_net_imagenet_jacintonet11v2.bin
paramsBinFile = ../test/testvecs/config/tidl_models/tidl_param_imagenet_jacintonet11v2.bin
inWidth = 224
inHeight = 224
inNumChannels = 3
# Enable tracing of output buffers
enableTrace = true
Overriding layer group assignment¶
The TIDL device translation tool assigns layer group ids to layers during the translation process. TIDL API 1.1 and higher allows the user to override this assignment by specifying explicit mappings. There are two ways for the user to provide an updated mapping:
- Specify a mapping in the configuration file to indicate that layers 12, 13 and 14 are assigned to layer group 2:
layerIndex2LayerGroupId = { {12, 2}, {13, 2}, {14, 2} }
- User can also provide the layer index to group mapping in the code:
Configuration c;
c.ReadFromFile("test.cfg");
c.layerIndex2LayerGroupId = { {12, 2}, {13, 2}, {14, 2} };
Executor¶
-
class tidl
::
Executor
¶ Manages the overall execution of a layersGroup in a network using the specified configuration and the set of devices available to the executor.
Public Functions
-
tidl::Executor
Executor
(DeviceType device_type, const DeviceIds &ids, const Configuration &configuration, int layers_group_id = OCL_TIDL_DEFAULT_LAYERS_GROUP_ID)¶ Create an Executor object.
The Executor will create the required ExecutionObject’s and initialize them with the specified TI DL network. E.g.
Configuration configuration; configuration.ReadFromFile("path to configuration file"); DeviceIds ids = {DeviceId::ID2, DeviceId::ID3}; Executor executor(DeviceType::EVE, ids, configuration);
- Parameters
device_type
: DSP or EVE deviceids
: Set of devices uses by this instance of the Executorconfiguration
: Configuration used to initialize the Executorlayers_group_id
: Layers group that this Executor should run
-
ExecutionObject *tidl::Executor
operator[]
(uint32_t index) const¶ Returns a single execution object at index.
-
tidl::Executor
ExecutionObject¶
-
class tidl
::
ExecutionObject
¶ Runs the TIDL network on an OpenCL device.
Inherits from ExecutionObjectInternalInterface
Public Functions
-
void tidl::ExecutionObject
SetInputOutputBuffer
(const ArgInfo &in, const ArgInfo &out)¶ Specify the input and output buffers used by the EO
- Parameters
in
: buffer used for input.out
: buffer used for output.
-
char *tidl::ExecutionObject
GetInputBufferPtr
() const¶ Returns a pointer to the input buffer set via SetInputOutputBuffer.
-
size_t tidl::ExecutionObject
GetInputBufferSizeInBytes
() const¶ Returns size of the input buffer.
-
char *tidl::ExecutionObject
GetOutputBufferPtr
() const¶ Returns a pointer to the output buffer.
-
size_t tidl::ExecutionObject
GetOutputBufferSizeInBytes
() const¶ Returns size of the output buffer.
-
void tidl::ExecutionObject
SetFrameIndex
(int idx)¶ Set the frame index of the frame currently processed by the ExecutionObject. Used for trace/debug messages.
- Parameters
idx
: index of the frame
-
int tidl::ExecutionObject
GetFrameIndex
() const¶ Returns the index of a frame being processed (set by SetFrameIndex)
-
bool tidl::ExecutionObject
ProcessFrameStartAsync
()¶ Start processing a frame. The call is asynchronous and returns immediately. Use ExecutionObject::ProcessFrameWait to wait.
-
bool tidl::ExecutionObject
ProcessFrameWait
()¶ Wait for the execution object to complete processing a frame
- Return
- false if ExecutionObject::ProcessFrameWait was called without a corresponding call to ExecutionObject::ProcessFrameStartAsync.
-
float tidl::ExecutionObject
GetProcessTimeInMilliSeconds
() const¶ return the number of milliseconds taken on the device to execute the process call
- Return
- Number of milliseconds to process a frame on the device.
-
const std::string &tidl::ExecutionObject
GetDeviceName
() const¶ Returns the device name that the ExecutionObject runs on.
-
void tidl::ExecutionObject
WriteLayerOutputsToFile
(const std::string &filename_prefix = "trace_dump_") const¶ Write the output buffer for each layer to a file <filename_prefix>_<ID>_HxW.bin
-
const LayerOutput *tidl::ExecutionObject
GetOutputFromLayer
(uint32_t layer_index, uint32_t output_index = 0) const¶ Returns a LayerOutput object corresponding to a layer. Caller is responsible for deleting the LayerOutput object.
- See
- LayerOutput
- Parameters
layer_index
: The layer index of the layeroutput_index
: The output index of the buffer for a given layer. Defaults to 0.
-
const LayerOutputs *tidl::ExecutionObject
GetOutputsFromAllLayers
() const¶ Get output buffers from all layers.
-
int tidl::ExecutionObject
GetLayersGroupId
() const¶ Returns the layersGrupId that the ExecutionObject is processing.
-
void tidl::ExecutionObject
ExecutionObjectPipeline¶
-
class tidl
::
ExecutionObjectPipeline
¶ Manages the pipelined execution using multiple ExecutionObjects. Each executor runs one layersGroup of the network. ExecutionObjects must run consecutive layersGroups to form a pipelined execution.
Inherits from ExecutionObjectInternalInterface
Public Functions
-
tidl::ExecutionObjectPipeline
ExecutionObjectPipeline
(std::vector<ExecutionObject *> eos)¶ Create an ExecutionObjectPipeline object.
The ExecutionObjectPipeline will take the provided ExecutionObjects to create an execution pipeline. E.g.
Configuration config("path to configuration file"); DeviceIds ids = {DeviceId::ID0, DeviceId::ID1}; Executor exe_eve(DeviceType::EVE, ids, config, 1); Executor exe_dsp(DeviceType::DSP, ids, config, 2); ExecutionObjectPipeline ep0({exe_eve[0], exe_dsp[0]}); ExecutionObjectPipeline ep1({exe_eve[1], exe_dsp[1]});
- Parameters
eos
: DSP or EVE ExecutionObjects forming a pipeline
-
tidl::ExecutionObjectPipeline
~ExecutionObjectPipeline
()¶ Tear down an ExecutionObjectPipeline and free used resources.
-
uint32_t tidl::ExecutionObjectPipeline
GetNumExecutionObjects
() const¶ Returns the number of ExecutionObjects associated with the ExecutionObjectPipeline
-
void tidl::ExecutionObjectPipeline
SetInputOutputBuffer
(const ArgInfo &in, const ArgInfo &out)¶ Specify the input and output buffers used by the EOP
- Parameters
in
: buffer used for input.out
: buffer used for output.
-
char *tidl::ExecutionObjectPipeline
GetInputBufferPtr
() const¶ Returns a pointer to the input buffer.
-
size_t tidl::ExecutionObjectPipeline
GetInputBufferSizeInBytes
() const¶ Returns size of the input buffer.
-
char *tidl::ExecutionObjectPipeline
GetOutputBufferPtr
() const¶ Returns a pointer to the output buffer.
-
size_t tidl::ExecutionObjectPipeline
GetOutputBufferSizeInBytes
() const¶ Returns the number of bytes written to the output buffer.
-
void tidl::ExecutionObjectPipeline
SetFrameIndex
(int idx)¶ Set the frame index of the frame currently processed by the ExecutionObjectPipeline. Used for trace/debug messages.
- Parameters
idx
: index of the frame
-
int tidl::ExecutionObjectPipeline
GetFrameIndex
() const¶ Returns the index of a frame being processed (set by SetFrameIndex)
-
bool tidl::ExecutionObjectPipeline
ProcessFrameStartAsync
()¶ Start processing a frame. The call is asynchronous and returns immediately. Use ProcessFrameWait() to wait.
-
bool tidl::ExecutionObjectPipeline
ProcessFrameWait
()¶ Wait for the executor pipeline to complete processing a frame
- Return
- false if ProcessFrameWait() was called without a corresponding call to ExecutionObjectPipeline::ProcessFrameStartAsync().
-
const std::string &tidl::ExecutionObjectPipeline
GetDeviceName
() const¶ Return the combined device names that this pipeline runs on.
-
void tidl::ExecutionObjectPipeline
WriteLayerOutputsToFile
(const std::string &filename_prefix = "trace_dump_") const¶ Write the output buffer for each layer to a file <filename_prefix>_<ID>_HxW.bin
-
const LayerOutput *tidl::ExecutionObjectPipeline
GetOutputFromLayer
(uint32_t layer_index, uint32_t output_index = 0) const¶ Returns a LayerOutput object corresponding to a layer. Caller is responsible for deleting the LayerOutput object.
- See
- LayerOutput
- Parameters
layer_index
: The layer index of the layeroutput_index
: The output index of the buffer for a given layer. Defaults to 0.
-
const LayerOutputs *tidl::ExecutionObjectPipeline
GetOutputsFromAllLayers
() const¶ Get output buffers from all layers.
-
tidl::ExecutionObjectPipeline