Doxygen Book
tensor_filter_common.h File Reference

Common functions for various tensor_filters. More...

#include <glib-object.h>
#include <errno.h>
#include <nnstreamer_subplugin.h>
#include <nnstreamer_plugin_api_util.h>
#include <nnstreamer_plugin_api_filter.h>
#include "nnstreamer_watchdog.h"
Include dependency graph for tensor_filter_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _GstTensorFilterStatistics
 Structure definition for tensor-filter statistics. More...
 
struct  _GstTensorFilterCombination
 Structure definition for tensor-filter in/out combination. More...
 
struct  GstTensorFilterSharedModelRepresentation
 Data Structure to store shared table. More...
 
struct  _GstTensorFilterPrivate
 Structure definition for common tensor-filter properties. More...
 

Macros

#define DBG   (!priv->silent)
 Macro for debug mode. More...
 
#define GST_TF_FW_VN(fw, vn)   (fw && checkGstTensorFilterFrameworkVersion (fw->version, vn))
 
#define GST_TF_FW_V0(fw)   GST_TF_FW_VN (fw, 0)
 
#define GST_TF_FW_V1(fw)   GST_TF_FW_VN (fw, 1)
 
#define gst_tensor_filter_v0_call(priv, ret, funcname, ...)
 Invoke callbacks of nn framework. Guarantees calling open for the first call. More...
 
#define gst_tensor_filter_v1_call(priv, ret, funcname, ...)
 
#define GST_TF_FW_INVOKE_COMPAT(priv, ret, in, out)
 
#define GST_TF_STAT_MAX_RECENT   (10)
 

Typedefs

typedef struct _GstTensorFilterStatistics GstTensorFilterStatistics
 Structure definition for tensor-filter statistics. More...
 
typedef struct _GstTensorFilterCombination GstTensorFilterCombination
 Structure definition for tensor-filter in/out combination. More...
 
typedef struct _GstTensorFilterPrivate GstTensorFilterPrivate
 Structure definition for common tensor-filter properties. More...
 

Enumerations

enum  {
  PROP_0, PROP_SILENT, PROP_FRAMEWORK, PROP_MODEL,
  PROP_INPUT, PROP_INPUTTYPE, PROP_INPUTNAME, PROP_INPUTLAYOUT,
  PROP_INPUTRANKS, PROP_OUTPUT, PROP_OUTPUTTYPE, PROP_OUTPUTNAME,
  PROP_OUTPUTLAYOUT, PROP_OUTPUTRANKS, PROP_CUSTOM, PROP_SUBPLUGINS,
  PROP_ACCELERATOR, PROP_IS_UPDATABLE, PROP_LATENCY, PROP_THROUGHPUT,
  PROP_INPUTCOMBINATION, PROP_OUTPUTCOMBINATION, PROP_SHARED_TENSOR_FILTER_KEY, PROP_LATENCY_REPORT,
  PROP_INVOKE_DYNAMIC, PROP_CONFIG, PROP_SUSPEND
}
 GstTensorFilter properties. More...
 

Functions

gchar * gst_tensorsinfo_compare_to_string (const GstTensorsInfo *info, const GstTensorsInfo *info2)
 Printout the comparison results of two tensors as a string. More...
 
void gst_tensorsinfo_compare_print (const GstTensorsInfo *info1, const GstTensorsInfo *info2)
 Printout the comparison results of two tensors. More...
 
gboolean gst_tensor_filter_allocate_in_invoke (GstTensorFilterPrivate *priv)
 check if the allocate_in_invoke is valid for the framework More...
 
void gst_tensor_filter_install_properties (GObjectClass *gobject_class)
 Installs all the properties for tensor_filter. More...
 
void gst_tensor_filter_common_init_property (GstTensorFilterPrivate *priv)
 Initialize the properties for tensor-filter. More...
 
void gst_tensor_filter_common_free_property (GstTensorFilterPrivate *priv)
 Free the properties for tensor-filter. More...
 
gboolean gst_tensor_filter_common_set_property (GstTensorFilterPrivate *priv, guint prop_id, const GValue *value, GParamSpec *pspec)
 Set the properties for tensor_filter. More...
 
gboolean gst_tensor_filter_common_get_property (GstTensorFilterPrivate *priv, guint prop_id, GValue *value, GParamSpec *pspec)
 Get the properties for tensor_filter. More...
 
gboolean gst_tensor_filter_common_get_combined_in_info (GstTensorFilterPrivate *priv, const GstTensorsInfo *in, GstTensorsInfo *combined)
 Configure input tensor info with combi option. More...
 
gboolean gst_tensor_filter_common_get_combined_out_info (GstTensorFilterPrivate *priv, const GstTensorsInfo *in, const GstTensorsInfo *out, GstTensorsInfo *combined)
 Configure output tensor info with combi option. More...
 
gboolean gst_tensor_filter_common_get_out_info (GstTensorFilterPrivate *priv, GstTensorsInfo *in, GstTensorsInfo *out)
 Get output tensor info from NN model with given input info. More...
 
void gst_tensor_filter_load_tensor_info (GstTensorFilterPrivate *priv)
 Load tensor info from NN model. (both input and output tensor) More...
 
void gst_tensor_filter_common_open_fw (GstTensorFilterPrivate *priv)
 Open NN framework. More...
 
void gst_tensor_filter_common_unload_fw (GstTensorFilterPrivate *priv)
 Unload NN framework. More...
 
void gst_tensor_filter_common_close_fw (GstTensorFilterPrivate *priv)
 Close NN framework. More...
 
gchar * gst_tensor_filter_detect_framework (const gchar *const *model_files, const guint num_models, const gboolean load_conf)
 Get neural network framework name from given model file. This does not guarantee the framework is available on the target device. More...
 
gboolean gst_tensor_filter_check_hw_availability (const gchar *name, const accl_hw hw, const char *custom)
 Check if the given hw is supported by the framework. More...
 
void gst_tensor_filter_destroy_notify_util (GstTensorFilterPrivate *priv, void *data)
 Free the data allocated for tensor filter output. More...
 

Detailed Description

Common functions for various tensor_filters.

Copyright (C) 2019 Parichay kapoor pk.ka.nosp@m.poor.nosp@m.@sams.nosp@m.ung..nosp@m.com

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

Date
28 Aug 2019
See also
http://github.com/nnstreamer/nnstreamer
Author
Parichay Kapoor pk.ka.nosp@m.poor.nosp@m.@sams.nosp@m.ung..nosp@m.com
MyungJoo Ham myung.nosp@m.joo..nosp@m.ham@s.nosp@m.amsu.nosp@m.ng.co.nosp@m.m
Bug:
No known bugs except for NYI items

Definition in file tensor_filter_common.h.

Macro Definition Documentation

◆ DBG

#define DBG   (!priv->silent)

Macro for debug mode.

Definition at line 41 of file tensor_filter_common.h.

◆ gst_tensor_filter_v0_call

#define gst_tensor_filter_v0_call (   priv,
  ret,
  funcname,
  ... 
)
Value:
do { \
gst_tensor_filter_common_open_fw (priv); \
ret = -1; \
if ((priv)->prop.fw_opened && (priv)->fw && (priv)->fw->funcname) { \
ret = (priv)->fw->funcname (&(priv)->prop, &(priv)->privateData, __VA_ARGS__); \
} \
} while (0)

Invoke callbacks of nn framework. Guarantees calling open for the first call.

Definition at line 53 of file tensor_filter_common.h.

◆ gst_tensor_filter_v1_call

#define gst_tensor_filter_v1_call (   priv,
  ret,
  funcname,
  ... 
)
Value:
do { \
gst_tensor_filter_common_open_fw (priv); \
ret = -1; \
if ((priv)->prop.fw_opened && (priv)->fw && (priv)->fw->funcname) { \
ret = (priv)->fw->funcname ((priv)->fw, &(priv)->prop, (priv)->privateData, __VA_ARGS__); \
} \
} while (0)

Definition at line 61 of file tensor_filter_common.h.

◆ GST_TF_FW_INVOKE_COMPAT

#define GST_TF_FW_INVOKE_COMPAT (   priv,
  ret,
  in,
  out 
)
Value:
do { \
ret = -1; \
if (GST_TF_FW_V0 ((priv)->fw)) { \
ret = (priv)->fw->invoke_NN (&(priv)->prop, &(priv)->privateData, (in), (out)); \
} else if (GST_TF_FW_V1 ((priv)->fw)) { \
ret = (priv)->fw->invoke ((priv)->fw, &(priv)->prop, (priv)->privateData, (in), (out)); \
} \
} while (0)

Definition at line 69 of file tensor_filter_common.h.

◆ GST_TF_FW_V0

#define GST_TF_FW_V0 (   fw)    GST_TF_FW_VN (fw, 0)

Definition at line 47 of file tensor_filter_common.h.

◆ GST_TF_FW_V1

#define GST_TF_FW_V1 (   fw)    GST_TF_FW_VN (fw, 1)

Definition at line 48 of file tensor_filter_common.h.

◆ GST_TF_FW_VN

#define GST_TF_FW_VN (   fw,
  vn 
)    (fw && checkGstTensorFilterFrameworkVersion (fw->version, vn))

Check tensor_filter framework version

Definition at line 45 of file tensor_filter_common.h.

◆ GST_TF_STAT_MAX_RECENT

#define GST_TF_STAT_MAX_RECENT   (10)

Definition at line 78 of file tensor_filter_common.h.

Typedef Documentation

◆ GstTensorFilterCombination

Structure definition for tensor-filter in/out combination.

◆ GstTensorFilterPrivate

Structure definition for common tensor-filter properties.

◆ GstTensorFilterStatistics

Structure definition for tensor-filter statistics.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

GstTensorFilter properties.

Enumerator
PROP_0 
PROP_SILENT 
PROP_FRAMEWORK 
PROP_MODEL 
PROP_INPUT 
PROP_INPUTTYPE 
PROP_INPUTNAME 
PROP_INPUTLAYOUT 
PROP_INPUTRANKS 
PROP_OUTPUT 
PROP_OUTPUTTYPE 
PROP_OUTPUTNAME 
PROP_OUTPUTLAYOUT 
PROP_OUTPUTRANKS 
PROP_CUSTOM 
PROP_SUBPLUGINS 
PROP_ACCELERATOR 
PROP_IS_UPDATABLE 
PROP_LATENCY 
PROP_THROUGHPUT 
PROP_INPUTCOMBINATION 
PROP_OUTPUTCOMBINATION 
PROP_SHARED_TENSOR_FILTER_KEY 
PROP_LATENCY_REPORT 
PROP_INVOKE_DYNAMIC 
PROP_CONFIG 
PROP_SUSPEND 

Definition at line 83 of file tensor_filter_common.h.

Function Documentation

◆ gst_tensor_filter_allocate_in_invoke()

gboolean gst_tensor_filter_allocate_in_invoke ( GstTensorFilterPrivate priv)

check if the allocate_in_invoke is valid for the framework

Parameters
[in]privStruct containing the properties of the object
Returns
TRUE if valid, FALSE on error

Definition at line 757 of file tensor_filter_common.c.

Here is the caller graph for this function:

◆ gst_tensor_filter_check_hw_availability()

gboolean gst_tensor_filter_check_hw_availability ( const gchar *  name,
const accl_hw  hw,
const char *  custom 
)

Check if the given hw is supported by the framework.

Parameters
[in]nameThe name of filter sub-plugin.
[in]hwBackend accelerator hardware.
[in]customUser-defined string to handle detailed hardware option.
Returns
TRUE if given hw is available.
Note
This function is included in nnstreamer internal header for native APIs. When changing the declaration, you should update the internal header (nnstreamer_internal.h).

Only check for specific HW, DEFAULT/AUTO are always supported

Definition at line 2923 of file tensor_filter_common.c.

Here is the call graph for this function:

◆ gst_tensor_filter_common_close_fw()

void gst_tensor_filter_common_close_fw ( GstTensorFilterPrivate priv)

Close NN framework.

Definition at line 2560 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_free_property()

void gst_tensor_filter_common_free_property ( GstTensorFilterPrivate priv)

Free the properties for tensor-filter.

Definition at line 1065 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_get_combined_in_info()

gboolean gst_tensor_filter_common_get_combined_in_info ( GstTensorFilterPrivate priv,
const GstTensorsInfo in,
GstTensorsInfo combined 
)

Configure input tensor info with combi option.

Definition at line 2270 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_get_combined_out_info()

gboolean gst_tensor_filter_common_get_combined_out_info ( GstTensorFilterPrivate priv,
const GstTensorsInfo in,
const GstTensorsInfo out,
GstTensorsInfo combined 
)

Configure output tensor info with combi option.

Definition at line 2315 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_get_out_info()

gboolean gst_tensor_filter_common_get_out_info ( GstTensorFilterPrivate priv,
GstTensorsInfo in,
GstTensorsInfo out 
)

Get output tensor info from NN model with given input info.

Definition at line 2374 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_get_property()

gboolean gst_tensor_filter_common_get_property ( GstTensorFilterPrivate priv,
guint  prop_id,
GValue *  value,
GParamSpec *  pspec 
)

Get the properties for tensor_filter.

Parameters
[in]privStruct containing the properties of the object
[in]prop_idId for the property
[in]valueContainer to return the asked property
[in]pspecMetadata to specify the parameter
Returns
TRUE if prop_id is value, else FALSE

Definition at line 2102 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_init_property()

void gst_tensor_filter_common_init_property ( GstTensorFilterPrivate priv)

Initialize the properties for tensor-filter.

Definition at line 1041 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_open_fw()

void gst_tensor_filter_common_open_fw ( GstTensorFilterPrivate priv)

Open NN framework.

Definition at line 2491 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_set_property()

gboolean gst_tensor_filter_common_set_property ( GstTensorFilterPrivate priv,
guint  prop_id,
const GValue *  value,
GParamSpec *  pspec 
)

Set the properties for tensor_filter.

Parameters
[in]privStruct containing the properties of the object
[in]prop_idId for the property
[in]valueContainer to return the asked property
[in]pspecMetadata to specify the parameter
Returns
TRUE if prop_id is value, else FALSE

Although no one return !0 at this point, let's enable error handling.

Definition at line 1967 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_common_unload_fw()

void gst_tensor_filter_common_unload_fw ( GstTensorFilterPrivate priv)

Unload NN framework.

Definition at line 2545 of file tensor_filter_common.c.

Here is the caller graph for this function:

◆ gst_tensor_filter_destroy_notify_util()

void gst_tensor_filter_destroy_notify_util ( GstTensorFilterPrivate priv,
void *  data 
)

Free the data allocated for tensor filter output.

Parameters
[in]privStruct containing the properties of the object
[in]dataData to be freed

Definition at line 786 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_detect_framework()

gchar* gst_tensor_filter_detect_framework ( const gchar *const *  model_files,
const guint  num_models,
const gboolean  load_conf 
)

Get neural network framework name from given model file. This does not guarantee the framework is available on the target device.

Parameters
[in]model_filesthe prediction model paths
[in]num_modelsthe number of model files
[in]load_confflag to load configuration for the priority of framework
Returns
Possible framework name (NULL if it fails to detect automatically). Caller should free returned value using g_free().
Parameters
[in]model_filesthe prediction model paths
[in]num_modelsthe number of model files
[in]load_confflag to load configuration for the priority of framework
Returns
Possible framework name (NULL if it fails to detect automatically). Caller should free returned value using g_free().
Note
This function is included in nnstreamer internal header for native APIs. When changing the declaration, you should update the internal header (nnstreamer_internal.h).
Note
When adding new file extension for auto fw detection, you should check the condition to validate model file - ml_validate_model_file() in ML-API.

Definition at line 1232 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_install_properties()

void gst_tensor_filter_install_properties ( GObjectClass *  gobject_class)

Installs all the properties for tensor_filter.

Parameters
[in]gobject_classGlib object class whose properties will be set

min

max

default: off

min

max

default: off

Definition at line 888 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_filter_load_tensor_info()

void gst_tensor_filter_load_tensor_info ( GstTensorFilterPrivate priv)

Load tensor info from NN model. (both input and output tensor)

if set-property called and already has info, verify it!

In case of dynamic invoke, output tensors info is determined after invoke.

if set-property called and already has info, verify it!

Definition at line 2409 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensorsinfo_compare_print()

void gst_tensorsinfo_compare_print ( const GstTensorsInfo info1,
const GstTensorsInfo info2 
)

Printout the comparison results of two tensors.

Parameters
[in]info1The tensors to be shown on the left hand side
[in]info2The tensors to be shown on the right hand side
Todo:
If this is going to be used by other elements, move this to nnstreamer/tensor_common.
Parameters
[in]info1The tensors to be shown on the left hand side
[in]info2The tensors to be shown on the right hand side

Definition at line 874 of file tensor_filter_common.c.

Here is the call graph for this function:

◆ gst_tensorsinfo_compare_to_string()

gchar* gst_tensorsinfo_compare_to_string ( const GstTensorsInfo info1,
const GstTensorsInfo info2 
)

Printout the comparison results of two tensors as a string.

Parameters
[in]info1The tensors to be shown on the left hand side
[in]info2The tensors to be shown on the right hand side
Returns
The printout string allocated. Caller should free the value.

Definition at line 811 of file tensor_filter_common.c.

Here is the call graph for this function:
Here is the caller graph for this function:
GST_TF_FW_V0
#define GST_TF_FW_V0(fw)
Definition: tensor_filter_common.h:47
prop
GstTensorSrcIIOChannelProperties * prop
DTYPE_UNSIGNED ( .
Definition: gsttensor_srciio.c:110
GST_TF_FW_V1
#define GST_TF_FW_V1(fw)
Definition: tensor_filter_common.h:48